UNPKG

@atomist/atomist-sdm

Version:

Atomist SDM to deliver our own projects

104 lines 4.4 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const sdm_1 = require("@atomist/sdm"); const semver = require("semver"); const goals_1 = require("./goals"); const release_1 = require("./release"); /** * Version projects based on the value in the file `VERSION`. */ function fileVersioner(sdmGoal, p, log) { return __awaiter(this, void 0, void 0, function* () { const baseVersion = (yield exports.fileProjectIdentifier(p)).version; log.write(`Using base version '${baseVersion}'`); const prereleaseVersion = release_1.addBranchPreRelease(baseVersion, sdmGoal); log.write(`Calculated pre-release version '${prereleaseVersion}'`); return prereleaseVersion; }); } exports.fileVersioner = fileVersioner; exports.HasFileVersion = { name: "HasFileVersion", mapping: inv => inv.project.hasFile("VERSION"), }; exports.FileVersionerRegistration = { name: "file-versioner", versioner: fileVersioner, logInterpreter: sdm_1.LogSuppressor, pushTest: exports.HasFileVersion, }; /** * Command for incrementing the patch value in `VERSION`. */ function fileIncrementPatch(p, log) { return __awaiter(this, void 0, void 0, function* () { const vPath = "VERSION"; const vFile = yield p.getFile(vPath); if (!vFile) { const msg = `Project does not have '${vPath}' file`; log.write(msg); return { code: 1, message: msg }; } const currentVersion = (yield vFile.getContent()).trim(); if (!currentVersion) { const msg = `Failed to extract version from '${vPath}' file`; log.write(msg); return { code: 1, message: msg }; } const newVersion = semver.inc(currentVersion, "patch"); if (!newVersion || newVersion === currentVersion) { const msg = `Failed to increment patch in version '${currentVersion}' from '${vPath}' file`; log.write(msg); return { code: 1, message: msg }; } yield vFile.setContent(newVersion + "\n"); const message = `Incremented patch level in '${vPath}' file: ${currentVersion} => ${newVersion}`; log.write(message); return { code: 0, message }; }); } exports.fileIncrementPatch = fileIncrementPatch; /** * Project identifier for projects storing the version in `VERSION`. */ exports.fileProjectIdentifier = (p) => __awaiter(this, void 0, void 0, function* () { const versionFile = yield p.getFile("VERSION"); const versionContents = (versionFile) ? yield versionFile.getContent() : "0.0.0"; const v = versionContents.trim(); return { name: p.name, version: v }; }); function addFileVersionerSupport(sdm) { goals_1.version.with(exports.FileVersionerRegistration); goals_1.releaseVersion.with({ name: "file-release-version", goalExecutor: release_1.executeReleaseVersion(exports.fileProjectIdentifier, fileIncrementPatch), logInterpreter: sdm_1.LogSuppressor, pushTest: exports.HasFileVersion, }); return sdm; } exports.addFileVersionerSupport = addFileVersionerSupport; //# sourceMappingURL=version.js.map