@capacitor/cli 4.0.1-alpha.0 → 4.0.1
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.
- package/CHANGELOG.md +121 -1
- package/assets/android-template.tar.gz +0 -0
- package/assets/capacitor-cordova-android-plugins.tar.gz +0 -0
- package/assets/capacitor-cordova-ios-plugins.tar.gz +0 -0
- package/assets/ios-template.tar.gz +0 -0
- package/dist/android/open.js +1 -1
- package/dist/android/update.js +42 -3
- package/dist/declarations.d.ts +55 -0
- package/dist/index.js +27 -20
- package/dist/tasks/copy.js +47 -5
- package/dist/tasks/migrate.js +638 -0
- package/dist/util/fs.js +18 -1
- package/package.json +22 -24
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,40 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [4.0.1
|
|
6
|
+
## [4.0.1](https://github.com/ionic-team/capacitor/compare/4.0.0...4.0.1) (2022-07-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **cli:** Correct Splash theme update ([#5805](https://github.com/ionic-team/capacitor/issues/5805)) ([25b82a8](https://github.com/ionic-team/capacitor/commit/25b82a84425bf09b2be45b213788b0e13982b9b3))
|
|
12
|
+
* **cli:** Revert some splash migration errors ([#5806](https://github.com/ionic-team/capacitor/issues/5806)) ([471feed](https://github.com/ionic-team/capacitor/commit/471feedc07bef357ac798fcba664bd373e9f8ebf))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [4.0.0](https://github.com/ionic-team/capacitor/compare/4.0.0-beta.2...4.0.0) (2022-07-27)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* **android:** Add android.minWebviewVersion configuration option ([#5768](https://github.com/ionic-team/capacitor/issues/5768)) ([ad83827](https://github.com/ionic-team/capacitor/commit/ad838279e9cd190ce6f1a020a0ac9e3916786324))
|
|
24
|
+
* **cli:** add migrator for cap3 to cap4 ([#5762](https://github.com/ionic-team/capacitor/issues/5762)) ([7cb660a](https://github.com/ionic-team/capacitor/commit/7cb660a34d9a87274761d4492d0d77c9ef44ace8))
|
|
25
|
+
* Add option for custom error page ([#5723](https://github.com/ionic-team/capacitor/issues/5723)) ([e8bdef3](https://github.com/ionic-team/capacitor/commit/e8bdef3b4634e4ad45fa8fc34c7c0ab8dfa383f3))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# [4.0.0-beta.2](https://github.com/ionic-team/capacitor/compare/4.0.0-beta.1...4.0.0-beta.2) (2022-07-08)
|
|
32
|
+
|
|
33
|
+
**Note:** Version bump only for package @capacitor/cli
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# [4.0.0-beta.1](https://github.com/ionic-team/capacitor/compare/4.0.0-beta.0...4.0.0-beta.1) (2022-06-27)
|
|
7
40
|
|
|
8
41
|
**Note:** Version bump only for package @capacitor/cli
|
|
9
42
|
|
|
@@ -11,6 +44,93 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
44
|
|
|
12
45
|
|
|
13
46
|
|
|
47
|
+
# [4.0.0-beta.0](https://github.com/ionic-team/capacitor/compare/3.6.0...4.0.0-beta.0) (2022-06-17)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
* **android:** Use java 11 ([#5552](https://github.com/ionic-team/capacitor/issues/5552)) ([e47959f](https://github.com/ionic-team/capacitor/commit/e47959fcbd6a89b97b1275a5814fdb4e7ce30672))
|
|
53
|
+
* **ios:** Add preferredContentMode configuration option ([#5583](https://github.com/ionic-team/capacitor/issues/5583)) ([5b6dfa3](https://github.com/ionic-team/capacitor/commit/5b6dfa3fe29c85632546b299f03cc04a77cf7475))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# [3.6.0](https://github.com/ionic-team/capacitor/compare/3.5.1...3.6.0) (2022-06-17)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Features
|
|
63
|
+
|
|
64
|
+
* **android:** update support for Portals for Capacitor to include Live Updates ([#5660](https://github.com/ionic-team/capacitor/issues/5660)) ([62f0a5e](https://github.com/ionic-team/capacitor/commit/62f0a5eaa40776aad79dbf8f8c0900037d3cc97e))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# [4.0.0-alpha.2](https://github.com/ionic-team/capacitor/compare/3.4.1...4.0.0-alpha.2) (2022-05-12)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### Features
|
|
74
|
+
|
|
75
|
+
* **android:** Use java 11 ([#5552](https://github.com/ionic-team/capacitor/issues/5552)) ([e47959f](https://github.com/ionic-team/capacitor/commit/e47959fcbd6a89b97b1275a5814fdb4e7ce30672))
|
|
76
|
+
* **ios:** Add preferredContentMode configuration option ([#5583](https://github.com/ionic-team/capacitor/issues/5583)) ([5b6dfa3](https://github.com/ionic-team/capacitor/commit/5b6dfa3fe29c85632546b299f03cc04a77cf7475))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## [3.5.1](https://github.com/ionic-team/capacitor/compare/3.5.0...3.5.1) (2022-05-04)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### Bug Fixes
|
|
86
|
+
|
|
87
|
+
* **android:** move initialFocus on webview into config ([#5579](https://github.com/ionic-team/capacitor/issues/5579)) ([8b4e861](https://github.com/ionic-team/capacitor/commit/8b4e861514b0fbe08e9296f49c280234f54742e1))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# [3.5.0](https://github.com/ionic-team/capacitor/compare/3.4.3...3.5.0) (2022-04-22)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Features
|
|
97
|
+
|
|
98
|
+
* **cli:** support capacitor portals plugin changes needed ([#5558](https://github.com/ionic-team/capacitor/issues/5558)) ([6810a19](https://github.com/ionic-team/capacitor/commit/6810a19ae2bbda1f4b2afad61d37ca822ca157f5))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# [4.0.0-alpha.1](https://github.com/ionic-team/capacitor/compare/3.4.1...4.0.0-alpha.1) (2022-03-25)
|
|
105
|
+
|
|
106
|
+
**Note:** Version bump only for package @capacitor/cli
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## [3.4.3](https://github.com/ionic-team/capacitor/compare/3.4.2...3.4.3) (2022-03-04)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### Bug Fixes
|
|
117
|
+
|
|
118
|
+
* **cli:** avoid srcFiles is not iterable on kotlinNeededCheck ([#5481](https://github.com/ionic-team/capacitor/issues/5481)) ([3c2b579](https://github.com/ionic-team/capacitor/commit/3c2b579c6edb1fc69d85689b268eb92067b7821b))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
## [3.4.2](https://github.com/ionic-team/capacitor/compare/3.4.1...3.4.2) (2022-03-03)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
### Bug Fixes
|
|
128
|
+
|
|
129
|
+
* **android:** compatibility with cordova kotlin plugins ([#5438](https://github.com/ionic-team/capacitor/issues/5438)) ([55bf004](https://github.com/ionic-team/capacitor/commit/55bf004897b3feb280ab6b6575d2a2c1a0a183e2))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
14
134
|
## [3.4.1](https://github.com/ionic-team/capacitor/compare/3.4.0...3.4.1) (2022-02-09)
|
|
15
135
|
|
|
16
136
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/android/open.js
CHANGED
|
@@ -15,7 +15,7 @@ async function openAndroid(config) {
|
|
|
15
15
|
if (!(await utils_fs_1.pathExists(androidStudioPath))) {
|
|
16
16
|
throw new Error(`Android Studio does not exist at: ${androidStudioPath}`);
|
|
17
17
|
}
|
|
18
|
-
await open_1.default(dir, { app: androidStudioPath, wait: false });
|
|
18
|
+
await open_1.default(dir, { app: { name: androidStudioPath }, wait: false });
|
|
19
19
|
log_1.logger.info(`Opening Android project at: ${colors_1.default.strong(config.android.platformDir)}.`);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
package/dist/android/update.js
CHANGED
|
@@ -141,8 +141,8 @@ project(':${getGradlePackageName(p.id)}').projectDir = new File('${relativePlugi
|
|
|
141
141
|
|
|
142
142
|
android {
|
|
143
143
|
compileOptions {
|
|
144
|
-
sourceCompatibility JavaVersion.
|
|
145
|
-
targetCompatibility JavaVersion.
|
|
144
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
145
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -166,7 +166,10 @@ if (hasProperty('postBuildExtras')) {
|
|
|
166
166
|
}
|
|
167
167
|
exports.installGradlePlugins = installGradlePlugins;
|
|
168
168
|
async function handleCordovaPluginsGradle(config, cordovaPlugins) {
|
|
169
|
+
var _a, _b, _c;
|
|
169
170
|
const pluginsGradlePath = path_1.join(config.android.cordovaPluginsDirAbs, 'build.gradle');
|
|
171
|
+
const kotlinNeeded = await kotlinNeededCheck(config, cordovaPlugins);
|
|
172
|
+
const kotlinVersionString = (_c = (_b = (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.GradlePluginKotlinVersion) !== null && _c !== void 0 ? _c : '1.7.0';
|
|
170
173
|
const frameworksArray = [];
|
|
171
174
|
let prefsArray = [];
|
|
172
175
|
const applyArray = [];
|
|
@@ -193,10 +196,21 @@ async function handleCordovaPluginsGradle(config, cordovaPlugins) {
|
|
|
193
196
|
})
|
|
194
197
|
.join('\n');
|
|
195
198
|
frameworkString = await replaceFrameworkVariables(config, prefsArray, frameworkString);
|
|
199
|
+
if (kotlinNeeded) {
|
|
200
|
+
frameworkString += `\n implementation "androidx.core:core-ktx:$androidxCoreKTXVersion"`;
|
|
201
|
+
frameworkString += `\n implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"`;
|
|
202
|
+
}
|
|
196
203
|
const applyString = applyArray.join('\n');
|
|
197
204
|
let buildGradle = await utils_fs_1.readFile(pluginsGradlePath, { encoding: 'utf-8' });
|
|
198
205
|
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + frameworkString.concat('\n') + ' $2');
|
|
199
206
|
buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + applyString.concat('\n') + '$2');
|
|
207
|
+
if (kotlinNeeded) {
|
|
208
|
+
buildGradle = buildGradle.replace(/(buildscript\s{\n(\t|\s{4})repositories\s{\n((\t{2}|\s{8}).+\n)+(\t|\s{4})}\n(\t|\s{4})dependencies\s{\n(\t{2}|\s{8}).+)\n((\t|\s{4})}\n}\n)/, `$1\n classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"\n$8`);
|
|
209
|
+
buildGradle = buildGradle.replace(/(ext\s{)/, `$1\n androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.8.0'`);
|
|
210
|
+
buildGradle = buildGradle.replace(/(buildscript\s{)/, `$1\n ext.kotlin_version = project.hasProperty('kotlin_version') ? rootProject.ext.kotlin_version : '${kotlinVersionString}'`);
|
|
211
|
+
buildGradle = buildGradle.replace(/(apply\splugin:\s'com\.android\.library')/, `$1\napply plugin: 'kotlin-android'`);
|
|
212
|
+
buildGradle = buildGradle.replace(/(compileOptions\s{\n((\t{2}|\s{8}).+\n)+(\t|\s{4})})\n(})/, `$1\n sourceSets {\n main.java.srcDirs += 'src/main/kotlin'\n }\n$5`);
|
|
213
|
+
}
|
|
200
214
|
await utils_fs_1.writeFile(pluginsGradlePath, buildGradle);
|
|
201
215
|
const cordovaVariables = `// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
|
202
216
|
ext {
|
|
@@ -208,6 +222,27 @@ ext {
|
|
|
208
222
|
await utils_fs_1.writeFile(path_1.join(config.android.cordovaPluginsDirAbs, 'cordova.variables.gradle'), cordovaVariables);
|
|
209
223
|
}
|
|
210
224
|
exports.handleCordovaPluginsGradle = handleCordovaPluginsGradle;
|
|
225
|
+
async function kotlinNeededCheck(config, cordovaPlugins) {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
if (((_b = (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.GradlePluginKotlinEnabled) !==
|
|
228
|
+
'true') {
|
|
229
|
+
for (const plugin of cordovaPlugins) {
|
|
230
|
+
const androidPlatform = plugin_1.getPluginPlatform(plugin, platform);
|
|
231
|
+
const sourceFiles = androidPlatform['source-file'];
|
|
232
|
+
if (sourceFiles) {
|
|
233
|
+
for (const srcFile of sourceFiles) {
|
|
234
|
+
if (/^.*\.kt$/.test(srcFile['$'].src)) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
211
246
|
async function copyPluginsNativeFiles(config, cordovaPlugins) {
|
|
212
247
|
const pluginsPath = path_1.join(config.android.cordovaPluginsDirAbs, 'src', 'main');
|
|
213
248
|
for (const p of cordovaPlugins) {
|
|
@@ -257,12 +292,16 @@ async function getPluginsTask(config) {
|
|
|
257
292
|
return androidPlugins;
|
|
258
293
|
});
|
|
259
294
|
}
|
|
260
|
-
async function
|
|
295
|
+
async function getVariablesGradleFile(config) {
|
|
261
296
|
const variablesFile = path_1.resolve(config.android.platformDirAbs, 'variables.gradle');
|
|
262
297
|
let variablesGradle = '';
|
|
263
298
|
if (await utils_fs_1.pathExists(variablesFile)) {
|
|
264
299
|
variablesGradle = await utils_fs_1.readFile(variablesFile, { encoding: 'utf-8' });
|
|
265
300
|
}
|
|
301
|
+
return variablesGradle;
|
|
302
|
+
}
|
|
303
|
+
async function replaceFrameworkVariables(config, prefsArray, frameworkString) {
|
|
304
|
+
const variablesGradle = await getVariablesGradleFile(config);
|
|
266
305
|
prefsArray.map((preference) => {
|
|
267
306
|
if (!variablesGradle.includes(preference.$.name)) {
|
|
268
307
|
frameworkString = frameworkString.replace(new RegExp(('$' + preference.$.name).replace('$', '\\$&'), 'g'), preference.$.default);
|
package/dist/declarations.d.ts
CHANGED
|
@@ -184,6 +184,22 @@ export interface CapacitorConfig {
|
|
|
184
184
|
* @since 3.1.0
|
|
185
185
|
*/
|
|
186
186
|
flavor?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Whether to give the webview initial focus.
|
|
189
|
+
*
|
|
190
|
+
* @since 3.5.1
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
193
|
+
initialFocus?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* The minimum supported webview version on Android supported by your app.
|
|
196
|
+
*
|
|
197
|
+
* The minimum supported cannot be lower than version `55`, which is required for Capacitor.
|
|
198
|
+
*
|
|
199
|
+
* @since 4.0.0
|
|
200
|
+
* @default 60
|
|
201
|
+
*/
|
|
202
|
+
minWebViewVersion?: number;
|
|
187
203
|
};
|
|
188
204
|
ios?: {
|
|
189
205
|
/**
|
|
@@ -314,6 +330,17 @@ export interface CapacitorConfig {
|
|
|
314
330
|
* @default false
|
|
315
331
|
*/
|
|
316
332
|
limitsNavigationsToAppBoundDomains?: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* The content mode for the web view to use when it loads and renders web content.
|
|
335
|
+
*
|
|
336
|
+
* - 'recommended': The content mode that is appropriate for the current device.
|
|
337
|
+
* - 'desktop': The content mode that represents a desktop experience.
|
|
338
|
+
* - 'mobile': The content mode that represents a mobile experience.
|
|
339
|
+
*
|
|
340
|
+
* @since 4.0.0
|
|
341
|
+
* @default recommended
|
|
342
|
+
*/
|
|
343
|
+
preferredContentMode?: 'recommended' | 'desktop' | 'mobile';
|
|
317
344
|
};
|
|
318
345
|
server?: {
|
|
319
346
|
/**
|
|
@@ -385,6 +412,13 @@ export interface CapacitorConfig {
|
|
|
385
412
|
* @default []
|
|
386
413
|
*/
|
|
387
414
|
allowNavigation?: string[];
|
|
415
|
+
/**
|
|
416
|
+
* Specify path to a local html page to display in case of errors.
|
|
417
|
+
*
|
|
418
|
+
* @since 4.0.0
|
|
419
|
+
* @default null
|
|
420
|
+
*/
|
|
421
|
+
errorPath?: string;
|
|
388
422
|
};
|
|
389
423
|
cordova?: {
|
|
390
424
|
/**
|
|
@@ -432,6 +466,18 @@ export interface CapacitorConfig {
|
|
|
432
466
|
*/
|
|
433
467
|
includePlugins?: string[];
|
|
434
468
|
}
|
|
469
|
+
export interface Portal {
|
|
470
|
+
name: string;
|
|
471
|
+
webDir: string;
|
|
472
|
+
liveUpdateConfig?: LiveUpdateConfig;
|
|
473
|
+
}
|
|
474
|
+
export interface LiveUpdateConfig {
|
|
475
|
+
appId: string;
|
|
476
|
+
channel: string;
|
|
477
|
+
autoUpdateMethod: AutoUpdateMethod;
|
|
478
|
+
maxVersions?: number;
|
|
479
|
+
}
|
|
480
|
+
export declare type AutoUpdateMethod = 'none' | 'background';
|
|
435
481
|
export interface PluginsConfig {
|
|
436
482
|
/**
|
|
437
483
|
* Plugin configuration by class name.
|
|
@@ -441,4 +487,13 @@ export interface PluginsConfig {
|
|
|
441
487
|
[key: string]: {
|
|
442
488
|
[key: string]: any;
|
|
443
489
|
} | undefined;
|
|
490
|
+
/**
|
|
491
|
+
* Capacitor Portals plugin configuration
|
|
492
|
+
*
|
|
493
|
+
* @since 3.5.0
|
|
494
|
+
*/
|
|
495
|
+
Portals?: {
|
|
496
|
+
shell: Portal;
|
|
497
|
+
apps: Portal[];
|
|
498
|
+
};
|
|
444
499
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runProgram = exports.run = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const commander_1 =
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
6
|
const colors_1 = tslib_1.__importDefault(require("./colors"));
|
|
7
7
|
const config_1 = require("./config");
|
|
8
8
|
const errors_1 = require("./errors");
|
|
@@ -27,8 +27,8 @@ async function run() {
|
|
|
27
27
|
}
|
|
28
28
|
exports.run = run;
|
|
29
29
|
function runProgram(config) {
|
|
30
|
-
commander_1.
|
|
31
|
-
commander_1.
|
|
30
|
+
commander_1.program.version(config.cli.package.version);
|
|
31
|
+
commander_1.program
|
|
32
32
|
.command('config', { hidden: true })
|
|
33
33
|
.description(`print evaluated Capacitor config`)
|
|
34
34
|
.option('--json', 'Print in JSON format')
|
|
@@ -36,14 +36,14 @@ function runProgram(config) {
|
|
|
36
36
|
const { configCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/config')));
|
|
37
37
|
await configCommand(config, json);
|
|
38
38
|
}));
|
|
39
|
-
commander_1.
|
|
39
|
+
commander_1.program
|
|
40
40
|
.command('create [directory] [name] [id]', { hidden: true })
|
|
41
41
|
.description('Creates a new Capacitor project')
|
|
42
42
|
.action(cli_1.wrapAction(async () => {
|
|
43
43
|
const { createCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/create')));
|
|
44
44
|
await createCommand();
|
|
45
45
|
}));
|
|
46
|
-
commander_1.
|
|
46
|
+
commander_1.program
|
|
47
47
|
.command('init [appName] [appId]')
|
|
48
48
|
.description(`Initialize Capacitor configuration`)
|
|
49
49
|
.option('--web-dir <value>', 'Optional: Directory of your projects built web assets')
|
|
@@ -51,14 +51,14 @@ function runProgram(config) {
|
|
|
51
51
|
const { initCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/init')));
|
|
52
52
|
await initCommand(config, appName, appId, webDir);
|
|
53
53
|
})));
|
|
54
|
-
commander_1.
|
|
54
|
+
commander_1.program
|
|
55
55
|
.command('serve', { hidden: true })
|
|
56
56
|
.description('Serves a Capacitor Progressive Web App in the browser')
|
|
57
57
|
.action(cli_1.wrapAction(async () => {
|
|
58
58
|
const { serveCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/serve')));
|
|
59
59
|
await serveCommand();
|
|
60
60
|
}));
|
|
61
|
-
commander_1.
|
|
61
|
+
commander_1.program
|
|
62
62
|
.command('sync [platform]')
|
|
63
63
|
.description(`${colors_1.default.input('copy')} + ${colors_1.default.input('update')}`)
|
|
64
64
|
.option('--deployment', "Optional: if provided, Podfile.lock won't be deleted and pod install will use --deployment option")
|
|
@@ -67,7 +67,7 @@ function runProgram(config) {
|
|
|
67
67
|
const { syncCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/sync')));
|
|
68
68
|
await syncCommand(config, platform, deployment);
|
|
69
69
|
})));
|
|
70
|
-
commander_1.
|
|
70
|
+
commander_1.program
|
|
71
71
|
.command('update [platform]')
|
|
72
72
|
.description(`updates the native plugins and dependencies based on ${colors_1.default.strong('package.json')}`)
|
|
73
73
|
.option('--deployment', "Optional: if provided, Podfile.lock won't be deleted and pod install will use --deployment option")
|
|
@@ -76,7 +76,7 @@ function runProgram(config) {
|
|
|
76
76
|
const { updateCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/update')));
|
|
77
77
|
await updateCommand(config, platform, deployment);
|
|
78
78
|
})));
|
|
79
|
-
commander_1.
|
|
79
|
+
commander_1.program
|
|
80
80
|
.command('copy [platform]')
|
|
81
81
|
.description('copies the web app build into the native app')
|
|
82
82
|
.action(cli_1.wrapAction(telemetry_1.telemetryAction(config, async (platform) => {
|
|
@@ -84,7 +84,7 @@ function runProgram(config) {
|
|
|
84
84
|
const { copyCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/copy')));
|
|
85
85
|
await copyCommand(config, platform);
|
|
86
86
|
})));
|
|
87
|
-
commander_1.
|
|
87
|
+
commander_1.program
|
|
88
88
|
.command(`run [platform]`)
|
|
89
89
|
.description(`runs ${colors_1.default.input('sync')}, then builds and deploys the native app`)
|
|
90
90
|
.option('--list', 'list targets, then quit')
|
|
@@ -96,14 +96,14 @@ function runProgram(config) {
|
|
|
96
96
|
const { runCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/run')));
|
|
97
97
|
await runCommand(config, platform, { list, target, sync });
|
|
98
98
|
})));
|
|
99
|
-
commander_1.
|
|
99
|
+
commander_1.program
|
|
100
100
|
.command('open [platform]')
|
|
101
101
|
.description('opens the native project workspace (Xcode for iOS)')
|
|
102
102
|
.action(cli_1.wrapAction(telemetry_1.telemetryAction(config, async (platform) => {
|
|
103
103
|
const { openCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/open')));
|
|
104
104
|
await openCommand(config, platform);
|
|
105
105
|
})));
|
|
106
|
-
commander_1.
|
|
106
|
+
commander_1.program
|
|
107
107
|
.command('add [platform]')
|
|
108
108
|
.description('add a native platform project')
|
|
109
109
|
.action(cli_1.wrapAction(telemetry_1.telemetryAction(config, async (platform) => {
|
|
@@ -111,7 +111,7 @@ function runProgram(config) {
|
|
|
111
111
|
const { addCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/add')));
|
|
112
112
|
await addCommand(config, platform);
|
|
113
113
|
})));
|
|
114
|
-
commander_1.
|
|
114
|
+
commander_1.program
|
|
115
115
|
.command('ls [platform]')
|
|
116
116
|
.description('list installed Cordova and Capacitor plugins')
|
|
117
117
|
.action(cli_1.wrapAction(telemetry_1.telemetryAction(config, async (platform) => {
|
|
@@ -119,7 +119,7 @@ function runProgram(config) {
|
|
|
119
119
|
const { listCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/list')));
|
|
120
120
|
await listCommand(config, platform);
|
|
121
121
|
})));
|
|
122
|
-
commander_1.
|
|
122
|
+
commander_1.program
|
|
123
123
|
.command('doctor [platform]')
|
|
124
124
|
.description('checks the current setup for common errors')
|
|
125
125
|
.action(cli_1.wrapAction(telemetry_1.telemetryAction(config, async (platform) => {
|
|
@@ -127,35 +127,42 @@ function runProgram(config) {
|
|
|
127
127
|
const { doctorCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/doctor')));
|
|
128
128
|
await doctorCommand(config, platform);
|
|
129
129
|
})));
|
|
130
|
-
commander_1.
|
|
130
|
+
commander_1.program
|
|
131
131
|
.command('telemetry [on|off]', { hidden: true })
|
|
132
132
|
.description('enable or disable telemetry')
|
|
133
133
|
.action(cli_1.wrapAction(async (onOrOff) => {
|
|
134
134
|
const { telemetryCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/telemetry')));
|
|
135
135
|
await telemetryCommand(onOrOff);
|
|
136
136
|
}));
|
|
137
|
-
commander_1.
|
|
137
|
+
commander_1.program
|
|
138
138
|
.command('📡', { hidden: true })
|
|
139
139
|
.description('IPC receiver command')
|
|
140
140
|
.action(() => {
|
|
141
141
|
// no-op: IPC messages are received via `process.on('message')`
|
|
142
142
|
});
|
|
143
|
-
commander_1.
|
|
143
|
+
commander_1.program
|
|
144
144
|
.command('plugin:generate', { hidden: true })
|
|
145
145
|
.description('start a new Capacitor plugin')
|
|
146
146
|
.action(cli_1.wrapAction(async () => {
|
|
147
147
|
const { newPluginCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/new-plugin')));
|
|
148
148
|
await newPluginCommand();
|
|
149
149
|
}));
|
|
150
|
-
commander_1.
|
|
150
|
+
commander_1.program
|
|
151
|
+
.command('migrate')
|
|
152
|
+
.description('Migrate your current Capacitor app to the latest major version of Capacitor.')
|
|
153
|
+
.action(cli_1.wrapAction(async () => {
|
|
154
|
+
const { migrateCommand } = await Promise.resolve().then(() => tslib_1.__importStar(require('./tasks/migrate')));
|
|
155
|
+
await migrateCommand(config);
|
|
156
|
+
}));
|
|
157
|
+
commander_1.program.arguments('[command]').action(cli_1.wrapAction(async (cmd) => {
|
|
151
158
|
if (typeof cmd === 'undefined') {
|
|
152
159
|
log_1.output.write(`\n ${emoji_1.emoji('⚡️', '--')} ${colors_1.default.strong('Capacitor - Cross-Platform apps with JavaScript and the Web')} ${emoji_1.emoji('⚡️', '--')}\n\n`);
|
|
153
|
-
commander_1.
|
|
160
|
+
commander_1.program.outputHelp();
|
|
154
161
|
}
|
|
155
162
|
else {
|
|
156
163
|
errors_1.fatal(`Unknown command: ${colors_1.default.input(cmd)}`);
|
|
157
164
|
}
|
|
158
165
|
}));
|
|
159
|
-
commander_1.
|
|
166
|
+
commander_1.program.parse(process.argv);
|
|
160
167
|
}
|
|
161
168
|
exports.runProgram = runProgram;
|
package/dist/tasks/copy.js
CHANGED
|
@@ -9,6 +9,7 @@ const common_1 = require("../common");
|
|
|
9
9
|
const cordova_1 = require("../cordova");
|
|
10
10
|
const errors_1 = require("../errors");
|
|
11
11
|
const log_1 = require("../log");
|
|
12
|
+
const plugin_1 = require("../plugin");
|
|
12
13
|
const promise_1 = require("../util/promise");
|
|
13
14
|
const copy_1 = require("../web/copy");
|
|
14
15
|
async function copyCommand(config, selectedPlatformName) {
|
|
@@ -43,21 +44,41 @@ async function copy(config, platformName) {
|
|
|
43
44
|
throw result;
|
|
44
45
|
}
|
|
45
46
|
await common_1.runPlatformHook(config, platformName, config.app.rootDir, 'capacitor:copy:before');
|
|
47
|
+
const allPlugins = await plugin_1.getPlugins(config, platformName);
|
|
48
|
+
let usesCapacitorPortals = false;
|
|
49
|
+
if (allPlugins.filter(plugin => plugin.id === '@ionic-enterprise/capacitor-portals').length > 0) {
|
|
50
|
+
usesCapacitorPortals = true;
|
|
51
|
+
}
|
|
46
52
|
if (platformName === config.ios.name) {
|
|
47
|
-
|
|
53
|
+
if (usesCapacitorPortals) {
|
|
54
|
+
await copyFederatedWebDirs(config, await config.ios.webDirAbs);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
await copyWebDir(config, await config.ios.webDirAbs, config.app.webDirAbs);
|
|
58
|
+
}
|
|
48
59
|
await copyCapacitorConfig(config, config.ios.nativeTargetDirAbs);
|
|
49
60
|
const cordovaPlugins = await cordova_1.getCordovaPlugins(config, platformName);
|
|
50
61
|
await cordova_1.handleCordovaPluginsJS(cordovaPlugins, config, platformName);
|
|
51
62
|
}
|
|
52
63
|
else if (platformName === config.android.name) {
|
|
53
|
-
|
|
64
|
+
if (usesCapacitorPortals) {
|
|
65
|
+
await copyFederatedWebDirs(config, config.android.webDirAbs);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
await copyWebDir(config, config.android.webDirAbs, config.app.webDirAbs);
|
|
69
|
+
}
|
|
54
70
|
await copyCapacitorConfig(config, config.android.assetsDirAbs);
|
|
55
71
|
const cordovaPlugins = await cordova_1.getCordovaPlugins(config, platformName);
|
|
56
72
|
await cordova_1.handleCordovaPluginsJS(cordovaPlugins, config, platformName);
|
|
57
73
|
await cordova_1.writeCordovaAndroidManifest(cordovaPlugins, config, platformName);
|
|
58
74
|
}
|
|
59
75
|
else if (platformName === config.web.name) {
|
|
60
|
-
|
|
76
|
+
if (usesCapacitorPortals) {
|
|
77
|
+
log_1.logger.info('Capacitor Portals Plugin installed, skipping web bundling...');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await copy_1.copyWeb(config);
|
|
81
|
+
}
|
|
61
82
|
}
|
|
62
83
|
else {
|
|
63
84
|
throw `Platform ${platformName} is not valid.`;
|
|
@@ -76,9 +97,8 @@ async function copyCapacitorConfig(config, nativeAbsDir) {
|
|
|
76
97
|
});
|
|
77
98
|
});
|
|
78
99
|
}
|
|
79
|
-
async function copyWebDir(config, nativeAbsDir) {
|
|
100
|
+
async function copyWebDir(config, nativeAbsDir, webAbsDir) {
|
|
80
101
|
var _a;
|
|
81
|
-
const webAbsDir = config.app.webDirAbs;
|
|
82
102
|
const webRelDir = path_1.basename(webAbsDir);
|
|
83
103
|
const nativeRelDir = path_1.relative(config.app.rootDir, nativeAbsDir);
|
|
84
104
|
if (((_a = config.app.extConfig.server) === null || _a === void 0 ? void 0 : _a.url) && !(await utils_fs_1.pathExists(webAbsDir))) {
|
|
@@ -91,3 +111,25 @@ async function copyWebDir(config, nativeAbsDir) {
|
|
|
91
111
|
return utils_fs_1.copy(webAbsDir, nativeAbsDir);
|
|
92
112
|
});
|
|
93
113
|
}
|
|
114
|
+
async function copyFederatedWebDirs(config, nativeAbsDir) {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
log_1.logger.info('Capacitor Portals Plugin Loaded - Copying Web Assets');
|
|
117
|
+
if (!((_b = (_a = config.app.extConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.Portals)) {
|
|
118
|
+
throw `Capacitor Portals plugin is present but no valid config is defined.`;
|
|
119
|
+
}
|
|
120
|
+
const portalsConfig = config.app.extConfig.plugins.Portals;
|
|
121
|
+
if (!isPortal(portalsConfig.shell)) {
|
|
122
|
+
throw `Capacitor Portals plugin is present but no valid Shell application is defined in the config.`;
|
|
123
|
+
}
|
|
124
|
+
if (!portalsConfig.apps.every(isPortal)) {
|
|
125
|
+
throw `Capacitor Portals plugin is present but there is a problem with the apps defined in the config.`;
|
|
126
|
+
}
|
|
127
|
+
await Promise.all([...portalsConfig.apps, portalsConfig.shell].map(app => {
|
|
128
|
+
const appDir = path_1.resolve(config.app.rootDir, app.webDir);
|
|
129
|
+
return copyWebDir(config, path_1.resolve(nativeAbsDir, app.name), appDir);
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
function isPortal(config) {
|
|
133
|
+
return (config.webDir !== undefined &&
|
|
134
|
+
config.name !== undefined);
|
|
135
|
+
}
|
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const utils_fs_1 = require("@ionic/utils-fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const rimraf_1 = tslib_1.__importDefault(require("rimraf"));
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const log_1 = require("../log");
|
|
11
|
+
const fs_1 = require("../util/fs");
|
|
12
|
+
const subprocess_1 = require("../util/subprocess");
|
|
13
|
+
const template_1 = require("../util/template");
|
|
14
|
+
const xml_1 = require("../util/xml");
|
|
15
|
+
// eslint-disable-next-line prefer-const
|
|
16
|
+
let allDependencies = {};
|
|
17
|
+
const libs = [
|
|
18
|
+
'@capacitor/core',
|
|
19
|
+
'@capacitor/cli',
|
|
20
|
+
'@capacitor/ios',
|
|
21
|
+
'@capacitor/android',
|
|
22
|
+
];
|
|
23
|
+
const plugins = [
|
|
24
|
+
'@capacitor/action-sheet',
|
|
25
|
+
'@capacitor/app',
|
|
26
|
+
'@capacitor/app-launcher',
|
|
27
|
+
'@capacitor/browser',
|
|
28
|
+
'@capacitor/camera',
|
|
29
|
+
'@capacitor/clipboard',
|
|
30
|
+
'@capacitor/device',
|
|
31
|
+
'@capacitor/dialog',
|
|
32
|
+
'@capacitor/filesystem',
|
|
33
|
+
'@capacitor/geolocation',
|
|
34
|
+
'@capacitor/google-maps',
|
|
35
|
+
'@capacitor/haptics',
|
|
36
|
+
'@capacitor/keyboard',
|
|
37
|
+
'@capacitor/local-notifications',
|
|
38
|
+
'@capacitor/motion',
|
|
39
|
+
'@capacitor/network',
|
|
40
|
+
'@capacitor/push-notifications',
|
|
41
|
+
'@capacitor/screen-reader',
|
|
42
|
+
'@capacitor/share',
|
|
43
|
+
'@capacitor/splash-screen',
|
|
44
|
+
'@capacitor/status-bar',
|
|
45
|
+
'@capacitor/text-zoom',
|
|
46
|
+
'@capacitor/toast',
|
|
47
|
+
];
|
|
48
|
+
const coreVersion = '^4.0.0';
|
|
49
|
+
const pluginVersion = '^4.0.0';
|
|
50
|
+
async function migrateCommand(config) {
|
|
51
|
+
if (config === null) {
|
|
52
|
+
errors_1.fatal('Config data missing');
|
|
53
|
+
}
|
|
54
|
+
const variablesAndClasspaths = await getAndroidVarriablesAndClasspaths(config);
|
|
55
|
+
if (!variablesAndClasspaths) {
|
|
56
|
+
errors_1.fatal('Variable and Classpath info could not be read.');
|
|
57
|
+
}
|
|
58
|
+
//*
|
|
59
|
+
allDependencies = {
|
|
60
|
+
...config.app.package.dependencies,
|
|
61
|
+
...config.app.package.devDependencies,
|
|
62
|
+
};
|
|
63
|
+
const monorepoWarning = 'Please note this tool is not intended for use in a mono-repo enviroment, please check out the Ionic vscode extension for this functionality.';
|
|
64
|
+
log_1.logger.info(monorepoWarning);
|
|
65
|
+
const { migrateconfirm } = await log_1.logPrompt(`Capacitor 4 sets a deployment target of iOS 13 and Android 12 (SDK 32). \n`, {
|
|
66
|
+
type: 'text',
|
|
67
|
+
name: 'migrateconfirm',
|
|
68
|
+
message: `Are you sure you want to migrate? (Y/n)`,
|
|
69
|
+
initial: 'y',
|
|
70
|
+
});
|
|
71
|
+
if (typeof migrateconfirm === 'string' &&
|
|
72
|
+
migrateconfirm.toLowerCase() === 'y') {
|
|
73
|
+
try {
|
|
74
|
+
const { npmInstallConfirm } = await log_1.logPrompt(`Would you like the migrator to run npm install to install the latest versions of capacitor packages? (Those using other package managers should answer N)`, {
|
|
75
|
+
type: 'text',
|
|
76
|
+
name: 'npmInstallConfirm',
|
|
77
|
+
message: `Run Npm Install? (Y/n)`,
|
|
78
|
+
initial: 'y',
|
|
79
|
+
});
|
|
80
|
+
const runNpmInstall = typeof npmInstallConfirm === 'string' &&
|
|
81
|
+
npmInstallConfirm.toLowerCase() === 'y';
|
|
82
|
+
await common_1.runTask(`Installing Latest NPM Modules.`, () => {
|
|
83
|
+
return installLatestNPMLibs(runNpmInstall, config);
|
|
84
|
+
});
|
|
85
|
+
await common_1.runTask(`Migrating @capacitor/storage to @capacitor/preferences.`, () => {
|
|
86
|
+
return migrateStoragePluginToPreferences(runNpmInstall);
|
|
87
|
+
});
|
|
88
|
+
if (allDependencies['@capacitor/ios'] &&
|
|
89
|
+
utils_fs_1.existsSync(config.ios.platformDirAbs)) {
|
|
90
|
+
// Set deployment target to 13.0
|
|
91
|
+
await common_1.runTask(`Migrating deployment target to 13.0.`, () => {
|
|
92
|
+
return updateFile(config, path_1.join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'), 'IPHONEOS_DEPLOYMENT_TARGET = ', ';', '13.0');
|
|
93
|
+
});
|
|
94
|
+
// Update Podfile to 13.0
|
|
95
|
+
await common_1.runTask(`Migrating Podfile to 13.0.`, () => {
|
|
96
|
+
return updateFile(config, path_1.join(config.ios.nativeProjectDirAbs, 'Podfile'), `platform :ios, '`, `'`, '13.0');
|
|
97
|
+
});
|
|
98
|
+
await common_1.runTask(`Migrating Podfile to use post_install script.`, () => {
|
|
99
|
+
return podfileAssertDeploymentTarget(path_1.join(config.ios.nativeProjectDirAbs, 'Podfile'));
|
|
100
|
+
});
|
|
101
|
+
// Remove touchesBegan
|
|
102
|
+
await common_1.runTask(`Migrating AppDelegate.swift by removing touchesBegan.`, () => {
|
|
103
|
+
return updateFile(config, path_1.join(config.ios.nativeTargetDirAbs, 'AppDelegate.swift'), `override func touchesBegan`, `}`, undefined, true);
|
|
104
|
+
});
|
|
105
|
+
// Remove NSAppTransportSecurity
|
|
106
|
+
await common_1.runTask(`Migrating Info.plist by removing NSAppTransportSecurity key.`, () => {
|
|
107
|
+
return removeKey(path_1.join(config.ios.nativeTargetDirAbs, 'Info.plist'), 'NSAppTransportSecurity');
|
|
108
|
+
});
|
|
109
|
+
// Remove USE_PUSH
|
|
110
|
+
await common_1.runTask(`Migrating by removing USE_PUSH.`, () => {
|
|
111
|
+
return replacePush(path_1.join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'));
|
|
112
|
+
});
|
|
113
|
+
// Remove from App Delegate
|
|
114
|
+
await common_1.runTask(`Migrating App Delegate.`, () => {
|
|
115
|
+
return replaceIfUsePush(config);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (allDependencies['@capacitor/android'] &&
|
|
119
|
+
utils_fs_1.existsSync(config.android.platformDirAbs)) {
|
|
120
|
+
// AndroidManifest.xml add attribute: <activity android:exported="true"
|
|
121
|
+
await common_1.runTask(`Migrating AndroidManifest.xml by adding android:exported attribute to Activity.`, () => {
|
|
122
|
+
return updateAndroidManifest(path_1.join(config.android.srcMainDirAbs, 'AndroidManifest.xml'));
|
|
123
|
+
});
|
|
124
|
+
// Update build.gradle
|
|
125
|
+
const { leaveJCenterPrompt } = await log_1.logPrompt(`Some projects still require JCenter to function. If your project does, please answer yes below.`, {
|
|
126
|
+
type: 'text',
|
|
127
|
+
name: 'leaveJCenterPrompt',
|
|
128
|
+
message: `Keep JCenter if present? (y/N)`,
|
|
129
|
+
initial: 'n',
|
|
130
|
+
});
|
|
131
|
+
await common_1.runTask(`Migrating build.gradle file.`, () => {
|
|
132
|
+
return updateBuildGradle(path_1.join(config.android.platformDirAbs, 'build.gradle'), typeof leaveJCenterPrompt === 'string' &&
|
|
133
|
+
leaveJCenterPrompt.toLowerCase() === 'y', variablesAndClasspaths);
|
|
134
|
+
});
|
|
135
|
+
// Update app.gradle
|
|
136
|
+
await common_1.runTask(`Migrating app/build.gradle file.`, () => {
|
|
137
|
+
return updateAppBuildGradle(path_1.join(config.android.appDirAbs, 'build.gradle'));
|
|
138
|
+
});
|
|
139
|
+
// Update gradle-wrapper.properties
|
|
140
|
+
await common_1.runTask(`Migrating gradle-wrapper.properties by updating gradle version from 7.0 to 7.4.2.`, () => {
|
|
141
|
+
return updateGradleWrapper(path_1.join(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
|
|
142
|
+
});
|
|
143
|
+
// Variables gradle
|
|
144
|
+
await common_1.runTask(`Migrating variables.gradle file.`, () => {
|
|
145
|
+
return (async () => {
|
|
146
|
+
for (const variable of Object.keys(variablesAndClasspaths.variables)) {
|
|
147
|
+
if (!(await updateFile(config, path_1.join(config.android.platformDirAbs, 'variables.gradle'), `${variable} = '`, `'`, variablesAndClasspaths.variables[variable].toString(), true))) {
|
|
148
|
+
const didWork = await updateFile(config, path_1.join(config.android.platformDirAbs, 'variables.gradle'), `${variable} = `, `\n`, variablesAndClasspaths.variables[variable].toString(), true);
|
|
149
|
+
if (!didWork) {
|
|
150
|
+
let file = readFile(path_1.join(config.android.platformDirAbs, 'variables.gradle'));
|
|
151
|
+
if (file) {
|
|
152
|
+
file = file.replace('}', ` ${variable} = '${variablesAndClasspaths.variables[variable].toString()}'\n}`);
|
|
153
|
+
utils_fs_1.writeFileSync(path_1.join(config.android.platformDirAbs, 'variables.gradle'), file);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
})();
|
|
159
|
+
});
|
|
160
|
+
// remove init
|
|
161
|
+
await common_1.runTask('Migrating MainActivity by removing init().', () => {
|
|
162
|
+
return removeOldInitAndroid(config);
|
|
163
|
+
});
|
|
164
|
+
rimraf_1.default.sync(path_1.join(config.android.appDirAbs, 'build'));
|
|
165
|
+
// add new splashscreen
|
|
166
|
+
await common_1.runTask('Migrate to Android 12 Splashscreen and apply DayNight theme.', () => {
|
|
167
|
+
return addNewSplashScreen(config);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Run Cap Sync
|
|
171
|
+
await common_1.runTask(`Running cap sync.`, () => {
|
|
172
|
+
return subprocess_1.getCommandOutput('npx', ['cap', 'sync']);
|
|
173
|
+
});
|
|
174
|
+
// Write all breaking changes
|
|
175
|
+
await common_1.runTask(`Writing breaking changes.`, () => {
|
|
176
|
+
return writeBreakingChanges();
|
|
177
|
+
});
|
|
178
|
+
log_1.logSuccess(`Migration to Capacitor ${coreVersion} is complete. Run and test your app!`);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
errors_1.fatal(`Failed to migrate: ${err}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
errors_1.fatal(`User canceled migration.`);
|
|
186
|
+
}
|
|
187
|
+
//*/
|
|
188
|
+
}
|
|
189
|
+
exports.migrateCommand = migrateCommand;
|
|
190
|
+
async function installLatestNPMLibs(runInstall, config) {
|
|
191
|
+
const pkgJsonPath = path_1.join(config.app.rootDir, 'package.json');
|
|
192
|
+
const pkgJsonFile = readFile(pkgJsonPath);
|
|
193
|
+
if (!pkgJsonFile) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const pkgJson = JSON.parse(pkgJsonFile);
|
|
197
|
+
for (const devDepKey of Object.keys(pkgJson['devDependencies'])) {
|
|
198
|
+
if (libs.includes(devDepKey)) {
|
|
199
|
+
pkgJson['devDependencies'][devDepKey] = coreVersion;
|
|
200
|
+
}
|
|
201
|
+
else if (plugins.includes(devDepKey)) {
|
|
202
|
+
pkgJson['devDependencies'][devDepKey] = pluginVersion;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const depKey of Object.keys(pkgJson['dependencies'])) {
|
|
206
|
+
if (libs.includes(depKey)) {
|
|
207
|
+
pkgJson['dependencies'][depKey] = coreVersion;
|
|
208
|
+
}
|
|
209
|
+
else if (plugins.includes(depKey)) {
|
|
210
|
+
pkgJson['dependencies'][depKey] = pluginVersion;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
utils_fs_1.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2), {
|
|
214
|
+
encoding: 'utf-8',
|
|
215
|
+
});
|
|
216
|
+
if (runInstall) {
|
|
217
|
+
rimraf_1.default.sync(path_1.join(config.app.rootDir, 'package-lock.json'));
|
|
218
|
+
rimraf_1.default.sync(path_1.join(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
|
|
219
|
+
await subprocess_1.getCommandOutput('npm', ['i']);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
log_1.logger.info(`Please run an install command with your package manager of choice. (ex: yarn install)`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function migrateStoragePluginToPreferences(runInstall) {
|
|
226
|
+
if (allDependencies['@capacitor/storage']) {
|
|
227
|
+
log_1.logger.info('NOTE: @capacitor/storage was renamed to @capacitor/preferences, please be sure to replace occurances in your code.');
|
|
228
|
+
if (runInstall) {
|
|
229
|
+
await subprocess_1.getCommandOutput('npm', ['uninstall', '@capacitor/storage']);
|
|
230
|
+
await subprocess_1.getCommandOutput('npm', [
|
|
231
|
+
'i',
|
|
232
|
+
`@capacitor/preferences@${pluginVersion}`,
|
|
233
|
+
]);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
log_1.logger.info(`Please manually uninstall @capacitor/storage and replace it with @capacitor/preferences@${pluginVersion}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async function writeBreakingChanges() {
|
|
241
|
+
const breaking = [
|
|
242
|
+
'@capacitor/storage',
|
|
243
|
+
'@capacitor/camera',
|
|
244
|
+
'@capacitor/push-notifications',
|
|
245
|
+
'@capacitor/local-notifications',
|
|
246
|
+
];
|
|
247
|
+
const broken = [];
|
|
248
|
+
for (const lib of breaking) {
|
|
249
|
+
if (allDependencies[lib]) {
|
|
250
|
+
broken.push(lib);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (broken.length > 0) {
|
|
254
|
+
log_1.logger.info(`IMPORTANT: Review https://capacitorjs.com/docs/updating/4-0#plugins for breaking changes in these plugins that you use: ${broken.join(', ')}.`);
|
|
255
|
+
}
|
|
256
|
+
if (allDependencies['@capacitor/android']) {
|
|
257
|
+
log_1.logger.info('Warning: The Android Gradle plugin was updated and it requires Java 11 to run. You may need to select this in Android Studio.');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function updateAndroidManifest(filename) {
|
|
261
|
+
const txt = readFile(filename);
|
|
262
|
+
if (!txt) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const hasAndroidExportedAlreadySet = new RegExp(/<activity([^>]*(android:exported=")[^>]*)>/g).test(txt);
|
|
266
|
+
let isAndroidExportedSetToFalse = false;
|
|
267
|
+
if (hasAndroidExportedAlreadySet) {
|
|
268
|
+
isAndroidExportedSetToFalse = new RegExp(/<activity([^>]*(android:exported="false")[^>]*)>/g).test(txt);
|
|
269
|
+
}
|
|
270
|
+
// AndroidManifest.xml add attribute: <activity android:exported="true"
|
|
271
|
+
if (hasAndroidExportedAlreadySet && !isAndroidExportedSetToFalse) {
|
|
272
|
+
return; // Probably already updated manually
|
|
273
|
+
}
|
|
274
|
+
let replaced = txt;
|
|
275
|
+
if (!hasAndroidExportedAlreadySet) {
|
|
276
|
+
replaced = setAllStringIn(txt, '<activity', ' ', `\n android:exported="true"\n`);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
log_1.logger.info(`Found 'android:exported="false"' in your AndroidManifest.xml, if this is not intentional please update it manually to "true".`);
|
|
280
|
+
}
|
|
281
|
+
if (txt == replaced) {
|
|
282
|
+
log_1.logger.error(`Unable to update Android Manifest. Missing <activity> tag`);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
286
|
+
}
|
|
287
|
+
async function updateBuildGradle(filename, leaveJCenter, variablesAndClasspaths) {
|
|
288
|
+
// In build.gradle add dependencies:
|
|
289
|
+
// classpath 'com.android.tools.build:gradle:7.2.1'
|
|
290
|
+
// classpath 'com.google.gms:google-services:4.3.10'
|
|
291
|
+
const txt = readFile(filename);
|
|
292
|
+
if (!txt) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const neededDeps = {
|
|
296
|
+
'com.android.tools.build:gradle': variablesAndClasspaths['com.android.tools.build:gradle'],
|
|
297
|
+
'com.google.gms:google-services': variablesAndClasspaths['com.google.gms:google-services'],
|
|
298
|
+
};
|
|
299
|
+
let replaced = txt;
|
|
300
|
+
for (const dep of Object.keys(neededDeps)) {
|
|
301
|
+
if (!replaced.includes(`classpath '${dep}`)) {
|
|
302
|
+
replaced = txt.replace('dependencies {', `dependencies {\n classpath '${dep}:${neededDeps[dep]}'`);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
// Update
|
|
306
|
+
replaced = setAllStringIn(replaced, `classpath '${dep}:`, `'`, neededDeps[dep]);
|
|
307
|
+
log_1.logger.info(`Set ${dep} = ${neededDeps[dep]}.`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Replace jcenter()
|
|
311
|
+
const lines = replaced.split('\n');
|
|
312
|
+
let inRepositories = false;
|
|
313
|
+
let hasMavenCentral = false;
|
|
314
|
+
let final = '';
|
|
315
|
+
for (const line of lines) {
|
|
316
|
+
if (line.includes('repositories {')) {
|
|
317
|
+
inRepositories = true;
|
|
318
|
+
hasMavenCentral = false;
|
|
319
|
+
}
|
|
320
|
+
else if (line.trim() == '}') {
|
|
321
|
+
// Make sure we have mavenCentral()
|
|
322
|
+
if (inRepositories && !hasMavenCentral) {
|
|
323
|
+
final += ' mavenCentral()\n';
|
|
324
|
+
log_1.logger.info(`Added mavenCentral().`);
|
|
325
|
+
}
|
|
326
|
+
inRepositories = false;
|
|
327
|
+
}
|
|
328
|
+
if (inRepositories && line.trim() === 'mavenCentral()') {
|
|
329
|
+
hasMavenCentral = true;
|
|
330
|
+
}
|
|
331
|
+
if (inRepositories && line.trim() === 'jcenter()' && !leaveJCenter) {
|
|
332
|
+
// skip jCentral()
|
|
333
|
+
log_1.logger.info(`Removed jcenter().`);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
final += line + '\n';
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (txt !== final) {
|
|
340
|
+
utils_fs_1.writeFileSync(filename, final, 'utf-8');
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async function getAndroidVarriablesAndClasspaths(config) {
|
|
345
|
+
const tempAndroidTemplateFolder = path_1.join(config.cli.assetsDirAbs, 'tempAndroidTemplate');
|
|
346
|
+
await template_1.extractTemplate(config.cli.assets.android.platformTemplateArchiveAbs, tempAndroidTemplateFolder);
|
|
347
|
+
const variablesGradleFile = readFile(path_1.join(tempAndroidTemplateFolder, 'variables.gradle'));
|
|
348
|
+
const buildGradleFile = readFile(path_1.join(tempAndroidTemplateFolder, 'build.gradle'));
|
|
349
|
+
if (!variablesGradleFile || !buildGradleFile) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
fs_1.deleteFolderRecursive(tempAndroidTemplateFolder);
|
|
353
|
+
const firstIndxOfCATBGV = buildGradleFile.indexOf(`classpath 'com.android.tools.build:gradle:`) + 42;
|
|
354
|
+
const firstIndxOfCGGGS = buildGradleFile.indexOf(`com.google.gms:google-services:`) + 31;
|
|
355
|
+
const comAndroidToolsBuildGradleVersion = '' +
|
|
356
|
+
buildGradleFile.substring(firstIndxOfCATBGV, buildGradleFile.indexOf("'", firstIndxOfCATBGV));
|
|
357
|
+
const comGoogleGmsGoogleServices = '' +
|
|
358
|
+
buildGradleFile.substring(firstIndxOfCGGGS, buildGradleFile.indexOf("'", firstIndxOfCGGGS));
|
|
359
|
+
const variablesGradleAsJSON = JSON.parse(variablesGradleFile
|
|
360
|
+
.replace('ext ', '')
|
|
361
|
+
.replace(/=/g, ':')
|
|
362
|
+
.replace(/\n/g, ',')
|
|
363
|
+
.replace(/,([^:]+):/g, function (_k, p1) {
|
|
364
|
+
return `,"${p1}":`;
|
|
365
|
+
})
|
|
366
|
+
.replace('{,', '{')
|
|
367
|
+
.replace(',}', '}')
|
|
368
|
+
.replace(/\s/g, '')
|
|
369
|
+
.replace(/'/g, '"'));
|
|
370
|
+
return {
|
|
371
|
+
'variables': variablesGradleAsJSON,
|
|
372
|
+
'com.android.tools.build:gradle': comAndroidToolsBuildGradleVersion,
|
|
373
|
+
'com.google.gms:google-services': comGoogleGmsGoogleServices,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function readFile(filename) {
|
|
377
|
+
try {
|
|
378
|
+
if (!utils_fs_1.existsSync(filename)) {
|
|
379
|
+
log_1.logger.error(`Unable to find ${filename}. Try updating it manually`);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
return utils_fs_1.readFileSync(filename, 'utf-8');
|
|
383
|
+
}
|
|
384
|
+
catch (err) {
|
|
385
|
+
log_1.logger.error(`Unable to read ${filename}. Verify it is not already open. ${err}`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function updateAppBuildGradle(filename) {
|
|
389
|
+
const txt = readFile(filename);
|
|
390
|
+
if (!txt) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
let replaced = txt;
|
|
394
|
+
if (!txt.includes('androidx.coordinatorlayout:coordinatorlayout:')) {
|
|
395
|
+
replaced = replaced.replace('dependencies {', 'dependencies {\n implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"');
|
|
396
|
+
}
|
|
397
|
+
if (!txt.includes('androidx.core:core-splashscreen:')) {
|
|
398
|
+
replaced = replaced.replace('dependencies {', 'dependencies {\n implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"');
|
|
399
|
+
}
|
|
400
|
+
// const lines = txt.split('\n');
|
|
401
|
+
if (replaced !== txt) {
|
|
402
|
+
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
async function updateGradleWrapper(filename) {
|
|
406
|
+
const txt = readFile(filename);
|
|
407
|
+
if (!txt) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const replaced = setAllStringIn(txt, 'distributionUrl=', '\n',
|
|
411
|
+
// eslint-disable-next-line no-useless-escape
|
|
412
|
+
`https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip`);
|
|
413
|
+
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
414
|
+
}
|
|
415
|
+
async function updateFile(config, filename, textStart, textEnd, replacement, skipIfNotFound) {
|
|
416
|
+
if (config === null) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
const path = filename;
|
|
420
|
+
let txt = readFile(path);
|
|
421
|
+
if (!txt) {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
if (txt.includes(textStart)) {
|
|
425
|
+
if (replacement) {
|
|
426
|
+
txt = setAllStringIn(txt, textStart, textEnd, replacement);
|
|
427
|
+
utils_fs_1.writeFileSync(path, txt, { encoding: 'utf-8' });
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
// Replacing in code so we need to count the number of brackets to find the end of the function in swift
|
|
431
|
+
const lines = txt.split('\n');
|
|
432
|
+
let replaced = '';
|
|
433
|
+
let keep = true;
|
|
434
|
+
let brackets = 0;
|
|
435
|
+
for (const line of lines) {
|
|
436
|
+
if (line.includes(textStart)) {
|
|
437
|
+
keep = false;
|
|
438
|
+
}
|
|
439
|
+
if (!keep) {
|
|
440
|
+
brackets += (line.match(/{/g) || []).length;
|
|
441
|
+
brackets -= (line.match(/}/g) || []).length;
|
|
442
|
+
if (brackets == 0) {
|
|
443
|
+
keep = true;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
replaced += line + '\n';
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
utils_fs_1.writeFileSync(path, replaced, { encoding: 'utf-8' });
|
|
451
|
+
}
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
else if (!skipIfNotFound) {
|
|
455
|
+
log_1.logger.error(`Unable to find "${textStart}" in ${filename}. Try updating it manually`);
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
function setAllStringIn(data, start, end, replacement) {
|
|
460
|
+
let position = 0;
|
|
461
|
+
let result = data;
|
|
462
|
+
let replaced = true;
|
|
463
|
+
while (replaced) {
|
|
464
|
+
const foundIdx = result.indexOf(start, position);
|
|
465
|
+
if (foundIdx == -1) {
|
|
466
|
+
replaced = false;
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
const idx = foundIdx + start.length;
|
|
470
|
+
position = idx + replacement.length;
|
|
471
|
+
result =
|
|
472
|
+
result.substring(0, idx) +
|
|
473
|
+
replacement +
|
|
474
|
+
result.substring(result.indexOf(end, idx));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return result;
|
|
478
|
+
}
|
|
479
|
+
async function replaceIfUsePush(config) {
|
|
480
|
+
const startLine = '#if USE_PUSH';
|
|
481
|
+
const endLine = '#endif';
|
|
482
|
+
const filename = path_1.join(config.ios.nativeTargetDirAbs, 'AppDelegate.swift');
|
|
483
|
+
const txt = readFile(filename);
|
|
484
|
+
if (!txt) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const lines = txt.split('\n');
|
|
488
|
+
let startLineIndex = null;
|
|
489
|
+
let endLineIndex = null;
|
|
490
|
+
for (const [key, item] of lines.entries()) {
|
|
491
|
+
if (item.includes(startLine)) {
|
|
492
|
+
startLineIndex = key;
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (startLineIndex !== null) {
|
|
497
|
+
for (const [key, item] of lines.entries()) {
|
|
498
|
+
if (item.includes(endLine) && key > startLineIndex) {
|
|
499
|
+
endLineIndex = key;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (endLineIndex !== null) {
|
|
504
|
+
lines[endLineIndex] = '';
|
|
505
|
+
lines[startLineIndex] = '';
|
|
506
|
+
utils_fs_1.writeFileSync(filename, lines.join('\n'), 'utf-8');
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
async function replacePush(filename) {
|
|
511
|
+
const txt = readFile(filename);
|
|
512
|
+
if (!txt) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
let replaced = txt;
|
|
516
|
+
replaced = replaced.replace('DEBUG USE_PUSH', 'DEBUG');
|
|
517
|
+
replaced = replaced.replace('USE_PUSH', '""');
|
|
518
|
+
if (replaced != txt) {
|
|
519
|
+
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async function removeKey(filename, key) {
|
|
523
|
+
const txt = readFile(filename);
|
|
524
|
+
if (!txt) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
let lines = txt.split('\n');
|
|
528
|
+
let removed = false;
|
|
529
|
+
let removing = false;
|
|
530
|
+
lines = lines.filter(line => {
|
|
531
|
+
if (removing && line.includes('</dict>')) {
|
|
532
|
+
removing = false;
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
if (line.includes(`<key>${key}</key`)) {
|
|
536
|
+
removing = true;
|
|
537
|
+
removed = true;
|
|
538
|
+
}
|
|
539
|
+
return !removing;
|
|
540
|
+
});
|
|
541
|
+
if (removed) {
|
|
542
|
+
utils_fs_1.writeFileSync(filename, lines.join('\n'), 'utf-8');
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
async function podfileAssertDeploymentTarget(filename) {
|
|
546
|
+
const txt = readFile(filename);
|
|
547
|
+
if (!txt) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
let replaced = txt;
|
|
551
|
+
if (!replaced.includes(`require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers`)) {
|
|
552
|
+
replaced =
|
|
553
|
+
`require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'\n\n` +
|
|
554
|
+
txt;
|
|
555
|
+
}
|
|
556
|
+
if (replaced.includes('post_install do |installer|')) {
|
|
557
|
+
if (!replaced.includes(`assertDeploymentTarget(installer)`)) {
|
|
558
|
+
replaced = replaced.replace('post_install do |installer|', `post_install do |installer|\n assertDeploymentTarget(installer)\n`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
replaced =
|
|
563
|
+
replaced +
|
|
564
|
+
`\n\npost_install do |installer|\n assertDeploymentTarget(installer)\nend\n`;
|
|
565
|
+
}
|
|
566
|
+
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
567
|
+
}
|
|
568
|
+
async function removeOldInitAndroid(config) {
|
|
569
|
+
const xmlData = await xml_1.readXML(path_1.join(config.android.srcMainDirAbs, 'AndroidManifest.xml'));
|
|
570
|
+
const manifestNode = xmlData.manifest;
|
|
571
|
+
const applicationChildNodes = manifestNode.application;
|
|
572
|
+
let mainActivityClassPath = '';
|
|
573
|
+
applicationChildNodes.find(applicationChildNode => {
|
|
574
|
+
const activityChildNodes = applicationChildNode.activity;
|
|
575
|
+
if (!Array.isArray(activityChildNodes)) {
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
const mainActivityNode = activityChildNodes.find(activityChildNode => {
|
|
579
|
+
const intentFilterChildNodes = activityChildNode['intent-filter'];
|
|
580
|
+
if (!Array.isArray(intentFilterChildNodes)) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
return intentFilterChildNodes.find(intentFilterChildNode => {
|
|
584
|
+
const actionChildNodes = intentFilterChildNode.action;
|
|
585
|
+
if (!Array.isArray(actionChildNodes)) {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
const mainActionChildNode = actionChildNodes.find(actionChildNode => {
|
|
589
|
+
const androidName = actionChildNode.$['android:name'];
|
|
590
|
+
return androidName === 'android.intent.action.MAIN';
|
|
591
|
+
});
|
|
592
|
+
if (!mainActionChildNode) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
const categoryChildNodes = intentFilterChildNode.category;
|
|
596
|
+
if (!Array.isArray(categoryChildNodes)) {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
return categoryChildNodes.find(categoryChildNode => {
|
|
600
|
+
const androidName = categoryChildNode.$['android:name'];
|
|
601
|
+
return androidName === 'android.intent.category.LAUNCHER';
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
if (mainActivityNode) {
|
|
606
|
+
mainActivityClassPath = mainActivityNode.$['android:name'];
|
|
607
|
+
}
|
|
608
|
+
return mainActivityNode;
|
|
609
|
+
});
|
|
610
|
+
const mainActivityClassName = mainActivityClassPath.split('.').pop();
|
|
611
|
+
const mainActivityPathArray = mainActivityClassPath.split('.');
|
|
612
|
+
mainActivityPathArray.pop();
|
|
613
|
+
const mainActivityClassFileName = `${mainActivityClassName}.java`;
|
|
614
|
+
const mainActivityClassFilePath = path_1.join(path_1.join(config.android.srcMainDirAbs, 'java'), ...mainActivityPathArray, mainActivityClassFileName);
|
|
615
|
+
let data = readFile(mainActivityClassFilePath);
|
|
616
|
+
if (data) {
|
|
617
|
+
const bindex = data.indexOf('this.init(savedInstanceState');
|
|
618
|
+
if (bindex == -1)
|
|
619
|
+
return;
|
|
620
|
+
const eindex = data.indexOf('}});', bindex) + 4;
|
|
621
|
+
data = data.replace(data.substring(bindex, eindex), '');
|
|
622
|
+
data = data.replace('// Initializes the Bridge', '');
|
|
623
|
+
utils_fs_1.writeFileSync(mainActivityClassFilePath, data);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
async function addNewSplashScreen(config) {
|
|
627
|
+
const stylePath = path_1.join(config.android.srcMainDirAbs, 'res', 'values', 'styles.xml');
|
|
628
|
+
let stylesXml = readFile(stylePath);
|
|
629
|
+
if (!stylesXml)
|
|
630
|
+
return;
|
|
631
|
+
stylesXml = stylesXml.replace(`parent="AppTheme.NoActionBar"`, `parent="Theme.SplashScreen"`);
|
|
632
|
+
// revert wrong replaces
|
|
633
|
+
stylesXml = stylesXml.replace(`name="Theme.SplashScreen"`, `name="AppTheme.NoActionBar"`);
|
|
634
|
+
stylesXml = stylesXml.replace(`name="Theme.SplashScreenLaunch"`, `name="AppTheme.NoActionBarLaunch"`);
|
|
635
|
+
// Apply DayNight theme
|
|
636
|
+
stylesXml = stylesXml.replace(`parent="Theme.AppCompat.NoActionBar"`, `parent="Theme.AppCompat.DayNight.NoActionBar"`);
|
|
637
|
+
utils_fs_1.writeFileSync(stylePath, stylesXml);
|
|
638
|
+
}
|
package/dist/util/fs.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertToUnixPath = void 0;
|
|
3
|
+
exports.deleteFolderRecursive = exports.convertToUnixPath = void 0;
|
|
4
|
+
const utils_fs_1 = require("@ionic/utils-fs");
|
|
5
|
+
const path_1 = require("path");
|
|
4
6
|
const convertToUnixPath = (path) => {
|
|
5
7
|
return path.replace(/\\/g, '/');
|
|
6
8
|
};
|
|
7
9
|
exports.convertToUnixPath = convertToUnixPath;
|
|
10
|
+
const deleteFolderRecursive = (directoryPath) => {
|
|
11
|
+
if (utils_fs_1.existsSync(directoryPath)) {
|
|
12
|
+
utils_fs_1.readdirSync(directoryPath).forEach(file => {
|
|
13
|
+
const curPath = path_1.join(directoryPath, file);
|
|
14
|
+
if (utils_fs_1.lstatSync(curPath).isDirectory()) {
|
|
15
|
+
exports.deleteFolderRecursive(curPath);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
utils_fs_1.unlinkSync(curPath);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
utils_fs_1.rmdirSync(directoryPath);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.deleteFolderRecursive = deleteFolderRecursive;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/cli",
|
|
3
|
-
"version": "4.0.1
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Capacitor: Cross-platform apps with JavaScript and the web",
|
|
5
5
|
"homepage": "https://capacitorjs.com",
|
|
6
6
|
"author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
|
|
@@ -44,37 +44,35 @@
|
|
|
44
44
|
"watch": "npm run assets && tsc -w"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ionic/cli-framework-output": "^2.2.
|
|
48
|
-
"@ionic/utils-fs": "^3.1.
|
|
49
|
-
"@ionic/utils-subprocess": "^2.1.
|
|
50
|
-
"@ionic/utils-terminal": "^2.3.
|
|
51
|
-
"commander": "^
|
|
52
|
-
"debug": "^4.
|
|
47
|
+
"@ionic/cli-framework-output": "^2.2.5",
|
|
48
|
+
"@ionic/utils-fs": "^3.1.6",
|
|
49
|
+
"@ionic/utils-subprocess": "^2.1.11",
|
|
50
|
+
"@ionic/utils-terminal": "^2.3.3",
|
|
51
|
+
"commander": "^9.3.0",
|
|
52
|
+
"debug": "^4.3.4",
|
|
53
53
|
"env-paths": "^2.2.0",
|
|
54
|
-
"kleur": "^4.1.
|
|
55
|
-
"native-run": "^1.
|
|
56
|
-
"open": "^
|
|
57
|
-
"plist": "^3.0.
|
|
58
|
-
"prompts": "^2.
|
|
59
|
-
"
|
|
54
|
+
"kleur": "^4.1.4",
|
|
55
|
+
"native-run": "^1.6.0",
|
|
56
|
+
"open": "^8.4.0",
|
|
57
|
+
"plist": "^3.0.5",
|
|
58
|
+
"prompts": "^2.4.2",
|
|
59
|
+
"rimraf": "^3.0.2",
|
|
60
|
+
"semver": "^7.3.7",
|
|
60
61
|
"tar": "^6.1.11",
|
|
61
|
-
"tslib": "^2.
|
|
62
|
+
"tslib": "^2.4.0",
|
|
62
63
|
"xml2js": "^0.4.23"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@types/debug": "^4.1.
|
|
66
|
-
"@types/fs-extra": "^9.0.1",
|
|
66
|
+
"@types/debug": "^4.1.7",
|
|
67
67
|
"@types/jest": "^26.0.4",
|
|
68
|
-
"@types/open": "^6.1.0",
|
|
69
68
|
"@types/plist": "^3.0.2",
|
|
70
|
-
"@types/prompts": "^2.0.
|
|
71
|
-
"@types/
|
|
72
|
-
"@types/
|
|
73
|
-
"@types/tar": "^
|
|
74
|
-
"@types/tmp": "^0.2.
|
|
69
|
+
"@types/prompts": "^2.0.14",
|
|
70
|
+
"@types/rimraf": "^3.0.2",
|
|
71
|
+
"@types/semver": "^7.3.10",
|
|
72
|
+
"@types/tar": "^6.1.1",
|
|
73
|
+
"@types/tmp": "^0.2.3",
|
|
75
74
|
"@types/xml2js": "0.4.5",
|
|
76
75
|
"jest": "^26.1.0",
|
|
77
|
-
"rimraf": "^3.0.2",
|
|
78
76
|
"tmp": "^0.2.1",
|
|
79
77
|
"ts-jest": "^26.1.3",
|
|
80
78
|
"typescript": "~4.1.2"
|
|
@@ -85,5 +83,5 @@
|
|
|
85
83
|
"publishConfig": {
|
|
86
84
|
"access": "public"
|
|
87
85
|
},
|
|
88
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "a14824b660ccd39b7ed150a26debb15e9a161303"
|
|
89
87
|
}
|