@vortex.so/cli
Version:
CLI to interact with Vortex.
87 lines (81 loc) • 2.52 kB
JavaScript
;
const execa = require('execa');
const prompts = require('prompts');
require('node:process');
const c = require('chalk');
require('figures');
require('jiti');
const index = require('../../utils/log/index.cjs');
const ship_constants = require('./ship.constants.cjs');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts);
const c__default = /*#__PURE__*/_interopDefaultCompat(c);
const log = new index.Log("Ship");
async function gitAdd() {
try {
await execa.$({ stdio: "inherit" })`git add .`;
} catch (error) {
throw new Error(`Failed to add files to Git. ${error?.message}`);
}
}
async function gitCommit(operation) {
const answers = await prompts__default([
{
type: "confirm",
name: "isConfirmed",
message: "Are you sure you want to commit new version?",
initial: false
}
]);
if (!answers.isConfirmed)
throw new Error(`Cancelled.`);
const { handle, oldVersion, oldBuild } = operation.state;
const version = `${oldVersion}-${oldBuild}`;
try {
const command = [
"git",
"commit",
"-m",
`chore(${handle}): evolved to version ${version}`,
"--no-verify"
];
await execa.$({ stdio: "inherit" })`${command}`;
} catch (error) {
throw new Error(`Failed to commit to Git. ${error?.message}`);
}
}
async function gitTag(operation) {
const answers = await prompts__default([
{
type: "confirm",
name: "isConfirmed",
message: "Are you sure you want to tag new version?",
initial: false
}
]);
if (!answers.isConfirmed)
throw new Error(`Cancelled.`);
const { name, type, handle, oldVersion, oldBuild } = operation.state;
const version = `${oldVersion}-${oldBuild}`;
const componentTypes = ship_constants.COMPONENT_TYPES.enums.filter((t) => {
return type?.includes(t);
});
const componenTypeStrings = componentTypes.join(",").toLowerCase();
try {
const command = [
"git",
"tag",
"-a",
`${handle}@${version}`,
"-m",
`${name} ${componenTypeStrings}, version ${version}`
];
await execa.$({ stdio: "inherit" })`${command}`;
log.ok(`${name} tagged with ${c__default.bold(`${handle}@${oldVersion}`)}.`);
} catch (error) {
throw new Error(`Failed to tag to Git. ${error?.message}`);
}
}
exports.gitAdd = gitAdd;
exports.gitCommit = gitCommit;
exports.gitTag = gitTag;