Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@abdulghani/release-tag

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@abdulghani/release-tag - npm Package Compare versions

Comparing version
0.0.10
to
0.0.11
+2
-1
package.json
{
"name": "@abdulghani/release-tag",
"version": "0.0.10",
"version": "0.0.11",
"description": "package to manage release tag for a repository in a cli",

@@ -10,2 +10,3 @@ "homepage": "https://github.com/abdulghani/release-tag",

"scripts": {
"prepublish": "npm run build",
"build": "[ -d ./build ] && rm -rf ./build; npm run test && ttsc --project ./tsconfig.build.json",

@@ -12,0 +13,0 @@ "test": "jest --config ./jest.config.ts --verbose --runInBand --coverage",

#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const git_tags_1 = __importDefault(require("./utils/git-tags"));
(async () => {
try {
const instance = new git_tags_1.default();
await instance.createRelease();
}
catch (err) {
console.log("FAILED", err.message);
}
})();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ReleaseStage;
(function (ReleaseStage) {
ReleaseStage["stage"] = "stage";
ReleaseStage["rc"] = "rc";
ReleaseStage["release"] = "release";
})(ReleaseStage || (ReleaseStage = {}));
exports.default = ReleaseStage;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ReleaseType;
(function (ReleaseType) {
ReleaseType["major"] = "major";
ReleaseType["minor"] = "minor";
ReleaseType["patch"] = "patch";
})(ReleaseType || (ReleaseType = {}));
exports.default = ReleaseType;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
async function executeCommand(command, args) {
return new Promise((resolve, reject) => {
const cmd = (0, child_process_1.spawn)(command, args);
const stream = [];
const errStream = [];
cmd.stdout.on("data", (data) => {
stream.push(...data
.toString()
.trim()
.split("\n")
.map((item) => item.trim()));
});
cmd.stderr.on("data", (data) => {
errStream.push(...data
.toString()
.trim()
.split("\n")
.map((item) => item.trim()));
});
cmd.on("exit", (code) => {
if (Number(code) === 0) {
resolve(stream.join("\n"));
}
reject(errStream.join("\n"));
});
});
}
exports.default = executeCommand;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getVersionDetail(version) {
var _a, _b;
const match = version.match(/^(?:v)?([0-9]+)\.([0-9]+)\.([0-9]+)(?:-(.+)\.([0-9]+))?$/i);
if (!match) {
throw new Error(`version string (${version}) is invalid.`);
}
const [major, minor, patch, stage, iteration] = [
Number(match[1]),
Number(match[2]),
Number(match[3]),
(_a = match[4]) === null || _a === void 0 ? void 0 : _a.replace(/-/gi, "/"),
Number((_b = match[5]) !== null && _b !== void 0 ? _b : 0),
];
return {
major,
minor,
patch,
stage,
iteration,
};
}
exports.default = getVersionDetail;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const release_stage_1 = __importDefault(require("../constants/release-stage"));
const release_type_1 = __importDefault(require("../constants/release-type"));
const lodash_1 = __importDefault(require("lodash"));
const yargs_1 = __importDefault(require("yargs"));
const execute_command_1 = __importDefault(require("./execute-command"));
const get_version_detail_1 = __importDefault(require("./get-version-detail"));
const is_pure_tags_1 = __importDefault(require("./is-pure-tags"));
class GitTags {
constructor() {
const { stage, type } = this.getArguments();
this.stage = stage;
this.type = type;
}
getArguments() {
const args = (0, yargs_1.default)(process.argv).argv;
const type = (() => {
const argval = args.type;
if (argval in release_type_1.default) {
return release_type_1.default[argval];
}
if (argval === undefined || argval === true) {
// DEFAULT TO MINOR RELEASE
return release_type_1.default.minor;
}
console.log(`invalid type (${argval}). valid --type arguments (${Object.values(release_type_1.default).join(", ")})`);
process.exit(1);
})();
const stage = (() => {
const argval = args.stage;
if (argval in release_stage_1.default) {
return release_stage_1.default[argval];
}
console.log(`invalid stage (${argval}). valid --stage arguments (${Object.values(release_stage_1.default).join(", ")})`);
process.exit(1);
})();
return { stage, type };
}
async getCurrentBranch() {
if (this.currentBranch) {
return this.currentBranch;
}
this.currentBranch = await (0, execute_command_1.default)("git", [
"branch",
"--show-current",
]);
return this.currentBranch;
}
async pruneLocalTags() {
const tags = await (0, execute_command_1.default)("git", ["tag", "-l"]).then((res) => { var _a; return (_a = res.split("\n").filter((i) => i.trim() !== "")) !== null && _a !== void 0 ? _a : []; });
if (tags.length) {
await (0, execute_command_1.default)("git", ["tag", "-d", ...tags]);
}
}
sortTags(tags) {
return tags.sort((a, b) => {
const [vA, vB] = [(0, get_version_detail_1.default)(a), (0, get_version_detail_1.default)(b)];
if (vA.major !== vB.major) {
return vB.major - vA.major;
}
else if (vA.minor !== vB.minor) {
return vB.minor - vA.minor;
}
else if (vA.patch !== vB.patch) {
return vB.patch - vA.patch;
}
else if (vA.stage !== vB.stage) {
return (!vA.stage && vB.stage) ||
(vA.stage === "rc" && vB.stage !== "rc")
? -1
: 1;
}
return vB.iteration - vA.iteration;
});
}
async getRemoteTags() {
await this.pruneLocalTags();
const stash = await (0, execute_command_1.default)("git", [
"stash",
"--include-untracked",
]).then((res) => !res.match(/no local changes to save/i));
const branch = await this.getCurrentBranch();
await (0, execute_command_1.default)("git", ["fetch", "origin", branch, "--tags"]);
if (stash)
await (0, execute_command_1.default)("git", ["stash", "pop"]);
const tags = await (0, execute_command_1.default)("git", ["tag", "-l"]).then((res) => {
var _a;
const tags = ((_a = res.split("\n")) !== null && _a !== void 0 ? _a : []).map((i) => i.trim());
tags.push("v0.0.0");
return this.sortTags(tags);
});
return tags;
}
async cleanupRelatedTags(version) {
console.log("CLEANING UP TAGS");
const versionDetail = (0, get_version_detail_1.default)(version);
const tags = await this.getRemoteTags();
const relatedTags = tags.filter((item) => {
if (item.match(/^v([0-9]+)\.([0-9]+)\.([0-9]+)$/i)) {
return false;
}
const itemDetail = (0, get_version_detail_1.default)(item);
return (versionDetail.major === itemDetail.major &&
versionDetail.minor === itemDetail.minor &&
versionDetail.patch === itemDetail.patch);
});
if (relatedTags.length > 0) {
console.log("DELETING REMOTE TAGS", relatedTags);
await (0, execute_command_1.default)("git", [
"push",
"--delete",
"--no-verify",
"origin",
...relatedTags,
]);
}
}
async genNewTag() {
var _a;
const tags = await this.getRemoteTags();
const pureTags = tags.filter((i) => (0, is_pure_tags_1.default)(i));
const branch = await this.getCurrentBranch();
// BUMP VERSION
const bumpedVersion = (() => {
const v = (0, get_version_detail_1.default)(pureTags[0]);
if (this.type === release_type_1.default.patch) {
v.patch += 1;
}
else if (this.type === release_type_1.default.minor) {
v.minor += 1;
}
else if (this.type === release_type_1.default.major) {
v.major += 1;
}
return `v${v.major}.${v.minor}.${v.patch}`;
})();
// ITERATION
const iterations = (() => {
const v = (0, get_version_detail_1.default)(bumpedVersion);
const relatedTags = tags.filter((i) => {
if ((0, is_pure_tags_1.default)(i))
return false;
const idetail = (0, get_version_detail_1.default)(i);
return (v.major === idetail.major &&
v.minor === idetail.minor &&
v.patch === idetail.patch &&
(this.stage === release_stage_1.default.stage ? branch : "rc") === idetail.stage);
});
return relatedTags;
})();
const newTag = (() => {
if (this.stage === release_stage_1.default.stage) {
return `${bumpedVersion}-${lodash_1.default.kebabCase(branch)}.${iterations.length}`;
}
else if (this.stage === release_stage_1.default.rc) {
return `${bumpedVersion}-rc.${iterations.length}`;
}
// DEFAULT TO STAGE RELEASE
return bumpedVersion;
})();
console.log(`LATEST TAG (${(_a = iterations[0]) !== null && _a !== void 0 ? _a : pureTags[0]})`);
console.log(`BUMPING TAG (${newTag})`);
return newTag;
}
async createTag(tag) {
tag = tag.replace(/\//gi, "-");
const branch = await this.getCurrentBranch();
await (0, execute_command_1.default)("git", [
"tag",
tag,
"-m",
`release: ${this.type} release ${tag}, from branch (${branch}).`,
]);
await (0, execute_command_1.default)("git", ["push", "--no-verify", "origin", tag]);
console.log(`CREATED NEW TAG ${tag}`);
}
async createRelease() {
console.log();
console.log("FETCHING REMOTE TAGS...");
const newTag = await this.genNewTag();
if (this.stage === release_stage_1.default.release) {
await this.cleanupRelatedTags(newTag);
}
await this.createTag(newTag);
console.log();
}
}
exports.default = GitTags;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function isPureTag(tag) {
return !!tag.match(/^(?:v)?([0-9]+)\.([0-9]+)\.([0-9]+)$/i);
}
exports.default = isPureTag;