mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-04-21 05:09:32 +08:00
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { build } = require('esbuild');
|
|
|
|
!(async () => {
|
|
const version = JSON.parse(
|
|
fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'),
|
|
).version.trim();
|
|
|
|
let content = fs.readFileSync(path.join(__dirname, 'sub-store.min.js'), {
|
|
encoding: 'utf8',
|
|
});
|
|
content = content.replace(
|
|
/eval\(('|")(require\(('|").*?('|")\))('|")\)/g,
|
|
'$2',
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(__dirname, 'dist/sub-store.no-bundle.js'),
|
|
content,
|
|
{
|
|
encoding: 'utf8',
|
|
},
|
|
);
|
|
|
|
await build({
|
|
entryPoints: ['dist/sub-store.no-bundle.js'],
|
|
bundle: true,
|
|
minify: true,
|
|
sourcemap: true,
|
|
platform: 'node',
|
|
format: 'cjs',
|
|
outfile: 'dist/sub-store.bundle.js',
|
|
});
|
|
fs.writeFileSync(
|
|
path.join(__dirname, 'dist/sub-store.bundle.js'),
|
|
`// SUB_STORE_BACKEND_VERSION: ${version}
|
|
${fs.readFileSync(path.join(__dirname, 'dist/sub-store.bundle.js'), {
|
|
encoding: 'utf8',
|
|
})}`,
|
|
{
|
|
encoding: 'utf8',
|
|
},
|
|
);
|
|
})()
|
|
.catch((e) => {
|
|
console.log(e);
|
|
})
|
|
.finally(() => {
|
|
console.log('done');
|
|
});
|