1#!/usr/bin/env node
2import chalk from 'chalk';
3
4import { Command } from './cli';
5import { 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      '--output': String,
14      '--validity-duration-years': Number,
15      '--common-name': String,
16      // Aliases
17      '-h': '--help',
18      '-o': '--output',
19      '-d': '--validity-duration-years',
20      '-c': '--common-name',
21    },
22    argv ?? []
23  );
24
25  if (args['--help']) {
26    Log.exit(
27      chalk`
28      {bold Description}
29      Generate expo-updates code signing keys and certificates
30
31      {bold Usage}
32        $ npx expo-updates codesigning:generate
33
34        Options
35        -o, --output <string>                   Directory in which to put the generated keys and certificate
36        -d, --validity-duration-years <number>  Validity duration in years
37        -c, --common-name <string>              Common name attribute for certificate
38        -h, --help                              Output usage information
39    `,
40      0
41    );
42  }
43
44  const { generateCodeSigningAsync } = await import('./generateCodeSigningAsync');
45  return await generateCodeSigningAsync(getProjectRoot(args), {
46    validityDurationYears: args['--validity-duration-years'],
47    output: args['--output'],
48    commonName: args['--common-name'],
49  });
50};
51