Exemple #1
0
Plugin.prototype.build = function() {
  var options = this.options;
  var destPath = this.outputPath + '/' + this.path;
  var wrapEntry = options.wrapEntry;
  var localesData = extract(options);

  mkdirp.sync(destPath);

  Object.keys(localesData).forEach(function(locale) {
    var result = localesData[locale];

    if (typeof wrapEntry === 'function') {
      result = wrapEntry(result);
    }

    var outFile = destPath + '/' + locale.toLocaleLowerCase() + '.js';
    var data = options.prelude + result;

    fs.writeFileSync(outFile, data, { encoding: 'utf8' });
  });
}
Exemple #2
0
import * as fs from 'fs';
import * as p from 'path';
import {sync as mkdirpSync} from 'mkdirp';
import extractCLDRData from 'formatjs-extract-cldr-data';
import serialize from 'serialize-javascript';
import {rollup} from 'rollup';
import memory from 'rollup-plugin-memory';
import uglify from 'rollup-plugin-uglify';

const DEFAULT_LOCALE = 'en';

const cldrData = extractCLDRData({
    pluralRules   : true,
    relativeFields: true,
});

const cldrDataByLocale = new Map(
    Object.keys(cldrData).map((locale) => [locale, cldrData[locale]])
);

const cldrDataByLang = [...cldrDataByLocale].reduce((map, [locale, data]) => {
    const [lang]   = locale.split('-');
    const langData = map.get(lang) || [];
    return map.set(lang, langData.concat(data));
}, new Map());

function createDataModule(localeData) {
    return (
`// GENERATED FILE
export default ${serialize(localeData)};
`