All files / src cli.js

85.71% Statements 18/21
90% Branches 9/10
50% Functions 1/2
85.71% Lines 18/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                          1x 1x   1x                                   5x   5x 2x 2x     3x 1x 1x 1x     2x 1x 1x     1x 1x     1x             1x  
#!/usr/bin/env node
 
/**
 * @file cli.js
 * @description spec-up-t command-line entry. Published as the `spec-up-t` bin
 * so consuming repos can run `npx spec-up-t@2 custom-update` without depending
 * on their (possibly stale) package.json script.
 *
 * This file must stay: it is the public CLI. Invoke it with
 * `npx spec-up-t <command>` or `spec-up-t <command>` from a consumer's
 * node_modules/.bin after install.
 */
 
const customUpdate = require('./install-from-boilerplate/custom-update');
const Logger = require('./utils/logger');
 
const HELP = `Usage: spec-up-t <command>
 
Commands:
  custom-update   Upgrade this Spec-Up-T repo in place (scripts, files, deps)
 
1.x → 2.x:
  npx spec-up-t@2 custom-update
 
On 2.x (after the first successful update):
  npm run custom-update
 
`;
 
/**
 * Parses argv and runs the requested command.
 * @param {string[]} argv - process.argv
 */
async function main(argv) {
    const command = argv[2];
 
    if (command === '--help' || command === '-h') {
        process.stdout.write(HELP);
        return;
    }
 
    if (!command) {
        process.stderr.write(HELP);
        process.exitCode = 1;
        return;
    }
 
    if (command === 'custom-update') {
        await customUpdate();
        return;
    }
 
    process.stderr.write(`Unknown command: ${command}\n\n${HELP}`);
    process.exitCode = 1;
}
 
Iif (require.main === module) {
    main(process.argv).catch((error) => {
        Logger.error('spec-up-t failed:', error);
        process.exitCode = 1;
    });
}
 
module.exports = { main, HELP };