feat(cli): add site cli to run scripts + handle media
This commit is contained in:
parent
5055816f68
commit
d08787f5aa
12 changed files with 1615 additions and 26 deletions
42
cli/lib/runScript.js
Normal file
42
cli/lib/runScript.js
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue