From 7602d63b99694f7bc36ec41704af608d47393e5b Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Wed, 7 Dec 2022 23:12:01 +0000 Subject: [PATCH] glugun: initial commit --- glugun/index.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 glugun/index.js diff --git a/glugun/index.js b/glugun/index.js new file mode 100644 index 0000000..6951ff8 --- /dev/null +++ b/glugun/index.js @@ -0,0 +1,45 @@ +import { cp, writeFile, readFile, readdir, rm } from 'fs/promises'; +import { join, dirname } from 'path'; + +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const buildDir = join(__dirname, '..', 'build'); +const _buildWin32 = async (name, dir, attrs) => { + await cp(dir, join(buildDir, 'src'), { recursive: true }); // copy project src to build + await cp(join(__dirname, '..', 'gluon'), join(buildDir, 'src', 'gluon'), { recursive: true }); // copy gluon into build + + for (const m of [ 'ws', 'chrome-remote-interface' ]) { + const dest = join(buildDir, 'src', 'node_modules', m); + await cp(join(__dirname, '..', 'node_modules', m), dest, { recursive: true }); // copy gluon deps into build + + for (const x of await readdir(dest)) { + if ([ 'bin', 'README.md', 'webpack.config.json', 'browser.js' ].includes(x)) await rm(join(dest, x), { recursive: true }); + } + } + + await writeFile(join(buildDir, `${name}.bat`), `node src`); + + // await writeFile(join(buildDir, 'gluon_info.txt'), `Gluon 0.1, built with Glugun 0.1 (win32 ${attrs.join(',')})`); + let indexContent = await readFile(join(buildDir, 'src', 'index.js'), 'utf8'); + + indexContent = indexContent.replace('../gluon/', './gluon/') + .replaceAll('GLUGUN_VERSION', '1.0') + .replaceAll('SYSTEM_CHROMIUM', attrs.includes('system-chromium')) + .replaceAll('SYSTEM_NODE', attrs.includes('system-node')); + + await writeFile(join(buildDir, 'src', 'index.js'), indexContent); +}; + +export const build = async (name, dir, platform = 'win32', attrs = 'system-chromium,system-node') => { + console.log('building...', name, dir, platform, attrs); + + switch (platform) { + case 'win32': _buildWin32(name, dir, attrs.split(',')); + } +}; + +const [ name, dir ] = process.argv.slice(2); +build(name, dir); \ No newline at end of file