1#!/usr/bin/env node
2import chalk from 'chalk';
3
4import { Command } from './cli';
5import { requireArg, assertArgs, getProjectRoot } from './utils/args';
6import * as Log from './utils/log';
7
8export const generateCodeSigning: Command = async (argv) => {
9  const args = assertArgs(
10    {
11      // Types
12      '--help': Boolean,
13      '--key-output-directory': String,
14      '--certificate-output-directory': String,
15      '--certificate-validity-duration-years': Number,
16      '--certificate-common-name': String,
17      // Aliases
18      '-h': '--help',
19    },
20    argv ?? []
21  );
22
23  if (args['--help']) {
24    Log.exit(
25      chalk`
26      {bold Description}
27      Generate expo-updates private key, public key, and code signing certificate using that public key (self-signed by the private key)
28
29      {bold Usage}
30        $ npx expo-updates codesigning:generate
31
32        Options
33        --key-output-directory <string>                  Directory in which to put the generated private and public keys
34        --certificate-output-directory <string>          Directory in which to put the generated certificate
35        --certificate-validity-duration-years <number>   Validity duration in years
36        --certificate-common-name <string>               Common name attribute for certificate
37        -h, --help                                       Output usage information
38    `,
39      0
40    );
41  }
42
43  const { generateCodeSigningAsync } = await import('./generateCodeSigningAsync');
44
45  const keyOutput = requireArg(args, '--key-output-directory');
46  const certificateOutput = requireArg(args, '--certificate-output-directory');
47  const certificateValidityDurationYears = requireArg(
48    args,
49    '--certificate-validity-duration-years'
50  );
51  const certificateCommonName = requireArg(args, '--certificate-common-name');
52
53  return await generateCodeSigningAsync(getProjectRoot(args), {
54    certificateValidityDurationYears,
55    keyOutput,
56    certificateOutput,
57    certificateCommonName,
58  });
59};
60