otus-localization
Version:
A translation tool for Angular i18n(angular-t9n)
25 lines (21 loc) • 886 B
JavaScript
;
var fs = require('fs');
var path = require('path');
function resolveNgLocales(_options) {
return (tree, _context) => {
const file = path.join(tree.getDir(_options.dist).path, 'locales.ts');
const ngCommonPath = path.dirname(require.resolve('@angular/common/package.json'));
const localesPath = path.join(ngCommonPath, 'locales');
const locales = fs.readdirSync(localesPath, { withFileTypes: true })
.filter((d) => d.isFile() && d.name.endsWith('.d.ts'))
.map((d) => d.name.replace(/\.d\.ts$/, ''));
const content = `export const locales = [\n${locales.map((l) => ` '${l}'`).join(',\n')}\n];\n`;
if (tree.exists(file)) {
tree.overwrite(file, content);
}
else {
tree.create(file, content);
}
};
}
exports.resolveNgLocales = resolveNgLocales;