@releaseotto/core
Version:
OTTO performs your action on new versioning of APIs, packages, schemas, etc. Keepings things nice and neatly automated.
110 lines • 5.93 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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.getVersionDiffs = exports.getVersionChangeToDo = void 0;
const Semver = __importStar(require("semver"));
const semver_1 = require("./semver");
const GithubLocationConfigVersionType_1 = require("../../types/automator/GithubLocationConfigVersionType");
const LocationType_1 = require("../../types/automator/LocationType");
const DependenciesType_1 = require("../../types/automator/DependenciesType");
const GithubRepositoryPackage_1 = require("../../types/automator/GithubRepositoryPackage");
const GithubRepositoryPackageVersionType_1 = require("../../types/automator/GithubRepositoryPackageVersionType");
const globals_1 = require("../globals");
const path = __importStar(require("path"));
const git_1 = require("../../commands/git");
const npm_1 = require("../../commands/npm");
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_1.LocationType.GITHUB:
if (((_c = (_b = config.location) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.versionType) === GithubLocationConfigVersionType_1.GithubLocationConfigVersionType.SEMVER || ((_e = (_d = config.location) === null || _d === void 0 ? void 0 : _d.config) === null || _e === void 0 ? void 0 : _e.versionType) === undefined) {
return (0, semver_1.getSemverVersionChangeToDo)(config, dependencyVersions);
}
throw new Error("Unable to determine versioning type for location");
default:
throw new Error("Unable to determine location type");
}
}
exports.getVersionChangeToDo = getVersionChangeToDo;
function checkVersion(version, versionType) {
if (versionType === GithubRepositoryPackageVersionType_1.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
*/
function getVersionDiffs(config, metaInfo) {
return __awaiter(this, void 0, void 0, function* () {
const versionDiffs = {};
for (const dependency of config.dependencies || []) {
if (dependency.type === DependenciesType_1.DependenciesType.GITHUB_MINUS_REPOSITORY_MINUS_PACKAGE) {
const githubPackageConf = GithubRepositoryPackage_1.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(globals_1.temporaryLocation, githubPackageConf.repo);
(0, git_1.cloneRepository)({
branch: githubPackageConf.branch,
repository: githubPackageConf.repo,
toLocation: location
});
const localPackageLocation = path.resolve(location, githubPackageConf.packageMinusLocation);
const packageInfo = yield (0, npm_1.loadPackageInformation)({ location: localPackageLocation });
const newVersion = packageInfo['version'];
versionDiffs[dependency.id] = {
localVersion: oldVersion,
remoteVersion: newVersion
};
}
}
return versionDiffs;
});
}
exports.getVersionDiffs = getVersionDiffs;
//# sourceMappingURL=index.js.map