UNPKG

@releaseotto/core

Version:

OTTO performs your action on new versioning of APIs, packages, schemas, etc. Keepings things nice and neatly automated.

82 lines 4.5 kB
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()); }); }; import * as Semver from 'semver'; import { getSemverVersionChangeToDo } from "./semver"; import { GithubLocationConfigVersionType } from '../../types/automator/GithubLocationConfigVersionType'; import { LocationType } from '../../types/automator/LocationType'; import { DependenciesType } from '../../types/automator/DependenciesType'; import { GithubRepositoryPackage } from '../../types/automator/GithubRepositoryPackage'; import { GithubRepositoryPackageVersionType } from '../../types/automator/GithubRepositoryPackageVersionType'; import { temporaryLocation } from '../globals'; import * as path from 'path'; import { cloneRepository } from '../../commands/git'; import { loadPackageInformation } from '../../commands/npm'; export function getVersionChangeToDo(config, dependencyVersions) { var _a, _b, _c, _d, _e; const locationType = (_a = config.location) === null || _a === void 0 ? void 0 : _a.type; switch (locationType) { case LocationType.GITHUB: if (((_c = (_b = config.location) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.versionType) === GithubLocationConfigVersionType.SEMVER || ((_e = (_d = config.location) === null || _d === void 0 ? void 0 : _d.config) === null || _e === void 0 ? void 0 : _e.versionType) === undefined) { return getSemverVersionChangeToDo(config, dependencyVersions); } throw new Error("Unable to determine versioning type for location"); default: throw new Error("Unable to determine location type"); } } function checkVersion(version, versionType) { if (versionType === GithubRepositoryPackageVersionType.SEMVER) { const validVersion = Semver.valid(version); if (validVersion === null) { throw new Error(`Expected semver version but didn't get that, value was ${versionType}`); } const inUseVersion = Semver.clean(version); if (inUseVersion === null) { throw new Error("Could not clean semver version"); } return inUseVersion; } return version; } /** * Get version diffs between the versions of the generated code is relying on, vs what the remote version is. * * This is a generic function that */ export function getVersionDiffs(config, metaInfo) { return __awaiter(this, void 0, void 0, function* () { const versionDiffs = {}; for (const dependency of config.dependencies || []) { if (dependency.type === DependenciesType.GITHUB_MINUS_REPOSITORY_MINUS_PACKAGE) { const githubPackageConf = GithubRepositoryPackage.unmarshal(JSON.stringify(dependency.config)); let oldVersion = metaInfo.dependencies[dependency.id] || '0.0.0'; if (!oldVersion) { throw new Error("Expected meta information for dependency, got nothing."); } oldVersion = checkVersion(oldVersion, githubPackageConf.versionType); const location = path.resolve(temporaryLocation, githubPackageConf.repo); cloneRepository({ branch: githubPackageConf.branch, repository: githubPackageConf.repo, toLocation: location }); const localPackageLocation = path.resolve(location, githubPackageConf.packageMinusLocation); const packageInfo = yield loadPackageInformation({ location: localPackageLocation }); const newVersion = packageInfo['version']; versionDiffs[dependency.id] = { localVersion: oldVersion, remoteVersion: newVersion }; } } return versionDiffs; }); } //# sourceMappingURL=index.js.map