You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
808 B
JavaScript
33 lines
808 B
JavaScript
/* 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);
|
|
}
|