sv
Version:
A command line interface (CLI) for creating and maintaining Svelte applications
60 lines (59 loc) • 2.51 kB
JavaScript
import { _ as name, a as detectPackageManager, d as program, g as helpConfig, h as forwardExitCode, l as from, n as add, r as create, u as Command, v as version } from "./engine-DSL32Woe.mjs";
import { color, resolveCommandArray } from "@sveltejs/sv-utils";
import process from "node:process";
import { execSync } from "node:child_process";
//#region src/cli/check.ts
const check = new Command("check").description("a CLI for checking your Svelte code").allowUnknownOption(true).allowExcessArguments(true).option("-C, --cwd <path>", "path to working directory", process.cwd()).helpOption(false).action(async (options, check) => {
const cwd = options.cwd;
const args = check.args;
await runCheck(cwd, args);
});
async function runCheck(cwd, args) {
const pm = await detectPackageManager(cwd);
if (!from(cwd, "svelte-check", true)) {
console.error(`'svelte-check' is not installed locally. Install it with: ${color.command(resolveCommandArray(pm, "add", ["-D", "svelte-check"]))}`);
process.exit(1);
}
if (args.includes("--help")) {
console.log(`All svelte-check [options] are available in sv check [options]`);
console.log("Find here all options for both tools");
}
try {
execSync(resolveCommandArray(pm, "execute-local", ["svelte-check", ...args]).join(" "), {
stdio: "inherit",
cwd
});
} catch (error) {
forwardExitCode(error);
} finally {
if (args.includes("--help")) check.help();
}
}
//#endregion
//#region src/cli/migrate.ts
const migrate = new Command("migrate").description("a CLI for migrating Svelte(Kit) codebases").argument("[migration]", "migration to run").option("-C, --cwd <path>", "path to working directory", process.cwd()).action(async (migration, options) => {
await runMigrate(options.cwd, [migration]);
});
async function runMigrate(cwd, args) {
const pm = await detectPackageManager(cwd);
try {
const cmdArgs = ["svelte-migrate@latest", ...args];
if (pm === "npm") cmdArgs.unshift("--yes");
execSync(resolveCommandArray(pm, "execute", cmdArgs).join(" "), {
stdio: "inherit",
cwd
});
} catch (error) {
forwardExitCode(error);
}
}
//#endregion
//#region bin.ts
console.log();
program.name(name).version(version, "-v, --version").configureHelp(helpConfig);
program.addCommand(create).addCommand(add).addCommand(migrate).addCommand(check);
if (process.argv.includes("--help") || process.argv.includes("-h")) program.addHelpText("after", () => "\n" + create.helpInformation());
program.parse();
//#endregion
export {};