@o3r/apis-manager
Version:
This module provides services to help you communicate with your APIs. Its responsibility is to provide an API configuration to a service factory so that it could instantiate an API with the right configurations. It contains a default configuration and a m
52 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngAdd = void 0;
const path = require("node:path");
const schematics_1 = require("@angular-devkit/schematics");
const schematics_2 = require("@o3r/schematics");
/**
* Add Otter apis manager to an Angular Project
* @param options
*/
function ngAddFn(options) {
return async (tree) => {
const { updateApiDependencies } = await Promise.resolve().then(() => require('../helpers/update-api-deps'));
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const depsInfo = (0, schematics_2.getO3rPeerDeps)(packageJsonPath);
const rulesToExecute = [];
const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
const projectType = workspaceProject?.projectType || 'application';
if (projectType === 'application') {
rulesToExecute.push(updateApiDependencies(options));
}
if (!options.skipCodeSample) {
depsInfo.o3rPeerDeps.push('@ama-sdk/client-fetch');
}
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));
return () => (0, schematics_1.chain)([
...rulesToExecute,
options.skipLinter ? schematics_1.noop : (0, schematics_2.applyEsLintFix)(),
(0, schematics_2.setupDependencies)({
projectName: options.projectName,
dependencies,
ngAddToRun: depsInfo.o3rPeerDeps
})
]);
};
}
/**
* Add Otter apis manager to an Angular Project
* @param options
*/
const ngAdd = (options) => (0, schematics_2.createOtterSchematic)(ngAddFn)(options);
exports.ngAdd = ngAdd;
//# sourceMappingURL=index.js.map