UNPKG

ngx-deploy-npm

Version:

Publish your libraries to NPM with just one command

105 lines 5.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = update; const tslib_1 = require("tslib"); /* eslint-disable @typescript-eslint/no-unused-vars */ /** Remove the old `configuration` option and: - create a new target to build the library with the right configuration - create the `dependsOn` option on the deploy target - Remove deprecated options `buildTarget` and `noBuild` */ const devkit_1 = require("@nx/devkit"); function update(host) { return tslib_1.__awaiter(this, void 0, void 0, function* () { dependsOnMigration(host); removeDeprecatedOptionsMigration(host); yield (0, devkit_1.formatFiles)(host); }); } function dependsOnMigration(host) { // Get projects that require creating of dependsOn const projectToCreateDependsOn = Array.from((0, devkit_1.getProjects)(host)) // remove projects that doesn't have the our executor or already have the option distFolderPath .filter(([_, project]) => { var _a; const projectTargets = Object.values((_a = project.targets) !== null && _a !== void 0 ? _a : {}); return projectTargets.some(targetRequiresMigrationCreationDependsOn); }); // Create the `dependencyOn` the deploy target projectToCreateDependsOn.forEach(([projectKey, project]) => { createDependsOn(projectKey, project); (0, devkit_1.updateProjectConfiguration)(host, projectKey, project); }); function targetRequiresMigrationCreationDependsOn(target) { var _a; return (target.executor === 'ngx-deploy-npm:deploy' && // has the right executor ((_a = target.options) === null || _a === void 0 ? void 0 : _a.noBuild) !== true // the target will build the library ); } function createDependsOn(projectKey, project) { var _a; const deployExecutors = Object.entries((_a = project.targets) !== null && _a !== void 0 ? _a : {}).filter(([targetName, targetConfig]) => targetRequiresMigrationCreationDependsOn(targetConfig)); deployExecutors.forEach(([targetName, targetConfig]) => { var _a, _b; // store the old buildTarget value const buildTarget = (_a = targetConfig.options) === null || _a === void 0 ? void 0 : _a.buildTarget; // Create targets in case that they doesn't already exists if (!project.targets) { project.targets = {}; } // If our executor was building the library, it needs to depend on the build target let newDependsOn = 'build'; if (typeof buildTarget === 'string') { const newPreDeployTargetName = `pre-${targetName}-build-${buildTarget}`; newDependsOn = newPreDeployTargetName; project.targets[newPreDeployTargetName] = { executor: 'nx:run-commands', options: { command: `nx run ${projectKey}:build:${buildTarget}`, }, }; } const dependsOn = project.targets[targetName].dependsOn; if (dependsOn === undefined) { project.targets[targetName].dependsOn = []; } (_b = project.targets[targetName].dependsOn) === null || _b === void 0 ? void 0 : _b.push(newDependsOn); }); } } function removeDeprecatedOptionsMigration(host) { return tslib_1.__awaiter(this, void 0, void 0, function* () { // Get projects that require removing of buildTarget and noBuild const projectToMigrate = Array.from((0, devkit_1.getProjects)(host)) // remove projects that doesn't have the our executor or already have the option distFolderPath .filter(([_, project]) => { var _a; const projectTargets = Object.values((_a = project.targets) !== null && _a !== void 0 ? _a : {}); return projectTargets.some(targetRequiresMigration); }); // Remove Deprecated options the `dependencyOn` the deploy target projectToMigrate.forEach(([projectKey, project]) => { removeBuildTargetAndNoBuildOptions(project); (0, devkit_1.updateProjectConfiguration)(host, projectKey, project); }); function targetRequiresMigration(target) { var _a, _b; return (target.executor === 'ngx-deploy-npm:deploy' && // has the right executor (((_a = target.options) === null || _a === void 0 ? void 0 : _a.noBuild) !== undefined || // the target will build the library ((_b = target === null || target === void 0 ? void 0 : target.options) === null || _b === void 0 ? void 0 : _b.buildTarget) !== undefined) // the target has the buildTarget option ); } function removeBuildTargetAndNoBuildOptions(project) { var _a; const deployExecutors = Object.entries((_a = project.targets) !== null && _a !== void 0 ? _a : {}).filter(([_, targetConfig]) => targetRequiresMigration(targetConfig)); deployExecutors.forEach(([_, targetConfig]) => { var _a, _b; // Remove option build target (_a = targetConfig.options) === null || _a === void 0 ? true : delete _a.buildTarget; (_b = targetConfig.options) === null || _b === void 0 ? true : delete _b.noBuild; }); } }); } //# sourceMappingURL=replace-buildtarget-for-depends-on.js.map