coryd.dev/cli/lib/runScript.js
Cory Dransfeldt efe701f939
feat(*.liquid): apply prettier to liquid templates
- offer to create tag when none is found while adding a link from cli
- fix tag display in search
2025-06-16 14:41:29 -07:00

44 lines
1.1 KiB
JavaScript

import fs from "fs-extra";
import path from "path";
import inquirer from "inquirer";
import { execSync } from "child_process";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname, "..", "..");
const packageJsonPath = path.join(rootDir, "package.json");
export const runRootScript = async (scriptArg) => {
const pkg = await fs.readJson(packageJsonPath);
const scripts = pkg.scripts || {};
let script = scriptArg;
if (!script) {
const { selected } = await inquirer.prompt([
{
type: "list",
name: "selected",
message: "Select a script to run:",
choices: Object.keys(scripts)
}
]);
script = selected;
}
if (!scripts[script]) {
console.error(`❌ Script "${script}" not found in package.json`);
process.exit(1);
}
try {
execSync(`npm run ${script}`, {
stdio: "inherit",
cwd: rootDir
});
} catch (err) {
console.error(`❌ Failed to run script "${script}"`);
process.exit(1);
}
};