UNPKG

@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

73 lines 3.19 kB
"use strict"; 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"); /** * List of external dependencies to be added to the project as peer dependencies */ const dependenciesToInstall = [ '@angular/common', '@angular/core', 'rxjs' ]; /** * List of external dependencies to be added to the project as dev dependencies */ const devDependenciesToInstall = []; /** * Add Otter apis manager to an Angular Project * @param options */ function ngAddFn(options) { return async (tree, context) => { 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 projectDirectory = workspaceProject?.root || '.'; const projectPackageJson = tree.readJson(path.posix.join(projectDirectory, 'package.json')); const externalDependenciesInfo = (0, schematics_2.getExternalDependenciesInfo)({ dependenciesToInstall, devDependenciesToInstall, projectType: workspaceProject?.projectType, o3rPackageJsonPath: packageJsonPath, projectPackageJson }, context.logger); 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: { ...dependencies, ...externalDependenciesInfo }, 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