Updated to new build script.
This commit is contained in:
parent
bca1630ea9
commit
f40fe3cc4f
3 changed files with 1250 additions and 149 deletions
106
build.js
106
build.js
|
@ -1,102 +1,26 @@
|
||||||
// IMPORTS
|
const assproc = require('@railcomm/assproc');
|
||||||
|
const { join: pathJoin } = require('path');
|
||||||
const fs = require('fs');
|
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');
|
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
|
||||||
|
|
||||||
// CONFIG
|
const env = {
|
||||||
const rootDir = __dirname;
|
root: __dirname,
|
||||||
const srcDir = path.join(rootDir, 'scripts');
|
source: pathJoin(__dirname, 'scripts'),
|
||||||
const pubDir = path.join(rootDir, 'public');
|
public: pathJoin(__dirname, 'public'),
|
||||||
const pubAssetsDir = path.join(pubDir, 'scripts');
|
debug: isDebug,
|
||||||
|
swc: {
|
||||||
|
es: 'es2021',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const isDebugBuild = fs.existsSync(path.join(rootDir, '.debug'));
|
const tasks = {
|
||||||
|
|
||||||
const buildTasks = {
|
|
||||||
js: [
|
js: [
|
||||||
{ source: 'eepromv1.js', target: '/scripts', name: 'eepromv1.js', es: 'es5' },
|
{ source: 'eepromv1.js', target: '/scripts', name: 'eepromv1.js', es: 'es5' },
|
||||||
{ source: 'eepromv1a.js', target: '/scripts', name: 'eepromv1a.js' },
|
{ source: 'eepromv1a.js', target: '/scripts', name: 'eepromv1a.js' },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
await assproc.process(env, tasks);
|
||||||
// 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 = {};
|
|
||||||
|
|
||||||
console.log('Ensuring assets directory exists...');
|
|
||||||
fs.mkdirSync(pubAssetsDir, { recursive: true });
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
})();
|
})();
|
||||||
|
|
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": {
|
"dependencies": {
|
||||||
"@swc/core": "^1.3.107"
|
"@railcomm/assproc": "^1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue