-
Notifications
You must be signed in to change notification settings - Fork 1k
/
index.ts
324 lines (300 loc) · 9.29 KB
/
index.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import { Option, program } from 'commander';
import c from './colors';
import { checkExternalConfig, loadConfig } from './config';
import type { Config } from './definitions';
import { fatal, isFatal } from './errors';
import { receive } from './ipc';
import { logger, output } from './log';
import { telemetryAction } from './telemetry';
import { wrapAction } from './util/cli';
import { emoji as _e } from './util/emoji';
process.on('unhandledRejection', error => {
console.error(c.failure('[fatal]'), error);
});
process.on('message', receive);
export async function run(): Promise<void> {
try {
const config = await loadConfig();
runProgram(config);
} catch (e: any) {
process.exitCode = isFatal(e) ? e.exitCode : 1;
logger.error(e.message ? e.message : String(e));
}
}
export function runProgram(config: Config): void {
program.version(config.cli.package.version);
program
.command('config', { hidden: true })
.description(`print evaluated Capacitor config`)
.option('--json', 'Print in JSON format')
.action(
wrapAction(async ({ json }) => {
const { configCommand } = await import('./tasks/config');
await configCommand(config, json);
}),
);
program
.command('create [directory] [name] [id]', { hidden: true })
.description('Creates a new Capacitor project')
.action(
wrapAction(async () => {
const { createCommand } = await import('./tasks/create');
await createCommand();
}),
);
program
.command('init [appName] [appId]')
.description(`Initialize Capacitor configuration`)
.option(
'--web-dir <value>',
'Optional: Directory of your projects built web assets',
)
.action(
wrapAction(
telemetryAction(config, async (appName, appId, { webDir }) => {
const { initCommand } = await import('./tasks/init');
await initCommand(config, appName, appId, webDir);
}),
),
);
program
.command('serve', { hidden: true })
.description('Serves a Capacitor Progressive Web App in the browser')
.action(
wrapAction(async () => {
const { serveCommand } = await import('./tasks/serve');
await serveCommand();
}),
);
program
.command('sync [platform]')
.description(`${c.input('copy')} + ${c.input('update')}`)
.option(
'--deployment',
"Optional: if provided, Podfile.lock won't be deleted and pod install will use --deployment option",
)
.option(
'--inline',
'Optional: if true, all source maps will be inlined for easier debugging on mobile devices',
false,
)
.action(
wrapAction(
telemetryAction(config, async (platform, { deployment, inline }) => {
checkExternalConfig(config.app);
const { syncCommand } = await import('./tasks/sync');
await syncCommand(config, platform, deployment, inline);
}),
),
);
program
.command('update [platform]')
.description(
`updates the native plugins and dependencies based on ${c.strong(
'package.json',
)}`,
)
.option(
'--deployment',
"Optional: if provided, Podfile.lock won't be deleted and pod install will use --deployment option",
)
.action(
wrapAction(
telemetryAction(config, async (platform, { deployment }) => {
checkExternalConfig(config.app);
const { updateCommand } = await import('./tasks/update');
await updateCommand(config, platform, deployment);
}),
),
);
program
.command('copy [platform]')
.description('copies the web app build into the native app')
.option(
'--inline',
'Optional: if true, all source maps will be inlined for easier debugging on mobile devices',
false,
)
.action(
wrapAction(
telemetryAction(config, async (platform, { inline }) => {
checkExternalConfig(config.app);
const { copyCommand } = await import('./tasks/copy');
await copyCommand(config, platform, inline);
}),
),
);
program
.command('build <platform>')
.description('builds the release version of the selected platform')
.option('--scheme <schemeToBuild>', 'iOS Scheme to build')
.option('--keystorepath <keystorePath>', 'Path to the keystore')
.option('--keystorepass <keystorePass>', 'Password to the keystore')
.option('--keystorealias <keystoreAlias>', 'Key Alias in the keystore')
.option(
'--keystorealiaspass <keystoreAliasPass>',
'Password for the Key Alias',
)
.addOption(
new Option(
'--androidreleasetype <androidreleasetype>',
'Android release type; APK or AAB',
)
.choices(['AAB', 'APK'])
.default('AAB'),
)
.action(
wrapAction(
telemetryAction(
config,
async (
platform,
{
scheme,
keystorepath,
keystorepass,
keystorealias,
keystorealiaspass,
androidreleasetype,
},
) => {
const { buildCommand } = await import('./tasks/build');
await buildCommand(config, platform, {
scheme,
keystorepath,
keystorepass,
keystorealias,
keystorealiaspass,
androidreleasetype,
});
},
),
),
);
program
.command(`run [platform]`)
.description(
`runs ${c.input('sync')}, then builds and deploys the native app`,
)
.option('--scheme <schemeName>', 'set the scheme of the iOS project')
.option('--flavor <flavorName>', 'set the flavor of the Android project')
.option('--list', 'list targets, then quit')
// TODO: remove once --json is a hidden option (https://github.com/tj/commander.js/issues/1106)
.allowUnknownOption(true)
.option('--target <id>', 'use a specific target')
.option('--no-sync', `do not run ${c.input('sync')}`)
.action(
wrapAction(
telemetryAction(
config,
async (platform, { scheme, flavor, list, target, sync }) => {
const { runCommand } = await import('./tasks/run');
await runCommand(config, platform, {
scheme,
flavor,
list,
target,
sync,
});
},
),
),
);
program
.command('open [platform]')
.description('opens the native project workspace (Xcode for iOS)')
.action(
wrapAction(
telemetryAction(config, async platform => {
const { openCommand } = await import('./tasks/open');
await openCommand(config, platform);
}),
),
);
program
.command('add [platform]')
.description('add a native platform project')
.action(
wrapAction(
telemetryAction(config, async platform => {
checkExternalConfig(config.app);
const { addCommand } = await import('./tasks/add');
await addCommand(config, platform);
}),
),
);
program
.command('ls [platform]')
.description('list installed Cordova and Capacitor plugins')
.action(
wrapAction(
telemetryAction(config, async platform => {
checkExternalConfig(config.app);
const { listCommand } = await import('./tasks/list');
await listCommand(config, platform);
}),
),
);
program
.command('doctor [platform]')
.description('checks the current setup for common errors')
.action(
wrapAction(
telemetryAction(config, async platform => {
checkExternalConfig(config.app);
const { doctorCommand } = await import('./tasks/doctor');
await doctorCommand(config, platform);
}),
),
);
program
.command('telemetry [on|off]', { hidden: true })
.description('enable or disable telemetry')
.action(
wrapAction(async onOrOff => {
const { telemetryCommand } = await import('./tasks/telemetry');
await telemetryCommand(onOrOff);
}),
);
program
.command('📡', { hidden: true })
.description('IPC receiver command')
.action(() => {
// no-op: IPC messages are received via `process.on('message')`
});
program
.command('plugin:generate', { hidden: true })
.description('start a new Capacitor plugin')
.action(
wrapAction(async () => {
const { newPluginCommand } = await import('./tasks/new-plugin');
await newPluginCommand();
}),
);
program
.command('migrate')
.description(
'Migrate your current Capacitor app to the latest major version of Capacitor.',
)
.action(
wrapAction(async () => {
const { migrateCommand } = await import('./tasks/migrate');
await migrateCommand(config);
}),
);
program.arguments('[command]').action(
wrapAction(async cmd => {
if (typeof cmd === 'undefined') {
output.write(
`\n ${_e('⚡️', '--')} ${c.strong(
'Capacitor - Cross-Platform apps with JavaScript and the Web',
)} ${_e('⚡️', '--')}\n\n`,
);
program.outputHelp();
} else {
fatal(`Unknown command: ${c.input(cmd)}`);
}
}),
);
program.parse(process.argv);
}