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': () => import('./generateCodeSigning').then((i) => i.generateCodeSigning), 12 'codesigning:configure': () => 13 import('./configureCodeSigning').then((i) => i.configureCodeSigning), 14}; 15 16const args = arg( 17 { 18 // Types 19 '--help': Boolean, 20 21 // Aliases 22 '-h': '--help', 23 }, 24 { 25 permissive: true, 26 } 27); 28 29const command = args._[0]; 30const commandArgs = args._.slice(1); 31 32// Handle `--help` flag 33if ((args['--help'] && !command) || !command) { 34 Log.exit( 35 chalk` 36{bold Usage} 37 {dim $} npx expo-updates <command> 38 39{bold Commands} 40 ${Object.keys(commands).sort().join(', ')} 41 42{bold Options} 43 --help, -h Displays this message 44 45For more information run a command with the --help flag 46 {dim $} npx expo-updates codesigning:generate --help 47 `, 48 0 49 ); 50} 51 52// Push the help flag to the subcommand args. 53if (args['--help']) { 54 commandArgs.push('--help'); 55} 56 57// Install exit hooks 58process.on('SIGINT', () => process.exit(0)); 59process.on('SIGTERM', () => process.exit(0)); 60 61commands[command]().then((exec) => exec(commandArgs)); 62