Updated build script.
This commit is contained in:
parent
8cfa07bc8c
commit
37d8413118
4 changed files with 491 additions and 484 deletions
|
@ -1,5 +1,5 @@
|
||||||
#include csrfp.js
|
#include csrfp.js
|
||||||
#include msgbox.js
|
#include msgbox.jsx
|
||||||
#include utility.js
|
#include utility.js
|
||||||
#include messages/actbtn.js
|
#include messages/actbtn.js
|
||||||
#include messages/list.js
|
#include messages/list.js
|
||||||
|
|
171
build.js
171
build.js
|
@ -1,157 +1,30 @@
|
||||||
// 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 util = require('util');
|
|
||||||
const postcss = require('postcss');
|
|
||||||
const utils = require('./assets/utils.js');
|
|
||||||
const assproc = require('./assets/assproc.js');
|
|
||||||
|
|
||||||
|
|
||||||
// CONFIG
|
|
||||||
const rootDir = __dirname;
|
|
||||||
const srcDir = path.join(rootDir, 'assets');
|
|
||||||
const srcCurrentInfo = path.join(srcDir, 'current.json');
|
|
||||||
const pubDir = path.join(rootDir, 'public');
|
|
||||||
const pubAssetsDir = path.join(pubDir, 'assets');
|
|
||||||
|
|
||||||
const isDebugBuild = fs.existsSync(path.join(rootDir, '.debug'));
|
|
||||||
|
|
||||||
const buildTasks = {
|
|
||||||
js: [
|
|
||||||
{ source: 'misuzu.js', target: '/assets', name: 'misuzu.{hash}.js', },
|
|
||||||
],
|
|
||||||
css: [
|
|
||||||
{ source: 'misuzu.css', target: '/assets', name: 'misuzu.{hash}.css', },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// PREP
|
|
||||||
const postcssPlugins = [ require('autoprefixer')({ remove: false }) ];
|
|
||||||
if(!isDebugBuild)
|
|
||||||
postcssPlugins.push(require('cssnano')({
|
|
||||||
preset: [
|
|
||||||
'cssnano-preset-default',
|
|
||||||
{
|
|
||||||
minifyGradients: false,
|
|
||||||
reduceIdents: false,
|
|
||||||
zindex: true,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}));
|
|
||||||
|
|
||||||
const swcJscOptions = {
|
|
||||||
target: 'es2021',
|
|
||||||
loose: false,
|
|
||||||
externalHelpers: false,
|
|
||||||
keepClassNames: true,
|
|
||||||
preserveAllComments: false,
|
|
||||||
transform: {},
|
|
||||||
parser: {
|
|
||||||
syntax: 'ecmascript',
|
|
||||||
jsx: true,
|
|
||||||
dynamicImport: false,
|
|
||||||
privateMethod: false,
|
|
||||||
functionBind: false,
|
|
||||||
exportDefaultFrom: false,
|
|
||||||
exportNamespaceFrom: false,
|
|
||||||
decorators: false,
|
|
||||||
decoratorsBeforeExport: false,
|
|
||||||
topLevelAwait: true,
|
|
||||||
importMeta: false,
|
|
||||||
},
|
|
||||||
transform: {
|
|
||||||
react: {
|
|
||||||
runtime: 'classic',
|
|
||||||
pragma: '$er',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// BUILD
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const files = {};
|
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
|
||||||
|
|
||||||
console.log('Ensuring assets directory exists...');
|
const env = {
|
||||||
fs.mkdirSync(pubAssetsDir, { recursive: true });
|
root: __dirname,
|
||||||
|
source: pathJoin(__dirname, 'assets'),
|
||||||
|
public: pathJoin(__dirname, 'public'),
|
||||||
|
debug: isDebug,
|
||||||
|
swc: {
|
||||||
|
es: 'es2021',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const tasks = {
|
||||||
|
js: [
|
||||||
|
{ source: 'misuzu.js', target: '/assets', name: 'misuzu.{hash}.js', },
|
||||||
|
],
|
||||||
|
css: [
|
||||||
|
{ source: 'misuzu.css', target: '/assets', name: 'misuzu.{hash}.css', },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
console.log();
|
const files = await assproc.process(env, tasks);
|
||||||
console.log('JS assets');
|
|
||||||
for(const info of buildTasks.js) {
|
|
||||||
console.log(`=> Building ${info.source}...`);
|
|
||||||
|
|
||||||
let origTarget = undefined;
|
fs.writeFileSync(pathJoin(__dirname, 'assets/current.json'), JSON.stringify(files));
|
||||||
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('CSS assets');
|
|
||||||
for(const info of buildTasks.css) {
|
|
||||||
console.log(`=> Building ${info.source}...`);
|
|
||||||
|
|
||||||
const sourcePath = path.join(srcDir, info.source);
|
|
||||||
const assprocOpts = {
|
|
||||||
prefix: '@',
|
|
||||||
entry: info.entry || 'main.css',
|
|
||||||
};
|
|
||||||
const postcssOpts = { from: sourcePath };
|
|
||||||
|
|
||||||
files[info.source] = await assproc.process(sourcePath, assprocOpts)
|
|
||||||
.then(output => postcss(postcssPlugins).process(output, postcssOpts)
|
|
||||||
.then(output => {
|
|
||||||
const name = utils.strtr(info.name, { hash: utils.shortHash(output.css) });
|
|
||||||
const pubName = path.join(info.target || '', name);
|
|
||||||
|
|
||||||
console.log(` Saving to ${pubName}...`);
|
|
||||||
fs.writeFileSync(path.join(pubDir, pubName), output.css);
|
|
||||||
|
|
||||||
return pubName;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
console.log();
|
|
||||||
console.log('Writing assets info...');
|
|
||||||
fs.writeFileSync(srcCurrentInfo, JSON.stringify(files));
|
|
||||||
|
|
||||||
|
|
||||||
console.log();
|
|
||||||
console.log('Cleaning up old builds...');
|
|
||||||
assproc.housekeep(pubAssetsDir);
|
|
||||||
})();
|
})();
|
||||||
|
|
797
package-lock.json
generated
797
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,5 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@swc/core": "^1.5.24",
|
"@railcomm/assproc": "^1.0.0"
|
||||||
"autoprefixer": "^10.4.19",
|
|
||||||
"cssnano": "^6.1.2",
|
|
||||||
"postcss": "^8.4.38"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue