1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const program = require("commander");
|
4 | const chalk_1 = require("chalk");
|
5 | const create_1 = require("./tasks/create");
|
6 | const init_1 = require("./tasks/init");
|
7 | const copy_1 = require("./tasks/copy");
|
8 | const list_1 = require("./tasks/list");
|
9 | const update_1 = require("./tasks/update");
|
10 | const open_1 = require("./tasks/open");
|
11 | const serve_1 = require("./tasks/serve");
|
12 | const sync_1 = require("./tasks/sync");
|
13 | const config_1 = require("./config");
|
14 | const add_1 = require("./tasks/add");
|
15 | const new_plugin_1 = require("./tasks/new-plugin");
|
16 | const doctor_1 = require("./tasks/doctor");
|
17 | const emoji_1 = require("./util/emoji");
|
18 | process.on('unhandledRejection', error => {
|
19 | const chalk = require('chalk');
|
20 | console.error(chalk.red('[fatal]'), error);
|
21 | });
|
22 | function run(process, cliBinDir) {
|
23 | const config = new config_1.Config(process.platform, process.cwd(), cliBinDir);
|
24 | program
|
25 | .version(config.cli.package.version);
|
26 | program
|
27 | .command('create [directory] [name] [id]')
|
28 | .description('Creates a new Capacitor project')
|
29 | .option('--npm-client [npmClient]', 'Optional: npm client to use for dependency installation')
|
30 | .action((directory, name, id, { npmClient }) => {
|
31 | return create_1.createCommand(config, directory, name, id, npmClient);
|
32 | });
|
33 | program
|
34 | .command('init [appName] [appId]')
|
35 | .description('Initializes a new Capacitor project in the current directory')
|
36 | .option('--web-dir [value]', 'Optional: Directory of your projects built web assets', config.app.webDir ? config.app.webDir : 'www')
|
37 | .option('--npm-client [npmClient]', 'Optional: npm client to use for dependency installation')
|
38 | .action((appName, appId, { webDir, npmClient }) => {
|
39 | return init_1.initCommand(config, appName, appId, webDir, npmClient);
|
40 | });
|
41 | program
|
42 | .command('serve')
|
43 | .description('Serves a Capacitor Progressive Web App in the browser')
|
44 | .action(() => {
|
45 | return serve_1.serveCommand(config);
|
46 | });
|
47 | program
|
48 | .command('sync [platform]')
|
49 | .description('copy + update')
|
50 | .option('--deployment', 'Optional: if provided, Podfile.lock won\'t be deleted and pod install will use --deployment option')
|
51 | .action((platform, { deployment }) => {
|
52 | return sync_1.syncCommand(config, platform, deployment);
|
53 | });
|
54 | program
|
55 | .command('update [platform]')
|
56 | .description(`updates the native plugins and dependencies based in package.json`)
|
57 | .option('--deployment', 'Optional: if provided, Podfile.lock won\'t be deleted and pod install will use --deployment option')
|
58 | .action((platform, { deployment }) => {
|
59 | return update_1.updateCommand(config, platform, deployment);
|
60 | });
|
61 | program
|
62 | .command('copy [platform]')
|
63 | .description('copies the web app build into the native app')
|
64 | .action(platform => {
|
65 | return copy_1.copyCommand(config, platform);
|
66 | });
|
67 | program
|
68 | .command('open [platform]')
|
69 | .description('opens the native project workspace (xcode for iOS)')
|
70 | .action(platform => {
|
71 | return open_1.openCommand(config, platform);
|
72 | });
|
73 | program
|
74 | .command('add [platform]')
|
75 | .description('add a native platform project')
|
76 | .action((platform) => {
|
77 | return add_1.addCommand(config, platform);
|
78 | });
|
79 | program
|
80 | .command('ls [platform]')
|
81 | .description('list installed Cordova and Capacitor plugins')
|
82 | .action(platform => {
|
83 | return list_1.listCommand(config, platform);
|
84 | });
|
85 | program
|
86 | .command('doctor [platform]')
|
87 | .description('checks the current setup for common errors')
|
88 | .action(platform => {
|
89 | return doctor_1.doctorCommand(config, platform);
|
90 | });
|
91 | program
|
92 | .command('plugin:generate')
|
93 | .description('start a new Capacitor plugin')
|
94 | .action(() => {
|
95 | return new_plugin_1.newPluginCommand(config);
|
96 | });
|
97 | program
|
98 | .arguments('<command>')
|
99 | .action((cmd) => {
|
100 | program.outputHelp();
|
101 | console.log(` ` + chalk_1.default.red(`\n Unknown command ${chalk_1.default.yellow(cmd)}.`));
|
102 | console.log();
|
103 | });
|
104 | program.parse(process.argv);
|
105 | if (!program.args.length) {
|
106 | console.log(`\n ${emoji_1.emoji('⚡️', '--')} ${chalk_1.default.bold('Capacitor - Cross-Platform apps with JavaScript and the Web')} ${emoji_1.emoji('⚡️', '--')}`);
|
107 | program.help();
|
108 | }
|
109 | }
|
110 | exports.run = run;
|