From 189ec7e378a1f731f67047d756c7d73288421a71 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Mon, 4 Dec 2023 11:11:02 -0800 Subject: [PATCH] fix index.js on deploy --- build/copy.js | 47 ++++++++++++++++++++++++++++++++++++ build/prep-for-deploy.js | 18 ++++++++++++++ build/serve.js | 49 ++------------------------------------ examples/js/index/index.js | 2 +- index.html | 1 + package.json | 6 ++--- 6 files changed, 72 insertions(+), 51 deletions(-) create mode 100644 build/copy.js diff --git a/build/copy.js b/build/copy.js new file mode 100644 index 0000000..ce3b9e8 --- /dev/null +++ b/build/copy.js @@ -0,0 +1,47 @@ +import path from 'path'; +import fsPromise from 'fs/promises'; +import chokidar from 'chokidar'; + +export function copy({watch, transformFn = v => v}) { + return new Promise(resolve => { + const outDir = 'out'; + + async function copyFile(srcFilename) { + const dstFilename = path.join(outDir, srcFilename); + const dirname = path.dirname(dstFilename); + try { + await fsPromise.stat(dirname); + } catch { + await fsPromise.mkdir(dirname, { recursive: true }); + } + console.log('copy', srcFilename, '->', dstFilename); + const src = await fsPromise.readFile(srcFilename); + const dst = transformFn(src, srcFilename, dstFilename); + await fsPromise.writeFile(dstFilename, dst); + } + + chokidar.watch('.', { + ignored: [ + '.git', + 'node_modules', + 'build', + 'out', + 'src', + 'dist', + '**/.*', + ], + }).on('all', (event, path) => { + switch (event) { + case 'add': + case 'change': + copyFile(path); + break; + case 'ready': + if (!watch) { + resolve(); + } + break; + } + }); + }); +} \ No newline at end of file diff --git a/build/prep-for-deploy.js b/build/prep-for-deploy.js index e87158a..536550d 100644 --- a/build/prep-for-deploy.js +++ b/build/prep-for-deploy.js @@ -3,7 +3,25 @@ import path from 'path'; import * as url from 'url'; const dirname = url.fileURLToPath(new URL('.', import.meta.url)); + const ignoreFilename = path.join(dirname, '..', '.gitignore'); const ignore = fs.readFileSync(ignoreFilename, {encoding: 'utf8'}); const newIgnore = ignore.replace(/# -- clip-for-deploy-start --[\s\S]*?# -- clip-for-deploy-end --/, ''); fs.writeFileSync(ignoreFilename, newIgnore); + +const version = parseInt(JSON.parse(fs.readFileSync('package.json', {encoding: 'utf8'})).version); + +function transformJS(src) { + return src.replace(/'.*?'\s+\/*\s+muigui-include\s+*\//g, `dist/${version}.x/muigui.module.js`); +} + +[ + 'examples/js/index.js', +].forEach(filename => { + const src = fs.readFileSync(filename, {encoding: 'utf8'}); + const dst = transformJS(src); + if (src !== dst) { + fs.writeFileSync(filename, dst); + } +}); + diff --git a/build/serve.js b/build/serve.js index db9e638..25e04ca 100644 --- a/build/serve.js +++ b/build/serve.js @@ -1,7 +1,5 @@ -import path from 'path'; -import fsPromise from 'fs/promises'; import {spawn} from 'child_process'; -import chokidar from 'chokidar'; +import {copy} from './copy.js'; spawn('./node_modules/.bin/tsc', [ '--watch', @@ -17,47 +15,4 @@ spawn('./node_modules/.bin/servez', [ stdio: 'inherit', }); -const ignoreFns = [ - fn => fn.startsWith('.git'), - fn => fn.startsWith('node_modules'), - fn => fn.startsWith('build'), - fn => fn.startsWith('out'), - fn => fn.startsWith('src'), - fn => fn.startsWith('dist'), - fn => fn.startsWith('.'), -]; - -function ignore(fn) { - for (const ignoreFn of ignoreFns) { - if (ignoreFn(fn)) { - return true; - } - } - return false; -} - -const outDir = 'out'; - -async function copyFile(srcFilename) { - const dstFilename = path.join(outDir, srcFilename); - const dirname = path.dirname(dstFilename); - try { - await fsPromise.stat(dirname); - } catch { - await fsPromise.mkdir(dirname, { recursive: true }); - } - console.log('copy', srcFilename, '->', dstFilename); - await fsPromise.copyFile(srcFilename, dstFilename); -} - -chokidar.watch('.').on('all', (event, path) => { - switch (event) { - case 'add': - case 'change': - if (ignore(path)) { - return; - } - copyFile(path); - break; - } -}); +copy({watch: true}); diff --git a/examples/js/index/index.js b/examples/js/index/index.js index 2620286..33787cf 100644 --- a/examples/js/index/index.js +++ b/examples/js/index/index.js @@ -2,7 +2,7 @@ import * as twgl from '../../3rdParty/twgl-full.module.js'; import VSAEffect from './VSAEffect.js'; import effects from './effects.js'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -import GUI, { helpers, Direction, TextNumber } from '../../../src/esm.js'; +import GUI, { helpers, Direction, TextNumber } from '../../../src/esm.js'; /* muigui-include */ const canvas = document.querySelector('#bg'); const gl = canvas.getContext('webgl'); diff --git a/index.html b/index.html index c60e30d..1532635 100644 --- a/index.html +++ b/index.html @@ -661,6 +661,7 @@

Form Theme:

pointer-events: none; } #forkongithub a { + pointer-events: initial; background: #000; color: #fff; text-decoration: none; diff --git a/package.json b/package.json index d288459..6da0b37 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "muigui", "version": "0.0.14", "description": "A Simple GUI", - "main": "muigui.js", - "module": "src/muigui.js", + "main": "dist/0.x/muigui.js", + "module": "dist/0.x/muigui-module.js", "type": "module", "scripts": { "build": "npm run build-normal", @@ -33,7 +33,7 @@ "url": "https://github.com/greggman/muigui/issues" }, "files": [ - "muigui.js", + "dist/**/*", "src/**/*" ], "homepage": "https://github.com/greggman/muiguiy#readme",