mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
打包模块为单个文件
This commit is contained in:
1 parent
e3bbff7e11
commit
04941936bc
6 files changed
+88
-72
No files matched your search
+19
-2
@@ -1,13 +1,30 @@
|
||||
const fs = require('fs');
|
||||
const zlib = require('zlib');
|
||||
const yaml = require('js-yaml');
|
||||
const root = require('./root');
|
||||
const template = require('./template');
|
||||
const ignoreFailure = require('./ignoreFailure');
|
||||
|
||||
async function build(type) {
|
||||
if (!['development', 'production'].includes(type)) throw new Error(`Unknown type: ${type}`);
|
||||
ignoreFailure(fs.mkdirSync, root('.build'));
|
||||
await require('./locales')(type);
|
||||
const langs = fs.readdirSync(root('locales'));
|
||||
const lang = {};
|
||||
for (const i of langs) {
|
||||
const content = fs.readFileSync(root(`locales/${i}`)).toString();
|
||||
lang[i.split('.')[0]] = yaml.safeLoad(content);
|
||||
}
|
||||
const exclude = [
|
||||
'partials/training_default.json',
|
||||
'partials/problem_default.md',
|
||||
'bsod.html',
|
||||
];
|
||||
const builtin = {};
|
||||
builtin.locale = lang;
|
||||
builtin.template = template('templates', exclude);
|
||||
const data = zlib.gzipSync(Buffer.from(yaml.safeDump(builtin)), { level: 3 });
|
||||
fs.writeFileSync(root('.build/module/builtin.hydro-module'), data);
|
||||
await require('./buildModule')(type);
|
||||
await require('./buildTemplate')(type);
|
||||
await require('./webpack')(type);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user