@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,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runIOS = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
+ const path_1 = require("path");
7
+ const colors_1 = tslib_1.__importDefault(require("../colors"));
8
+ const common_1 = require("../common");
9
+ const native_run_1 = require("../util/native-run");
10
+ const spm_1 = require("../util/spm");
11
+ const subprocess_1 = require("../util/subprocess");
12
+ const debug = (0, debug_1.default)('capacitor:ios:run');
13
+ async function runIOS(config, { target: selectedTarget, targetName: selectedTargetName, targetNameSdkVersion: selectedTargetSdkVersion, scheme: selectedScheme, configuration: selectedConfiguration, }) {
14
+ const target = await (0, common_1.promptForPlatformTarget)(await (0, native_run_1.getPlatformTargets)('ios'), selectedTarget !== null && selectedTarget !== void 0 ? selectedTarget : selectedTargetName, selectedTargetSdkVersion, selectedTargetName !== undefined);
15
+ const runScheme = selectedScheme || config.ios.scheme;
16
+ const configuration = selectedConfiguration || 'Debug';
17
+ const derivedDataPath = (0, path_1.resolve)(config.ios.platformDirAbs, 'DerivedData', target.id);
18
+ const packageManager = await (0, spm_1.checkPackageManager)(config);
19
+ let typeOfBuild;
20
+ let projectName;
21
+ if (packageManager == 'Cocoapods') {
22
+ typeOfBuild = '-workspace';
23
+ projectName = (0, path_1.basename)(await config.ios.nativeXcodeWorkspaceDirAbs);
24
+ }
25
+ else {
26
+ typeOfBuild = '-project';
27
+ projectName = (0, path_1.basename)(await config.ios.nativeXcodeProjDirAbs);
28
+ }
29
+ const xcodebuildArgs = [
30
+ typeOfBuild,
31
+ projectName,
32
+ '-scheme',
33
+ runScheme,
34
+ '-configuration',
35
+ configuration,
36
+ '-destination',
37
+ `id=${target.id}`,
38
+ '-derivedDataPath',
39
+ derivedDataPath,
40
+ ];
41
+ debug('Invoking xcodebuild with args: %O', xcodebuildArgs);
42
+ await (0, common_1.runTask)('Running xcodebuild', async () => (0, subprocess_1.runCommand)('xcrun', ['xcodebuild', ...xcodebuildArgs], {
43
+ cwd: config.ios.nativeProjectDirAbs,
44
+ }));
45
+ const appName = `${runScheme}.app`;
46
+ const appPath = (0, path_1.resolve)(derivedDataPath, 'Build/Products', target.virtual ? `${configuration}-iphonesimulator` : `${configuration}-iphoneos`, appName);
47
+ const nativeRunArgs = ['ios', '--app', appPath, '--target', target.id];
48
+ debug('Invoking native-run with args: %O', nativeRunArgs);
49
+ await (0, common_1.runTask)(`Deploying ${colors_1.default.strong(appName)} to ${colors_1.default.input(target.id)}`, async () => (0, native_run_1.runNativeRun)(nativeRunArgs));
50
+ }
51
+ exports.runIOS = runIOS;
@@ -0,0 +1,449 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installCocoaPodsPlugins = exports.updateIOS = 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 log_1 = require("../log");
12
+ const plugin_1 = require("../plugin");
13
+ const copy_1 = require("../tasks/copy");
14
+ const fs_1 = require("../util/fs");
15
+ const iosplugin_1 = require("../util/iosplugin");
16
+ const node_1 = require("../util/node");
17
+ const spm_1 = require("../util/spm");
18
+ const subprocess_1 = require("../util/subprocess");
19
+ const template_1 = require("../util/template");
20
+ const common_2 = require("./common");
21
+ const platform = 'ios';
22
+ async function updateIOS(config, deployment) {
23
+ const plugins = await getPluginsTask(config);
24
+ const capacitorPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
25
+ await updatePluginFiles(config, plugins, deployment);
26
+ await (0, common_1.checkPlatformVersions)(config, platform);
27
+ (0, iosplugin_1.generateIOSPackageJSON)(config, plugins);
28
+ (0, plugin_1.printPlugins)(capacitorPlugins, 'ios');
29
+ }
30
+ exports.updateIOS = updateIOS;
31
+ async function updatePluginFiles(config, plugins, deployment) {
32
+ var _a;
33
+ await removePluginsNativeFiles(config);
34
+ const cordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
35
+ if (cordovaPlugins.length > 0) {
36
+ await copyPluginsNativeFiles(config, cordovaPlugins);
37
+ }
38
+ if (!(await (0, fs_extra_1.pathExists)(await config.ios.webDirAbs))) {
39
+ await (0, copy_1.copy)(config, platform);
40
+ }
41
+ await (0, cordova_1.handleCordovaPluginsJS)(cordovaPlugins, config, platform);
42
+ await (0, cordova_1.checkPluginDependencies)(plugins, platform, (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.failOnUninstalledPlugins);
43
+ if ((await (0, spm_1.checkPackageManager)(config)) === 'SPM') {
44
+ await generateCordovaPackageFiles(cordovaPlugins, config);
45
+ const validSPMPackages = await (0, spm_1.checkPluginsForPackageSwift)(config, plugins);
46
+ await (0, spm_1.generatePackageFile)(config, validSPMPackages.concat(cordovaPlugins));
47
+ }
48
+ else {
49
+ await generateCordovaPodspecs(cordovaPlugins, config);
50
+ await installCocoaPodsPlugins(config, plugins, deployment);
51
+ }
52
+ await (0, cordova_1.logCordovaManualSteps)(cordovaPlugins, config, platform);
53
+ const incompatibleCordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 2 /* PluginType.Incompatible */);
54
+ (0, plugin_1.printPlugins)(incompatibleCordovaPlugins, platform, 'incompatible');
55
+ }
56
+ async function generateCordovaPackageFiles(cordovaPlugins, config) {
57
+ cordovaPlugins.map((plugin) => {
58
+ generateCordovaPackageFile(plugin, config);
59
+ });
60
+ }
61
+ async function generateCordovaPackageFile(p, config) {
62
+ const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
63
+ const iosVersion = (0, common_2.getMajoriOSVersion)(config);
64
+ const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
65
+ let headersText = '';
66
+ if (headerFiles.length > 0) {
67
+ headersText = `,
68
+ publicHeadersPath: "."`;
69
+ }
70
+ const content = `// swift-tools-version: 5.9
71
+
72
+ import PackageDescription
73
+
74
+ let package = Package(
75
+ name: "${p.name}",
76
+ platforms: [.iOS(.v${iosVersion})],
77
+ products: [
78
+ .library(
79
+ name: "${p.name}",
80
+ targets: ["${p.name}"]
81
+ )
82
+ ],
83
+ dependencies: [
84
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "${iosPlatformVersion}")
85
+ ],
86
+ targets: [
87
+ .target(
88
+ name: "${p.name}",
89
+ dependencies: [
90
+ .product(name: "Cordova", package: "capacitor-swift-pm")
91
+ ],
92
+ path: "."${headersText}
93
+ )
94
+ ]
95
+ )`;
96
+ await (0, fs_extra_1.writeFile)((0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'sources', p.name, 'Package.swift'), content);
97
+ }
98
+ async function installCocoaPodsPlugins(config, plugins, deployment) {
99
+ await (0, common_1.runTask)(`Updating iOS native dependencies with ${colors_1.default.input(`${await config.ios.podPath} install`)}`, () => {
100
+ return updatePodfile(config, plugins, deployment);
101
+ });
102
+ }
103
+ exports.installCocoaPodsPlugins = installCocoaPodsPlugins;
104
+ async function updatePodfile(config, plugins, deployment) {
105
+ const dependenciesContent = await generatePodFile(config, plugins);
106
+ const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);
107
+ const podfilePath = (0, path_1.join)(config.ios.nativeProjectDirAbs, 'Podfile');
108
+ let podfileContent = await (0, fs_extra_1.readFile)(podfilePath, { encoding: 'utf-8' });
109
+ podfileContent = podfileContent.replace(/(def capacitor_pods)[\s\S]+?(\nend)/, `$1${dependenciesContent}$2`);
110
+ podfileContent = podfileContent.replace(/(require_relative)[\s\S]+?(@capacitor\/ios\/scripts\/pods_helpers')/, `require_relative '${relativeCapacitoriOSPath}/scripts/pods_helpers'`);
111
+ await (0, fs_extra_1.writeFile)(podfilePath, podfileContent, { encoding: 'utf-8' });
112
+ const podPath = await config.ios.podPath;
113
+ const useBundler = podPath.startsWith('bundle') && (await (0, subprocess_1.isInstalled)('bundle'));
114
+ const podCommandExists = await (0, subprocess_1.isInstalled)('pod');
115
+ if (useBundler || podCommandExists) {
116
+ if (useBundler) {
117
+ await (0, subprocess_1.runCommand)('bundle', ['exec', 'pod', 'install', ...(deployment ? ['--deployment'] : [])], {
118
+ cwd: config.ios.nativeProjectDirAbs,
119
+ });
120
+ }
121
+ else {
122
+ await (0, subprocess_1.runCommand)(podPath, ['install', ...(deployment ? ['--deployment'] : [])], {
123
+ cwd: config.ios.nativeProjectDirAbs,
124
+ });
125
+ }
126
+ }
127
+ else {
128
+ log_1.logger.warn('Skipping pod install because CocoaPods is not installed');
129
+ }
130
+ const isXcodebuildAvailable = await (0, subprocess_1.isInstalled)('xcodebuild');
131
+ if (isXcodebuildAvailable) {
132
+ await (0, subprocess_1.runCommand)('xcodebuild', ['-project', (0, path_1.basename)(`${config.ios.nativeXcodeProjDirAbs}`), 'clean'], {
133
+ cwd: config.ios.nativeProjectDirAbs,
134
+ });
135
+ }
136
+ else {
137
+ log_1.logger.warn('Unable to find "xcodebuild". Skipping xcodebuild clean step...');
138
+ }
139
+ }
140
+ async function getRelativeCapacitoriOSPath(config) {
141
+ const capacitoriOSPath = (0, node_1.resolveNode)(config.app.rootDir, '@capacitor/ios', 'package.json');
142
+ if (!capacitoriOSPath) {
143
+ (0, errors_1.fatal)(`Unable to find ${colors_1.default.strong('node_modules/@capacitor/ios')}.\n` +
144
+ `Are you sure ${colors_1.default.strong('@capacitor/ios')} is installed?`);
145
+ }
146
+ return (0, fs_1.convertToUnixPath)((0, path_1.relative)(config.ios.nativeProjectDirAbs, await (0, fs_extra_1.realpath)((0, path_1.dirname)(capacitoriOSPath))));
147
+ }
148
+ async function generatePodFile(config, plugins) {
149
+ const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);
150
+ const capacitorPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
151
+ const pods = await Promise.all(capacitorPlugins.map(async (p) => {
152
+ if (!p.ios) {
153
+ return '';
154
+ }
155
+ return ` pod '${p.ios.name}', :path => '${(0, fs_1.convertToUnixPath)((0, path_1.relative)(config.ios.nativeProjectDirAbs, await (0, fs_extra_1.realpath)(p.rootPath)))}'\n`;
156
+ }));
157
+ const cordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
158
+ cordovaPlugins.map(async (p) => {
159
+ const podspecs = (0, plugin_1.getPlatformElement)(p, platform, 'podspec');
160
+ podspecs.map((podspec) => {
161
+ podspec.pods.map((pPods) => {
162
+ pPods.pod.map((pod) => {
163
+ if (pod.$.git) {
164
+ let gitRef = '';
165
+ if (pod.$.tag) {
166
+ gitRef = `, :tag => '${pod.$.tag}'`;
167
+ }
168
+ else if (pod.$.branch) {
169
+ gitRef = `, :branch => '${pod.$.branch}'`;
170
+ }
171
+ else if (pod.$.commit) {
172
+ gitRef = `, :commit => '${pod.$.commit}'`;
173
+ }
174
+ pods.push(` pod '${pod.$.name}', :git => '${pod.$.git}'${gitRef}\n`);
175
+ }
176
+ });
177
+ });
178
+ });
179
+ });
180
+ const staticPlugins = cordovaPlugins.filter((p) => (0, cordova_1.needsStaticPod)(p));
181
+ const noStaticPlugins = cordovaPlugins.filter((el) => !staticPlugins.includes(el));
182
+ if (noStaticPlugins.length > 0) {
183
+ pods.push(` pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'\n`);
184
+ }
185
+ if (staticPlugins.length > 0) {
186
+ pods.push(` pod 'CordovaPluginsStatic', :path => '../capacitor-cordova-ios-plugins'\n`);
187
+ }
188
+ const resourcesPlugins = cordovaPlugins.filter(filterResources);
189
+ if (resourcesPlugins.length > 0) {
190
+ pods.push(` pod 'CordovaPluginsResources', :path => '../capacitor-cordova-ios-plugins'\n`);
191
+ }
192
+ return `
193
+ pod 'Capacitor', :path => '${relativeCapacitoriOSPath}'
194
+ pod 'CapacitorCordova', :path => '${relativeCapacitoriOSPath}'
195
+ ${pods.join('').trimRight()}`;
196
+ }
197
+ function getFrameworkName(framework) {
198
+ if (isFramework(framework)) {
199
+ if (framework.$.custom && framework.$.custom === 'true') {
200
+ return framework.$.src;
201
+ }
202
+ return framework.$.src.substr(0, framework.$.src.indexOf('.'));
203
+ }
204
+ return framework.$.src.substr(0, framework.$.src.indexOf('.')).replace('lib', '');
205
+ }
206
+ function isFramework(framework) {
207
+ return framework.$.src.split('.').pop().includes('framework');
208
+ }
209
+ async function generateCordovaPodspecs(cordovaPlugins, config) {
210
+ const staticPlugins = cordovaPlugins.filter((p) => (0, cordova_1.needsStaticPod)(p));
211
+ const noStaticPlugins = cordovaPlugins.filter((el) => !staticPlugins.includes(el));
212
+ generateCordovaPodspec(noStaticPlugins, config, false);
213
+ generateCordovaPodspec(staticPlugins, config, true);
214
+ }
215
+ async function generateCordovaPodspec(cordovaPlugins, config, isStatic) {
216
+ const weakFrameworks = [];
217
+ const linkedFrameworks = [];
218
+ const customFrameworks = [];
219
+ const systemLibraries = [];
220
+ const sourceFrameworks = [];
221
+ const frameworkDeps = [];
222
+ const compilerFlags = [];
223
+ let prefsArray = [];
224
+ let name = 'CordovaPlugins';
225
+ let sourcesFolderName = 'sources';
226
+ if (isStatic) {
227
+ name += 'Static';
228
+ frameworkDeps.push('s.static_framework = true');
229
+ sourcesFolderName += 'static';
230
+ }
231
+ cordovaPlugins.map((plugin) => {
232
+ const frameworks = (0, plugin_1.getPlatformElement)(plugin, platform, 'framework');
233
+ frameworks.map((framework) => {
234
+ if (!framework.$.type) {
235
+ const name = getFrameworkName(framework);
236
+ if (isFramework(framework)) {
237
+ if (framework.$.weak && framework.$.weak === 'true') {
238
+ if (!weakFrameworks.includes(name)) {
239
+ weakFrameworks.push(name);
240
+ }
241
+ }
242
+ else if (framework.$.custom && framework.$.custom === 'true') {
243
+ const frameworktPath = (0, path_1.join)(sourcesFolderName, plugin.name, name);
244
+ if (!customFrameworks.includes(frameworktPath)) {
245
+ customFrameworks.push(frameworktPath);
246
+ }
247
+ }
248
+ else {
249
+ if (!linkedFrameworks.includes(name)) {
250
+ linkedFrameworks.push(name);
251
+ }
252
+ }
253
+ }
254
+ else {
255
+ if (!systemLibraries.includes(name)) {
256
+ systemLibraries.push(name);
257
+ }
258
+ }
259
+ }
260
+ else if (framework.$.type && framework.$.type === 'podspec') {
261
+ let depString = `s.dependency '${framework.$.src}'`;
262
+ if (framework.$.spec && framework.$.spec !== '') {
263
+ depString += `, '${framework.$.spec}'`;
264
+ }
265
+ if (!frameworkDeps.includes(depString)) {
266
+ frameworkDeps.push(depString);
267
+ }
268
+ }
269
+ });
270
+ prefsArray = prefsArray.concat((0, plugin_1.getAllElements)(plugin, platform, 'preference'));
271
+ const podspecs = (0, plugin_1.getPlatformElement)(plugin, platform, 'podspec');
272
+ podspecs.map((podspec) => {
273
+ podspec.pods.map((pods) => {
274
+ pods.pod.map((pod) => {
275
+ let depString = `s.dependency '${pod.$.name}'`;
276
+ if (pod.$.spec && pod.$.spec !== '') {
277
+ depString += `, '${pod.$.spec}'`;
278
+ }
279
+ if (!frameworkDeps.includes(depString)) {
280
+ frameworkDeps.push(depString);
281
+ }
282
+ });
283
+ });
284
+ });
285
+ const sourceFiles = (0, plugin_1.getPlatformElement)(plugin, platform, 'source-file');
286
+ sourceFiles.map((sourceFile) => {
287
+ if (sourceFile.$.framework && sourceFile.$.framework === 'true') {
288
+ let fileName = sourceFile.$.src.split('/').pop();
289
+ if (!fileName.startsWith('lib')) {
290
+ fileName = 'lib' + fileName;
291
+ }
292
+ const frameworktPath = (0, path_1.join)(sourcesFolderName, plugin.name, fileName);
293
+ if (!sourceFrameworks.includes(frameworktPath)) {
294
+ sourceFrameworks.push(frameworktPath);
295
+ }
296
+ }
297
+ else if (sourceFile.$['compiler-flags']) {
298
+ const cFlag = sourceFile.$['compiler-flags'];
299
+ if (!compilerFlags.includes(cFlag)) {
300
+ compilerFlags.push(cFlag);
301
+ }
302
+ }
303
+ });
304
+ });
305
+ const onlySystemLibraries = systemLibraries.filter((library) => removeNoSystem(library, sourceFrameworks));
306
+ if (weakFrameworks.length > 0) {
307
+ frameworkDeps.push(`s.weak_frameworks = '${weakFrameworks.join(`', '`)}'`);
308
+ }
309
+ if (linkedFrameworks.length > 0) {
310
+ frameworkDeps.push(`s.frameworks = '${linkedFrameworks.join(`', '`)}'`);
311
+ }
312
+ if (onlySystemLibraries.length > 0) {
313
+ frameworkDeps.push(`s.libraries = '${onlySystemLibraries.join(`', '`)}'`);
314
+ }
315
+ if (customFrameworks.length > 0) {
316
+ frameworkDeps.push(`s.vendored_frameworks = '${customFrameworks.join(`', '`)}'`);
317
+ frameworkDeps.push(`s.exclude_files = 'sources/**/*.framework/Headers/*.h', 'sources/**/*.framework/PrivateHeaders/*.h'`);
318
+ }
319
+ if (sourceFrameworks.length > 0) {
320
+ frameworkDeps.push(`s.vendored_libraries = '${sourceFrameworks.join(`', '`)}'`);
321
+ }
322
+ if (compilerFlags.length > 0) {
323
+ frameworkDeps.push(`s.compiler_flags = '${compilerFlags.join(' ')}'`);
324
+ }
325
+ const arcPlugins = cordovaPlugins.filter(filterARCFiles);
326
+ if (arcPlugins.length > 0) {
327
+ frameworkDeps.push(`s.subspec 'noarc' do |sna|
328
+ sna.requires_arc = false
329
+ sna.source_files = 'noarc/**/*.{swift,h,m,c,cc,mm,cpp}'
330
+ end`);
331
+ }
332
+ let frameworksString = frameworkDeps.join('\n ');
333
+ frameworksString = await replaceFrameworkVariables(config, prefsArray, frameworksString);
334
+ const content = `
335
+ Pod::Spec.new do |s|
336
+ s.name = '${name}'
337
+ s.version = '${config.cli.package.version}'
338
+ s.summary = 'Autogenerated spec'
339
+ s.license = 'Unknown'
340
+ s.homepage = 'https://example.com'
341
+ s.authors = { 'Capacitor Generator' => 'hi@example.com' }
342
+ s.source = { :git => 'https://github.com/ionic-team/does-not-exist.git', :tag => '${config.cli.package.version}' }
343
+ s.source_files = '${sourcesFolderName}/**/*.{swift,h,m,c,cc,mm,cpp}'
344
+ s.ios.deployment_target = '${config.ios.minVersion}'
345
+ s.xcconfig = {'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1 WK_WEB_VIEW_ONLY=1' }
346
+ s.dependency 'CapacitorCordova'${getLinkerFlags(config)}
347
+ s.swift_version = '5.1'
348
+ ${frameworksString}
349
+ end`;
350
+ await (0, fs_extra_1.writeFile)((0, path_1.join)(config.ios.cordovaPluginsDirAbs, `${name}.podspec`), content);
351
+ }
352
+ function getLinkerFlags(config) {
353
+ var _a;
354
+ if ((_a = config.app.extConfig.ios) === null || _a === void 0 ? void 0 : _a.cordovaLinkerFlags) {
355
+ return `\n s.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '${config.app.extConfig.ios.cordovaLinkerFlags.join(' ')}' }`;
356
+ }
357
+ return '';
358
+ }
359
+ async function copyPluginsNativeFiles(config, cordovaPlugins) {
360
+ for (const p of cordovaPlugins) {
361
+ const sourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'source-file');
362
+ const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
363
+ const codeFiles = sourceFiles.concat(headerFiles);
364
+ const frameworks = (0, plugin_1.getPlatformElement)(p, platform, 'framework');
365
+ let sourcesFolderName = 'sources';
366
+ if ((0, cordova_1.needsStaticPod)(p)) {
367
+ sourcesFolderName += 'static';
368
+ }
369
+ const sourcesFolder = (0, path_1.join)(config.ios.cordovaPluginsDirAbs, sourcesFolderName, p.name);
370
+ for (const codeFile of codeFiles) {
371
+ let fileName = codeFile.$.src.split('/').pop();
372
+ const fileExt = codeFile.$.src.split('.').pop();
373
+ if (fileExt === 'a' && !fileName.startsWith('lib')) {
374
+ fileName = 'lib' + fileName;
375
+ }
376
+ let destFolder = sourcesFolderName;
377
+ if (codeFile.$['compiler-flags'] && codeFile.$['compiler-flags'] === '-fno-objc-arc') {
378
+ destFolder = 'noarc';
379
+ }
380
+ const filePath = (0, plugin_1.getFilePath)(config, p, codeFile.$.src);
381
+ const fileDest = (0, path_1.join)(config.ios.cordovaPluginsDirAbs, destFolder, p.name, fileName);
382
+ await (0, fs_extra_1.copy)(filePath, fileDest);
383
+ if (!codeFile.$.framework) {
384
+ let fileContent = await (0, fs_extra_1.readFile)(fileDest, { encoding: 'utf-8' });
385
+ if (fileExt === 'swift') {
386
+ fileContent = 'import Cordova\n' + fileContent;
387
+ await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
388
+ }
389
+ else {
390
+ if (fileContent.includes('@import Firebase;')) {
391
+ fileContent = fileContent.replace('@import Firebase;', '#import <Firebase/Firebase.h>');
392
+ await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
393
+ }
394
+ if (fileContent.includes('[NSBundle bundleForClass:[self class]]') ||
395
+ fileContent.includes('[NSBundle bundleForClass:[CDVCapture class]]')) {
396
+ fileContent = fileContent.replace('[NSBundle bundleForClass:[self class]]', '[NSBundle mainBundle]');
397
+ fileContent = fileContent.replace('[NSBundle bundleForClass:[CDVCapture class]]', '[NSBundle mainBundle]');
398
+ await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
399
+ }
400
+ if (fileContent.includes('[self.webView superview]') || fileContent.includes('self.webView.superview')) {
401
+ fileContent = fileContent.replace(/\[self.webView superview\]/g, 'self.viewController.view');
402
+ fileContent = fileContent.replace(/self.webView.superview/g, 'self.viewController.view');
403
+ await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
404
+ }
405
+ }
406
+ }
407
+ }
408
+ const resourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'resource-file');
409
+ for (const resourceFile of resourceFiles) {
410
+ const fileName = resourceFile.$.src.split('/').pop();
411
+ await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, resourceFile.$.src), (0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'resources', fileName));
412
+ }
413
+ for (const framework of frameworks) {
414
+ if (framework.$.custom && framework.$.custom === 'true') {
415
+ await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, framework.$.src), (0, path_1.join)(sourcesFolder, framework.$.src));
416
+ }
417
+ }
418
+ }
419
+ }
420
+ async function removePluginsNativeFiles(config) {
421
+ await (0, fs_extra_1.remove)(config.ios.cordovaPluginsDirAbs);
422
+ await (0, template_1.extractTemplate)(config.cli.assets.ios.cordovaPluginsTemplateArchiveAbs, config.ios.cordovaPluginsDirAbs);
423
+ }
424
+ function filterResources(plugin) {
425
+ const resources = (0, plugin_1.getPlatformElement)(plugin, platform, 'resource-file');
426
+ return resources.length > 0;
427
+ }
428
+ function filterARCFiles(plugin) {
429
+ const sources = (0, plugin_1.getPlatformElement)(plugin, platform, 'source-file');
430
+ const sourcesARC = sources.filter((sourceFile) => sourceFile.$['compiler-flags'] && sourceFile.$['compiler-flags'] === '-fno-objc-arc');
431
+ return sourcesARC.length > 0;
432
+ }
433
+ function removeNoSystem(library, sourceFrameworks) {
434
+ const libraries = sourceFrameworks.filter((framework) => framework.includes(library));
435
+ return libraries.length === 0;
436
+ }
437
+ async function getPluginsTask(config) {
438
+ return await (0, common_1.runTask)('Updating iOS plugins', async () => {
439
+ const allPlugins = await (0, plugin_1.getPlugins)(config, 'ios');
440
+ const iosPlugins = await (0, common_2.getIOSPlugins)(allPlugins);
441
+ return iosPlugins;
442
+ });
443
+ }
444
+ async function replaceFrameworkVariables(config, prefsArray, frameworkString) {
445
+ prefsArray.map((preference) => {
446
+ frameworkString = frameworkString.replace(new RegExp(('$' + preference.$.name).replace('$', '\\$&'), 'g'), preference.$.default);
447
+ });
448
+ return frameworkString;
449
+ }
package/dist/ipc.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.receive = exports.send = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const utils_subprocess_1 = require("@ionic/utils-subprocess");
6
+ const debug_1 = tslib_1.__importDefault(require("debug"));
7
+ const fs_extra_1 = require("fs-extra");
8
+ const https_1 = require("https");
9
+ const path_1 = require("path");
10
+ const cli_1 = require("./util/cli");
11
+ const debug = (0, debug_1.default)('capacitor:ipc');
12
+ /**
13
+ * Send an IPC message to a forked process.
14
+ */
15
+ async function send(msg) {
16
+ const dir = cli_1.ENV_PATHS.log;
17
+ await (0, fs_extra_1.mkdirp)(dir);
18
+ const logPath = (0, path_1.resolve)(dir, 'ipc.log');
19
+ debug('Sending %O IPC message to forked process (logs: %O)', msg.type, logPath);
20
+ const fd = await (0, fs_extra_1.open)(logPath, 'a');
21
+ const p = (0, utils_subprocess_1.fork)(process.argv[1], ['📡'], { stdio: ['ignore', fd, fd, 'ipc'] });
22
+ p.send(msg);
23
+ p.disconnect();
24
+ p.unref();
25
+ }
26
+ exports.send = send;
27
+ /**
28
+ * Receive and handle an IPC message.
29
+ *
30
+ * Assume minimal context and keep external dependencies to a minimum.
31
+ */
32
+ async function receive(msg) {
33
+ debug('Received %O IPC message', msg.type);
34
+ if (msg.type === 'telemetry') {
35
+ const now = new Date().toISOString();
36
+ const { data } = msg;
37
+ // This request is only made if telemetry is on.
38
+ const req = (0, https_1.request)({
39
+ hostname: 'api.ionicjs.com',
40
+ port: 443,
41
+ path: '/events/metrics',
42
+ method: 'POST',
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ },
46
+ }, (response) => {
47
+ debug('Sent %O metric to events service (status: %O)', data.name, response.statusCode);
48
+ if (response.statusCode !== 204) {
49
+ response.on('data', (chunk) => {
50
+ debug('Bad response from events service. Request body: %O', chunk.toString());
51
+ });
52
+ }
53
+ });
54
+ const body = {
55
+ metrics: [data],
56
+ sent_at: now,
57
+ };
58
+ req.end(JSON.stringify(body));
59
+ }
60
+ }
61
+ exports.receive = receive;
package/dist/log.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logSuccess = exports.logPrompt = exports.logger = exports.output = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cli_framework_output_1 = require("@ionic/cli-framework-output");
6
+ const colors_1 = tslib_1.__importDefault(require("./colors"));
7
+ const term_1 = require("./util/term");
8
+ const options = {
9
+ colors: colors_1.default,
10
+ stream: process.argv.includes('--json') ? process.stderr : process.stdout,
11
+ };
12
+ exports.output = (0, term_1.isInteractive)() ? new cli_framework_output_1.TTYOutputStrategy(options) : new cli_framework_output_1.StreamOutputStrategy(options);
13
+ exports.logger = (0, cli_framework_output_1.createDefaultLogger)({
14
+ output: exports.output,
15
+ formatterOptions: {
16
+ titleize: false,
17
+ tags: new Map([
18
+ [cli_framework_output_1.LOGGER_LEVELS.DEBUG, colors_1.default.log.DEBUG('[debug]')],
19
+ [cli_framework_output_1.LOGGER_LEVELS.INFO, colors_1.default.log.INFO('[info]')],
20
+ [cli_framework_output_1.LOGGER_LEVELS.WARN, colors_1.default.log.WARN('[warn]')],
21
+ [cli_framework_output_1.LOGGER_LEVELS.ERROR, colors_1.default.log.ERROR('[error]')],
22
+ ]),
23
+ },
24
+ });
25
+ async function logPrompt(msg, promptObject) {
26
+ const { wordWrap } = await Promise.resolve().then(() => tslib_1.__importStar(require('@ionic/cli-framework-output')));
27
+ const { prompt } = await Promise.resolve().then(() => tslib_1.__importStar(require('prompts')));
28
+ exports.logger.log({
29
+ msg: `${colors_1.default.input('[?]')} ${wordWrap(msg, { indentation: 4 })}`,
30
+ logger: exports.logger,
31
+ format: false,
32
+ });
33
+ return prompt(promptObject, { onCancel: () => process.exit(1) });
34
+ }
35
+ exports.logPrompt = logPrompt;
36
+ function logSuccess(msg) {
37
+ exports.logger.msg(`${colors_1.default.success('[success]')} ${msg}`);
38
+ }
39
+ exports.logSuccess = logSuccess;