ng-extract-i18n-merge
Version:
Extract and merge i18n xliff translation files for angular projects.
50 lines (49 loc) • 2.74 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const workspace_1 = require("@schematics/angular/utility/workspace");
function updateNpmScript(tree, logger) {
var _a;
const pkgPath = '/package.json';
const buffer = tree.read(pkgPath);
if (buffer === null) {
throw new schematics_1.SchematicsException('Could not read package.json');
}
const pkg = JSON.parse(buffer.toString());
if (pkg === null || typeof pkg !== 'object' || Array.isArray(pkg)) {
throw new schematics_1.SchematicsException('Error reading package.json');
}
if ((_a = pkg.scripts) === null || _a === void 0 ? void 0 : _a['extract-i18n-merge']) {
logger.info('updating npm script "extract-i18n-merge" (you can delete it if you like!)..');
pkg.scripts['extract-i18n-merge'] = 'ng extract-i18n';
}
tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
}
function default_1() {
return (tree, context) => {
updateNpmScript(tree, context.logger);
return (0, workspace_1.updateWorkspace)(async (workspace) => {
workspace.projects.forEach((project, projectName) => {
var _a, _b, _c, _d, _e;
const i18nMergeTarget = project.targets.get('extract-i18n-merge');
if (i18nMergeTarget) {
context.logger.info(`updating extract-i18n(-merge) targets for project ${projectName}..`);
const i18nTarget = { ...((_a = project.targets.get('extract-i18n')) !== null && _a !== void 0 ? _a : { builder: 'ng-extract-i18n-merge:ng-extract-i18n-merge' }) };
i18nTarget.builder = 'ng-extract-i18n-merge:ng-extract-i18n-merge';
i18nTarget.options = {
...i18nMergeTarget.options,
buildTarget: (_e = (_c = (_b = i18nTarget.options) === null || _b === void 0 ? void 0 : _b.browserTarget) !== null && _c !== void 0 ? _c : (_d = i18nTarget.options) === null || _d === void 0 ? void 0 : _d.buildTarget) !== null && _e !== void 0 ? _e : `${projectName}:build`
};
delete i18nTarget.options.browserTarget;
project.targets.delete('extract-i18n'); // 'project.targets.set' not working!?
project.targets.add({ name: 'extract-i18n', ...i18nTarget });
project.targets.delete('extract-i18n-merge');
}
else {
context.logger.warn('target "extract-i18n-merge" not found in workspace - please migrate manually!');
}
});
});
};
}
exports.default = default_1;
;