@capacitor-plus/cli 8.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -0
  3. package/assets/android-template.tar.gz +0 -0
  4. package/assets/capacitor-cordova-android-plugins.tar.gz +0 -0
  5. package/assets/capacitor-cordova-ios-plugins.tar.gz +0 -0
  6. package/assets/ios-pods-template.tar.gz +0 -0
  7. package/assets/ios-spm-template.tar.gz +0 -0
  8. package/bin/capacitor +18 -0
  9. package/dist/android/add.js +52 -0
  10. package/dist/android/build.js +104 -0
  11. package/dist/android/common.js +94 -0
  12. package/dist/android/doctor.js +160 -0
  13. package/dist/android/open.js +28 -0
  14. package/dist/android/run.js +42 -0
  15. package/dist/android/update.js +317 -0
  16. package/dist/colors.js +26 -0
  17. package/dist/common.js +435 -0
  18. package/dist/config.js +404 -0
  19. package/dist/cordova.js +801 -0
  20. package/dist/declarations.d.ts +674 -0
  21. package/dist/declarations.js +2 -0
  22. package/dist/definitions.js +13 -0
  23. package/dist/errors.js +27 -0
  24. package/dist/framework-configs.js +109 -0
  25. package/dist/index.js +253 -0
  26. package/dist/ios/add.js +13 -0
  27. package/dist/ios/build.js +96 -0
  28. package/dist/ios/common.js +105 -0
  29. package/dist/ios/doctor.js +45 -0
  30. package/dist/ios/open.js +17 -0
  31. package/dist/ios/run.js +51 -0
  32. package/dist/ios/update.js +449 -0
  33. package/dist/ipc.js +61 -0
  34. package/dist/log.js +39 -0
  35. package/dist/plugin.js +182 -0
  36. package/dist/sysconfig.js +35 -0
  37. package/dist/tasks/add.js +115 -0
  38. package/dist/tasks/build.js +63 -0
  39. package/dist/tasks/config.js +28 -0
  40. package/dist/tasks/copy.js +210 -0
  41. package/dist/tasks/create.js +10 -0
  42. package/dist/tasks/doctor.js +68 -0
  43. package/dist/tasks/init.js +138 -0
  44. package/dist/tasks/list.js +50 -0
  45. package/dist/tasks/migrate-spm.js +19 -0
  46. package/dist/tasks/migrate.js +518 -0
  47. package/dist/tasks/new-plugin.js +10 -0
  48. package/dist/tasks/open.js +62 -0
  49. package/dist/tasks/run.js +118 -0
  50. package/dist/tasks/serve.js +11 -0
  51. package/dist/tasks/sourcemaps.js +39 -0
  52. package/dist/tasks/sync.js +55 -0
  53. package/dist/tasks/telemetry.js +41 -0
  54. package/dist/tasks/update.js +74 -0
  55. package/dist/telemetry.js +119 -0
  56. package/dist/util/cli.js +25 -0
  57. package/dist/util/emoji.js +13 -0
  58. package/dist/util/fn.js +13 -0
  59. package/dist/util/fs.js +43 -0
  60. package/dist/util/iosplugin.js +66 -0
  61. package/dist/util/js.js +21 -0
  62. package/dist/util/livereload.js +148 -0
  63. package/dist/util/monorepotools.js +109 -0
  64. package/dist/util/native-run.js +63 -0
  65. package/dist/util/node.js +54 -0
  66. package/dist/util/promise.js +35 -0
  67. package/dist/util/spm.js +187 -0
  68. package/dist/util/subprocess.js +37 -0
  69. package/dist/util/template.js +11 -0
  70. package/dist/util/term.js +30 -0
  71. package/dist/util/uuid.js +11 -0
  72. package/dist/util/xml.js +55 -0
  73. package/package.json +89 -0
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = exports.runCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const utils_terminal_1 = require("@ionic/utils-terminal");
6
+ const run_1 = require("../android/run");
7
+ const colors_1 = tslib_1.__importDefault(require("../colors"));
8
+ const common_1 = require("../common");
9
+ const cordova_1 = require("../cordova");
10
+ const errors_1 = require("../errors");
11
+ const run_2 = require("../ios/run");
12
+ const log_1 = require("../log");
13
+ const livereload_1 = require("../util/livereload");
14
+ const native_run_1 = require("../util/native-run");
15
+ const sync_1 = require("./sync");
16
+ async function runCommand(config, selectedPlatformName, options) {
17
+ var _a, _b, _c, _d;
18
+ options.host = (_b = (_a = options.host) !== null && _a !== void 0 ? _a : livereload_1.CapLiveReloadHelper.getIpAddress()) !== null && _b !== void 0 ? _b : 'localhost';
19
+ options.port = (_c = options.port) !== null && _c !== void 0 ? _c : '3000';
20
+ if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
21
+ const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
22
+ if (platformDir) {
23
+ await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:run');
24
+ }
25
+ else {
26
+ log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
27
+ }
28
+ }
29
+ else {
30
+ const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
31
+ let platformName;
32
+ if (platforms.length === 1) {
33
+ platformName = platforms[0];
34
+ }
35
+ else {
36
+ platformName = await (0, common_1.promptForPlatform)(platforms.filter(createRunnablePlatformFilter(config)), `Please choose a platform to run:`);
37
+ }
38
+ if (options.list) {
39
+ const targets = await (0, native_run_1.getPlatformTargets)(platformName);
40
+ const outputTargets = targets.map((t) => {
41
+ var _a;
42
+ return ({
43
+ name: (0, common_1.getPlatformTargetName)(t),
44
+ api: `${t.platform === 'ios' ? 'iOS' : 'API'} ${t.sdkVersion}`,
45
+ id: (_a = t.id) !== null && _a !== void 0 ? _a : '?',
46
+ });
47
+ });
48
+ if (options.json) {
49
+ process.stdout.write(`${JSON.stringify(outputTargets)}\n`);
50
+ }
51
+ else {
52
+ const rows = outputTargets.map((t) => [t.name, t.api, t.id]);
53
+ log_1.output.write(`${(0, utils_terminal_1.columnar)(rows, {
54
+ headers: ['Name', 'API', 'Target ID'],
55
+ vsep: ' ',
56
+ })}\n`);
57
+ }
58
+ return;
59
+ }
60
+ try {
61
+ if (options.sync) {
62
+ await (0, sync_1.sync)(config, platformName, false, true);
63
+ }
64
+ const cordovaPlugins = await (0, cordova_1.getCordovaPlugins)(config, platformName);
65
+ if (options.liveReload) {
66
+ await livereload_1.CapLiveReloadHelper.editCapConfigForLiveReload(config, platformName, options);
67
+ if (platformName === config.android.name) {
68
+ await await (0, cordova_1.writeCordovaAndroidManifest)(cordovaPlugins, config, platformName, true);
69
+ }
70
+ }
71
+ await run(config, platformName, options);
72
+ if (options.liveReload) {
73
+ new Promise((resolve) => process.on('SIGINT', resolve))
74
+ .then(async () => {
75
+ await livereload_1.CapLiveReloadHelper.revertCapConfigForLiveReload();
76
+ if (platformName === config.android.name) {
77
+ await (0, cordova_1.writeCordovaAndroidManifest)(cordovaPlugins, config, platformName, false);
78
+ }
79
+ })
80
+ .then(() => process.exit());
81
+ log_1.logger.info(`App running with live reload listing for: http://${options.host}:${options.port}. Press Ctrl+C to quit.`);
82
+ await sleepForever();
83
+ }
84
+ }
85
+ catch (e) {
86
+ if (!(0, errors_1.isFatal)(e)) {
87
+ (0, errors_1.fatal)((_d = e.stack) !== null && _d !== void 0 ? _d : e);
88
+ }
89
+ throw e;
90
+ }
91
+ }
92
+ }
93
+ exports.runCommand = runCommand;
94
+ async function run(config, platformName, options) {
95
+ if (platformName == config.ios.name) {
96
+ await (0, run_2.runIOS)(config, options);
97
+ }
98
+ else if (platformName === config.android.name) {
99
+ await (0, run_1.runAndroid)(config, options);
100
+ }
101
+ else if (platformName === config.web.name) {
102
+ return;
103
+ }
104
+ else {
105
+ throw `Platform ${platformName} is not valid.`;
106
+ }
107
+ }
108
+ exports.run = run;
109
+ function createRunnablePlatformFilter(config) {
110
+ return (platform) => platform === config.ios.name || platform === config.android.name;
111
+ }
112
+ async function sleepForever() {
113
+ return new Promise(() => {
114
+ setInterval(() => {
115
+ /* do nothing */
116
+ }, 1000);
117
+ });
118
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serveCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const colors_1 = tslib_1.__importDefault(require("../colors"));
6
+ const errors_1 = require("../errors");
7
+ async function serveCommand() {
8
+ (0, errors_1.fatal)(`The serve command has been removed.\n` +
9
+ `Use a third-party tool for serving single page apps, such as ${colors_1.default.strong('serve')}: ${colors_1.default.strong('https://www.npmjs.com/package/serve')}`);
10
+ }
11
+ exports.serveCommand = serveCommand;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inlineSourceMaps = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("path");
6
+ const log_1 = require("../log");
7
+ function walkDirectory(dirPath) {
8
+ const files = (0, fs_extra_1.readdirSync)(dirPath);
9
+ files.forEach((file) => {
10
+ const targetFile = (0, path_1.join)(dirPath, file);
11
+ if ((0, fs_extra_1.existsSync)(targetFile) && (0, fs_extra_1.lstatSync)(targetFile).isDirectory()) {
12
+ walkDirectory(targetFile);
13
+ }
14
+ else {
15
+ const mapFile = (0, path_1.join)(dirPath, `${file}.map`);
16
+ if ((0, path_1.extname)(file) === '.js' && (0, fs_extra_1.existsSync)(mapFile)) {
17
+ const bufMap = (0, fs_extra_1.readFileSync)(mapFile).toString('base64');
18
+ const bufFile = (0, fs_extra_1.readFileSync)(targetFile, 'utf8');
19
+ const result = bufFile.replace(`sourceMappingURL=${file}.map`, 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + bufMap);
20
+ (0, fs_extra_1.writeFileSync)(targetFile, result);
21
+ (0, fs_extra_1.unlinkSync)(mapFile);
22
+ }
23
+ }
24
+ });
25
+ }
26
+ async function inlineSourceMaps(config, platformName) {
27
+ let buildDir = '';
28
+ if (platformName == config.ios.name) {
29
+ buildDir = await config.ios.webDirAbs;
30
+ }
31
+ if (platformName == config.android.name) {
32
+ buildDir = await config.android.webDirAbs;
33
+ }
34
+ if (buildDir) {
35
+ log_1.logger.info('Inlining sourcemaps');
36
+ walkDirectory(buildDir);
37
+ }
38
+ }
39
+ exports.inlineSourceMaps = inlineSourceMaps;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sync = exports.syncCommand = void 0;
4
+ const common_1 = require("../common");
5
+ const errors_1 = require("../errors");
6
+ const log_1 = require("../log");
7
+ const promise_1 = require("../util/promise");
8
+ const copy_1 = require("./copy");
9
+ const update_1 = require("./update");
10
+ /**
11
+ * Sync is a copy and an update in one.
12
+ */
13
+ async function syncCommand(config, selectedPlatformName, deployment, inline = false) {
14
+ var _a, _b;
15
+ if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
16
+ try {
17
+ await (0, copy_1.copyCommand)(config, selectedPlatformName, inline);
18
+ }
19
+ catch (e) {
20
+ log_1.logger.error((_a = e.stack) !== null && _a !== void 0 ? _a : e);
21
+ }
22
+ await (0, update_1.updateCommand)(config, selectedPlatformName, deployment);
23
+ }
24
+ else {
25
+ const then = +new Date();
26
+ const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
27
+ try {
28
+ await (0, common_1.check)([() => (0, common_1.checkPackage)(), () => (0, common_1.checkWebDir)(config), ...(0, update_1.updateChecks)(config, platforms)]);
29
+ await (0, promise_1.allSerial)(platforms.map((platformName) => () => sync(config, platformName, deployment, inline)));
30
+ const now = +new Date();
31
+ const diff = (now - then) / 1000;
32
+ log_1.logger.info(`Sync finished in ${diff}s`);
33
+ }
34
+ catch (e) {
35
+ if (!(0, errors_1.isFatal)(e)) {
36
+ (0, errors_1.fatal)((_b = e.stack) !== null && _b !== void 0 ? _b : e);
37
+ }
38
+ throw e;
39
+ }
40
+ }
41
+ }
42
+ exports.syncCommand = syncCommand;
43
+ async function sync(config, platformName, deployment, inline = false) {
44
+ var _a;
45
+ await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:sync:before');
46
+ try {
47
+ await (0, copy_1.copy)(config, platformName, inline);
48
+ }
49
+ catch (e) {
50
+ log_1.logger.error((_a = e.stack) !== null && _a !== void 0 ? _a : e);
51
+ }
52
+ await (0, update_1.update)(config, platformName, deployment);
53
+ await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:sync:after');
54
+ }
55
+ exports.sync = sync;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.telemetryCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const colors_1 = tslib_1.__importDefault(require("../colors"));
6
+ const errors_1 = require("../errors");
7
+ const log_1 = require("../log");
8
+ const sysconfig_1 = require("../sysconfig");
9
+ const THANK_YOU = `\nThank you for helping to make Capacitor better! 💖` +
10
+ `\nInformation about the data we collect is available on our website: ${colors_1.default.strong('https://capacitorjs.com/docs/next/cli/telemetry')}\n`;
11
+ async function telemetryCommand(onOrOff) {
12
+ const sysconfig = await (0, sysconfig_1.readConfig)();
13
+ const enabled = interpretEnabled(onOrOff);
14
+ if (typeof enabled === 'boolean') {
15
+ if (sysconfig.telemetry === enabled) {
16
+ log_1.logger.info(`Telemetry is already ${colors_1.default.strong(enabled ? 'on' : 'off')}`);
17
+ }
18
+ else {
19
+ await (0, sysconfig_1.writeConfig)({ ...sysconfig, telemetry: enabled });
20
+ (0, log_1.logSuccess)(`You have ${colors_1.default.strong(`opted ${enabled ? 'in' : 'out'}`)} ${enabled ? 'for' : 'of'} telemetry on this machine.`);
21
+ if (enabled) {
22
+ log_1.output.write(THANK_YOU);
23
+ }
24
+ }
25
+ }
26
+ else {
27
+ log_1.logger.info(`Telemetry is ${colors_1.default.strong(sysconfig.telemetry ? 'on' : 'off')}`);
28
+ }
29
+ }
30
+ exports.telemetryCommand = telemetryCommand;
31
+ function interpretEnabled(onOrOff) {
32
+ switch (onOrOff) {
33
+ case 'on':
34
+ return true;
35
+ case 'off':
36
+ return false;
37
+ case undefined:
38
+ return undefined;
39
+ }
40
+ (0, errors_1.fatal)(`Argument must be ${colors_1.default.strong('on')} or ${colors_1.default.strong('off')} (or left unspecified)`);
41
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.update = exports.updateChecks = exports.updateCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const update_1 = require("../android/update");
6
+ const colors_1 = tslib_1.__importDefault(require("../colors"));
7
+ const common_1 = require("../common");
8
+ const errors_1 = require("../errors");
9
+ const common_2 = require("../ios/common");
10
+ const update_2 = require("../ios/update");
11
+ const log_1 = require("../log");
12
+ const promise_1 = require("../util/promise");
13
+ async function updateCommand(config, selectedPlatformName, deployment) {
14
+ var _a;
15
+ if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
16
+ const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
17
+ if (platformDir) {
18
+ await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:update');
19
+ }
20
+ else {
21
+ log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
22
+ }
23
+ }
24
+ else {
25
+ const then = +new Date();
26
+ const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
27
+ try {
28
+ await (0, common_1.check)([() => (0, common_1.checkPackage)(), ...updateChecks(config, platforms)]);
29
+ await (0, promise_1.allSerial)(platforms.map((platformName) => async () => await update(config, platformName, deployment)));
30
+ const now = +new Date();
31
+ const diff = (now - then) / 1000;
32
+ log_1.logger.info(`Update finished in ${diff}s`);
33
+ }
34
+ catch (e) {
35
+ if (!(0, errors_1.isFatal)(e)) {
36
+ (0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
37
+ }
38
+ throw e;
39
+ }
40
+ }
41
+ }
42
+ exports.updateCommand = updateCommand;
43
+ function updateChecks(config, platforms) {
44
+ const checks = [];
45
+ for (const platformName of platforms) {
46
+ if (platformName === config.ios.name) {
47
+ checks.push(() => (0, common_2.checkBundler)(config) || (0, common_2.checkCocoaPods)(config));
48
+ }
49
+ else if (platformName === config.android.name) {
50
+ continue;
51
+ }
52
+ else if (platformName === config.web.name) {
53
+ continue;
54
+ }
55
+ else {
56
+ throw `Platform ${platformName} is not valid.`;
57
+ }
58
+ }
59
+ return checks;
60
+ }
61
+ exports.updateChecks = updateChecks;
62
+ async function update(config, platformName, deployment) {
63
+ await (0, common_1.runTask)(colors_1.default.success(colors_1.default.strong(`update ${platformName}`)), async () => {
64
+ await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:update:before');
65
+ if (platformName === config.ios.name) {
66
+ await (0, update_2.updateIOS)(config, deployment);
67
+ }
68
+ else if (platformName === config.android.name) {
69
+ await (0, update_1.updateAndroid)(config);
70
+ }
71
+ await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:update:after');
72
+ });
73
+ }
74
+ exports.update = update;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendMetric = exports.telemetryAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const commander_1 = require("commander");
6
+ const debug_1 = tslib_1.__importDefault(require("debug"));
7
+ const colors_1 = tslib_1.__importDefault(require("./colors"));
8
+ const ipc_1 = require("./ipc");
9
+ const log_1 = require("./log");
10
+ const sysconfig_1 = require("./sysconfig");
11
+ const subprocess_1 = require("./util/subprocess");
12
+ const term_1 = require("./util/term");
13
+ const debug = (0, debug_1.default)('capacitor:telemetry');
14
+ const THANK_YOU = `\nThank you for helping improve Capacitor by sharing anonymous usage data! 💖` +
15
+ `\nInformation about the data we collect is available on our website: ${colors_1.default.strong('https://capacitorjs.com/docs/next/cli/telemetry')}` +
16
+ `\nYou can disable telemetry at any time by using the ${colors_1.default.input('npx cap telemetry off')} command.`;
17
+ function telemetryAction(config, action) {
18
+ return async (...actionArgs) => {
19
+ const start = new Date();
20
+ // This is how commanderjs works--the command object is either the last
21
+ // element or second to last if there are additional options (via `.allowUnknownOption()`)
22
+ const lastArg = actionArgs[actionArgs.length - 1];
23
+ const cmd = lastArg instanceof commander_1.Command ? lastArg : actionArgs[actionArgs.length - 2];
24
+ const command = getFullCommandName(cmd);
25
+ let error;
26
+ try {
27
+ await action(...actionArgs);
28
+ }
29
+ catch (e) {
30
+ error = e;
31
+ }
32
+ const end = new Date();
33
+ const duration = end.getTime() - start.getTime();
34
+ const packages = Object.entries({
35
+ ...config.app.package.devDependencies,
36
+ ...config.app.package.dependencies,
37
+ });
38
+ // Only collect packages in the capacitor org:
39
+ // https://www.npmjs.com/org/capacitor
40
+ const capacitorPackages = packages.filter(([k]) => k.startsWith('@capacitor/'));
41
+ const versions = capacitorPackages.map(([k, v]) => [
42
+ `${k.replace(/^@capacitor\//, '').replace(/-/g, '_')}_version`,
43
+ v,
44
+ ]);
45
+ const data = {
46
+ app_id: await getAppIdentifier(config),
47
+ command,
48
+ arguments: cmd.args.join(' '),
49
+ options: JSON.stringify(cmd.opts()),
50
+ duration,
51
+ error: error ? (error.message ? error.message : String(error)) : null,
52
+ node_version: process.version,
53
+ os: config.cli.os,
54
+ ...Object.fromEntries(versions),
55
+ };
56
+ if ((0, term_1.isInteractive)()) {
57
+ let sysconfig = await (0, sysconfig_1.readConfig)();
58
+ if (!error && typeof sysconfig.telemetry === 'undefined') {
59
+ // Telemetry is opt-out; turn telemetry on then inform the user how to opt-out.
60
+ sysconfig = { ...sysconfig, telemetry: true };
61
+ await (0, sysconfig_1.writeConfig)(sysconfig);
62
+ log_1.output.write(THANK_YOU);
63
+ }
64
+ await sendMetric(sysconfig, 'capacitor_cli_command', data);
65
+ }
66
+ if (error) {
67
+ throw error;
68
+ }
69
+ };
70
+ }
71
+ exports.telemetryAction = telemetryAction;
72
+ /**
73
+ * If telemetry is enabled, send a metric via IPC to a forked process for uploading.
74
+ */
75
+ async function sendMetric(sysconfig, name, data) {
76
+ if (sysconfig.telemetry && (0, term_1.isInteractive)()) {
77
+ const message = {
78
+ name,
79
+ timestamp: new Date().toISOString(),
80
+ session_id: sysconfig.machine,
81
+ source: 'capacitor_cli',
82
+ value: data,
83
+ };
84
+ await (0, ipc_1.send)({ type: 'telemetry', data: message });
85
+ }
86
+ else {
87
+ debug('Telemetry is off (user choice, non-interactive terminal, or CI)--not sending metric');
88
+ }
89
+ }
90
+ exports.sendMetric = sendMetric;
91
+ /**
92
+ * Get a unique anonymous identifier for this app.
93
+ */
94
+ async function getAppIdentifier(config) {
95
+ const { createHash } = await Promise.resolve().then(() => tslib_1.__importStar(require('crypto')));
96
+ // get the first commit hash, which should be universally unique
97
+ const output = await (0, subprocess_1.getCommandOutput)('git', ['rev-list', '--max-parents=0', 'HEAD'], { cwd: config.app.rootDir });
98
+ const firstLine = output === null || output === void 0 ? void 0 : output.split('\n')[0];
99
+ if (!firstLine) {
100
+ debug('Could not obtain unique app identifier');
101
+ return null;
102
+ }
103
+ // use sha1 to create a one-way hash to anonymize
104
+ const id = createHash('sha1').update(firstLine).digest('hex');
105
+ return id;
106
+ }
107
+ /**
108
+ * Walk through the command's parent tree and construct a space-separated name.
109
+ *
110
+ * Probably overkill because we don't have nested commands, but whatever.
111
+ */
112
+ function getFullCommandName(cmd) {
113
+ const names = [];
114
+ while (cmd.parent !== null) {
115
+ names.push(cmd.name());
116
+ cmd = cmd.parent;
117
+ }
118
+ return names.reverse().join(' ');
119
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapAction = exports.ENV_PATHS = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const env_paths_1 = tslib_1.__importDefault(require("env-paths"));
6
+ const errors_1 = require("../errors");
7
+ const log_1 = require("../log");
8
+ exports.ENV_PATHS = (0, env_paths_1.default)('capacitor', { suffix: '' });
9
+ function wrapAction(action) {
10
+ return async (...args) => {
11
+ try {
12
+ await action(...args);
13
+ }
14
+ catch (e) {
15
+ if ((0, errors_1.isFatal)(e)) {
16
+ process.exitCode = e.exitCode;
17
+ log_1.logger.error(e.message);
18
+ }
19
+ else {
20
+ throw e;
21
+ }
22
+ }
23
+ };
24
+ }
25
+ exports.wrapAction = wrapAction;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emoji = void 0;
4
+ // Emoji falback, right now just uses fallback on windows,
5
+ // but could expand to be more sophisticated to allow emoji
6
+ // on Hyper term on windows, for example.
7
+ const emoji = (x, fallback) => {
8
+ if (process.platform === 'win32') {
9
+ return fallback;
10
+ }
11
+ return x;
12
+ };
13
+ exports.emoji = emoji;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tryFn = void 0;
4
+ const tryFn = async (fn, ...args) => {
5
+ try {
6
+ return await fn(...args);
7
+ }
8
+ catch {
9
+ // ignore
10
+ }
11
+ return null;
12
+ };
13
+ exports.tryFn = tryFn;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readdirp = exports.deleteFolderRecursive = exports.convertToUnixPath = void 0;
4
+ const fs_1 = require("fs");
5
+ const promises_1 = require("fs/promises");
6
+ const fs_extra_1 = require("fs-extra");
7
+ const path_1 = require("path");
8
+ const convertToUnixPath = (path) => {
9
+ return path.replace(/\\/g, '/');
10
+ };
11
+ exports.convertToUnixPath = convertToUnixPath;
12
+ const deleteFolderRecursive = (directoryPath) => {
13
+ if ((0, fs_extra_1.existsSync)(directoryPath)) {
14
+ (0, fs_extra_1.readdirSync)(directoryPath).forEach((file) => {
15
+ const curPath = (0, path_1.join)(directoryPath, file);
16
+ if ((0, fs_extra_1.lstatSync)(curPath).isDirectory()) {
17
+ (0, exports.deleteFolderRecursive)(curPath);
18
+ }
19
+ else {
20
+ (0, fs_extra_1.unlinkSync)(curPath);
21
+ }
22
+ });
23
+ (0, fs_extra_1.rmdirSync)(directoryPath);
24
+ }
25
+ };
26
+ exports.deleteFolderRecursive = deleteFolderRecursive;
27
+ async function readdirp(dir, { filter }) {
28
+ const dirContent = await (0, promises_1.readdir)(dir, { recursive: true });
29
+ const dirContentWalker = [];
30
+ const filteredContent = [];
31
+ dirContent.forEach((element) => {
32
+ const path = (0, path_1.join)(dir, element);
33
+ const stats = (0, fs_1.statSync)(path);
34
+ dirContentWalker.push({ path, stats });
35
+ });
36
+ dirContentWalker.forEach((element) => {
37
+ if (filter(element)) {
38
+ filteredContent.push(element.path);
39
+ }
40
+ });
41
+ return filteredContent;
42
+ }
43
+ exports.readdirp = readdirp;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateIOSPackageJSON = exports.writePluginJSON = exports.findPluginClasses = exports.getPluginFiles = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("path");
6
+ const cordova_1 = require("../cordova");
7
+ const plugin_1 = require("../plugin");
8
+ const fs_1 = require("./fs");
9
+ async function getPluginFiles(plugins) {
10
+ var _a;
11
+ let filenameList = [];
12
+ const options = {
13
+ filter: (item) => {
14
+ if (item.stats.isFile() && (item.path.endsWith('.swift') || item.path.endsWith('.m'))) {
15
+ return true;
16
+ }
17
+ else {
18
+ return false;
19
+ }
20
+ },
21
+ };
22
+ for (const plugin of plugins) {
23
+ if (plugin.ios && (0, plugin_1.getPluginType)(plugin, 'ios') === 0 /* PluginType.Core */) {
24
+ const pluginPath = (0, path_1.resolve)(plugin.rootPath, (_a = plugin.ios) === null || _a === void 0 ? void 0 : _a.path);
25
+ const filenames = await (0, fs_1.readdirp)(pluginPath, options);
26
+ filenameList = filenameList.concat(filenames);
27
+ }
28
+ }
29
+ return filenameList;
30
+ }
31
+ exports.getPluginFiles = getPluginFiles;
32
+ async function findPluginClasses(files) {
33
+ const classList = [];
34
+ for (const file of files) {
35
+ const fileData = (0, fs_extra_1.readFileSync)(file, 'utf-8');
36
+ const swiftPluginRegex = RegExp(/@objc\(([A-Za-z0-9_-]+)\)/);
37
+ const objcPluginRegex = RegExp(/CAP_PLUGIN\(([A-Za-z0-9_-]+)/);
38
+ const swiftMatches = swiftPluginRegex.exec(fileData);
39
+ if ((swiftMatches === null || swiftMatches === void 0 ? void 0 : swiftMatches[1]) && !classList.includes(swiftMatches[1])) {
40
+ classList.push(swiftMatches[1]);
41
+ }
42
+ const objcMatches = objcPluginRegex.exec(fileData);
43
+ if ((objcMatches === null || objcMatches === void 0 ? void 0 : objcMatches[1]) && !classList.includes(objcMatches[1])) {
44
+ classList.push(objcMatches[1]);
45
+ }
46
+ }
47
+ return classList;
48
+ }
49
+ exports.findPluginClasses = findPluginClasses;
50
+ async function writePluginJSON(config, classList) {
51
+ const capJSONFile = (0, path_1.resolve)(config.ios.nativeTargetDirAbs, 'capacitor.config.json');
52
+ const capJSON = (0, fs_extra_1.readJSONSync)(capJSONFile);
53
+ capJSON['packageClassList'] = classList;
54
+ (0, fs_extra_1.writeJSONSync)(capJSONFile, capJSON, { spaces: '\t' });
55
+ }
56
+ exports.writePluginJSON = writePluginJSON;
57
+ async function generateIOSPackageJSON(config, plugins) {
58
+ const fileList = await getPluginFiles(plugins);
59
+ const classList = await findPluginClasses(fileList);
60
+ const cordovaPlugins = await (0, cordova_1.getCordovaPlugins)(config, 'ios');
61
+ if (cordovaPlugins.length > 0) {
62
+ classList.push('CDVPlugin');
63
+ }
64
+ writePluginJSON(config, classList);
65
+ }
66
+ exports.generateIOSPackageJSON = generateIOSPackageJSON;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatJSObject = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const util_1 = tslib_1.__importDefault(require("util"));
6
+ function formatJSObject(o) {
7
+ try {
8
+ o = JSON.parse(JSON.stringify(o));
9
+ }
10
+ catch (e) {
11
+ throw new Error(`Cannot parse object as JSON: ${e.stack ? e.stack : e}`);
12
+ }
13
+ return util_1.default.inspect(o, {
14
+ compact: false,
15
+ breakLength: Infinity,
16
+ depth: Infinity,
17
+ maxArrayLength: Infinity,
18
+ maxStringLength: Infinity,
19
+ });
20
+ }
21
+ exports.formatJSObject = formatJSObject;