UNPKG

@vortex.so/cli

Version:

CLI to interact with Vortex.

97 lines (91 loc) 3.16 kB
'use strict'; const process = require('node:process'); const execa = require('execa'); const pathe = require('pathe'); const prompts = require('prompts'); const semver = require('semver'); const c = require('chalk'); require('figures'); require('jiti'); const index = require('../../utils/log/index.cjs'); const index$1 = require('../../utils/package/index.cjs'); const ship_input = require('./ship.input.cjs'); const ship_operation = require('./ship.operation.cjs'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const process__default = /*#__PURE__*/_interopDefaultCompat(process); const prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts); const c__default = /*#__PURE__*/_interopDefaultCompat(c); const log = new index.Log("Ship"); async function publish() { let operation = await ship_operation.Operation.start({ release: { type: "prompt", preid: "beta" }, push: false, files: ["vortex.yaml"], cwd: process__default.cwd(), ignoreScripts: false, interface: { input: process__default.stdin, output: process__default.stdout } }); operation = await ship_input.getInput(operation); const { name, type, version } = operation.state; if (!type?.includes("pkg")) { throw new Error("This component is not package, can't publish it."); } const answers = await prompts__default([ { type: "confirm", name: "isConfirmed", message: `Are you sure you want to publish ${c__default.bold.green(name)}?`, initial: false } ]); if (!answers.isConfirmed) throw new Error(`Cancelled.`); const loader = log.wait(); try { const rootDir = pathe.resolve("."); if (!version) throw new Error("Missing version."); if (!semver.valid(version)) { throw new Error("Version is invalid."); } const commands = { yarn: { build: () => execa.$`yarn build`, publish: ["yarn", "npm", "publish"] }, pnpm: { build: () => execa.$`pnpm build`, publish: ["pnpm", "publish"] } }; const manager = index$1.getPackageManager(rootDir); if (!manager) throw new Error("Unknown package manager."); if (manager === "npm") throw new Error("NPM is not supported."); const cmd = commands[manager]; loader.text(`Building ${c__default.bold.green(name)} v${version}...`); const { stdout: r1 } = await cmd.build(); if (r1) loader.persist(c__default.gray(r1)); const command = cmd.publish; const isBeta = version.includes("beta"); if (isBeta) command.push("--tag", "beta"); if (manager === "pnpm") { command.push("--no-git-checks"); } loader.text(`Publishing ${c__default.bold.green(name)} v${version} to NPM...`); const { stdout: r2 } = await execa.$`${command}`; if (r2) loader.persist(c__default.gray(r2)); loader.ok(`${c__default.bold.green(name)} v${version} has been published to NPM!`); } catch (error) { console.error(error); loader.fail(c__default.gray(error?.message || "Something is failed.")); } } exports.publish = publish;