From e9f6881699e4184f7da173775bceb95e5ef0a2ea Mon Sep 17 00:00:00 2001 From: Ugur Aslan Date: Thu, 12 Dec 2024 16:58:02 +0100 Subject: [PATCH 1/5] implemented typescript transpiling for blits files --- vite/blitsFileConverter.js | 47 ++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/vite/blitsFileConverter.js b/vite/blitsFileConverter.js index efae87b8..8b354153 100644 --- a/vite/blitsFileConverter.js +++ b/vite/blitsFileConverter.js @@ -16,23 +16,52 @@ */ import blitsfileconverter from '../src/lib/blitsfileconverter/blitsfileconverter.js' +import path from 'node:path' +import fs from 'node:fs' +import { createRequire } from 'module' -export default function blitsFileType() { +export default function blitsFileTypePlugin() { return { name: 'vite-plugin-blits-file-type', enforce: 'pre', - transform(src, id) { + + resolveId(source, importer) { + if (source.endsWith('.blits')) { + return importer ? path.resolve(path.dirname(importer), source) : path.resolve(source) + } + return null + }, + + load(id) { if (id.endsWith('.blits')) { - try { - const transformedCode = blitsfileconverter(src) - return { - code: transformedCode, - map: null, // no source map + const source = fs.readFileSync(id, 'utf-8') + let code = blitsfileconverter(source) + + // Check for TypeScript and transpile to JS if needed + if (/ Date: Thu, 12 Dec 2024 16:58:50 +0100 Subject: [PATCH 2/5] fixed file extensions for typescript boilerplate --- packages/create-blits/boilerplate/ts/default/src/App.ts | 5 ++--- packages/create-blits/boilerplate/ts/default/src/index.ts | 2 +- .../create-blits/boilerplate/ts/default/src/pages/Home.ts | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/create-blits/boilerplate/ts/default/src/App.ts b/packages/create-blits/boilerplate/ts/default/src/App.ts index f471d6f8..849442a3 100644 --- a/packages/create-blits/boilerplate/ts/default/src/App.ts +++ b/packages/create-blits/boilerplate/ts/default/src/App.ts @@ -1,12 +1,11 @@ import Blits from '@lightningjs/blits' -import Home from './pages/Home.js' +import Home from './pages/Home' export default Blits.Application({ template: ` - - `, + `, routes: [{ path: '/', component: Home }], }) diff --git a/packages/create-blits/boilerplate/ts/default/src/index.ts b/packages/create-blits/boilerplate/ts/default/src/index.ts index 49f45587..e400c62a 100644 --- a/packages/create-blits/boilerplate/ts/default/src/index.ts +++ b/packages/create-blits/boilerplate/ts/default/src/index.ts @@ -1,5 +1,5 @@ import Blits from '@lightningjs/blits' -import App from './App.js' +import App from './App' Blits.Launch(App, 'app', { w: 1920, diff --git a/packages/create-blits/boilerplate/ts/default/src/pages/Home.ts b/packages/create-blits/boilerplate/ts/default/src/pages/Home.ts index 2f268305..06c246f8 100644 --- a/packages/create-blits/boilerplate/ts/default/src/pages/Home.ts +++ b/packages/create-blits/boilerplate/ts/default/src/pages/Home.ts @@ -1,6 +1,6 @@ import Blits from '@lightningjs/blits' -import Loader from '../components/Loader.js' +import Loader from '../components/Loader' const colors = ['#f5f3ff', '#ede9fe', '#ddd6fe', '#c4b5fd', '#a78bfa'] @@ -38,8 +38,7 @@ export default Blits.Component('Home', { /> - - `, + `, state() { return { /** From 591511a5ef5b0a19ef58960a8cd476d676c9a167 Mon Sep 17 00:00:00 2001 From: Ugur Aslan Date: Thu, 12 Dec 2024 16:59:31 +0100 Subject: [PATCH 3/5] fixes return value for non-component files in precompiler --- vite/preCompiler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vite/preCompiler.js b/vite/preCompiler.js index efc44691..31ec2519 100644 --- a/vite/preCompiler.js +++ b/vite/preCompiler.js @@ -34,8 +34,9 @@ export default function () { if (fileExtension === '.js' || fileExtension === '.ts') { return compiler(source, filePath) } - const relativePath = path.relative(process.cwd(), filePath) - return compiler(source, relativePath) + + // vite expects null if there is no modification + return null }, } } From 6ab1da39beb009379f7a63c764dcf859d08556f1 Mon Sep 17 00:00:00 2001 From: Ugur Aslan Date: Thu, 12 Dec 2024 17:05:28 +0100 Subject: [PATCH 4/5] fixed the blits converter plugin function name --- vite/blitsFileConverter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vite/blitsFileConverter.js b/vite/blitsFileConverter.js index 8b354153..fda3e75f 100644 --- a/vite/blitsFileConverter.js +++ b/vite/blitsFileConverter.js @@ -20,7 +20,7 @@ import path from 'node:path' import fs from 'node:fs' import { createRequire } from 'module' -export default function blitsFileTypePlugin() { +export default function blitsFileType() { return { name: 'vite-plugin-blits-file-type', enforce: 'pre', From 3d1ce99d70c13792fba898c29ddac15a4d2e1444 Mon Sep 17 00:00:00 2001 From: Ugur Aslan Date: Fri, 13 Dec 2024 09:34:22 +0100 Subject: [PATCH 5/5] added .blits extension to precompiler --- vite/preCompiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vite/preCompiler.js b/vite/preCompiler.js index 31ec2519..d6372add 100644 --- a/vite/preCompiler.js +++ b/vite/preCompiler.js @@ -30,8 +30,8 @@ export default function () { const fileExtension = path.extname(filePath) - // we should only precompile .js and .ts files - if (fileExtension === '.js' || fileExtension === '.ts') { + // we should only precompile .blits, .js and .ts files + if (fileExtension === '.js' || fileExtension === '.ts' || fileExtension === '.blits') { return compiler(source, filePath) }