@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
package/dist/plugin.js ADDED
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllElements = exports.getFilePath = exports.getAssets = exports.getJSModules = exports.getPluginType = exports.getPlatformElement = exports.getPluginPlatform = exports.printPlugins = exports.fixName = exports.getDependencies = exports.resolvePlugin = exports.getPlugins = exports.getIncludedPluginPackages = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const path_1 = require("path");
7
+ const colors_1 = tslib_1.__importDefault(require("./colors"));
8
+ const errors_1 = require("./errors");
9
+ const log_1 = require("./log");
10
+ const node_1 = require("./util/node");
11
+ const xml_1 = require("./util/xml");
12
+ function getIncludedPluginPackages(config, platform) {
13
+ var _a, _b, _c, _d;
14
+ const { extConfig } = config.app;
15
+ switch (platform) {
16
+ case 'android':
17
+ return (_b = (_a = extConfig.android) === null || _a === void 0 ? void 0 : _a.includePlugins) !== null && _b !== void 0 ? _b : extConfig.includePlugins;
18
+ case 'ios':
19
+ return (_d = (_c = extConfig.ios) === null || _c === void 0 ? void 0 : _c.includePlugins) !== null && _d !== void 0 ? _d : extConfig.includePlugins;
20
+ }
21
+ }
22
+ exports.getIncludedPluginPackages = getIncludedPluginPackages;
23
+ async function getPlugins(config, platform) {
24
+ var _a;
25
+ const possiblePlugins = (_a = getIncludedPluginPackages(config, platform)) !== null && _a !== void 0 ? _a : getDependencies(config);
26
+ const resolvedPlugins = await Promise.all(possiblePlugins.map(async (p) => resolvePlugin(config, p)));
27
+ return resolvedPlugins.filter((p) => !!p);
28
+ }
29
+ exports.getPlugins = getPlugins;
30
+ async function resolvePlugin(config, name) {
31
+ try {
32
+ const packagePath = (0, node_1.resolveNode)(config.app.rootDir, name, 'package.json');
33
+ if (!packagePath) {
34
+ (0, errors_1.fatal)(`Unable to find ${colors_1.default.strong(`node_modules/${name}`)}.\n` + `Are you sure ${colors_1.default.strong(name)} is installed?`);
35
+ }
36
+ const rootPath = (0, path_1.dirname)(packagePath);
37
+ const meta = await (0, fs_extra_1.readJSON)(packagePath);
38
+ if (!meta) {
39
+ return null;
40
+ }
41
+ if (meta.capacitor) {
42
+ return {
43
+ id: name,
44
+ name: fixName(name),
45
+ version: meta.version,
46
+ rootPath,
47
+ repository: meta.repository,
48
+ manifest: meta.capacitor,
49
+ };
50
+ }
51
+ const pluginXMLPath = (0, path_1.join)(rootPath, 'plugin.xml');
52
+ const xmlMeta = await (0, xml_1.readXML)(pluginXMLPath);
53
+ return {
54
+ id: name,
55
+ name: fixName(name),
56
+ version: meta.version,
57
+ rootPath: rootPath,
58
+ repository: meta.repository,
59
+ xml: xmlMeta.plugin,
60
+ };
61
+ }
62
+ catch (e) {
63
+ // ignore
64
+ }
65
+ return null;
66
+ }
67
+ exports.resolvePlugin = resolvePlugin;
68
+ function getDependencies(config) {
69
+ var _a, _b;
70
+ return [
71
+ ...Object.keys((_a = config.app.package.dependencies) !== null && _a !== void 0 ? _a : {}),
72
+ ...Object.keys((_b = config.app.package.devDependencies) !== null && _b !== void 0 ? _b : {}),
73
+ ];
74
+ }
75
+ exports.getDependencies = getDependencies;
76
+ function fixName(name) {
77
+ name = name
78
+ .replace(/\//g, '_')
79
+ .replace(/-/g, '_')
80
+ .replace(/@/g, '')
81
+ .replace(/_\w/g, (m) => m[1].toUpperCase());
82
+ return name.charAt(0).toUpperCase() + name.slice(1);
83
+ }
84
+ exports.fixName = fixName;
85
+ function printPlugins(plugins, platform, type = 'capacitor') {
86
+ if (plugins.length === 0) {
87
+ return;
88
+ }
89
+ let msg;
90
+ const plural = plugins.length === 1 ? '' : 's';
91
+ switch (type) {
92
+ case 'cordova':
93
+ msg = `Found ${plugins.length} Cordova plugin${plural} for ${colors_1.default.strong(platform)}:\n`;
94
+ break;
95
+ case 'incompatible':
96
+ msg = `Found ${plugins.length} incompatible Cordova plugin${plural} for ${colors_1.default.strong(platform)}, skipped install:\n`;
97
+ break;
98
+ case 'capacitor':
99
+ msg = `Found ${plugins.length} Capacitor plugin${plural} for ${colors_1.default.strong(platform)}:\n`;
100
+ break;
101
+ }
102
+ msg += plugins.map((p) => `${p.id}${colors_1.default.weak(`@${p.version}`)}`).join('\n');
103
+ log_1.logger.info(msg);
104
+ }
105
+ exports.printPlugins = printPlugins;
106
+ function getPluginPlatform(p, platform) {
107
+ const platforms = p.xml.platform;
108
+ if (platforms) {
109
+ const platforms = p.xml.platform.filter(function (item) {
110
+ return item.$.name === platform;
111
+ });
112
+ return platforms[0];
113
+ }
114
+ return [];
115
+ }
116
+ exports.getPluginPlatform = getPluginPlatform;
117
+ function getPlatformElement(p, platform, elementName) {
118
+ const platformTag = getPluginPlatform(p, platform);
119
+ if (platformTag) {
120
+ const element = platformTag[elementName];
121
+ if (element) {
122
+ return element;
123
+ }
124
+ }
125
+ return [];
126
+ }
127
+ exports.getPlatformElement = getPlatformElement;
128
+ function getPluginType(p, platform) {
129
+ var _a, _b, _c, _d;
130
+ switch (platform) {
131
+ case 'ios':
132
+ return (_b = (_a = p.ios) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 0 /* PluginType.Core */;
133
+ case 'android':
134
+ return (_d = (_c = p.android) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : 0 /* PluginType.Core */;
135
+ }
136
+ return 0 /* PluginType.Core */;
137
+ }
138
+ exports.getPluginType = getPluginType;
139
+ /**
140
+ * Get each JavaScript Module for the given plugin
141
+ */
142
+ function getJSModules(p, platform) {
143
+ return getAllElements(p, platform, 'js-module');
144
+ }
145
+ exports.getJSModules = getJSModules;
146
+ /**
147
+ * Get each asset tag for the given plugin
148
+ */
149
+ function getAssets(p, platform) {
150
+ return getAllElements(p, platform, 'asset');
151
+ }
152
+ exports.getAssets = getAssets;
153
+ function getFilePath(config, plugin, path) {
154
+ if (path.startsWith('node_modules')) {
155
+ let pathSegments = path.split('/').slice(1);
156
+ if (pathSegments[0].startsWith('@')) {
157
+ pathSegments = [pathSegments[0] + '/' + pathSegments[1], ...pathSegments.slice(2)];
158
+ }
159
+ const filePath = (0, node_1.resolveNode)(config.app.rootDir, ...pathSegments);
160
+ if (!filePath) {
161
+ throw new Error(`Can't resolve module ${pathSegments[0]}`);
162
+ }
163
+ return filePath;
164
+ }
165
+ return (0, path_1.join)(plugin.rootPath, path);
166
+ }
167
+ exports.getFilePath = getFilePath;
168
+ /**
169
+ * For a given plugin, return all the plugin.xml elements with elementName, checking root and specified platform
170
+ */
171
+ function getAllElements(p, platform, elementName) {
172
+ let modules = [];
173
+ if (p.xml[elementName]) {
174
+ modules = modules.concat(p.xml[elementName]);
175
+ }
176
+ const platformModules = getPluginPlatform(p, platform);
177
+ if (platformModules === null || platformModules === void 0 ? void 0 : platformModules[elementName]) {
178
+ modules = modules.concat(platformModules[elementName]);
179
+ }
180
+ return modules;
181
+ }
182
+ exports.getAllElements = getAllElements;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeConfig = exports.readConfig = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
+ const fs_extra_1 = require("fs-extra");
7
+ const path_1 = require("path");
8
+ const cli_1 = require("./util/cli");
9
+ const uuid_1 = require("./util/uuid");
10
+ const debug = (0, debug_1.default)('capacitor:sysconfig');
11
+ const SYSCONFIG_FILE = 'sysconfig.json';
12
+ const SYSCONFIG_PATH = (0, path_1.resolve)(cli_1.ENV_PATHS.config, SYSCONFIG_FILE);
13
+ async function readConfig() {
14
+ debug('Reading from %O', SYSCONFIG_PATH);
15
+ try {
16
+ return await (0, fs_extra_1.readJSON)(SYSCONFIG_PATH);
17
+ }
18
+ catch (e) {
19
+ if (e.code !== 'ENOENT') {
20
+ throw e;
21
+ }
22
+ const sysconfig = {
23
+ machine: (0, uuid_1.uuidv4)(),
24
+ };
25
+ await writeConfig(sysconfig);
26
+ return sysconfig;
27
+ }
28
+ }
29
+ exports.readConfig = readConfig;
30
+ async function writeConfig(sysconfig) {
31
+ debug('Writing to %O', SYSCONFIG_PATH);
32
+ await (0, fs_extra_1.mkdirp)((0, path_1.dirname)(SYSCONFIG_PATH));
33
+ await (0, fs_extra_1.writeJSON)(SYSCONFIG_PATH, sysconfig, { spaces: '\t' });
34
+ }
35
+ exports.writeConfig = writeConfig;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const utils_terminal_1 = require("@ionic/utils-terminal");
6
+ const fs_extra_1 = require("fs-extra");
7
+ const add_1 = require("../android/add");
8
+ const common_1 = require("../android/common");
9
+ const colors_1 = tslib_1.__importDefault(require("../colors"));
10
+ const common_2 = require("../common");
11
+ const errors_1 = require("../errors");
12
+ const add_2 = require("../ios/add");
13
+ const common_3 = require("../ios/common");
14
+ const log_1 = require("../log");
15
+ const sync_1 = require("./sync");
16
+ async function addCommand(config, selectedPlatformName) {
17
+ var _a;
18
+ if (selectedPlatformName && !(await (0, common_2.isValidPlatform)(selectedPlatformName))) {
19
+ const platformDir = (0, common_2.resolvePlatform)(config, selectedPlatformName);
20
+ if (platformDir) {
21
+ await (0, common_2.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:add');
22
+ }
23
+ else {
24
+ let msg = `Platform ${colors_1.default.input(selectedPlatformName)} not found.`;
25
+ if (await (0, common_2.isValidCommunityPlatform)(selectedPlatformName)) {
26
+ msg += `\nTry installing ${colors_1.default.strong(`@capacitor-community/${selectedPlatformName}`)} and adding the platform again.`;
27
+ }
28
+ if (await (0, common_2.isValidEnterprisePlatform)(selectedPlatformName)) {
29
+ msg +=
30
+ `\nThis is an enterprise platform and @ionic-enterprise/capacitor-${selectedPlatformName} is not installed.\n` +
31
+ `To learn how to use this platform, visit https://ionic.io/docs/${selectedPlatformName}`;
32
+ }
33
+ log_1.logger.error(msg);
34
+ }
35
+ }
36
+ else {
37
+ const knownPlatforms = await (0, common_2.getKnownPlatforms)();
38
+ const platformName = await (0, common_2.promptForPlatform)(knownPlatforms, `Please choose a platform to add:`, selectedPlatformName);
39
+ if (platformName === config.web.name) {
40
+ webWarning();
41
+ return;
42
+ }
43
+ const existingPlatformDir = await (0, common_2.getProjectPlatformDirectory)(config, platformName);
44
+ if (existingPlatformDir) {
45
+ (0, errors_1.fatal)(`${colors_1.default.input(platformName)} platform already exists.\n` +
46
+ `To re-add this platform, first remove ${colors_1.default.strong((0, utils_terminal_1.prettyPath)(existingPlatformDir))}, then run this command again.\n` +
47
+ `${colors_1.default.strong('WARNING')}: Your native project will be completely removed.`);
48
+ }
49
+ try {
50
+ await (0, common_2.check)([() => (0, common_2.checkPackage)(), () => (0, common_2.checkAppConfig)(config), ...addChecks(config, platformName)]);
51
+ await doAdd(config, platformName);
52
+ await editPlatforms(config, platformName);
53
+ if (await (0, fs_extra_1.pathExists)(config.app.webDirAbs)) {
54
+ await (0, sync_1.sync)(config, platformName, false, false);
55
+ if (platformName === config.android.name) {
56
+ await (0, common_2.runTask)('Syncing Gradle', async () => {
57
+ return (0, add_1.createLocalProperties)(config.android.platformDirAbs);
58
+ });
59
+ }
60
+ }
61
+ else {
62
+ log_1.logger.warn(`${colors_1.default.success(colors_1.default.strong('sync'))} could not run--missing ${colors_1.default.strong(config.app.webDir)} directory.`);
63
+ }
64
+ printNextSteps(platformName);
65
+ }
66
+ catch (e) {
67
+ if (!(0, errors_1.isFatal)(e)) {
68
+ (0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
69
+ }
70
+ throw e;
71
+ }
72
+ }
73
+ }
74
+ exports.addCommand = addCommand;
75
+ function printNextSteps(platformName) {
76
+ (0, log_1.logSuccess)(`${colors_1.default.strong(platformName)} platform added!`);
77
+ log_1.output.write(`Follow the Developer Workflow guide to get building:\n${colors_1.default.strong(`https://capacitorjs.com/docs/basics/workflow`)}\n`);
78
+ }
79
+ function addChecks(config, platformName) {
80
+ if (platformName === config.ios.name) {
81
+ return [() => (0, common_3.checkIOSPackage)(config), () => (0, common_3.checkBundler)(config) || (0, common_3.checkCocoaPods)(config)];
82
+ }
83
+ else if (platformName === config.android.name) {
84
+ return [() => (0, common_1.checkAndroidPackage)(config)];
85
+ }
86
+ else if (platformName === config.web.name) {
87
+ return [];
88
+ }
89
+ else {
90
+ throw `Platform ${platformName} is not valid.`;
91
+ }
92
+ }
93
+ async function doAdd(config, platformName) {
94
+ await (0, common_2.runTask)(colors_1.default.success(colors_1.default.strong('add')), async () => {
95
+ if (platformName === config.ios.name) {
96
+ await (0, add_2.addIOS)(config);
97
+ }
98
+ else if (platformName === config.android.name) {
99
+ await (0, add_1.addAndroid)(config);
100
+ }
101
+ });
102
+ }
103
+ async function editPlatforms(config, platformName) {
104
+ if (platformName === config.ios.name) {
105
+ await (0, common_3.editProjectSettingsIOS)(config);
106
+ }
107
+ else if (platformName === config.android.name) {
108
+ await (0, common_1.editProjectSettingsAndroid)(config);
109
+ }
110
+ }
111
+ function webWarning() {
112
+ log_1.logger.error(`Not adding platform ${colors_1.default.strong('web')}.\n` +
113
+ `In Capacitor, the web platform is just your web app! For example, if you have a React or Angular project, the web platform is that project.\n` +
114
+ `To add Capacitor functionality to your web app, follow the Web Getting Started Guide: ${colors_1.default.strong('https://capacitorjs.com/docs/web')}`);
115
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.build = exports.buildCommand = void 0;
4
+ const build_1 = require("../android/build");
5
+ const common_1 = require("../common");
6
+ const definitions_1 = require("../definitions");
7
+ const errors_1 = require("../errors");
8
+ const build_2 = require("../ios/build");
9
+ async function buildCommand(config, selectedPlatformName, buildOptions) {
10
+ var _a;
11
+ const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
12
+ let platformName;
13
+ if (platforms.length === 1) {
14
+ platformName = platforms[0];
15
+ }
16
+ else {
17
+ platformName = await (0, common_1.promptForPlatform)(platforms.filter(createBuildablePlatformFilter(config)), `Please choose a platform to build for:`);
18
+ }
19
+ const buildCommandOptions = {
20
+ scheme: buildOptions.scheme || config.ios.scheme,
21
+ flavor: buildOptions.flavor || config.android.flavor,
22
+ keystorepath: buildOptions.keystorepath || config.android.buildOptions.keystorePath,
23
+ keystorepass: buildOptions.keystorepass || config.android.buildOptions.keystorePassword,
24
+ keystorealias: buildOptions.keystorealias || config.android.buildOptions.keystoreAlias,
25
+ keystorealiaspass: buildOptions.keystorealiaspass || config.android.buildOptions.keystoreAliasPassword,
26
+ androidreleasetype: buildOptions.androidreleasetype || config.android.buildOptions.releaseType || 'AAB',
27
+ signingtype: buildOptions.signingtype || config.android.buildOptions.signingType || 'jarsigner',
28
+ configuration: buildOptions.configuration || 'Release',
29
+ xcodeTeamId: buildOptions.xcodeTeamId || config.ios.buildOptions.teamId,
30
+ xcodeExportMethod: buildOptions.xcodeExportMethod || config.ios.buildOptions.exportMethod || definitions_1.XcodeExportMethod.AppStoreConnect,
31
+ xcodeSigningType: buildOptions.xcodeSigningType || config.ios.buildOptions.xcodeSigningStyle || 'automatic',
32
+ xcodeSigningCertificate: buildOptions.xcodeSigningCertificate || config.ios.buildOptions.signingCertificate,
33
+ xcodeProvisioningProfile: buildOptions.xcodeProvisioningProfile || config.ios.buildOptions.provisioningProfile,
34
+ };
35
+ try {
36
+ await build(config, platformName, buildCommandOptions);
37
+ }
38
+ catch (e) {
39
+ if (!(0, errors_1.isFatal)(e)) {
40
+ (0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
41
+ }
42
+ throw e;
43
+ }
44
+ }
45
+ exports.buildCommand = buildCommand;
46
+ async function build(config, platformName, buildOptions) {
47
+ if (platformName == config.ios.name) {
48
+ await (0, build_2.buildiOS)(config, buildOptions);
49
+ }
50
+ else if (platformName === config.android.name) {
51
+ await (0, build_1.buildAndroid)(config, buildOptions);
52
+ }
53
+ else if (platformName === config.web.name) {
54
+ throw `Platform "${platformName}" is not available in the build command.`;
55
+ }
56
+ else {
57
+ throw `Platform "${platformName}" is not valid.`;
58
+ }
59
+ }
60
+ exports.build = build;
61
+ function createBuildablePlatformFilter(config) {
62
+ return (platform) => platform === config.ios.name || platform === config.android.name;
63
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const util_1 = tslib_1.__importDefault(require("util"));
6
+ const log_1 = require("../log");
7
+ async function configCommand(config, json) {
8
+ const evaluatedConfig = await deepAwait(config);
9
+ if (json) {
10
+ process.stdout.write(`${JSON.stringify(evaluatedConfig)}\n`);
11
+ }
12
+ else {
13
+ log_1.output.write(`${util_1.default.inspect(evaluatedConfig, { depth: Infinity, colors: true })}\n`);
14
+ }
15
+ }
16
+ exports.configCommand = configCommand;
17
+ async function deepAwait(obj) {
18
+ if (obj && !Array.isArray(obj) && typeof obj === 'object' && obj.constructor === Object) {
19
+ const o = {};
20
+ for (const [k, v] of Object.entries(obj)) {
21
+ o[k] = await deepAwait(v);
22
+ }
23
+ return o;
24
+ }
25
+ else {
26
+ return await obj;
27
+ }
28
+ }
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copy = exports.copyCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const path_1 = require("path");
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 common_2 = require("../ios/common");
12
+ const log_1 = require("../log");
13
+ const plugin_1 = require("../plugin");
14
+ const iosplugin_1 = require("../util/iosplugin");
15
+ const promise_1 = require("../util/promise");
16
+ const sourcemaps_1 = require("./sourcemaps");
17
+ async function copyCommand(config, selectedPlatformName, inline = false) {
18
+ var _a;
19
+ if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
20
+ const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
21
+ if (platformDir) {
22
+ await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:copy');
23
+ }
24
+ else {
25
+ log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
26
+ }
27
+ }
28
+ else {
29
+ const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
30
+ try {
31
+ await (0, promise_1.allSerial)(platforms.map((platformName) => () => copy(config, platformName, inline)));
32
+ }
33
+ catch (e) {
34
+ if ((0, errors_1.isFatal)(e)) {
35
+ throw e;
36
+ }
37
+ log_1.logger.error((_a = e.stack) !== null && _a !== void 0 ? _a : e);
38
+ }
39
+ }
40
+ }
41
+ exports.copyCommand = copyCommand;
42
+ async function copy(config, platformName, inline = false) {
43
+ await (0, common_1.runTask)(colors_1.default.success(colors_1.default.strong(`copy ${platformName}`)), async () => {
44
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
45
+ const result = await (0, common_1.checkWebDir)(config);
46
+ if (result) {
47
+ throw result;
48
+ }
49
+ await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:copy:before');
50
+ const allPlugins = await (0, plugin_1.getPlugins)(config, platformName);
51
+ let usesFederatedCapacitor = false;
52
+ if (allPlugins.filter((plugin) => plugin.id === '@ionic-enterprise/federated-capacitor').length > 0) {
53
+ usesFederatedCapacitor = true;
54
+ }
55
+ let usesLiveUpdates = false;
56
+ if (allPlugins.filter((plugin) => plugin.id === '@capacitor/live-updates').length > 0) {
57
+ usesLiveUpdates = true;
58
+ }
59
+ let usesSSLPinning = false;
60
+ if (allPlugins.filter((plugin) => plugin.id === '@ionic-enterprise/ssl-pinning' || plugin.id === '@capacitor/ssl-pinning').length > 0) {
61
+ usesSSLPinning = true;
62
+ }
63
+ if (platformName === config.ios.name) {
64
+ if (usesFederatedCapacitor) {
65
+ await copyFederatedWebDirs(config, await config.ios.webDirAbs);
66
+ if ((_c = (_b = (_a = config.app.extConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.FederatedCapacitor) === null || _c === void 0 ? void 0 : _c.liveUpdatesKey) {
67
+ await copySecureLiveUpdatesKey(config.app.extConfig.plugins.FederatedCapacitor.liveUpdatesKey, config.app.rootDir, config.ios.nativeTargetDirAbs);
68
+ }
69
+ }
70
+ else {
71
+ await copyWebDir(config, await config.ios.webDirAbs, config.app.webDirAbs);
72
+ }
73
+ if (usesLiveUpdates && ((_f = (_e = (_d = config.app.extConfig) === null || _d === void 0 ? void 0 : _d.plugins) === null || _e === void 0 ? void 0 : _e.LiveUpdates) === null || _f === void 0 ? void 0 : _f.key)) {
74
+ await copySecureLiveUpdatesKey(config.app.extConfig.plugins.LiveUpdates.key, config.app.rootDir, config.ios.nativeTargetDirAbs);
75
+ }
76
+ if (usesSSLPinning && ((_j = (_h = (_g = config.app.extConfig) === null || _g === void 0 ? void 0 : _g.plugins) === null || _h === void 0 ? void 0 : _h.SSLPinning) === null || _j === void 0 ? void 0 : _j.certs)) {
77
+ await copySSLCert((_k = config.app.extConfig.plugins.SSLPinning) === null || _k === void 0 ? void 0 : _k.certs, config.app.rootDir, await config.ios.webDirAbs);
78
+ }
79
+ await copyCapacitorConfig(config, config.ios.nativeTargetDirAbs);
80
+ const cordovaPlugins = await (0, cordova_1.getCordovaPlugins)(config, platformName);
81
+ await (0, cordova_1.handleCordovaPluginsJS)(cordovaPlugins, config, platformName);
82
+ const iosPlugins = await (0, common_2.getIOSPlugins)(allPlugins);
83
+ await (0, iosplugin_1.generateIOSPackageJSON)(config, iosPlugins);
84
+ }
85
+ else if (platformName === config.android.name) {
86
+ if (usesFederatedCapacitor) {
87
+ await copyFederatedWebDirs(config, config.android.webDirAbs);
88
+ if ((_o = (_m = (_l = config.app.extConfig) === null || _l === void 0 ? void 0 : _l.plugins) === null || _m === void 0 ? void 0 : _m.FederatedCapacitor) === null || _o === void 0 ? void 0 : _o.liveUpdatesKey) {
89
+ await copySecureLiveUpdatesKey(config.app.extConfig.plugins.FederatedCapacitor.liveUpdatesKey, config.app.rootDir, config.android.assetsDirAbs);
90
+ }
91
+ }
92
+ else {
93
+ await copyWebDir(config, config.android.webDirAbs, config.app.webDirAbs);
94
+ }
95
+ if (usesLiveUpdates && ((_r = (_q = (_p = config.app.extConfig) === null || _p === void 0 ? void 0 : _p.plugins) === null || _q === void 0 ? void 0 : _q.LiveUpdates) === null || _r === void 0 ? void 0 : _r.key)) {
96
+ await copySecureLiveUpdatesKey(config.app.extConfig.plugins.LiveUpdates.key, config.app.rootDir, config.android.assetsDirAbs);
97
+ }
98
+ if (usesSSLPinning && ((_u = (_t = (_s = config.app.extConfig) === null || _s === void 0 ? void 0 : _s.plugins) === null || _t === void 0 ? void 0 : _t.SSLPinning) === null || _u === void 0 ? void 0 : _u.certs)) {
99
+ await copySSLCert((_v = config.app.extConfig.plugins.SSLPinning) === null || _v === void 0 ? void 0 : _v.certs, config.app.rootDir, config.android.assetsDirAbs);
100
+ }
101
+ await copyCapacitorConfig(config, config.android.assetsDirAbs);
102
+ const cordovaPlugins = await (0, cordova_1.getCordovaPlugins)(config, platformName);
103
+ await (0, cordova_1.handleCordovaPluginsJS)(cordovaPlugins, config, platformName);
104
+ await (0, cordova_1.writeCordovaAndroidManifest)(cordovaPlugins, config, platformName);
105
+ }
106
+ else if (platformName === config.web.name) {
107
+ if (usesFederatedCapacitor) {
108
+ log_1.logger.info('FederatedCapacitor Plugin installed, skipping web bundling...');
109
+ }
110
+ }
111
+ else {
112
+ throw `Platform ${platformName} is not valid.`;
113
+ }
114
+ if (inline) {
115
+ await (0, sourcemaps_1.inlineSourceMaps)(config, platformName);
116
+ }
117
+ });
118
+ await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:copy:after');
119
+ }
120
+ exports.copy = copy;
121
+ async function copyCapacitorConfig(config, nativeAbsDir) {
122
+ const nativeRelDir = (0, path_1.relative)(config.app.rootDir, nativeAbsDir);
123
+ const nativeConfigFile = 'capacitor.config.json';
124
+ const nativeConfigFilePath = (0, path_1.join)(nativeAbsDir, nativeConfigFile);
125
+ await (0, common_1.runTask)(`Creating ${colors_1.default.strong(nativeConfigFile)} in ${nativeRelDir}`, async () => {
126
+ var _a, _b;
127
+ (_a = config.app.extConfig.android) === null || _a === void 0 ? true : delete _a.buildOptions;
128
+ (_b = config.app.extConfig.ios) === null || _b === void 0 ? true : delete _b.buildOptions;
129
+ await (0, fs_extra_1.writeJSON)(nativeConfigFilePath, config.app.extConfig, {
130
+ spaces: '\t',
131
+ });
132
+ });
133
+ }
134
+ async function copyWebDir(config, nativeAbsDir, webAbsDir) {
135
+ var _a;
136
+ const webRelDir = (0, path_1.basename)(webAbsDir);
137
+ const nativeRelDir = (0, path_1.relative)(config.app.rootDir, nativeAbsDir);
138
+ if (((_a = config.app.extConfig.server) === null || _a === void 0 ? void 0 : _a.url) && !(await (0, fs_extra_1.pathExists)(webAbsDir))) {
139
+ log_1.logger.warn(`Cannot copy web assets from ${colors_1.default.strong(webRelDir)} to ${nativeRelDir}\n` +
140
+ `Web asset directory specified by ${colors_1.default.input('webDir')} does not exist. This is not an error because ${colors_1.default.input('server.url')} is set in config.`);
141
+ return;
142
+ }
143
+ await (0, common_1.runTask)(`Copying web assets from ${colors_1.default.strong(webRelDir)} to ${nativeRelDir}`, async () => {
144
+ await (0, fs_extra_1.remove)(nativeAbsDir);
145
+ return (0, fs_extra_1.copy)(webAbsDir, nativeAbsDir);
146
+ });
147
+ }
148
+ async function copyFederatedWebDirs(config, nativeAbsDir) {
149
+ var _a, _b;
150
+ log_1.logger.info('FederatedCapacitor Plugin Loaded - Copying Web Assets');
151
+ if (!((_b = (_a = config.app.extConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.FederatedCapacitor)) {
152
+ throw `FederatedCapacitor plugin is present but no valid config is defined.`;
153
+ }
154
+ const federatedConfig = config.app.extConfig.plugins.FederatedCapacitor;
155
+ if (federatedConfig) {
156
+ if (federatedConfig.shell.name === undefined) {
157
+ throw `FederatedCapacitor plugin is present but no valid Shell application is defined in the config.`;
158
+ }
159
+ if (!federatedConfig.apps.every(isFederatedApp)) {
160
+ throw `FederatedCapacitor plugin is present but there is a problem with the apps defined in the config.`;
161
+ }
162
+ const copyApps = () => {
163
+ return federatedConfig.apps.map((app) => {
164
+ const appDir = (0, path_1.resolve)(config.app.rootDir, app.webDir);
165
+ return copyWebDir(config, (0, path_1.resolve)(nativeAbsDir, app.name), appDir);
166
+ });
167
+ };
168
+ const copyShell = () => {
169
+ return copyWebDir(config, (0, path_1.resolve)(nativeAbsDir, federatedConfig.shell.name), config.app.webDirAbs);
170
+ };
171
+ await Promise.all([...copyApps(), copyShell()]);
172
+ }
173
+ }
174
+ function isFederatedApp(config) {
175
+ return config.webDir !== undefined && config.name !== undefined;
176
+ }
177
+ async function copySecureLiveUpdatesKey(secureLiveUpdatesKeyFile, rootDir, nativeAbsDir) {
178
+ const keyAbsFromPath = (0, path_1.join)(rootDir, secureLiveUpdatesKeyFile);
179
+ const keyAbsToPath = (0, path_1.join)(nativeAbsDir, (0, path_1.basename)(keyAbsFromPath));
180
+ const keyRelToDir = (0, path_1.relative)(rootDir, nativeAbsDir);
181
+ if (!(await (0, fs_extra_1.pathExists)(keyAbsFromPath))) {
182
+ log_1.logger.warn(`Cannot copy Secure Live Updates signature file from ${colors_1.default.strong(keyAbsFromPath)} to ${keyRelToDir}\n` +
183
+ `Signature file does not exist at specified key path.`);
184
+ return;
185
+ }
186
+ await (0, common_1.runTask)(`Copying Secure Live Updates key from ${colors_1.default.strong(secureLiveUpdatesKeyFile)} to ${keyRelToDir}`, async () => {
187
+ return (0, fs_extra_1.copy)(keyAbsFromPath, keyAbsToPath);
188
+ });
189
+ }
190
+ async function copySSLCert(sslCertPaths, rootDir, targetDir) {
191
+ const validCertPaths = [];
192
+ for (const sslCertPath of sslCertPaths) {
193
+ const certAbsFromPath = (0, path_1.join)(rootDir, sslCertPath);
194
+ if (!(await (0, fs_extra_1.pathExists)(certAbsFromPath))) {
195
+ log_1.logger.warn(`Cannot copy SSL Certificate file from ${colors_1.default.strong(certAbsFromPath)}\n` +
196
+ `SSL Certificate does not exist at specified path.`);
197
+ return;
198
+ }
199
+ validCertPaths.push(certAbsFromPath);
200
+ }
201
+ const certsDirAbsToPath = (0, path_1.join)(targetDir, 'certs');
202
+ const certsDirRelToDir = (0, path_1.relative)(rootDir, targetDir);
203
+ await (0, common_1.runTask)(`Copying SSL Certificates from to ${certsDirRelToDir}`, async () => {
204
+ const promises = [];
205
+ for (const certPath of validCertPaths) {
206
+ promises.push((0, fs_extra_1.copy)(certPath, (0, path_1.join)(certsDirAbsToPath, (0, path_1.basename)(certPath))));
207
+ }
208
+ return Promise.all(promises);
209
+ });
210
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCommand = 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 createCommand() {
8
+ (0, errors_1.fatal)(`The create command has been removed.\n` + `Use ${colors_1.default.input('npm init @capacitor/app')}`);
9
+ }
10
+ exports.createCommand = createCommand;