84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Usage (from examples/pear-discord-bot):
|
|
* npm run pear:stage [-- <extra pear-args>]
|
|
* npm run pear:release [-- <extra pear-args>]
|
|
* npm run pear:ship [-- <extra pear-args>] # prepare once, then stage + release
|
|
*
|
|
* With no CLI args after the subcommand, `pear.channel` from examples/pear-discord-bot/package.json
|
|
* is used (fallback: pear.name). Override by passing <channel-or-link> first.
|
|
*/
|
|
|
|
import { spawnSync } from 'node:child_process';
|
|
import { readFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const repoRoot = path.join(__dirname, '..');
|
|
const pearDir = path.join(repoRoot, 'examples', 'pear-discord-bot');
|
|
|
|
const sub = process.argv[2];
|
|
let pearArgs = process.argv.slice(3);
|
|
|
|
function defaultPearChannel() {
|
|
const pkgPath = path.join(pearDir, 'package.json');
|
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
const ch = pkg.pear?.channel ?? pkg.pear?.name;
|
|
if (!ch || typeof ch !== 'string') {
|
|
console.error(
|
|
'examples/pear-discord-bot/package.json must define pear.channel or pear.name for stage/release/ship'
|
|
);
|
|
process.exit(1);
|
|
}
|
|
return ch;
|
|
}
|
|
|
|
function ensureDefaultPearArgs() {
|
|
if (pearArgs.length === 0) {
|
|
pearArgs = [defaultPearChannel()];
|
|
}
|
|
}
|
|
|
|
function runPrepare() {
|
|
const prep = spawnSync(process.execPath, [path.join(repoRoot, 'scripts', 'pear-prepare-release.mjs')], {
|
|
cwd: repoRoot,
|
|
stdio: 'inherit'
|
|
});
|
|
if (prep.status !== 0) process.exit(prep.status ?? 1);
|
|
}
|
|
|
|
const pearBin = process.platform === 'win32' ? 'pear.cmd' : 'pear';
|
|
|
|
if (sub === 'ship') {
|
|
ensureDefaultPearArgs();
|
|
runPrepare();
|
|
const st = spawnSync(pearBin, ['stage', ...pearArgs], {
|
|
cwd: pearDir,
|
|
stdio: 'inherit',
|
|
shell: process.platform === 'win32'
|
|
});
|
|
if (st.status !== 0) process.exit(st.status ?? 1);
|
|
const rel = spawnSync(pearBin, ['release', ...pearArgs], {
|
|
cwd: pearDir,
|
|
stdio: 'inherit',
|
|
shell: process.platform === 'win32'
|
|
});
|
|
process.exit(rel.status ?? 1);
|
|
}
|
|
|
|
if (sub !== 'stage' && sub !== 'release') {
|
|
console.error('Usage: pear-run.mjs <stage|release|ship> [...pear-args]');
|
|
process.exit(1);
|
|
}
|
|
|
|
ensureDefaultPearArgs();
|
|
runPrepare();
|
|
|
|
const pr = spawnSync(pearBin, [sub, ...pearArgs], {
|
|
cwd: pearDir,
|
|
stdio: 'inherit',
|
|
shell: process.platform === 'win32'
|
|
});
|
|
process.exit(pr.status ?? 1);
|