@capacitor/cli 4.7.3 → 5.0.0-alpha.2
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/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/add.js +6 -6
- package/dist/android/build.js +12 -9
- package/dist/android/common.js +27 -29
- package/dist/android/doctor.js +24 -24
- package/dist/android/open.js +3 -3
- package/dist/android/run.js +9 -6
- package/dist/android/update.js +53 -53
- package/dist/common.js +23 -23
- package/dist/config.js +67 -61
- package/dist/cordova.js +75 -75
- package/dist/declarations.d.ts +17 -1
- package/dist/index.js +32 -29
- package/dist/ios/add.js +2 -2
- package/dist/ios/build.js +9 -9
- package/dist/ios/common.js +12 -12
- package/dist/ios/doctor.js +6 -6
- package/dist/ios/open.js +2 -2
- package/dist/ios/run.js +7 -7
- package/dist/ios/update.js +58 -62
- package/dist/ipc.js +6 -6
- package/dist/log.js +2 -2
- package/dist/plugin.js +11 -11
- package/dist/sysconfig.js +6 -6
- package/dist/tasks/add.js +27 -27
- package/dist/tasks/build.js +7 -6
- package/dist/tasks/copy.js +42 -42
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/doctor.js +10 -10
- package/dist/tasks/init.js +30 -27
- package/dist/tasks/list.js +12 -12
- package/dist/tasks/migrate.js +189 -407
- package/dist/tasks/new-plugin.js +1 -1
- package/dist/tasks/open.js +10 -10
- package/dist/tasks/run.js +13 -13
- package/dist/tasks/serve.js +1 -1
- package/dist/tasks/sourcemaps.js +9 -9
- package/dist/tasks/sync.js +15 -15
- package/dist/tasks/telemetry.js +4 -4
- package/dist/tasks/update.js +14 -14
- package/dist/telemetry.js +8 -8
- package/dist/util/cli.js +2 -2
- package/dist/util/fs.js +7 -7
- package/dist/util/native-run.js +3 -3
- package/dist/util/node.js +2 -2
- package/dist/util/subprocess.js +1 -1
- package/dist/util/template.js +1 -1
- package/dist/util/term.js +1 -1
- package/dist/util/xml.js +1 -1
- package/dist/web/copy.js +4 -4
- package/package.json +12 -11
- package/CHANGELOG.md +0 -805
package/dist/tasks/migrate.js
CHANGED
|
@@ -12,7 +12,6 @@ const log_1 = require("../log");
|
|
|
12
12
|
const fs_1 = require("../util/fs");
|
|
13
13
|
const subprocess_1 = require("../util/subprocess");
|
|
14
14
|
const template_1 = require("../util/template");
|
|
15
|
-
const xml_1 = require("../util/xml");
|
|
16
15
|
// eslint-disable-next-line prefer-const
|
|
17
16
|
let allDependencies = {};
|
|
18
17
|
const libs = [
|
|
@@ -41,22 +40,27 @@ const plugins = [
|
|
|
41
40
|
'@capacitor/preferences',
|
|
42
41
|
'@capacitor/push-notifications',
|
|
43
42
|
'@capacitor/screen-reader',
|
|
43
|
+
'@capacitor/screen-orientation',
|
|
44
44
|
'@capacitor/share',
|
|
45
45
|
'@capacitor/splash-screen',
|
|
46
46
|
'@capacitor/status-bar',
|
|
47
47
|
'@capacitor/text-zoom',
|
|
48
48
|
'@capacitor/toast',
|
|
49
49
|
];
|
|
50
|
-
const coreVersion = '
|
|
51
|
-
const pluginVersion = '
|
|
52
|
-
const gradleVersion = '7.
|
|
50
|
+
const coreVersion = 'next'; // TODO: Update when Capacitor 5 releases
|
|
51
|
+
const pluginVersion = 'next'; // TODO: Update when Capacitor 5 releases
|
|
52
|
+
const gradleVersion = '7.5';
|
|
53
53
|
async function migrateCommand(config) {
|
|
54
54
|
if (config === null) {
|
|
55
|
-
errors_1.fatal('Config data missing');
|
|
55
|
+
(0, errors_1.fatal)('Config data missing');
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const capMajor = await checkCapacitorMajorVersion(config);
|
|
58
|
+
if (capMajor < 4) {
|
|
59
|
+
(0, errors_1.fatal)('Migrate can only be used on capacitor 4 and above, please use the CLI in Capacitor 4 to upgrade to 4 first');
|
|
60
|
+
}
|
|
61
|
+
const variablesAndClasspaths = await getAndroidVariablesAndClasspaths(config);
|
|
58
62
|
if (!variablesAndClasspaths) {
|
|
59
|
-
errors_1.fatal('Variable and Classpath info could not be read.');
|
|
63
|
+
(0, errors_1.fatal)('Variable and Classpath info could not be read.');
|
|
60
64
|
}
|
|
61
65
|
//*
|
|
62
66
|
allDependencies = {
|
|
@@ -65,7 +69,7 @@ async function migrateCommand(config) {
|
|
|
65
69
|
};
|
|
66
70
|
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.';
|
|
67
71
|
log_1.logger.info(monorepoWarning);
|
|
68
|
-
const { migrateconfirm } = await log_1.logPrompt(`Capacitor
|
|
72
|
+
const { migrateconfirm } = await (0, log_1.logPrompt)(`Capacitor 5 sets a deployment target of iOS 13 and Android 13 (SDK 33). \n`, {
|
|
69
73
|
type: 'text',
|
|
70
74
|
name: 'migrateconfirm',
|
|
71
75
|
message: `Are you sure you want to migrate? (Y/n)`,
|
|
@@ -74,95 +78,73 @@ async function migrateCommand(config) {
|
|
|
74
78
|
if (typeof migrateconfirm === 'string' &&
|
|
75
79
|
migrateconfirm.toLowerCase() === 'y') {
|
|
76
80
|
try {
|
|
77
|
-
const {
|
|
81
|
+
const { depInstallConfirm } = await (0, log_1.logPrompt)(`Would you like the migrator to run npm, yarn, or pnpm install to install the latest versions of capacitor packages? (Those using other package managers should answer N)`, {
|
|
78
82
|
type: 'text',
|
|
79
|
-
name: '
|
|
80
|
-
message: `Run
|
|
83
|
+
name: 'depInstallConfirm',
|
|
84
|
+
message: `Run Dependency Install? (Y/n)`,
|
|
81
85
|
initial: 'y',
|
|
82
86
|
});
|
|
83
|
-
const runNpmInstall = typeof
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
const runNpmInstall = typeof depInstallConfirm === 'string' &&
|
|
88
|
+
depInstallConfirm.toLowerCase() === 'y';
|
|
89
|
+
let installerType = 'npm';
|
|
90
|
+
if (runNpmInstall) {
|
|
91
|
+
const { manager } = await (0, log_1.logPrompt)('What dependency manager do you use?', {
|
|
92
|
+
type: 'select',
|
|
93
|
+
name: 'manager',
|
|
94
|
+
message: `Dependency Management Tool`,
|
|
95
|
+
choices: [
|
|
96
|
+
{ title: 'NPM', value: 'npm' },
|
|
97
|
+
{ title: 'Yarn', value: 'yarn' },
|
|
98
|
+
{ title: 'PNPM', value: 'pnpm' },
|
|
99
|
+
],
|
|
100
|
+
initial: 0,
|
|
88
101
|
});
|
|
89
|
-
|
|
90
|
-
catch (ex) {
|
|
91
|
-
log_1.logger.error(`npm install failed. Try deleting node_modules folder and running ${colors_1.default.input('npm install --force')} manually.`);
|
|
102
|
+
installerType = manager;
|
|
92
103
|
}
|
|
93
104
|
try {
|
|
94
|
-
await common_1.runTask(`
|
|
95
|
-
return
|
|
105
|
+
await (0, common_1.runTask)(`Installing Latest Modules using ${installerType}.`, () => {
|
|
106
|
+
return installLatestLibs(installerType, runNpmInstall, config);
|
|
96
107
|
});
|
|
97
108
|
}
|
|
98
109
|
catch (ex) {
|
|
99
|
-
|
|
110
|
+
console.log(ex);
|
|
111
|
+
log_1.logger.error(`${installerType} install failed. Try deleting node_modules folder and running ${colors_1.default.input(`${installerType} install --force`)} manually.`);
|
|
100
112
|
}
|
|
113
|
+
// Update iOS Projects
|
|
101
114
|
if (allDependencies['@capacitor/ios'] &&
|
|
102
|
-
utils_fs_1.existsSync(config.ios.platformDirAbs)) {
|
|
103
|
-
//
|
|
104
|
-
await common_1.runTask(
|
|
105
|
-
return
|
|
106
|
-
});
|
|
107
|
-
// Update Podfile to 13.0
|
|
108
|
-
await common_1.runTask(`Migrating Podfile to 13.0.`, () => {
|
|
109
|
-
return updateFile(config, path_1.join(config.ios.nativeProjectDirAbs, 'Podfile'), `platform :ios, '`, `'`, '13.0');
|
|
110
|
-
});
|
|
111
|
-
await common_1.runTask(`Migrating Podfile to use post_install script.`, () => {
|
|
112
|
-
return podfileAssertDeploymentTarget(path_1.join(config.ios.nativeProjectDirAbs, 'Podfile'));
|
|
115
|
+
(0, utils_fs_1.existsSync)(config.ios.platformDirAbs)) {
|
|
116
|
+
//Update icon to single 1024 x 1024 icon
|
|
117
|
+
await (0, common_1.runTask)('Update App Icon to only 1024 x 1024', () => {
|
|
118
|
+
return updateAppIcons(config);
|
|
113
119
|
});
|
|
114
|
-
//
|
|
115
|
-
await common_1.runTask(
|
|
116
|
-
return
|
|
117
|
-
});
|
|
118
|
-
// Remove NSAppTransportSecurity
|
|
119
|
-
await common_1.runTask(`Migrating Info.plist by removing NSAppTransportSecurity key.`, () => {
|
|
120
|
-
return removeKey(path_1.join(config.ios.nativeTargetDirAbs, 'Info.plist'), 'NSAppTransportSecurity');
|
|
121
|
-
});
|
|
122
|
-
// Remove USE_PUSH
|
|
123
|
-
await common_1.runTask(`Migrating by removing USE_PUSH.`, () => {
|
|
124
|
-
return replacePush(path_1.join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'));
|
|
125
|
-
});
|
|
126
|
-
// Remove from App Delegate
|
|
127
|
-
await common_1.runTask(`Migrating App Delegate.`, () => {
|
|
128
|
-
return replaceIfUsePush(config);
|
|
120
|
+
//Remove Podfile.lock from .gitignore
|
|
121
|
+
await (0, common_1.runTask)('Remove Podfile.lock from iOS .gitignore', () => {
|
|
122
|
+
return updateIosGitIgnore((0, path_1.join)(config.ios.platformDirAbs, '.gitignore'));
|
|
129
123
|
});
|
|
130
124
|
}
|
|
131
125
|
if (allDependencies['@capacitor/android'] &&
|
|
132
|
-
utils_fs_1.existsSync(config.android.platformDirAbs)) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return updateAndroidManifest(path_1.join(config.android.srcMainDirAbs, 'AndroidManifest.xml'));
|
|
126
|
+
(0, utils_fs_1.existsSync)(config.android.platformDirAbs)) {
|
|
127
|
+
await (0, common_1.runTask)(`Migrating build.gradle file.`, () => {
|
|
128
|
+
return updateBuildGradle((0, path_1.join)(config.android.platformDirAbs, 'build.gradle'), variablesAndClasspaths);
|
|
136
129
|
});
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
name: 'leaveJCenterPrompt',
|
|
141
|
-
message: `Keep JCenter if present? (y/N)`,
|
|
142
|
-
initial: 'n',
|
|
143
|
-
});
|
|
144
|
-
await common_1.runTask(`Migrating build.gradle file.`, () => {
|
|
145
|
-
return updateBuildGradle(path_1.join(config.android.platformDirAbs, 'build.gradle'), typeof leaveJCenterPrompt === 'string' &&
|
|
146
|
-
leaveJCenterPrompt.toLowerCase() === 'y', variablesAndClasspaths);
|
|
147
|
-
});
|
|
148
|
-
// Update app.gradle
|
|
149
|
-
await common_1.runTask(`Migrating app/build.gradle file.`, () => {
|
|
150
|
-
return updateAppBuildGradle(path_1.join(config.android.appDirAbs, 'build.gradle'));
|
|
130
|
+
// Remove enableJetifier
|
|
131
|
+
await (0, common_1.runTask)('Remove android.enableJetifier=true from gradle.properties', () => {
|
|
132
|
+
return updateGradleProperties((0, path_1.join)(config.android.platformDirAbs, 'gradle.properties'));
|
|
151
133
|
});
|
|
152
134
|
// Update gradle-wrapper.properties
|
|
153
|
-
await common_1.runTask(`Migrating gradle-wrapper.properties by updating gradle version
|
|
154
|
-
return updateGradleWrapper(path_1.join(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
|
|
135
|
+
await (0, common_1.runTask)(`Migrating gradle-wrapper.properties by updating gradle version to ${gradleVersion}.`, () => {
|
|
136
|
+
return updateGradleWrapper((0, path_1.join)(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
|
|
155
137
|
});
|
|
156
138
|
// Variables gradle
|
|
157
|
-
await common_1.runTask(`Migrating variables.gradle file.`, () => {
|
|
139
|
+
await (0, common_1.runTask)(`Migrating variables.gradle file.`, () => {
|
|
158
140
|
return (async () => {
|
|
159
|
-
const variablesPath = path_1.join(config.android.platformDirAbs, 'variables.gradle');
|
|
141
|
+
const variablesPath = (0, path_1.join)(config.android.platformDirAbs, 'variables.gradle');
|
|
160
142
|
let txt = readFile(variablesPath);
|
|
161
143
|
if (!txt) {
|
|
162
144
|
return;
|
|
163
145
|
}
|
|
164
146
|
txt = txt.replace(/= {2}'/g, `= '`);
|
|
165
|
-
utils_fs_1.writeFileSync(variablesPath, txt, { encoding: 'utf-8' });
|
|
147
|
+
(0, utils_fs_1.writeFileSync)(variablesPath, txt, { encoding: 'utf-8' });
|
|
166
148
|
for (const variable of Object.keys(variablesAndClasspaths.variables)) {
|
|
167
149
|
if (!(await updateFile(config, variablesPath, `${variable} = '`, `'`, variablesAndClasspaths.variables[variable].toString(), true))) {
|
|
168
150
|
const didWork = await updateFile(config, variablesPath, `${variable} = `, `\n`, variablesAndClasspaths.variables[variable].toString(), true);
|
|
@@ -170,39 +152,31 @@ async function migrateCommand(config) {
|
|
|
170
152
|
let file = readFile(variablesPath);
|
|
171
153
|
if (file) {
|
|
172
154
|
file = file.replace('}', ` ${variable} = '${variablesAndClasspaths.variables[variable].toString()}'\n}`);
|
|
173
|
-
utils_fs_1.writeFileSync(variablesPath, file);
|
|
155
|
+
(0, utils_fs_1.writeFileSync)(variablesPath, file);
|
|
174
156
|
}
|
|
175
157
|
}
|
|
176
158
|
}
|
|
177
159
|
}
|
|
178
160
|
const pluginVariables = {
|
|
179
|
-
firebaseMessagingVersion: '23.
|
|
180
|
-
playServicesLocationVersion: '
|
|
181
|
-
androidxBrowserVersion: '1.
|
|
182
|
-
androidxMaterialVersion: '1.
|
|
183
|
-
androidxExifInterfaceVersion: '1.3.
|
|
161
|
+
firebaseMessagingVersion: '23.1.2',
|
|
162
|
+
playServicesLocationVersion: '21.0.1',
|
|
163
|
+
androidxBrowserVersion: '1.5.0',
|
|
164
|
+
androidxMaterialVersion: '1.8.0',
|
|
165
|
+
androidxExifInterfaceVersion: '1.3.6',
|
|
184
166
|
};
|
|
185
167
|
for (const variable of Object.keys(pluginVariables)) {
|
|
186
168
|
await updateFile(config, variablesPath, `${variable} = '`, `'`, pluginVariables[variable], true);
|
|
187
169
|
}
|
|
188
170
|
})();
|
|
189
171
|
});
|
|
190
|
-
|
|
191
|
-
await common_1.runTask('Migrating MainActivity', () => {
|
|
192
|
-
return migrateMainActivity(config);
|
|
193
|
-
});
|
|
194
|
-
rimraf_1.default.sync(path_1.join(config.android.appDirAbs, 'build'));
|
|
195
|
-
// add new splashscreen
|
|
196
|
-
await common_1.runTask('Migrate to Android 12 Splashscreen and apply DayNight theme.', () => {
|
|
197
|
-
return addNewSplashScreen(config);
|
|
198
|
-
});
|
|
172
|
+
rimraf_1.default.sync((0, path_1.join)(config.android.appDirAbs, 'build'));
|
|
199
173
|
}
|
|
200
174
|
// Run Cap Sync
|
|
201
|
-
await common_1.runTask(`Running cap sync.`, () => {
|
|
202
|
-
return subprocess_1.getCommandOutput('npx', ['cap', 'sync']);
|
|
175
|
+
await (0, common_1.runTask)(`Running cap sync.`, () => {
|
|
176
|
+
return (0, subprocess_1.getCommandOutput)('npx', ['cap', 'sync']);
|
|
203
177
|
});
|
|
204
178
|
try {
|
|
205
|
-
await common_1.runTask(`Upgrading gradle wrapper files`, () => {
|
|
179
|
+
await (0, common_1.runTask)(`Upgrading gradle wrapper files`, () => {
|
|
206
180
|
return updateGradleWrapperFiles(config.android.platformDirAbs);
|
|
207
181
|
});
|
|
208
182
|
}
|
|
@@ -215,23 +189,30 @@ async function migrateCommand(config) {
|
|
|
215
189
|
}
|
|
216
190
|
}
|
|
217
191
|
// Write all breaking changes
|
|
218
|
-
await common_1.runTask(`Writing breaking changes.`, () => {
|
|
192
|
+
await (0, common_1.runTask)(`Writing breaking changes.`, () => {
|
|
219
193
|
return writeBreakingChanges();
|
|
220
194
|
});
|
|
221
|
-
log_1.logSuccess(`Migration to Capacitor ${coreVersion} is complete. Run and test your app!`);
|
|
195
|
+
(0, log_1.logSuccess)(`Migration to Capacitor ${coreVersion} is complete. Run and test your app!`);
|
|
222
196
|
}
|
|
223
197
|
catch (err) {
|
|
224
|
-
errors_1.fatal(`Failed to migrate: ${err}`);
|
|
198
|
+
(0, errors_1.fatal)(`Failed to migrate: ${err}`);
|
|
225
199
|
}
|
|
226
200
|
}
|
|
227
201
|
else {
|
|
228
|
-
errors_1.fatal(`User canceled migration.`);
|
|
202
|
+
(0, errors_1.fatal)(`User canceled migration.`);
|
|
229
203
|
}
|
|
230
204
|
//*/
|
|
231
205
|
}
|
|
232
206
|
exports.migrateCommand = migrateCommand;
|
|
233
|
-
async function
|
|
234
|
-
|
|
207
|
+
async function checkCapacitorMajorVersion(config) {
|
|
208
|
+
var _a;
|
|
209
|
+
const capacitorVersion = await (0, common_1.getCoreVersion)(config);
|
|
210
|
+
const versionArray = (_a = capacitorVersion.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/)) !== null && _a !== void 0 ? _a : [];
|
|
211
|
+
const majorVersion = parseInt(versionArray[1]);
|
|
212
|
+
return majorVersion;
|
|
213
|
+
}
|
|
214
|
+
async function installLatestLibs(dependencyManager, runInstall, config) {
|
|
215
|
+
const pkgJsonPath = (0, path_1.join)(config.app.rootDir, 'package.json');
|
|
235
216
|
const pkgJsonFile = readFile(pkgJsonPath);
|
|
236
217
|
if (!pkgJsonFile) {
|
|
237
218
|
return;
|
|
@@ -253,36 +234,19 @@ async function installLatestNPMLibs(runInstall, config) {
|
|
|
253
234
|
pkgJson['dependencies'][depKey] = pluginVersion;
|
|
254
235
|
}
|
|
255
236
|
}
|
|
256
|
-
utils_fs_1.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2), {
|
|
237
|
+
(0, utils_fs_1.writeFileSync)(pkgJsonPath, JSON.stringify(pkgJson, null, 2), {
|
|
257
238
|
encoding: 'utf-8',
|
|
258
239
|
});
|
|
259
240
|
if (runInstall) {
|
|
260
|
-
rimraf_1.default.sync(path_1.join(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
|
|
261
|
-
await subprocess_1.runCommand(
|
|
241
|
+
rimraf_1.default.sync((0, path_1.join)(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
|
|
242
|
+
await (0, subprocess_1.runCommand)(dependencyManager, ['install']);
|
|
262
243
|
}
|
|
263
244
|
else {
|
|
264
245
|
log_1.logger.info(`Please run an install command with your package manager of choice. (ex: yarn install)`);
|
|
265
246
|
}
|
|
266
247
|
}
|
|
267
|
-
async function migrateStoragePluginToPreferences(runInstall) {
|
|
268
|
-
if (allDependencies['@capacitor/storage']) {
|
|
269
|
-
log_1.logger.info('NOTE: @capacitor/storage was renamed to @capacitor/preferences, please be sure to replace occurances in your code.');
|
|
270
|
-
if (runInstall) {
|
|
271
|
-
await subprocess_1.getCommandOutput('npm', ['uninstall', '@capacitor/storage']);
|
|
272
|
-
await subprocess_1.runCommand('npm', ['i', `@capacitor/preferences@${pluginVersion}`]);
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
log_1.logger.info(`Please manually uninstall @capacitor/storage and replace it with @capacitor/preferences@${pluginVersion}`);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
248
|
async function writeBreakingChanges() {
|
|
280
|
-
const breaking = [
|
|
281
|
-
'@capacitor/storage',
|
|
282
|
-
'@capacitor/camera',
|
|
283
|
-
'@capacitor/push-notifications',
|
|
284
|
-
'@capacitor/local-notifications',
|
|
285
|
-
];
|
|
249
|
+
const breaking = ['@capacitor/device'];
|
|
286
250
|
const broken = [];
|
|
287
251
|
for (const lib of breaking) {
|
|
288
252
|
if (allDependencies[lib]) {
|
|
@@ -290,106 +254,18 @@ async function writeBreakingChanges() {
|
|
|
290
254
|
}
|
|
291
255
|
}
|
|
292
256
|
if (broken.length > 0) {
|
|
293
|
-
log_1.logger.info(`IMPORTANT: Review https://capacitorjs.com/docs/updating/
|
|
294
|
-
}
|
|
295
|
-
if (allDependencies['@capacitor/android']) {
|
|
296
|
-
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.');
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
async function updateAndroidManifest(filename) {
|
|
300
|
-
const txt = readFile(filename);
|
|
301
|
-
if (!txt) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
const hasAndroidExportedAlreadySet = new RegExp(/<activity([^>]*(android:exported=")[^>]*)>/g).test(txt);
|
|
305
|
-
let isAndroidExportedSetToFalse = false;
|
|
306
|
-
if (hasAndroidExportedAlreadySet) {
|
|
307
|
-
isAndroidExportedSetToFalse = new RegExp(/<activity([^>]*(android:exported="false")[^>]*)>/g).test(txt);
|
|
308
|
-
}
|
|
309
|
-
// AndroidManifest.xml add attribute: <activity android:exported="true"
|
|
310
|
-
if (hasAndroidExportedAlreadySet && !isAndroidExportedSetToFalse) {
|
|
311
|
-
return; // Probably already updated manually
|
|
312
|
-
}
|
|
313
|
-
let replaced = txt;
|
|
314
|
-
if (!hasAndroidExportedAlreadySet) {
|
|
315
|
-
replaced = setAllStringIn(txt, '<activity', ' ', `\n android:exported="true"\n`);
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
log_1.logger.info(`Found 'android:exported="false"' in your AndroidManifest.xml, if this is not intentional please update it manually to "true".`);
|
|
319
|
-
}
|
|
320
|
-
if (txt == replaced) {
|
|
321
|
-
log_1.logger.error(`Unable to update Android Manifest. Missing <activity> tag`);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
325
|
-
}
|
|
326
|
-
async function updateBuildGradle(filename, leaveJCenter, variablesAndClasspaths) {
|
|
327
|
-
// In build.gradle add dependencies:
|
|
328
|
-
// classpath 'com.android.tools.build:gradle:7.2.1'
|
|
329
|
-
// classpath 'com.google.gms:google-services:4.3.13'
|
|
330
|
-
const txt = readFile(filename);
|
|
331
|
-
if (!txt) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
const neededDeps = {
|
|
335
|
-
'com.android.tools.build:gradle': variablesAndClasspaths['com.android.tools.build:gradle'],
|
|
336
|
-
'com.google.gms:google-services': variablesAndClasspaths['com.google.gms:google-services'],
|
|
337
|
-
};
|
|
338
|
-
let replaced = txt;
|
|
339
|
-
for (const dep of Object.keys(neededDeps)) {
|
|
340
|
-
if (replaced.includes(`classpath '${dep}`)) {
|
|
341
|
-
const semver = await Promise.resolve().then(() => tslib_1.__importStar(require('semver')));
|
|
342
|
-
const firstIndex = replaced.indexOf(dep) + dep.length + 1;
|
|
343
|
-
const existingVersion = '' + replaced.substring(firstIndex, replaced.indexOf("'", firstIndex));
|
|
344
|
-
if (semver.gte(neededDeps[dep], existingVersion)) {
|
|
345
|
-
replaced = setAllStringIn(replaced, `classpath '${dep}:`, `'`, neededDeps[dep]);
|
|
346
|
-
log_1.logger.info(`Set ${dep} = ${neededDeps[dep]}.`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
// Replace jcenter()
|
|
351
|
-
const lines = replaced.split('\n');
|
|
352
|
-
let inRepositories = false;
|
|
353
|
-
let hasMavenCentral = false;
|
|
354
|
-
let final = '';
|
|
355
|
-
for (const line of lines) {
|
|
356
|
-
if (line.includes('repositories {')) {
|
|
357
|
-
inRepositories = true;
|
|
358
|
-
hasMavenCentral = false;
|
|
359
|
-
}
|
|
360
|
-
else if (line.trim() == '}') {
|
|
361
|
-
// Make sure we have mavenCentral()
|
|
362
|
-
if (inRepositories && !hasMavenCentral) {
|
|
363
|
-
final += ' mavenCentral()\n';
|
|
364
|
-
log_1.logger.info(`Added mavenCentral().`);
|
|
365
|
-
}
|
|
366
|
-
inRepositories = false;
|
|
367
|
-
}
|
|
368
|
-
if (inRepositories && line.trim() === 'mavenCentral()') {
|
|
369
|
-
hasMavenCentral = true;
|
|
370
|
-
}
|
|
371
|
-
if (inRepositories && line.trim() === 'jcenter()' && !leaveJCenter) {
|
|
372
|
-
// skip jCentral()
|
|
373
|
-
log_1.logger.info(`Removed jcenter().`);
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
final += line + '\n';
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
if (txt !== final) {
|
|
380
|
-
utils_fs_1.writeFileSync(filename, final, 'utf-8');
|
|
381
|
-
return;
|
|
257
|
+
log_1.logger.info(`IMPORTANT: Review https://capacitorjs.com/docs/updating/5-0#plugins for breaking changes in these plugins that you use: ${broken.join(', ')}.`);
|
|
382
258
|
}
|
|
383
259
|
}
|
|
384
|
-
async function
|
|
385
|
-
const tempAndroidTemplateFolder = path_1.join(config.cli.assetsDirAbs, 'tempAndroidTemplate');
|
|
386
|
-
await template_1.extractTemplate(config.cli.assets.android.platformTemplateArchiveAbs, tempAndroidTemplateFolder);
|
|
387
|
-
const variablesGradleFile = readFile(path_1.join(tempAndroidTemplateFolder, 'variables.gradle'));
|
|
388
|
-
const buildGradleFile = readFile(path_1.join(tempAndroidTemplateFolder, 'build.gradle'));
|
|
260
|
+
async function getAndroidVariablesAndClasspaths(config) {
|
|
261
|
+
const tempAndroidTemplateFolder = (0, path_1.join)(config.cli.assetsDirAbs, 'tempAndroidTemplate');
|
|
262
|
+
await (0, template_1.extractTemplate)(config.cli.assets.android.platformTemplateArchiveAbs, tempAndroidTemplateFolder);
|
|
263
|
+
const variablesGradleFile = readFile((0, path_1.join)(tempAndroidTemplateFolder, 'variables.gradle'));
|
|
264
|
+
const buildGradleFile = readFile((0, path_1.join)(tempAndroidTemplateFolder, 'build.gradle'));
|
|
389
265
|
if (!variablesGradleFile || !buildGradleFile) {
|
|
390
266
|
return;
|
|
391
267
|
}
|
|
392
|
-
fs_1.deleteFolderRecursive(tempAndroidTemplateFolder);
|
|
268
|
+
(0, fs_1.deleteFolderRecursive)(tempAndroidTemplateFolder);
|
|
393
269
|
const firstIndxOfCATBGV = buildGradleFile.indexOf(`classpath 'com.android.tools.build:gradle:`) + 42;
|
|
394
270
|
const firstIndxOfCGGGS = buildGradleFile.indexOf(`com.google.gms:google-services:`) + 31;
|
|
395
271
|
const comAndroidToolsBuildGradleVersion = '' +
|
|
@@ -415,33 +291,16 @@ async function getAndroidVarriablesAndClasspaths(config) {
|
|
|
415
291
|
}
|
|
416
292
|
function readFile(filename) {
|
|
417
293
|
try {
|
|
418
|
-
if (!utils_fs_1.existsSync(filename)) {
|
|
294
|
+
if (!(0, utils_fs_1.existsSync)(filename)) {
|
|
419
295
|
log_1.logger.error(`Unable to find ${filename}. Try updating it manually`);
|
|
420
296
|
return;
|
|
421
297
|
}
|
|
422
|
-
return utils_fs_1.readFileSync(filename, 'utf-8');
|
|
298
|
+
return (0, utils_fs_1.readFileSync)(filename, 'utf-8');
|
|
423
299
|
}
|
|
424
300
|
catch (err) {
|
|
425
301
|
log_1.logger.error(`Unable to read ${filename}. Verify it is not already open. ${err}`);
|
|
426
302
|
}
|
|
427
303
|
}
|
|
428
|
-
async function updateAppBuildGradle(filename) {
|
|
429
|
-
const txt = readFile(filename);
|
|
430
|
-
if (!txt) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
let replaced = txt;
|
|
434
|
-
if (!txt.includes('androidx.coordinatorlayout:coordinatorlayout:')) {
|
|
435
|
-
replaced = replaced.replace('dependencies {', 'dependencies {\n implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"');
|
|
436
|
-
}
|
|
437
|
-
if (!txt.includes('androidx.core:core-splashscreen:')) {
|
|
438
|
-
replaced = replaced.replace('dependencies {', 'dependencies {\n implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"');
|
|
439
|
-
}
|
|
440
|
-
// const lines = txt.split('\n');
|
|
441
|
-
if (replaced !== txt) {
|
|
442
|
-
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
304
|
async function updateGradleWrapper(filename) {
|
|
446
305
|
const txt = readFile(filename);
|
|
447
306
|
if (!txt) {
|
|
@@ -450,10 +309,10 @@ async function updateGradleWrapper(filename) {
|
|
|
450
309
|
const replaced = setAllStringIn(txt, 'distributionUrl=', '\n',
|
|
451
310
|
// eslint-disable-next-line no-useless-escape
|
|
452
311
|
`https\\://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip`);
|
|
453
|
-
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
312
|
+
(0, utils_fs_1.writeFileSync)(filename, replaced, 'utf-8');
|
|
454
313
|
}
|
|
455
314
|
async function updateGradleWrapperFiles(platformDir) {
|
|
456
|
-
await subprocess_1.runCommand(`./gradlew`, [
|
|
315
|
+
await (0, subprocess_1.runCommand)(`./gradlew`, [
|
|
457
316
|
'wrapper',
|
|
458
317
|
'--distribution-type',
|
|
459
318
|
'all',
|
|
@@ -465,6 +324,102 @@ async function updateGradleWrapperFiles(platformDir) {
|
|
|
465
324
|
cwd: platformDir,
|
|
466
325
|
});
|
|
467
326
|
}
|
|
327
|
+
async function updateIosGitIgnore(filename) {
|
|
328
|
+
const txt = readFile(filename);
|
|
329
|
+
if (!txt) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const lines = txt.split('\n');
|
|
333
|
+
let linesToKeep = '';
|
|
334
|
+
for (const line of lines) {
|
|
335
|
+
// check for enableJetifier
|
|
336
|
+
const podfileMatch = line.match(/.+Podfile\.lock/) || [];
|
|
337
|
+
if (podfileMatch.length == 0) {
|
|
338
|
+
linesToKeep += line + '\n';
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
(0, utils_fs_1.writeFileSync)(filename, linesToKeep, { encoding: 'utf-8' });
|
|
342
|
+
}
|
|
343
|
+
async function updateAppIcons(config) {
|
|
344
|
+
const iconToKeep = 'AppIcon-512@2x.png';
|
|
345
|
+
const contentsFile = 'Contents.json';
|
|
346
|
+
const newContentsFileContents = `{
|
|
347
|
+
"images" : [
|
|
348
|
+
{
|
|
349
|
+
"filename" : "${iconToKeep}",
|
|
350
|
+
"idiom" : "universal",
|
|
351
|
+
"platform" : "ios",
|
|
352
|
+
"size" : "1024x1024"
|
|
353
|
+
}
|
|
354
|
+
],
|
|
355
|
+
"info" : {
|
|
356
|
+
"author" : "xcode",
|
|
357
|
+
"version" : 1
|
|
358
|
+
}
|
|
359
|
+
}`;
|
|
360
|
+
const path = (0, path_1.join)(config.ios.platformDirAbs, 'App', 'App', 'Assets.xcassets', 'AppIcon.appiconset');
|
|
361
|
+
if (!(0, utils_fs_1.existsSync)(path)) {
|
|
362
|
+
log_1.logger.error(`Unable to find ${path}. Try updating it manually`);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (!(0, utils_fs_1.existsSync)((0, path_1.join)(path, iconToKeep))) {
|
|
366
|
+
log_1.logger.error(`Unable to find ${iconToKeep}. Try updating it manually`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (!(0, utils_fs_1.existsSync)((0, path_1.join)(path, contentsFile))) {
|
|
370
|
+
log_1.logger.error(`Unable to find ${path}. Try updating it manually`);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const filenames = (0, utils_fs_1.readdirSync)(path);
|
|
374
|
+
for (const filename of filenames) {
|
|
375
|
+
if (filename != iconToKeep && filename != contentsFile) {
|
|
376
|
+
(0, utils_fs_1.removeSync)((0, path_1.join)(path, filename));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
(0, utils_fs_1.writeFileSync)((0, path_1.join)(path, contentsFile), newContentsFileContents);
|
|
380
|
+
}
|
|
381
|
+
async function updateGradleProperties(filename) {
|
|
382
|
+
const txt = readFile(filename);
|
|
383
|
+
if (!txt) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const lines = txt.split('\n');
|
|
387
|
+
let linesToKeep = '';
|
|
388
|
+
for (const line of lines) {
|
|
389
|
+
// check for enableJetifier
|
|
390
|
+
const jetifierMatch = line.match(/android\.enableJetifier\s*=\s*true/) || [];
|
|
391
|
+
const commentMatch = line.match(/# Automatically convert third-party libraries to use AndroidX/) || [];
|
|
392
|
+
if (jetifierMatch.length == 0 && commentMatch.length == 0) {
|
|
393
|
+
linesToKeep += line + '\n';
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
(0, utils_fs_1.writeFileSync)(filename, linesToKeep, { encoding: 'utf-8' });
|
|
397
|
+
}
|
|
398
|
+
async function updateBuildGradle(filename, variablesAndClasspaths) {
|
|
399
|
+
// In build.gradle add dependencies:
|
|
400
|
+
// classpath 'com.android.tools.build:gradle:7.4.1'
|
|
401
|
+
// classpath 'com.google.gms:google-services:4.3.13'
|
|
402
|
+
const txt = readFile(filename);
|
|
403
|
+
if (!txt) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const neededDeps = {
|
|
407
|
+
'com.android.tools.build:gradle': variablesAndClasspaths['com.android.tools.build:gradle'],
|
|
408
|
+
'com.google.gms:google-services': variablesAndClasspaths['com.google.gms:google-services'],
|
|
409
|
+
};
|
|
410
|
+
let replaced = txt;
|
|
411
|
+
for (const dep of Object.keys(neededDeps)) {
|
|
412
|
+
if (replaced.includes(`classpath '${dep}`)) {
|
|
413
|
+
const semver = await Promise.resolve().then(() => tslib_1.__importStar(require('semver')));
|
|
414
|
+
const firstIndex = replaced.indexOf(dep) + dep.length + 1;
|
|
415
|
+
const existingVersion = '' + replaced.substring(firstIndex, replaced.indexOf("'", firstIndex));
|
|
416
|
+
if (semver.gte(neededDeps[dep], existingVersion)) {
|
|
417
|
+
replaced = setAllStringIn(replaced, `classpath '${dep}:`, `'`, neededDeps[dep]);
|
|
418
|
+
log_1.logger.info(`Set ${dep} = ${neededDeps[dep]}.`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
468
423
|
async function updateFile(config, filename, textStart, textEnd, replacement, skipIfNotFound) {
|
|
469
424
|
if (config === null) {
|
|
470
425
|
return false;
|
|
@@ -477,7 +432,7 @@ async function updateFile(config, filename, textStart, textEnd, replacement, ski
|
|
|
477
432
|
if (txt.includes(textStart)) {
|
|
478
433
|
if (replacement) {
|
|
479
434
|
txt = setAllStringIn(txt, textStart, textEnd, replacement);
|
|
480
|
-
utils_fs_1.writeFileSync(path, txt, { encoding: 'utf-8' });
|
|
435
|
+
(0, utils_fs_1.writeFileSync)(path, txt, { encoding: 'utf-8' });
|
|
481
436
|
}
|
|
482
437
|
else {
|
|
483
438
|
// Replacing in code so we need to count the number of brackets to find the end of the function in swift
|
|
@@ -500,7 +455,7 @@ async function updateFile(config, filename, textStart, textEnd, replacement, ski
|
|
|
500
455
|
replaced += line + '\n';
|
|
501
456
|
}
|
|
502
457
|
}
|
|
503
|
-
utils_fs_1.writeFileSync(path, replaced, { encoding: 'utf-8' });
|
|
458
|
+
(0, utils_fs_1.writeFileSync)(path, replaced, { encoding: 'utf-8' });
|
|
504
459
|
}
|
|
505
460
|
return true;
|
|
506
461
|
}
|
|
@@ -529,176 +484,3 @@ function setAllStringIn(data, start, end, replacement) {
|
|
|
529
484
|
}
|
|
530
485
|
return result;
|
|
531
486
|
}
|
|
532
|
-
async function replaceIfUsePush(config) {
|
|
533
|
-
const startLine = '#if USE_PUSH';
|
|
534
|
-
const endLine = '#endif';
|
|
535
|
-
const filename = path_1.join(config.ios.nativeTargetDirAbs, 'AppDelegate.swift');
|
|
536
|
-
const txt = readFile(filename);
|
|
537
|
-
if (!txt) {
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
const lines = txt.split('\n');
|
|
541
|
-
let startLineIndex = null;
|
|
542
|
-
let endLineIndex = null;
|
|
543
|
-
for (const [key, item] of lines.entries()) {
|
|
544
|
-
if (item.includes(startLine)) {
|
|
545
|
-
startLineIndex = key;
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
if (startLineIndex !== null) {
|
|
550
|
-
for (const [key, item] of lines.entries()) {
|
|
551
|
-
if (item.includes(endLine) && key > startLineIndex) {
|
|
552
|
-
endLineIndex = key;
|
|
553
|
-
break;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
if (endLineIndex !== null) {
|
|
557
|
-
lines[endLineIndex] = '';
|
|
558
|
-
lines[startLineIndex] = '';
|
|
559
|
-
utils_fs_1.writeFileSync(filename, lines.join('\n'), 'utf-8');
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
async function replacePush(filename) {
|
|
564
|
-
const txt = readFile(filename);
|
|
565
|
-
if (!txt) {
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
let replaced = txt;
|
|
569
|
-
replaced = replaced.replace('DEBUG USE_PUSH', 'DEBUG');
|
|
570
|
-
replaced = replaced.replace('USE_PUSH', '""');
|
|
571
|
-
if (replaced != txt) {
|
|
572
|
-
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
async function removeKey(filename, key) {
|
|
576
|
-
const txt = readFile(filename);
|
|
577
|
-
if (!txt) {
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
let lines = txt.split('\n');
|
|
581
|
-
let removed = false;
|
|
582
|
-
let removing = false;
|
|
583
|
-
lines = lines.filter(line => {
|
|
584
|
-
if (removing && line.includes('</dict>')) {
|
|
585
|
-
removing = false;
|
|
586
|
-
return false;
|
|
587
|
-
}
|
|
588
|
-
if (line.includes(`<key>${key}</key`)) {
|
|
589
|
-
removing = true;
|
|
590
|
-
removed = true;
|
|
591
|
-
}
|
|
592
|
-
return !removing;
|
|
593
|
-
});
|
|
594
|
-
if (removed) {
|
|
595
|
-
utils_fs_1.writeFileSync(filename, lines.join('\n'), 'utf-8');
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
async function podfileAssertDeploymentTarget(filename) {
|
|
599
|
-
const txt = readFile(filename);
|
|
600
|
-
if (!txt) {
|
|
601
|
-
return;
|
|
602
|
-
}
|
|
603
|
-
let replaced = txt;
|
|
604
|
-
if (!replaced.includes(`require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers`)) {
|
|
605
|
-
replaced =
|
|
606
|
-
`require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'\n\n` +
|
|
607
|
-
txt;
|
|
608
|
-
}
|
|
609
|
-
if (replaced.includes('post_install do |installer|')) {
|
|
610
|
-
if (!replaced.includes(`assertDeploymentTarget(installer)`)) {
|
|
611
|
-
replaced = replaced.replace('post_install do |installer|', `post_install do |installer|\n assertDeploymentTarget(installer)\n`);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
replaced =
|
|
616
|
-
replaced +
|
|
617
|
-
`\n\npost_install do |installer|\n assertDeploymentTarget(installer)\nend\n`;
|
|
618
|
-
}
|
|
619
|
-
utils_fs_1.writeFileSync(filename, replaced, 'utf-8');
|
|
620
|
-
}
|
|
621
|
-
async function migrateMainActivity(config) {
|
|
622
|
-
const xmlData = await xml_1.readXML(path_1.join(config.android.srcMainDirAbs, 'AndroidManifest.xml'));
|
|
623
|
-
const manifestNode = xmlData.manifest;
|
|
624
|
-
const applicationChildNodes = manifestNode.application;
|
|
625
|
-
let mainActivityClassPath = '';
|
|
626
|
-
applicationChildNodes.find(applicationChildNode => {
|
|
627
|
-
const activityChildNodes = applicationChildNode.activity;
|
|
628
|
-
if (!Array.isArray(activityChildNodes)) {
|
|
629
|
-
return false;
|
|
630
|
-
}
|
|
631
|
-
const mainActivityNode = activityChildNodes.find(activityChildNode => {
|
|
632
|
-
const intentFilterChildNodes = activityChildNode['intent-filter'];
|
|
633
|
-
if (!Array.isArray(intentFilterChildNodes)) {
|
|
634
|
-
return false;
|
|
635
|
-
}
|
|
636
|
-
return intentFilterChildNodes.find(intentFilterChildNode => {
|
|
637
|
-
const actionChildNodes = intentFilterChildNode.action;
|
|
638
|
-
if (!Array.isArray(actionChildNodes)) {
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
const mainActionChildNode = actionChildNodes.find(actionChildNode => {
|
|
642
|
-
const androidName = actionChildNode.$['android:name'];
|
|
643
|
-
return androidName === 'android.intent.action.MAIN';
|
|
644
|
-
});
|
|
645
|
-
if (!mainActionChildNode) {
|
|
646
|
-
return false;
|
|
647
|
-
}
|
|
648
|
-
const categoryChildNodes = intentFilterChildNode.category;
|
|
649
|
-
if (!Array.isArray(categoryChildNodes)) {
|
|
650
|
-
return false;
|
|
651
|
-
}
|
|
652
|
-
return categoryChildNodes.find(categoryChildNode => {
|
|
653
|
-
const androidName = categoryChildNode.$['android:name'];
|
|
654
|
-
return androidName === 'android.intent.category.LAUNCHER';
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
});
|
|
658
|
-
if (mainActivityNode) {
|
|
659
|
-
mainActivityClassPath = mainActivityNode.$['android:name'];
|
|
660
|
-
}
|
|
661
|
-
return mainActivityNode;
|
|
662
|
-
});
|
|
663
|
-
const mainActivityClassName = mainActivityClassPath.split('.').pop();
|
|
664
|
-
const mainActivityPathArray = mainActivityClassPath.split('.');
|
|
665
|
-
mainActivityPathArray.pop();
|
|
666
|
-
const mainActivityClassFileName = `${mainActivityClassName}.java`;
|
|
667
|
-
const mainActivityClassFilePath = path_1.join(path_1.join(config.android.srcMainDirAbs, 'java'), ...mainActivityPathArray, mainActivityClassFileName);
|
|
668
|
-
let data = readFile(mainActivityClassFilePath);
|
|
669
|
-
if (data) {
|
|
670
|
-
const bindex = data.indexOf('this.init(savedInstanceState');
|
|
671
|
-
if (bindex !== -1) {
|
|
672
|
-
const eindex = data.indexOf('}});', bindex) + 4;
|
|
673
|
-
data = data.replace(data.substring(bindex, eindex), '');
|
|
674
|
-
data = data.replace('// Initializes the Bridge', '');
|
|
675
|
-
}
|
|
676
|
-
const rindex = data.indexOf('registerPlugin');
|
|
677
|
-
const superLine = 'super.onCreate(savedInstanceState);';
|
|
678
|
-
if (rindex !== -1) {
|
|
679
|
-
if (data.indexOf(superLine) < rindex) {
|
|
680
|
-
const linePadding = rindex - data.indexOf(superLine) - superLine.length - 1;
|
|
681
|
-
data = data.replace(`${superLine}\n${' '.repeat(linePadding)}`, '');
|
|
682
|
-
const eindex = data.lastIndexOf('.class);') + 8;
|
|
683
|
-
data = data.replace(data.substring(bindex, eindex), `${data.substring(bindex, eindex)}\n${' '.repeat(linePadding) + superLine.padStart(linePadding)}`);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
if (bindex == -1 && rindex == -1) {
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
utils_fs_1.writeFileSync(mainActivityClassFilePath, data);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
async function addNewSplashScreen(config) {
|
|
693
|
-
const stylePath = path_1.join(config.android.srcMainDirAbs, 'res', 'values', 'styles.xml');
|
|
694
|
-
let stylesXml = readFile(stylePath);
|
|
695
|
-
if (!stylesXml)
|
|
696
|
-
return;
|
|
697
|
-
stylesXml = stylesXml.replace(`parent="AppTheme.NoActionBar"`, `parent="Theme.SplashScreen"`);
|
|
698
|
-
// revert wrong replaces
|
|
699
|
-
stylesXml = stylesXml.replace(`name="Theme.SplashScreen"`, `name="AppTheme.NoActionBar"`);
|
|
700
|
-
stylesXml = stylesXml.replace(`name="Theme.SplashScreenLaunch"`, `name="AppTheme.NoActionBarLaunch"`);
|
|
701
|
-
// Apply DayNight theme
|
|
702
|
-
stylesXml = stylesXml.replace(`parent="Theme.AppCompat.NoActionBar"`, `parent="Theme.AppCompat.DayNight.NoActionBar"`);
|
|
703
|
-
utils_fs_1.writeFileSync(stylePath, stylesXml);
|
|
704
|
-
}
|