1#!/usr/bin/env node 2import arg from 'arg'; 3import chalk from 'chalk'; 4 5import * as Log from './utils/log'; 6 7export type Command = (argv?: string[]) => void; 8 9const commands: { [command: string]: () => Promise<Command> } = { 10 // Add a new command here 11 'codesigning:generate': () => 12 import('./generateCodeSigning.js').then((i) => i.generateCodeSigning), 13 'codesigning:configure': () => 14 import('./configureCodeSigning.js').then((i) => i.configureCodeSigning), 15}; 16 17const args = arg( 18 { 19 // Types 20 '--help': Boolean, 21 22 // Aliases 23 '-h': '--help', 24 }, 25 { 26 permissive: true, 27 } 28); 29 30const command = args._[0]; 31const commandArgs = args._.slice(1); 32 33// Handle `--help` flag 34if ((args['--help'] && !command) || !command) { 35 Log.exit( 36 chalk` 37{bold Usage} 38 {dim $} npx expo-updates <command> 39 40{bold Commands} 41 ${Object.keys(commands).sort().join(', ')} 42 43{bold Options} 44 --help, -h Displays this message 45 46For more information run a command with the --help flag 47 {dim $} npx expo-updates codesigning:generate --help 48 `, 49 0 50 ); 51} 52 53// Push the help flag to the subcommand args. 54if (args['--help']) { 55 commandArgs.push('--help'); 56} 57 58// Install exit hooks 59process.on('SIGINT', () => process.exit(0)); 60process.on('SIGTERM', () => process.exit(0)); 61 62commands[command]().then((exec) => exec(commandArgs)); 63