@o3r/localization
Version:
This module provides a runtime dynamic language/translation support and debug tools.
69 lines • 3.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngAdd = void 0;
const fs = require("node:fs");
const path = require("node:path");
const schematics_1 = require("@angular-devkit/schematics");
const schematics_2 = require("@o3r/schematics");
const cms_adapter_1 = require("../cms-adapter");
const devtools_registration_1 = require("./helpers/devtools-registration");
const dependenciesToInstall = [
'chokidar',
'globby'
];
/**
* Add Otter localization to an Angular Project
* @param options for the dependencies installations
*/
function ngAddFn(options) {
return async (tree, context) => {
const { updateI18n, updateLocalization } = await Promise.resolve().then(() => require('../localization-base'));
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));
const depsInfo = (0, schematics_2.getO3rPeerDeps)(packageJsonPath);
context.logger.info(`The package ${depsInfo.packageName} comes with a debug mechanism`);
context.logger.info('Get information on https://github.com/AmadeusITGroup/otter/tree/main/docs/localization/LOCALIZATION.md#Debugging');
const { NodeDependencyType } = await Promise.resolve().then(() => require('@schematics/angular/utility/dependencies'));
const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
acc[dep] = {
inManifest: [{
range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`,
types: (0, schematics_2.getProjectNewDependenciesTypes)(workspaceProject)
}],
ngAddOptions: { exactO3rVersion: options.exactO3rVersion }
};
return acc;
}, (0, schematics_2.getPackageInstallConfig)(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion));
Object.entries((0, schematics_2.getExternalDependenciesVersionRange)(dependenciesToInstall, packageJsonPath, context.logger)).forEach(([dep, range]) => {
dependencies[dep] = {
inManifest: [{
range,
types: [NodeDependencyType.Dev]
}]
};
});
const registerDevtoolRule = (0, devtools_registration_1.registerDevtools)(options);
return (0, schematics_1.chain)([
updateLocalization(options, __dirname),
updateI18n(options),
options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)(),
(0, schematics_2.setupDependencies)({
projectName: options.projectName,
dependencies,
ngAddToRun: depsInfo.o3rPeerDeps
}),
(0, cms_adapter_1.updateCmsAdapter)(options),
(0, schematics_2.registerPackageCollectionSchematics)(packageJson),
(0, schematics_2.setupSchematicsParamsForProject)({ '@o3r/core:component*': { useLocalization: true } }, options.projectName),
registerDevtoolRule
]);
};
}
/**
* Add Otter localization to an Angular Project
* @param options for the dependencies installations
*/
const ngAdd = (options) => (0, schematics_2.createOtterSchematic)(ngAddFn)(options);
exports.ngAdd = ngAdd;
//# sourceMappingURL=index.js.map