Updated to new build script.
This commit is contained in:
parent
bca1630ea9
commit
f40fe3cc4f
3 changed files with 1250 additions and 149 deletions
114
build.js
114
build.js
|
@ -1,102 +1,26 @@
|
|||
// IMPORTS
|
||||
const assproc = require('@railcomm/assproc');
|
||||
const { join: pathJoin } = require('path');
|
||||
const fs = require('fs');
|
||||
const swc = require('@swc/core');
|
||||
const path = require('path');
|
||||
const utils = require('./scripts/utils.js');
|
||||
const assproc = require('./scripts/assproc.js');
|
||||
|
||||
|
||||
// CONFIG
|
||||
const rootDir = __dirname;
|
||||
const srcDir = path.join(rootDir, 'scripts');
|
||||
const pubDir = path.join(rootDir, 'public');
|
||||
const pubAssetsDir = path.join(pubDir, 'scripts');
|
||||
|
||||
const isDebugBuild = fs.existsSync(path.join(rootDir, '.debug'));
|
||||
|
||||
const buildTasks = {
|
||||
js: [
|
||||
{ source: 'eepromv1.js', target: '/scripts', name: 'eepromv1.js', es: 'es5' },
|
||||
{ source: 'eepromv1a.js', target: '/scripts', name: 'eepromv1a.js' },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
// PREP
|
||||
const swcJscOptions = {
|
||||
target: 'es2021',
|
||||
loose: false,
|
||||
externalHelpers: false,
|
||||
keepClassNames: true,
|
||||
preserveAllComments: false,
|
||||
transform: {},
|
||||
parser: {
|
||||
syntax: 'ecmascript',
|
||||
jsx: false,
|
||||
dynamicImport: false,
|
||||
privateMethod: false,
|
||||
functionBind: false,
|
||||
exportDefaultFrom: false,
|
||||
exportNamespaceFrom: false,
|
||||
decorators: false,
|
||||
decoratorsBeforeExport: false,
|
||||
topLevelAwait: true,
|
||||
importMeta: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
// BUILD
|
||||
(async () => {
|
||||
const files = {};
|
||||
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
|
||||
|
||||
console.log('Ensuring assets directory exists...');
|
||||
fs.mkdirSync(pubAssetsDir, { recursive: true });
|
||||
const env = {
|
||||
root: __dirname,
|
||||
source: pathJoin(__dirname, 'scripts'),
|
||||
public: pathJoin(__dirname, 'public'),
|
||||
debug: isDebug,
|
||||
swc: {
|
||||
es: 'es2021',
|
||||
},
|
||||
};
|
||||
|
||||
const tasks = {
|
||||
js: [
|
||||
{ source: 'eepromv1.js', target: '/scripts', name: 'eepromv1.js', es: 'es5' },
|
||||
{ source: 'eepromv1a.js', target: '/scripts', name: 'eepromv1a.js' },
|
||||
],
|
||||
};
|
||||
|
||||
console.log();
|
||||
console.log('JS assets');
|
||||
for(const info of buildTasks.js) {
|
||||
console.log(`=> Building ${info.source}...`);
|
||||
|
||||
let origTarget = undefined;
|
||||
if('es' in info) {
|
||||
origTarget = swcJscOptions.target;
|
||||
swcJscOptions.target = info.es;
|
||||
}
|
||||
|
||||
const assprocOpts = {
|
||||
prefix: '#',
|
||||
entry: info.entry || 'main.js',
|
||||
};
|
||||
const swcOpts = {
|
||||
filename: info.source,
|
||||
sourceMaps: false,
|
||||
isModule: false,
|
||||
minify: !isDebugBuild,
|
||||
jsc: swcJscOptions,
|
||||
};
|
||||
|
||||
const pubName = await assproc.process(path.join(srcDir, info.source), assprocOpts)
|
||||
.then(output => swc.transform(output, swcOpts))
|
||||
.then(output => {
|
||||
const name = utils.strtr(info.name, { hash: utils.shortHash(output.code) });
|
||||
const pubName = path.join(info.target || '', name);
|
||||
|
||||
console.log(` Saving to ${pubName}...`);
|
||||
fs.writeFileSync(path.join(pubDir, pubName), output.code);
|
||||
|
||||
return pubName;
|
||||
});
|
||||
|
||||
if(origTarget !== undefined)
|
||||
swcJscOptions.target = origTarget;
|
||||
|
||||
files[info.source] = pubName;
|
||||
}
|
||||
|
||||
|
||||
console.log();
|
||||
console.log('Cleaning up old builds...');
|
||||
assproc.housekeep(pubAssetsDir);
|
||||
await assproc.process(env, tasks);
|
||||
})();
|
||||
|
|
1283
package-lock.json
generated
1283
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@swc/core": "^1.3.107"
|
||||
"@railcomm/assproc": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue