This commit is contained in:
masnn committed 2020-04-08 21:43:41 +08:00
1 parent 9c45527522
commit 7dc31d02fa
15 files changed
+10521 -3

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
/* eslint-disable */
import yaml from 'js-yaml';
import PluginError from 'plugin-error';
import through from 'through2';
import path from 'path';
export default function generateLocales() {
function bufferContents(file, encoding, callback) {
if (file.isNull()) {
callback();
return;
}
if (file.isStream()) {
this.emit('error', new PluginError('gulpGenerateLocales', 'Stream not supported'));
callback();
return;
}
const doc = yaml.safeLoad(file.contents);
file.contents = Buffer.from(`window.LOCALES = ${JSON.stringify(doc, null, 2)}`);
file.path = path.join(
path.dirname(file.path),
`${path.basename(file.path, path.extname(file.path))}.js`
);
this.push(file);
callback();
}
return through.obj(bufferContents);
}