@o3r/configuration
Version:
This module contains configuration-related features such as CMS compatibility, Configuration override, store and debugging. It enables your application runtime configuration and comes with an integrated ng builder to help you generate configurations suppo
83 lines • 3.86 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 devtools_registration_1 = require("./helpers/devtools-registration");
/**
* List of external dependencies to be added to the project as peer dependencies
*/
const dependenciesToInstall = [
'@angular/core',
'@angular/platform-browser-dynamic',
'@ngrx/entity',
'@ngrx/store',
'rxjs'
];
/**
* List of external dependencies to be added to the project as dev dependencies
*/
const devDependenciesToInstall = [
'rxjs'
];
/**
* Add Otter configuration to an Angular Project
* @param options The options to pass to ng-add execution
*/
function ngAddFn(options) {
/* ng add rules */
return (tree, context) => {
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));
const depsInfo = (0, schematics_2.getO3rPeerDeps)(packageJsonPath);
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));
context.logger.info(`The package ${depsInfo.packageName} comes with a debug mechanism`);
context.logger.info('Get more information on the following page: https://github.com/AmadeusITGroup/otter/tree/main/docs/configuration/OVERVIEW.md#Runtime-debugging');
const schematicsDefaultOptions = { useOtterConfig: undefined };
const projectDirectory = workspaceProject?.root || '.';
const projectPackageJson = tree.readJson(path.posix.join(projectDirectory, 'package.json'));
const externalDependenciesInfo = (0, schematics_2.getExternalDependenciesInfo)({
devDependenciesToInstall,
dependenciesToInstall,
o3rPackageJsonPath: packageJsonPath,
projectType: workspaceProject?.projectType,
projectPackageJson
}, context.logger);
return () => (0, schematics_1.chain)([
(0, schematics_2.registerPackageCollectionSchematics)(packageJson),
(0, schematics_2.setupSchematicsParamsForProject)({
'@o3r/core:component': schematicsDefaultOptions,
'@o3r/core:component-container': schematicsDefaultOptions,
'@o3r/core:component-presenter': schematicsDefaultOptions
}, options.projectName),
(0, schematics_2.setupDependencies)({
projectName: options.projectName,
dependencies: {
...dependencies,
...externalDependenciesInfo
},
ngAddToRun: depsInfo.o3rPeerDeps
}),
() => (0, devtools_registration_1.registerDevtools)(options)
])(tree, context);
};
}
/**
* Add Otter configuration to an Angular Project
* @param options The options to pass to ng-add execution
*/
const ngAdd = (options) => (0, schematics_2.createOtterSchematic)(ngAddFn)(options);
exports.ngAdd = ngAdd;
//# sourceMappingURL=index.js.map