UNPKG

@jobgetapp/rush-needs-deploy-plugin

Version:

Utility to list all deployable projects with changes.

90 lines 4.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChangeService = void 0; /** * Service for managing project change state */ class ChangeService { /** * Create new ChangeService * @param rushConfiguration - Rush repo configuration * @param changeManager - Rush internal change management service */ constructor(rushConfiguration, changeManager, terminal) { this.rushConfiguration = rushConfiguration; this.changeManager = changeManager; this.terminal = terminal; } /** * Get all changed projects in the rush repo meeting the provided conditions * @param options - Options to filter projects */ getChangedProjects(options = {}) { return __awaiter(this, void 0, void 0, function* () { yield this.changeManager.loadAsync(this.rushConfiguration.changesFolder); /** * Helper function to resolve changed projects with a defined project * @param changedProject - * @returns */ const filterHasProjects = (changedProject) => !!changedProject.project; /** * Helper function to filter changed projects to the requested version policy * @param changedProject - * @returns */ const filterListProject = (changedProject) => options.versionPolicyName ? options.versionPolicyName === changedProject.project.versionPolicyName : true; /** * Helper function to filter changed projects with a path matching an optional pattern * @param changedProject - * @returns */ const filterProjectPath = (changedProject) => options.pathPattern ? (new RegExp(options.pathPattern)).test(changedProject.project.projectRelativeFolder) : true; /** * Helper function to filter projects based on provided options * @param changedProject - * @returns */ const filter = (changedProject) => filterHasProjects(changedProject) && filterListProject(changedProject) && filterProjectPath(changedProject); // Get changed projects const projectsJson = this.changeManager.packageChanges // Map to internal format .map(change => (Object.assign(Object.assign({}, change), { project: this.rushConfiguration.projectsByName.get(change.packageName) }))) // Filter results based on requested conditions .filter(filter) // Map to simple change format .map(changeProject => ({ name: changeProject.packageName, unscopedName: changeProject.project.unscopedTempProjectName, version: changeProject.newVersion, versionPolicyName: changeProject.project.versionPolicyName, projectRelativeFolder: changeProject.project.projectRelativeFolder })); // Ensure each project has a specified version in their package json for (const project of projectsJson) { if (!project.version) { throw new Error(`Could not resolve new version number for package ${project.name}`); } } // Return changed projects return projectsJson; }); } } exports.ChangeService = ChangeService; //# sourceMappingURL=change.js.map