添加站内消息,修复讨论节点丢失的问题

This commit is contained in:
undefined committed 2020-05-03 15:33:54 +08:00
1 parent 33e277f28f
commit 627e64a901
44 files changed
+582 -540

No files matched your search

+20
View File
@@ -1,8 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
const fs = require('fs');
const webpack = require('webpack');
const yaml = require('js-yaml');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const root = require('./root');
const template = require('./template');
const exist = (name) => {
try {
@@ -50,6 +52,24 @@ const build = async (type) => {
resolve();
});
});
for (const i of modules) {
if (!i.startsWith('.')) {
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[i.split('.')[0]] = yaml.safeLoad(content);
}
const file = root(`.build/module/${i}/locale.json`);
fs.writeFileSync(file, JSON.stringify(lang));
}
if (exist(`module/${i}/template`)) {
const file = root(`.build/module/${i}/template.yaml`);
fs.writeFileSync(file, yaml.safeDump(template(`module/${i}/template`)));
}
}
}
};
module.exports = build;
+7 -37
View File
@@ -1,45 +1,15 @@
const fs = require('fs');
const yaml = require('js-yaml');
const root = require('./root');
function getFiles(folder) {
const files = [];
const f = fs.readdirSync(root(folder));
for (const i of f) {
if (!i.startsWith('.')) {
if (fs.statSync(root(`${folder}/${i}`)).isDirectory()) {
const g = getFiles(`${folder}/${i}`);
for (const j of g) files.push(`${i}/${j}`);
} else files.push(i);
}
}
return files;
}
const template = require('./template');
const build = async () => {
const files = getFiles('templates');
const exclude = ['partials/training_default.json', 'partials/problem_default.md'];
const templates = {};
for (const i of files) {
let template = fs.readFileSync(root(`templates/${i}`)).toString();
if (!exclude.includes(i)) {
template = template
.trim()
.replace(/ *\n */gmi, ' ')
.replace(/, /gmi, ',')
.replace(/%} {%/gmi, '%}{%')
.replace(/ %}/gmi, '%}')
.replace(/{% /gmi, '{%')
.replace(/> </gmi, '><')
.replace(/}} </gmi, '}}<')
.replace(/> {{/gmi, '>{{')
.replace(/{{ /gmi, '{{')
.replace(/ }}/gmi, '}}')
.trim();
}
templates[i] = template;
}
fs.writeFileSync(root('.build/template.yaml'), yaml.safeDump(templates));
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;
+5
View File
@@ -0,0 +1,5 @@
module.exports = function ignoreFailure(func, ...params) {
try {
func(...params);
} catch (e) { } // eslint-disable-line no-empty
};
+7 -10
View File
@@ -1,18 +1,15 @@
const fs = require('fs');
const root = require('./root');
const ignoreFailure = require('./ignoreFailure');
async function build(type) {
if (!['development', 'production'].includes(type)) throw new Error(`Unknown type: ${type}`);
try {
fs.rmdirSync(root('.build'));
} catch (e) { }
fs.mkdirSync(root('.build'));
await Promise.all([
require('./locales')(type),
require('./buildModule')(type),
require('./buildTemplate')(type),
require('./webpack')(type),
]);
ignoreFailure(fs.mkdirSync, root('.cache'));
ignoreFailure(fs.mkdirSync, root('.build'));
await require('./locales')(type);
await require('./buildModule')(type);
await require('./buildTemplate')(type);
await require('./webpack')(type);
}
module.exports = build;
+43
View File
@@ -0,0 +1,43 @@
const fs = require('fs');
const root = require('./root');
function getFiles(folder) {
const files = [];
const f = fs.readdirSync(root(folder));
for (const i of f) {
if (!i.startsWith('.')) {
if (fs.statSync(root(`${folder}/${i}`)).isDirectory()) {
const g = getFiles(`${folder}/${i}`);
for (const j of g) files.push(`${i}/${j}`);
} else files.push(i);
}
}
return files;
}
const build = (dir, exclude = []) => {
const files = getFiles(dir);
const templates = {};
for (const i of files) {
let template = fs.readFileSync(root(`${dir}/${i}`)).toString();
if (!exclude.includes(i)) {
template = template
.trim()
.replace(/ *\n */gmi, ' ')
.replace(/, /gmi, ',')
.replace(/%} {%/gmi, '%}{%')
.replace(/ %}/gmi, '%}')
.replace(/{% /gmi, '{%')
.replace(/> </gmi, '><')
.replace(/}} </gmi, '}}<')
.replace(/> {{/gmi, '>{{')
.replace(/{{ /gmi, '{{')
.replace(/ }}/gmi, '}}')
.trim();
}
templates[i] = template;
}
return templates;
};
module.exports = build;