Skip to content

Commit

Permalink
Merge pull request #208 from lightning-js/dev
Browse files Browse the repository at this point in the history
Release 1.9.2
  • Loading branch information
michielvandergeest authored Nov 5, 2024
2 parents 28f599d + 3bd4547 commit 4154b41
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v1.9.2

_5 nov 2024_

- Fixed Element related tests
- Bumped renderer to version 2.6.0

## v1.9.1

_4 nov 2024_
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lightningjs/blits",
"version": "1.9.1",
"version": "1.9.2",
"description": "Blits: The Lightning 3 App Development Framework",
"bin": "bin/index.js",
"exports": {
Expand All @@ -9,7 +9,8 @@
"./transitions": "./src/router/transitions/index.js",
"./precompiler": "./src/lib/precompiler/precompiler.js",
"./plugins": "./src/plugins/index.js",
"./symbols": "./src/lib/symbols.js"
"./symbols": "./src/lib/symbols.js",
"./blitsFileConverter": "./src/lib/blitsfileconverter/blitsfileconverter.js"
},
"scripts": {
"test": "c8 npm run test:run",
Expand Down Expand Up @@ -49,7 +50,7 @@
},
"dependencies": {
"@lightningjs/msdf-generator": "^1.1.0",
"@lightningjs/renderer": "^2.5.1"
"@lightningjs/renderer": "^2.6.0"
},
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions packages/create-blits/boilerplate/js/default/blits.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// required for suppressing vscode typescript errors when importing .blits files in JS/TS files
declare module '*.blits' {
const value: any;
export default value;
}
5 changes: 5 additions & 0 deletions packages/create-blits/boilerplate/ts/default/blits.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// required for suppressing vscode typescript errors when importing .blits files in JS/TS files
declare module '*.blits' {
const value: any;
export default value;
}
16 changes: 8 additions & 8 deletions src/engines/L3/element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test('Element - Set `w` property', (assert) => {

assert.equal(el.node['width'], 100, 'Node width parameter should be set')
assert.equal(el.props.props['width'], 100, 'Props width parameter should be set')
assert.equal(el.props.raw.get('w'), 100, "Props' raw map entry should be added")
assert.equal(el.props.raw['w'], 100, "Props' raw map entry should be added")
assert.end()
})

Expand All @@ -116,7 +116,7 @@ test('Element - Set `mount` property', (assert) => {
assert.equal(el.node['mountY'], 20, 'Node mountY parameter should be set')
assert.equal(el.props.props['mountX'], 10, 'Props mountX parameter should be set')
assert.equal(el.props.props['mountY'], 20, 'Props mountY parameter should be set')
assert.equal(el.props.raw.get('mount'), value, "Props' raw map entry should be added")
assert.equal(el.props.raw['mount'], value, "Props' raw map entry should be added")
assert.end()
})

Expand All @@ -128,7 +128,7 @@ test('Element - Set `color` property', (assert) => {

assert.equal(el.node['color'], '0xf0ffffff', 'Node color parameter should be set')
assert.equal(el.props.props['color'], '0xf0ffffff', 'Props color parameter should be set')
assert.equal(el.props.raw.get('color'), 'azure', "Props' raw map entry should be added")
assert.equal(el.props.raw['color'], 'azure', "Props' raw map entry should be added")
assert.end()
})

Expand All @@ -141,7 +141,7 @@ test('Element - Set `src` property', (assert) => {

assert.equal(el.node['src'], value, 'Node src parameter should be set')
assert.equal(el.props.props['src'], value, 'Props src parameter should be set')
assert.equal(el.props.raw.get('src'), value, "Props' raw map entry should be added")
assert.equal(el.props.raw['src'], value, "Props' raw map entry should be added")
assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
assert.end()
})
Expand All @@ -154,7 +154,7 @@ test('Element - Set `texture` property', (assert) => {

assert.equal(el.node['texture'], 'foo', 'Node texture parameter should be set')
assert.equal(el.props.props['texture'], 'foo', 'Props texture parameter should be set')
assert.equal(el.props.raw.get('texture'), 'foo', "Props' raw map entry should be added")
assert.equal(el.props.raw['texture'], 'foo', "Props' raw map entry should be added")
assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
assert.end()
})
Expand All @@ -181,7 +181,7 @@ test('Element - Set `fit` property with a string type value', (assert) => {
fitVal,
'Props textureOptions parameter should be set'
)
assert.equal(el.props.raw.get('fit'), fitVal, "Props' raw map entry should be added")
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
assert.end()
})

Expand Down Expand Up @@ -212,7 +212,7 @@ test('Element - Set `fit` property with an object type value', (assert) => {
1,
'Node resizeMode "clipY" parameter should be set to correct value'
)
assert.equal(el.props.raw.get('fit'), fitVal, "Props' raw map entry should be added")
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
assert.end()
})

Expand Down Expand Up @@ -243,7 +243,7 @@ test('Element - Set `fit` property with position key as a string type value', (a
1,
'Node resizeMode "clipY" parameter should be set to correct value'
)
assert.equal(el.props.raw.get('fit'), fitVal, "Props' raw map entry should be added")
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
assert.end()
})

Expand Down
52 changes: 52 additions & 0 deletions src/lib/blitsfileconverter/blitsfileconverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

export default (source) => {
const { template, script } = parseBlitsFile(source)
return injectTemplate(script, template)
}

const parseBlitsFile = (source) => {
const templateMatch = source.match(/<template>([\s\S]*?)<\/template>/)
const scriptMatch = source.match(/<script(?:\s+lang=["'](?:js|ts)["'])?\s*>([\s\S]*?)<\/script>/)

return {
template: templateMatch ? templateMatch[1].trim() : '',
script: scriptMatch ? scriptMatch[1].trim() : '',
}
}

const injectTemplate = (script, template) => {
const componentRegex =
/(Blits\.Component|Component)\s*\(\s*(['"`])(?:(?=(\\?))\3.)*?\2\s*,\s*\{|Blits\.Application\s*\(\s*\{/

const match = script.match(componentRegex)

if (!match) {
// we might consider initializing a component if it's not found automatically
throw new Error(
'Could not find Blits.Component, Component, or Blits.Application initialization in the script'
)
}

// The insertion point is right after the opening curly brace
const insertIndex = match.index + match[0].length

// Using template literals to preserve multiline strings and escape characters
const injection = `\n template: \`${template.replace(/`/g, '\\`')}\`,\n`
return script.slice(0, insertIndex) + injection + script.slice(insertIndex)
}
38 changes: 38 additions & 0 deletions vite/blitsFileConverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

import blitsfileconverter from '../src/lib/blitsfileconverter/blitsfileconverter.js'

export default function blitsFileType() {
return {
name: 'vite-plugin-blits-file-type',
enforce: 'pre',
transform(src, id) {
if (id.endsWith('.blits')) {
try {
const transformedCode = blitsfileconverter(src)
return {
code: transformedCode,
map: null, // no source map
}
} catch (error) {
this.error(error)
}
}
},
}
}
4 changes: 3 additions & 1 deletion vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import preCompiler from './preCompiler.js'
import msdfGenerator from './msdfGenerator.js'
import blitsFileConverter from './blitsFileConverter.js'

export { default as preCompiler } from './preCompiler.js'
export { default as msdfGenerator } from './msdfGenerator.js'
export { default as blitsFileConverter } from './blitsFileConverter.js'

export default [preCompiler(), msdfGenerator()]
export default [blitsFileConverter(), preCompiler(), msdfGenerator()]
17 changes: 17 additions & 0 deletions vite/msdfGenerator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

import path from 'path'
import * as fs from 'fs'
import { createHash } from 'crypto'
Expand Down
7 changes: 7 additions & 0 deletions vite/preCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export default function () {
},
transform(source, filePath) {
if (config.blits && config.blits.precompile === false) return source

const fileExtension = path.extname(filePath)

// we should only precompile .js and .ts files
if (fileExtension === '.js' || fileExtension === '.ts') {
return compiler(source, filePath)
}
const relativePath = path.relative(process.cwd(), filePath)
return compiler(source, relativePath)
},
Expand Down

0 comments on commit 4154b41

Please sign in to comment.