UNPKG

@o3r/localization

Version:

This module provides a runtime dynamic language/translation support and debug tools.

78 lines 4.22 kB
"use strict"; 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 cms_adapter_1 = require("../cms-adapter"); const devtools_registration_1 = require("./helpers/devtools-registration"); const dependenciesToInstall = [ 'chokidar', 'globby' ]; const reportMissingSchematicsDep = (logger) => (reason) => { logger.error(`[ERROR]: Adding @o3r/localization has failed. If the error is related to missing @o3r dependencies you need to install '@o3r/core' to be able to use the localization package. Please run 'ng add @o3r/core' . Otherwise, use the error message as guidance.`); throw reason; }; /** * Add Otter localization to an Angular Project * @param options for the dependencies installations */ function ngAddFn(options) { return async (tree, context) => { const { applyEsLintFix, getPackageInstallConfig, getProjectNewDependenciesTypes, getWorkspaceConfig, setupDependencies, getO3rPeerDeps, getExternalDependenciesVersionRange, registerPackageCollectionSchematics, setupSchematicsParamsForProject } = await Promise.resolve().then(() => require('@o3r/schematics')); 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 = 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 ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined; const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => { acc[dep] = { inManifest: [{ range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`, types: getProjectNewDependenciesTypes(workspaceProject) }], ngAddOptions: { exactO3rVersion: options.exactO3rVersion } }; return acc; }, getPackageInstallConfig(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion)); Object.entries(getExternalDependenciesVersionRange(dependenciesToInstall, packageJsonPath, context.logger)).forEach(([dep, range]) => { dependencies[dep] = { inManifest: [{ range, types: [NodeDependencyType.Dev] }] }; }); const registerDevtoolRule = await (0, devtools_registration_1.registerDevtools)(options); return (0, schematics_1.chain)([ updateLocalization(options, __dirname), updateI18n(options), options.skipLinter ? (0, schematics_1.noop)() : applyEsLintFix(), setupDependencies({ projectName: options.projectName, dependencies, ngAddToRun: depsInfo.o3rPeerDeps }), (0, cms_adapter_1.updateCmsAdapter)(options), registerPackageCollectionSchematics(packageJson), 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) => async (_, { logger }) => { const { createOtterSchematic } = await Promise.resolve().then(() => require('@o3r/schematics')).catch(reportMissingSchematicsDep(logger)); return createOtterSchematic(ngAddFn)(options); }; exports.ngAdd = ngAdd; //# sourceMappingURL=index.js.map