@vortex.so/cli
Version:
CLI to interact with Vortex.
78 lines (75 loc) • 2.13 kB
JavaScript
import { $ } from 'execa';
import prompts from 'prompts';
import 'node:process';
import c from 'chalk';
import 'figures';
import 'jiti';
import { Log } from '../../utils/log/index.mjs';
import { COMPONENT_TYPES } from './ship.constants.mjs';
const log = new Log("Ship");
async function gitAdd() {
try {
await $({ 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([
{
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 $({ stdio: "inherit" })`${command}`;
} catch (error) {
throw new Error(`Failed to commit to Git. ${error?.message}`);
}
}
async function gitTag(operation) {
const answers = await prompts([
{
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 = 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 $({ stdio: "inherit" })`${command}`;
log.ok(`${name} tagged with ${c.bold(`${handle}@${oldVersion}`)}.`);
} catch (error) {
throw new Error(`Failed to tag to Git. ${error?.message}`);
}
}
export { gitAdd, gitCommit, gitTag };