-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from lightning-js/dev
Release 1.9.2
- Loading branch information
Showing
11 changed files
with
152 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters