测试构建

This commit is contained in:
undefined committed 2020-05-10 17:03:16 +08:00
1 parent 27cfe81e31
commit 9156fa3a9b
6 files changed
+80 -48

No files matched your search

+56 -46
View File
@@ -19,6 +19,7 @@ const exist = (name) => {
}; };
const build = async (type) => { const build = async (type) => {
const modules = fs.readdirSync(root('module')); const modules = fs.readdirSync(root('module'));
const failed = [];
const config = { const config = {
mode: type, mode: type,
entry: {}, entry: {},
@@ -37,24 +38,28 @@ const build = async (type) => {
}; };
for (const i of modules) { for (const i of modules) {
if (!i.startsWith('.')) { if (!i.startsWith('.')) {
const prepare = ['model', 'lib', 'handler', 'service']; try {
for (const j of prepare) { if (exist(`module/${i}/build.js`)) {
if (exist(`module/${i}/${j}.js`)) { const builder = require(root(`module/${i}/build.js`));
const file = fs.readFileSync(root(`module/${i}/${j}.js`)); if (builder.prebuild) await builder.prebuild();
if (file.includes('require')) { }
config.entry[`${i}/${j}`] = root(`module/${i}/${j}.js`); const prepare = ['model', 'lib', 'handler', 'service'];
for (const j of prepare) {
if (exist(`module/${i}/${j}.js`)) {
const file = fs.readFileSync(root(`module/${i}/${j}.js`));
if (file.includes('require')) {
config.entry[`${i}/${j}`] = root(`module/${i}/${j}.js`);
}
} }
} }
} catch (e) {
console.error(`Module build fail: ${i}`);
console.error(e);
failed.push(i);
} }
} }
} }
const compiler = webpack(config); const compiler = webpack(config);
for (const i of modules) {
if (exist(`module/${i}/build.js`)) {
const builder = require(root(`module/${i}/build.js`));
if (builder.prebuild) await builder.prebuild();
}
}
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
compiler.run((err, stats) => { compiler.run((err, stats) => {
if (err) { if (err) {
@@ -67,45 +72,50 @@ const build = async (type) => {
}); });
}); });
for (const i of modules) { for (const i of modules) {
if (!i.startsWith('.')) { if (!i.startsWith('.') && !failed.includes(i)) {
const current = {}; try {
const prepare = ['model', 'lib', 'handler', 'service']; const current = {};
for (const j of prepare) { const prepare = ['model', 'lib', 'handler', 'service'];
if (exist(`module/${i}/${j}.js`)) { for (const j of prepare) {
const file = fs.readFileSync(root(`module/${i}/${j}.js`)); if (exist(`module/${i}/${j}.js`)) {
if (file.includes('require')) { const file = fs.readFileSync(root(`module/${i}/${j}.js`));
current[j] = fs.readFileSync(root(`.build/module/${i}/${j}.js`)).toString(); if (file.includes('require')) {
} else { current[j] = fs.readFileSync(root(`.build/module/${i}/${j}.js`)).toString();
current[j] = fs.readFileSync(root(`module/${i}/${j}.js`)).toString(); } else {
current[j] = fs.readFileSync(root(`module/${i}/${j}.js`)).toString();
}
} }
} }
} if (exist(`module/${i}/locale`)) {
if (exist(`module/${i}/locale`)) { const locales = fs.readdirSync(root(`module/${i}/locale`));
const locales = fs.readdirSync(root(`module/${i}/locale`)); const lang = {};
const lang = {}; for (const j of locales) {
for (const j of locales) { const content = fs.readFileSync(root(`module/${i}/locale/${j}`)).toString();
const content = fs.readFileSync(root(`module/${i}/locale/${j}`)).toString(); lang[j.split('.')[0]] = yaml.safeLoad(content);
lang[j.split('.')[0]] = yaml.safeLoad(content); }
current.locale = lang;
} }
current.locale = lang; if (exist(`module/${i}/template`)) {
} current.template = template(`module/${i}/template`);
if (exist(`module/${i}/template`)) {
current.template = template(`module/${i}/template`);
}
if (exist(`module/${i}/file`)) {
const files = fs.readdirSync(root(`module/${i}/file`));
current.file = {};
for (const file of files) {
current.file[file] = fs.readFileSync(root(`module/${i}/file/${file}`)).toString('base64');
} }
if (exist(`module/${i}/file`)) {
const files = fs.readdirSync(root(`module/${i}/file`));
current.file = {};
for (const file of files) {
current.file[file] = fs.readFileSync(root(`module/${i}/file/${file}`)).toString('base64');
}
}
const m = require(root(`module/${i}/hydro.json`));
current.description = m.description || '';
current.requirements = m.requirements || [];
current.version = m.version || 'unknown';
if (m.os) current.os = m.os;
const data = zlib.gzipSync(Buffer.from(yaml.safeDump(current)), { level: -1 });
fs.writeFileSync(root(`.build/module/${i}.hydro`), data);
} catch (e) {
console.error(`Module build fail: ${i}`);
console.error(e);
} }
const m = require(root(`module/${i}/hydro.json`));
current.description = m.description || '';
current.requirements = m.requirements || [];
current.version = m.version || 'unknown';
if (m.os) current.os = m.os;
const data = zlib.gzipSync(Buffer.from(yaml.safeDump(current)), { level: -1 });
fs.writeFileSync(root(`.build/module/${i}.hydro`), data);
} }
} }
}; };
+10
View File
@@ -0,0 +1,10 @@
const fs = require('fs');
const path = require('path');
const child = require('child_process');
exports.prebuild = async function prebuild() {
if (!fs.existsSync(path.resolve(__dirname, 'HydroJudger'))) {
const res = child.spawnSync('git clone https://github.com/hydro-dev/HydroJudger.git');
if (res.error) throw res.error;
}
};
+11
View File
@@ -0,0 +1,11 @@
const fs = require('fs');
const path = require('path');
exports.prebuild = async function prebuild() {
if (!fs.existsSync(path.resolve(__dirname, 'file', 'executorserver'))) {
if (!fs.existsSync(path.resolve(__dirname, 'file'))) {
fs.mkdirSync(path.resolve(__dirname, 'file'));
}
// TODO download executorserver
}
};
File renamed without changes.
@@ -1,7 +1,8 @@
const os = require('os'); const os = require('os');
const path = require('path');
const child = require('child_process'); const child = require('child_process');
const p = child.spawn(path.resolve(os.tmpdir(), 'hydro', 'sandbox-linux', 'executorserver', ['-silent']); const p = child.spawn(path.resolve(os.tmpdir(), 'hydro', 'sandbox-linux-amd64', 'executorserver', ['-silent']));
if (!p.stdout) throw new Error('Cannot start executorserver'); if (!p.stdout) throw new Error('Cannot start executorserver');
else { else {
p.stdout.on('data', (data) => { p.stdout.on('data', (data) => {
+1 -1
View File
@@ -3,7 +3,7 @@ const path = require('path');
const root = (name) => path.resolve(__dirname, name); const root = (name) => path.resolve(__dirname, name);
exports.prebuild = () => { exports.prebuild = async () => {
const pages = fs.readdirSync(root('raw')); const pages = fs.readdirSync(root('raw'));
const res = {}; const res = {};
for (const page of pages) { for (const page of pages) {