feat(cli): add site cli to run scripts + handle media

This commit is contained in:
Cory Dransfeldt 2025-06-05 18:48:20 -07:00
parent 5055816f68
commit fc9ef6e5ed
No known key found for this signature in database
11 changed files with 1586 additions and 11 deletions

42
cli/lib/runScript.js Normal file
View file

@ -0,0 +1,42 @@
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);
}
}