@o3r/localization
Version:
This module provides a runtime dynamic language/translation support and debug tools.
90 lines • 4.15 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");
/**
* List of external dependencies to be added to the project as peer dependencies
*/
const dependenciesToInstall = [
'@angular/cdk',
'@angular/common',
'@angular/core',
'@angular/platform-browser-dynamic',
'@formatjs/intl-numberformat',
'@ngrx/store',
'@ngx-translate/core',
'intl-messageformat',
'rxjs'
];
/**
* List of external dependencies to be added to the project as dev dependencies
*/
const devDependenciesToInstall = [
'@angular-devkit/core',
'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 workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
const projectDirectory = workspaceProject?.root || '.';
const projectPackageJson = tree.readJson(path.posix.join(projectDirectory, 'package.json'));
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 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));
const externalDependenciesInfo = (0, schematics_2.getExternalDependenciesInfo)({
devDependenciesToInstall,
dependenciesToInstall,
projectType: workspaceProject?.projectType,
projectPackageJson,
o3rPackageJsonPath: packageJsonPath
}, context.logger);
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: {
...dependencies,
...externalDependenciesInfo
},
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