UNPKG

@o3r/core

Version:
70 lines 4.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareProject = 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 index_1 = require("../../rule-factories/index"); const update_builders_names_1 = require("../updates-for-v8/cms-adapters/update-builders-names"); const update_generators_names_1 = require("../updates-for-v8/generators/update-generators-names"); const replaced_packages_1 = require("../updates-for-v8/replaced-packages"); /** * Enable all the otter features requested by the user * Install all the related dependencies and import the features inside the application * @param options installation options to pass to the all the other packages' installation * @param dependenciesSetupConfig */ const prepareProject = (options, dependenciesSetupConfig) => (tree, context) => { const coreSchematicsFolder = path.resolve(__dirname, '..'); const corePackageJsonPath = path.resolve(coreSchematicsFolder, '..', '..', 'package.json'); const corePackageJsonContent = JSON.parse(fs.readFileSync(corePackageJsonPath, { encoding: 'utf8' })); if (!corePackageJsonContent) { context.logger.error('Could not find @o3r/core package. Are you sure it is installed?'); } const o3rCoreVersion = corePackageJsonContent.version; const workspaceConfig = (0, schematics_2.getWorkspaceConfig)(tree); const workspaceProject = (options.projectName && workspaceConfig?.projects?.[options.projectName]) || undefined; const projectType = workspaceProject?.projectType; const depsInfo = (0, schematics_2.getO3rPeerDeps)(corePackageJsonPath); const internalPackagesToInstallWithNgAdd = Array.from(new Set([ ...(projectType === 'application' ? ['@o3r/application'] : []), ...depsInfo.o3rPeerDeps ])); const projectDirectory = workspaceProject?.root; const optionsAndWorkingDir = { ...options, workingDirectory: projectDirectory, dependenciesSetupConfig }; internalPackagesToInstallWithNgAdd .forEach((dep) => { dependenciesSetupConfig.dependencies[dep] = { inManifest: [{ range: `${options.exactO3rVersion ? '' : '~'}${o3rCoreVersion}`, types: (0, schematics_2.getProjectNewDependenciesTypes)(workspaceProject) }], ngAddOptions: { exactO3rVersion: options.exactO3rVersion } }; }); (dependenciesSetupConfig.ngAddToRun ||= []).push(...internalPackagesToInstallWithNgAdd); let hasEslint = false; try { const eslintPackage = 'eslint'; require.resolve(eslintPackage); hasEslint = true; } catch { } const appLibRules = [ (0, update_builders_names_1.updateBuildersNames)(), (0, update_generators_names_1.updateOtterGeneratorsNames)(), (0, index_1.updateOtterEnvironmentAdapter)(optionsAndWorkingDir, coreSchematicsFolder), (0, index_1.updateStore)(optionsAndWorkingDir, projectType), options.enableCustomization && projectType === 'application' ? (0, index_1.updateCustomizationEnvironment)(coreSchematicsFolder, o3rCoreVersion, optionsAndWorkingDir, false) : schematics_1.noop, (0, index_1.updatePackageJson)(dependenciesSetupConfig, ['@angular/animations', '@angular/platform-browser-dynamic'], [], options.projectName), projectType === 'application' ? (0, index_1.updateAdditionalModules)(optionsAndWorkingDir, dependenciesSetupConfig) : schematics_1.noop, (0, schematics_2.removePackages)(replaced_packages_1.packagesToRemove), (0, index_1.o3rBasicUpdates)(options.projectName, o3rCoreVersion, projectType), // task that should run after the schematics should be after the ng-add task as they will wait for the package installation before running the other dependencies !options.skipLinter && hasEslint ? (0, schematics_2.applyEsLintFix)() : (0, schematics_1.noop)() ]; return (0, schematics_1.chain)(appLibRules); }; exports.prepareProject = prepareProject; //# sourceMappingURL=index.js.map