Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 virtual from 'rollup-plugin-virtual';
import ProgressBar from 'progress';
import PromiseQueue from 'promise-queue';
const DEFAULT_LOCALE = 'en';
const CONCURRENCY = require('os').cpus().length - 1;
const cldrData = extractCLDRData({
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)};
gulp.task("build-data", [ "clean-data" ], function()
{
let data = extractData(
{
pluralRules: true,
relativeFields: true
})
fs.mkdirSync("data")
return Promise.all(map(data, (value, locale) =>
{
return new Promise((resolve) =>
{
let stringified = stringify(value, null, " ")
let result = `"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=${stringified};`
fs.writeFile(`data/${locale}.js`, result, function(err)
{