mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
打包模块为单个文件
This commit is contained in:
1 parent
e3bbff7e11
commit
04941936bc
6 files changed
+88
-72
No files matched your search
@@ -2,6 +2,7 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
const fs = require('fs');
|
||||
const zlib = require('zlib');
|
||||
const webpack = require('webpack');
|
||||
const yaml = require('js-yaml');
|
||||
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
||||
@@ -54,6 +55,35 @@ const build = async (type) => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
for (const i of modules) {
|
||||
if (!i.startsWith('.')) {
|
||||
const current = {};
|
||||
if (exist(`module/${i}/locale`)) {
|
||||
const locales = fs.readdirSync(root(`module/${i}/locale`));
|
||||
const lang = {};
|
||||
for (const j of locales) {
|
||||
const content = fs.readFileSync(root(`module/${i}/locale/${j}`)).toString();
|
||||
lang[j.split('.')[0]] = yaml.safeLoad(content);
|
||||
}
|
||||
current.locale = lang;
|
||||
}
|
||||
if (exist(`module/${i}/template.build.js`)) {
|
||||
const builder = require(root(`module/${i}/template.build.js`));
|
||||
const [templates, exclude] = await builder.prebuild();
|
||||
current.template = template(templates, exclude);
|
||||
} else if (exist(`module/${i}/template`)) {
|
||||
current.template = template(`module/${i}/template`);
|
||||
}
|
||||
if (exist(`module/${i}/model.js`)) {
|
||||
current.model = fs.readFileSync(root(`.build/module/${i}/model.js`)).toString();
|
||||
}
|
||||
if (exist(`module/${i}/handler.js`)) {
|
||||
current.handler = fs.readFileSync(root(`.build/module/${i}/handler.js`)).toString();
|
||||
}
|
||||
const data = zlib.gzipSync(Buffer.from(yaml.safeDump(current)), { level: 3 });
|
||||
fs.writeFileSync(root(`.build/module/${i}.hydro-module`), data);
|
||||
}
|
||||
}
|
||||
for (const i of modules) {
|
||||
if (!i.startsWith('.')) {
|
||||
if (exist(`module/${i}/locale`)) {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const yaml = require('js-yaml');
|
||||
const root = require('./root');
|
||||
const template = require('./template');
|
||||
|
||||
const build = async () => {
|
||||
const exclude = [
|
||||
'partials/training_default.json',
|
||||
'partials/problem_default.md',
|
||||
'bsod.html',
|
||||
];
|
||||
fs.writeFileSync(root('.build/template.yaml'), yaml.safeDump(template('templates', exclude)));
|
||||
};
|
||||
|
||||
module.exports = build;
|
||||
+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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
const yaml = require('js-yaml');
|
||||
const fs = require('fs');
|
||||
const root = require('./root');
|
||||
|
||||
const build = async () => {
|
||||
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);
|
||||
}
|
||||
fs.writeFileSync(root('.build/locales.json'), JSON.stringify(lang));
|
||||
};
|
||||
module.exports = build;
|
||||
@@ -38,6 +38,10 @@ const build = (dirOrObject, exclude = []) => {
|
||||
.replace(/> {{/gmi, '>{{')
|
||||
.replace(/{{ /gmi, '{{')
|
||||
.replace(/ }}/gmi, '}}')
|
||||
.replace(/%} </gmi, '%}<')
|
||||
.replace(/> {%/gmi, '>{%')
|
||||
.replace(/= /gmi, '=')
|
||||
.replace(/ =/gmi, '=')
|
||||
.trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user