@capacitor-plus/cli 8.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +84 -0
- 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-pods-template.tar.gz +0 -0
- package/assets/ios-spm-template.tar.gz +0 -0
- package/bin/capacitor +18 -0
- package/dist/android/add.js +52 -0
- package/dist/android/build.js +104 -0
- package/dist/android/common.js +94 -0
- package/dist/android/doctor.js +160 -0
- package/dist/android/open.js +28 -0
- package/dist/android/run.js +42 -0
- package/dist/android/update.js +317 -0
- package/dist/colors.js +26 -0
- package/dist/common.js +435 -0
- package/dist/config.js +404 -0
- package/dist/cordova.js +801 -0
- package/dist/declarations.d.ts +674 -0
- package/dist/declarations.js +2 -0
- package/dist/definitions.js +13 -0
- package/dist/errors.js +27 -0
- package/dist/framework-configs.js +109 -0
- package/dist/index.js +253 -0
- package/dist/ios/add.js +13 -0
- package/dist/ios/build.js +96 -0
- package/dist/ios/common.js +105 -0
- package/dist/ios/doctor.js +45 -0
- package/dist/ios/open.js +17 -0
- package/dist/ios/run.js +51 -0
- package/dist/ios/update.js +449 -0
- package/dist/ipc.js +61 -0
- package/dist/log.js +39 -0
- package/dist/plugin.js +182 -0
- package/dist/sysconfig.js +35 -0
- package/dist/tasks/add.js +115 -0
- package/dist/tasks/build.js +63 -0
- package/dist/tasks/config.js +28 -0
- package/dist/tasks/copy.js +210 -0
- package/dist/tasks/create.js +10 -0
- package/dist/tasks/doctor.js +68 -0
- package/dist/tasks/init.js +138 -0
- package/dist/tasks/list.js +50 -0
- package/dist/tasks/migrate-spm.js +19 -0
- package/dist/tasks/migrate.js +518 -0
- package/dist/tasks/new-plugin.js +10 -0
- package/dist/tasks/open.js +62 -0
- package/dist/tasks/run.js +118 -0
- package/dist/tasks/serve.js +11 -0
- package/dist/tasks/sourcemaps.js +39 -0
- package/dist/tasks/sync.js +55 -0
- package/dist/tasks/telemetry.js +41 -0
- package/dist/tasks/update.js +74 -0
- package/dist/telemetry.js +119 -0
- package/dist/util/cli.js +25 -0
- package/dist/util/emoji.js +13 -0
- package/dist/util/fn.js +13 -0
- package/dist/util/fs.js +43 -0
- package/dist/util/iosplugin.js +66 -0
- package/dist/util/js.js +21 -0
- package/dist/util/livereload.js +148 -0
- package/dist/util/monorepotools.js +109 -0
- package/dist/util/native-run.js +63 -0
- package/dist/util/node.js +54 -0
- package/dist/util/promise.js +35 -0
- package/dist/util/spm.js +187 -0
- package/dist/util/subprocess.js +37 -0
- package/dist/util/template.js +11 -0
- package/dist/util/term.js +30 -0
- package/dist/util/uuid.js +11 -0
- package/dist/util/xml.js +55 -0
- package/package.json +89 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const rimraf_1 = require("rimraf");
|
|
8
|
+
const semver_1 = require("semver");
|
|
9
|
+
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
|
10
|
+
const common_1 = require("../common");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
12
|
+
const common_2 = require("../ios/common");
|
|
13
|
+
const log_1 = require("../log");
|
|
14
|
+
const fs_1 = require("../util/fs");
|
|
15
|
+
const spm_1 = require("../util/spm");
|
|
16
|
+
const subprocess_1 = require("../util/subprocess");
|
|
17
|
+
const template_1 = require("../util/template");
|
|
18
|
+
// eslint-disable-next-line prefer-const
|
|
19
|
+
let allDependencies = {};
|
|
20
|
+
const libs = ['@capacitor/core', '@capacitor/cli', '@capacitor/ios', '@capacitor/android'];
|
|
21
|
+
const plugins = [
|
|
22
|
+
'@capacitor/action-sheet',
|
|
23
|
+
'@capacitor/app',
|
|
24
|
+
'@capacitor/app-launcher',
|
|
25
|
+
'@capacitor/browser',
|
|
26
|
+
'@capacitor/camera',
|
|
27
|
+
'@capacitor/clipboard',
|
|
28
|
+
'@capacitor/device',
|
|
29
|
+
'@capacitor/dialog',
|
|
30
|
+
'@capacitor/filesystem',
|
|
31
|
+
'@capacitor/geolocation',
|
|
32
|
+
'@capacitor/haptics',
|
|
33
|
+
'@capacitor/keyboard',
|
|
34
|
+
'@capacitor/local-notifications',
|
|
35
|
+
'@capacitor/motion',
|
|
36
|
+
'@capacitor/network',
|
|
37
|
+
'@capacitor/preferences',
|
|
38
|
+
'@capacitor/push-notifications',
|
|
39
|
+
'@capacitor/screen-reader',
|
|
40
|
+
'@capacitor/screen-orientation',
|
|
41
|
+
'@capacitor/share',
|
|
42
|
+
'@capacitor/splash-screen',
|
|
43
|
+
'@capacitor/status-bar',
|
|
44
|
+
'@capacitor/text-zoom',
|
|
45
|
+
'@capacitor/toast',
|
|
46
|
+
];
|
|
47
|
+
const coreVersion = '^8.0.0';
|
|
48
|
+
const pluginVersion = '^8.0.0';
|
|
49
|
+
const gradleVersion = '8.14.3';
|
|
50
|
+
const iOSVersion = '15';
|
|
51
|
+
const kotlinVersion = '2.2.20';
|
|
52
|
+
let installFailed = false;
|
|
53
|
+
async function migrateCommand(config, noprompt, packagemanager) {
|
|
54
|
+
if (config === null) {
|
|
55
|
+
(0, errors_1.fatal)('Config data missing');
|
|
56
|
+
}
|
|
57
|
+
const capMajor = await checkCapacitorMajorVersion(config);
|
|
58
|
+
if (capMajor < 7) {
|
|
59
|
+
(0, errors_1.fatal)('Migrate can only be used on Capacitor 7, please use the CLI in Capacitor 7 to upgrade to 7 first');
|
|
60
|
+
}
|
|
61
|
+
const jdkMajor = await (0, common_1.checkJDKMajorVersion)();
|
|
62
|
+
if (jdkMajor < 21) {
|
|
63
|
+
log_1.logger.warn('Capacitor 8 requires JDK 21 or higher. Some steps may fail.');
|
|
64
|
+
}
|
|
65
|
+
const variablesAndClasspaths = await getAndroidVariablesAndClasspaths(config);
|
|
66
|
+
if (!variablesAndClasspaths) {
|
|
67
|
+
(0, errors_1.fatal)('Variable and Classpath info could not be read.');
|
|
68
|
+
}
|
|
69
|
+
allDependencies = {
|
|
70
|
+
...config.app.package.dependencies,
|
|
71
|
+
...config.app.package.devDependencies,
|
|
72
|
+
};
|
|
73
|
+
const monorepoWarning = 'Please note this tool is not intended for use in a mono-repo environment, you should migrate manually instead. Refer to https://capacitorjs.com/docs/next/updating/8-0';
|
|
74
|
+
log_1.logger.info(monorepoWarning);
|
|
75
|
+
const { migrateconfirm } = noprompt
|
|
76
|
+
? { migrateconfirm: 'y' }
|
|
77
|
+
: await (0, log_1.logPrompt)(`Capacitor 8 sets a deployment target of iOS ${iOSVersion} and Android 16 (SDK 36). \n`, {
|
|
78
|
+
type: 'text',
|
|
79
|
+
name: 'migrateconfirm',
|
|
80
|
+
message: `Are you sure you want to migrate? (Y/n)`,
|
|
81
|
+
initial: 'y',
|
|
82
|
+
});
|
|
83
|
+
if (typeof migrateconfirm === 'string' && migrateconfirm.toLowerCase() === 'y') {
|
|
84
|
+
try {
|
|
85
|
+
const { depInstallConfirm } = noprompt
|
|
86
|
+
? { depInstallConfirm: 'y' }
|
|
87
|
+
: await (0, log_1.logPrompt)(`Would you like the migrator to run npm, yarn, pnpm, or bun install to install the latest versions of capacitor packages? (Those using other package managers should answer N)`, {
|
|
88
|
+
type: 'text',
|
|
89
|
+
name: 'depInstallConfirm',
|
|
90
|
+
message: `Run Dependency Install? (Y/n)`,
|
|
91
|
+
initial: 'y',
|
|
92
|
+
});
|
|
93
|
+
const runNpmInstall = typeof depInstallConfirm === 'string' && depInstallConfirm.toLowerCase() === 'y';
|
|
94
|
+
let installerType = 'npm';
|
|
95
|
+
if (runNpmInstall) {
|
|
96
|
+
const { manager } = packagemanager
|
|
97
|
+
? { manager: packagemanager }
|
|
98
|
+
: await (0, log_1.logPrompt)('What dependency manager do you use?', {
|
|
99
|
+
type: 'select',
|
|
100
|
+
name: 'manager',
|
|
101
|
+
message: `Dependency Management Tool`,
|
|
102
|
+
choices: [
|
|
103
|
+
{ title: 'NPM', value: 'npm' },
|
|
104
|
+
{ title: 'Yarn', value: 'yarn' },
|
|
105
|
+
{ title: 'PNPM', value: 'pnpm' },
|
|
106
|
+
{ title: 'Bun', value: 'bun' },
|
|
107
|
+
],
|
|
108
|
+
initial: 0,
|
|
109
|
+
});
|
|
110
|
+
installerType = manager;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
await (0, common_1.runTask)(`Installing Latest Modules using ${installerType}.`, () => {
|
|
114
|
+
return installLatestLibs(installerType, runNpmInstall, config);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch (ex) {
|
|
118
|
+
log_1.logger.error(`${installerType} install failed. Try deleting node_modules folder and running ${colors_1.default.input(`${installerType} install --force`)} manually.`);
|
|
119
|
+
installFailed = true;
|
|
120
|
+
}
|
|
121
|
+
// Update iOS Projects
|
|
122
|
+
if (allDependencies['@capacitor/ios'] && (0, fs_extra_1.existsSync)(config.ios.platformDirAbs)) {
|
|
123
|
+
const currentiOSVersion = (0, common_2.getMajoriOSVersion)(config);
|
|
124
|
+
if (parseInt(currentiOSVersion) < parseInt(iOSVersion)) {
|
|
125
|
+
// ios template changes
|
|
126
|
+
await (0, common_1.runTask)(`Migrating deployment target to ${iOSVersion}.0.`, () => {
|
|
127
|
+
return updateFile(config, (0, path_1.join)(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'), 'IPHONEOS_DEPLOYMENT_TARGET = ', ';', `${iOSVersion}.0`);
|
|
128
|
+
});
|
|
129
|
+
if ((await (0, spm_1.checkPackageManager)(config)) === 'Cocoapods') {
|
|
130
|
+
// Update Podfile
|
|
131
|
+
await (0, common_1.runTask)(`Migrating Podfile to ${iOSVersion}.0.`, () => {
|
|
132
|
+
return updateFile(config, (0, path_1.join)(config.ios.nativeProjectDirAbs, 'Podfile'), `platform :ios, '`, `'`, `${iOSVersion}.0`);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
log_1.logger.warn('Skipped updating deployment target');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!installFailed) {
|
|
141
|
+
await (0, common_1.runTask)(`Running cap sync.`, () => {
|
|
142
|
+
return (0, subprocess_1.runCommand)('npx', ['cap', 'sync']);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
log_1.logger.warn('Skipped Running cap sync.');
|
|
147
|
+
}
|
|
148
|
+
if (allDependencies['@capacitor/android'] && (0, fs_extra_1.existsSync)(config.android.platformDirAbs)) {
|
|
149
|
+
// AndroidManifest.xml add "density"
|
|
150
|
+
await (0, common_1.runTask)(`Migrating AndroidManifest.xml by adding density to Activity configChanges.`, () => {
|
|
151
|
+
return updateAndroidManifest((0, path_1.join)(config.android.srcMainDirAbs, 'AndroidManifest.xml'));
|
|
152
|
+
});
|
|
153
|
+
const gradleWrapperVersion = getGradleWrapperVersion((0, path_1.join)(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
|
|
154
|
+
if (!installFailed && (0, semver_1.gte)(gradleVersion, gradleWrapperVersion)) {
|
|
155
|
+
try {
|
|
156
|
+
await (0, common_1.runTask)(`Upgrading gradle wrapper`, () => {
|
|
157
|
+
return updateGradleWrapperFiles(config.android.platformDirAbs);
|
|
158
|
+
});
|
|
159
|
+
// Run twice as first time it only updates the wrapper properties file
|
|
160
|
+
await (0, common_1.runTask)(`Upgrading gradle wrapper files`, () => {
|
|
161
|
+
return updateGradleWrapperFiles(config.android.platformDirAbs);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
if (e.includes('EACCES')) {
|
|
166
|
+
log_1.logger.error(`gradlew file does not have executable permissions. This can happen if the Android platform was added on a Windows machine. Please run ${colors_1.default.input(`chmod +x ./${config.android.platformDir}/gradlew`)} and ${colors_1.default.input(`cd ${config.android.platformDir} && ./gradlew wrapper --distribution-type all --gradle-version ${gradleVersion} --warning-mode all`)} to update the files manually`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
log_1.logger.error(`gradle wrapper files were not updated`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
log_1.logger.warn('Skipped upgrading gradle wrapper files');
|
|
175
|
+
}
|
|
176
|
+
await (0, common_1.runTask)(`Migrating root build.gradle file.`, () => {
|
|
177
|
+
return updateBuildGradle((0, path_1.join)(config.android.platformDirAbs, 'build.gradle'), variablesAndClasspaths);
|
|
178
|
+
});
|
|
179
|
+
await (0, common_1.runTask)(`Migrating app build.gradle file.`, () => {
|
|
180
|
+
return updateAppBuildGradle((0, path_1.join)(config.android.appDirAbs, 'build.gradle'));
|
|
181
|
+
});
|
|
182
|
+
// Variables gradle
|
|
183
|
+
await (0, common_1.runTask)(`Migrating variables.gradle file.`, () => {
|
|
184
|
+
return (async () => {
|
|
185
|
+
const variablesPath = (0, path_1.join)(config.android.platformDirAbs, 'variables.gradle');
|
|
186
|
+
let txt = readFile(variablesPath);
|
|
187
|
+
if (!txt) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
txt = txt.replace(/= {2}'/g, `= '`);
|
|
191
|
+
(0, fs_extra_1.writeFileSync)(variablesPath, txt, { encoding: 'utf-8' });
|
|
192
|
+
for (const variable of Object.keys(variablesAndClasspaths.variables)) {
|
|
193
|
+
let replaceStart = `${variable} = '`;
|
|
194
|
+
let replaceEnd = `'\n`;
|
|
195
|
+
if (typeof variablesAndClasspaths.variables[variable] === 'number') {
|
|
196
|
+
replaceStart = `${variable} = `;
|
|
197
|
+
replaceEnd = `\n`;
|
|
198
|
+
}
|
|
199
|
+
if (txt.includes(replaceStart)) {
|
|
200
|
+
const first = txt.indexOf(replaceStart) + replaceStart.length;
|
|
201
|
+
const value = txt.substring(first, txt.indexOf(replaceEnd, first));
|
|
202
|
+
if ((typeof variablesAndClasspaths.variables[variable] === 'number' &&
|
|
203
|
+
value <= variablesAndClasspaths.variables[variable]) ||
|
|
204
|
+
(typeof variablesAndClasspaths.variables[variable] === 'string' &&
|
|
205
|
+
(0, semver_1.lt)(value, variablesAndClasspaths.variables[variable]))) {
|
|
206
|
+
await updateFile(config, variablesPath, replaceStart, replaceEnd, variablesAndClasspaths.variables[variable].toString(), true);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
let file = readFile(variablesPath);
|
|
211
|
+
if (file) {
|
|
212
|
+
file = file.replace('}', ` ${replaceStart}${variablesAndClasspaths.variables[variable].toString()}${replaceEnd}}`);
|
|
213
|
+
(0, fs_extra_1.writeFileSync)(variablesPath, file);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const pluginVariables = {
|
|
218
|
+
firebaseMessagingVersion: '25.0.1',
|
|
219
|
+
playServicesLocationVersion: '21.3.0',
|
|
220
|
+
androidxBrowserVersion: '1.9.0',
|
|
221
|
+
androidxMaterialVersion: '1.13.0',
|
|
222
|
+
androidxExifInterfaceVersion: '1.4.1',
|
|
223
|
+
androidxCoreKTXVersion: '1.17.0',
|
|
224
|
+
googleMapsPlayServicesVersion: '19.2.0',
|
|
225
|
+
googleMapsUtilsVersion: '3.19.1',
|
|
226
|
+
googleMapsKtxVersion: '5.2.1',
|
|
227
|
+
googleMapsUtilsKtxVersion: '5.2.1',
|
|
228
|
+
kotlinxCoroutinesVersion: '1.10.2',
|
|
229
|
+
coreSplashScreenVersion: '1.2.0',
|
|
230
|
+
};
|
|
231
|
+
for (const variable of Object.keys(pluginVariables)) {
|
|
232
|
+
await updateFile(config, variablesPath, `${variable} = '`, `'`, pluginVariables[variable], true);
|
|
233
|
+
}
|
|
234
|
+
})();
|
|
235
|
+
});
|
|
236
|
+
rimraf_1.rimraf.sync((0, path_1.join)(config.android.appDirAbs, 'build'));
|
|
237
|
+
}
|
|
238
|
+
// Write all breaking changes
|
|
239
|
+
await (0, common_1.runTask)(`Writing breaking changes.`, () => {
|
|
240
|
+
return writeBreakingChanges();
|
|
241
|
+
});
|
|
242
|
+
if (!installFailed) {
|
|
243
|
+
(0, log_1.logSuccess)(`Migration to Capacitor ${coreVersion} is complete. Run and test your app!`);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
log_1.logger.warn(`Migration to Capacitor ${coreVersion} is incomplete. Check the log messages for more information.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
(0, errors_1.fatal)(`Failed to migrate: ${err}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
(0, errors_1.fatal)(`User canceled migration.`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.migrateCommand = migrateCommand;
|
|
258
|
+
async function checkCapacitorMajorVersion(config) {
|
|
259
|
+
var _a;
|
|
260
|
+
const capacitorVersion = await (0, common_1.getCoreVersion)(config);
|
|
261
|
+
const versionArray = (_a = capacitorVersion.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/)) !== null && _a !== void 0 ? _a : [];
|
|
262
|
+
const majorVersion = parseInt(versionArray[1]);
|
|
263
|
+
return majorVersion;
|
|
264
|
+
}
|
|
265
|
+
async function installLatestLibs(dependencyManager, runInstall, config) {
|
|
266
|
+
const pkgJsonPath = (0, path_1.join)(config.app.rootDir, 'package.json');
|
|
267
|
+
const pkgJsonFile = readFile(pkgJsonPath);
|
|
268
|
+
if (!pkgJsonFile) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const pkgJson = JSON.parse(pkgJsonFile);
|
|
272
|
+
for (const devDepKey of Object.keys(pkgJson['devDependencies'] || {})) {
|
|
273
|
+
if (libs.includes(devDepKey)) {
|
|
274
|
+
pkgJson['devDependencies'][devDepKey] = coreVersion;
|
|
275
|
+
}
|
|
276
|
+
else if (plugins.includes(devDepKey)) {
|
|
277
|
+
pkgJson['devDependencies'][devDepKey] = pluginVersion;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
for (const depKey of Object.keys(pkgJson['dependencies'] || {})) {
|
|
281
|
+
if (libs.includes(depKey)) {
|
|
282
|
+
pkgJson['dependencies'][depKey] = coreVersion;
|
|
283
|
+
}
|
|
284
|
+
else if (plugins.includes(depKey)) {
|
|
285
|
+
pkgJson['dependencies'][depKey] = pluginVersion;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
(0, fs_extra_1.writeFileSync)(pkgJsonPath, JSON.stringify(pkgJson, null, 2), {
|
|
289
|
+
encoding: 'utf-8',
|
|
290
|
+
});
|
|
291
|
+
if (runInstall) {
|
|
292
|
+
rimraf_1.rimraf.sync((0, path_1.join)(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
|
|
293
|
+
await (0, subprocess_1.runCommand)(dependencyManager, ['install']);
|
|
294
|
+
if (dependencyManager == 'yarn') {
|
|
295
|
+
await (0, subprocess_1.runCommand)(dependencyManager, ['upgrade']);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
await (0, subprocess_1.runCommand)(dependencyManager, ['update']);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
log_1.logger.info(`Please run an install command with your package manager of choice. (ex: yarn install)`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async function writeBreakingChanges() {
|
|
306
|
+
const breaking = [
|
|
307
|
+
'@capacitor/action-sheet',
|
|
308
|
+
'@capacitor/barcode-scanner',
|
|
309
|
+
'@capacitor/browser',
|
|
310
|
+
'@capacitor/camera',
|
|
311
|
+
'@capacitor/geolocation',
|
|
312
|
+
'@capacitor/google-maps',
|
|
313
|
+
'@capacitor/push-notifications',
|
|
314
|
+
'@capacitor/screen-orientation',
|
|
315
|
+
'@capacitor/splash-screen',
|
|
316
|
+
'@capacitor/status-bar',
|
|
317
|
+
];
|
|
318
|
+
const broken = [];
|
|
319
|
+
for (const lib of breaking) {
|
|
320
|
+
if (allDependencies[lib]) {
|
|
321
|
+
broken.push(lib);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (broken.length > 0) {
|
|
325
|
+
log_1.logger.info(`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/8-0#plugins for breaking changes in these plugins that you use: ${broken.join(', ')}.`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async function getAndroidVariablesAndClasspaths(config) {
|
|
329
|
+
const tempAndroidTemplateFolder = (0, path_1.join)(config.cli.assetsDirAbs, 'tempAndroidTemplate');
|
|
330
|
+
await (0, template_1.extractTemplate)(config.cli.assets.android.platformTemplateArchiveAbs, tempAndroidTemplateFolder);
|
|
331
|
+
const variablesGradleFile = readFile((0, path_1.join)(tempAndroidTemplateFolder, 'variables.gradle'));
|
|
332
|
+
const buildGradleFile = readFile((0, path_1.join)(tempAndroidTemplateFolder, 'build.gradle'));
|
|
333
|
+
if (!variablesGradleFile || !buildGradleFile) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
(0, fs_1.deleteFolderRecursive)(tempAndroidTemplateFolder);
|
|
337
|
+
const firstIndxOfCATBGV = buildGradleFile.indexOf(`classpath 'com.android.tools.build:gradle:`) + 42;
|
|
338
|
+
const firstIndxOfCGGGS = buildGradleFile.indexOf(`com.google.gms:google-services:`) + 31;
|
|
339
|
+
const comAndroidToolsBuildGradleVersion = '' + buildGradleFile.substring(firstIndxOfCATBGV, buildGradleFile.indexOf("'", firstIndxOfCATBGV));
|
|
340
|
+
const comGoogleGmsGoogleServices = '' + buildGradleFile.substring(firstIndxOfCGGGS, buildGradleFile.indexOf("'", firstIndxOfCGGGS));
|
|
341
|
+
const variablesGradleAsJSON = JSON.parse(variablesGradleFile
|
|
342
|
+
.replace('ext ', '')
|
|
343
|
+
.replace(/=/g, ':')
|
|
344
|
+
.replace(/\n/g, ',')
|
|
345
|
+
.replace(/,([^:]+):/g, function (_k, p1) {
|
|
346
|
+
return `,"${p1}":`;
|
|
347
|
+
})
|
|
348
|
+
.replace('{,', '{')
|
|
349
|
+
.replace(',}', '}')
|
|
350
|
+
.replace(/\s/g, '')
|
|
351
|
+
.replace(/'/g, '"'));
|
|
352
|
+
return {
|
|
353
|
+
variables: variablesGradleAsJSON,
|
|
354
|
+
'com.android.tools.build:gradle': comAndroidToolsBuildGradleVersion,
|
|
355
|
+
'com.google.gms:google-services': comGoogleGmsGoogleServices,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function readFile(filename) {
|
|
359
|
+
try {
|
|
360
|
+
if (!(0, fs_extra_1.existsSync)(filename)) {
|
|
361
|
+
log_1.logger.error(`Unable to find ${filename}. Try updating it manually`);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
return (0, fs_extra_1.readFileSync)(filename, 'utf-8');
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
log_1.logger.error(`Unable to read ${filename}. Verify it is not already open. ${err}`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function getGradleWrapperVersion(filename) {
|
|
371
|
+
var _a;
|
|
372
|
+
const txt = readFile(filename);
|
|
373
|
+
if (!txt) {
|
|
374
|
+
return '0.0.0';
|
|
375
|
+
}
|
|
376
|
+
const version = txt.substring(txt.indexOf('gradle-') + 7, txt.indexOf('-all.zip'));
|
|
377
|
+
const semverVersion = (_a = (0, semver_1.coerce)(version)) === null || _a === void 0 ? void 0 : _a.version;
|
|
378
|
+
return semverVersion ? semverVersion : '0.0.0';
|
|
379
|
+
}
|
|
380
|
+
async function updateGradleWrapperFiles(platformDir) {
|
|
381
|
+
await (0, subprocess_1.runCommand)(`./gradlew`, ['wrapper', '--distribution-type', 'all', '--gradle-version', gradleVersion, '--warning-mode', 'all'], {
|
|
382
|
+
cwd: platformDir,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
async function updateBuildGradle(filename, variablesAndClasspaths) {
|
|
386
|
+
const txt = readFile(filename);
|
|
387
|
+
if (!txt) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const neededDeps = {
|
|
391
|
+
'com.android.tools.build:gradle': variablesAndClasspaths['com.android.tools.build:gradle'],
|
|
392
|
+
'com.google.gms:google-services': variablesAndClasspaths['com.google.gms:google-services'],
|
|
393
|
+
};
|
|
394
|
+
let replaced = txt;
|
|
395
|
+
for (const dep of Object.keys(neededDeps)) {
|
|
396
|
+
if (replaced.includes(`classpath '${dep}`)) {
|
|
397
|
+
const firstIndex = replaced.indexOf(dep) + dep.length + 1;
|
|
398
|
+
const existingVersion = '' + replaced.substring(firstIndex, replaced.indexOf("'", firstIndex));
|
|
399
|
+
if ((0, semver_1.gte)(neededDeps[dep], existingVersion)) {
|
|
400
|
+
replaced = setAllStringIn(replaced, `classpath '${dep}:`, `'`, neededDeps[dep]);
|
|
401
|
+
log_1.logger.info(`Set ${dep} = ${neededDeps[dep]}.`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const beforeKotlinVersionUpdate = replaced;
|
|
406
|
+
replaced = replaceVersion(replaced, /(ext\.kotlin_version\s*=\s*['"])([^'"]+)(['"])/, kotlinVersion);
|
|
407
|
+
replaced = replaceVersion(replaced, /(org\.jetbrains\.kotlin:kotlin[^:]*:)([\d.]+)(['"])/, kotlinVersion);
|
|
408
|
+
if (beforeKotlinVersionUpdate !== replaced) {
|
|
409
|
+
log_1.logger.info(`Set Kotlin version to ${kotlinVersion}`);
|
|
410
|
+
}
|
|
411
|
+
(0, fs_extra_1.writeFileSync)(filename, replaced, 'utf-8');
|
|
412
|
+
}
|
|
413
|
+
function replaceVersion(text, regex, newVersion) {
|
|
414
|
+
return text.replace(regex, (match, prefix, currentVersion, suffix) => {
|
|
415
|
+
var _a;
|
|
416
|
+
const semVer = (_a = (0, semver_1.coerce)(currentVersion)) === null || _a === void 0 ? void 0 : _a.version;
|
|
417
|
+
if ((0, semver_1.gte)(newVersion, semVer ? semVer : '0.0.0')) {
|
|
418
|
+
return `${prefix || ''}${newVersion}${suffix || ''}`;
|
|
419
|
+
}
|
|
420
|
+
return match;
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
async function updateAppBuildGradle(filename) {
|
|
424
|
+
const txt = readFile(filename);
|
|
425
|
+
if (!txt) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
let replaced = txt;
|
|
429
|
+
const gradlePproperties = ['compileSdk', 'namespace', 'ignoreAssetsPattern'];
|
|
430
|
+
for (const prop of gradlePproperties) {
|
|
431
|
+
// Use updated Groovy DSL syntax with " = " assignment
|
|
432
|
+
const regex = new RegExp(`(^\\s*${prop})\\s+(?!=)(.+)$`, 'gm');
|
|
433
|
+
replaced = replaced.replace(regex, (_match, key, value) => {
|
|
434
|
+
return `${key} = ${value.trim()}`;
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
(0, fs_extra_1.writeFileSync)(filename, replaced, 'utf-8');
|
|
438
|
+
}
|
|
439
|
+
async function updateFile(config, filename, textStart, textEnd, replacement, skipIfNotFound) {
|
|
440
|
+
if (config === null) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
const path = filename;
|
|
444
|
+
let txt = readFile(path);
|
|
445
|
+
if (!txt) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
if (txt.includes(textStart)) {
|
|
449
|
+
if (replacement) {
|
|
450
|
+
txt = setAllStringIn(txt, textStart, textEnd, replacement);
|
|
451
|
+
(0, fs_extra_1.writeFileSync)(path, txt, { encoding: 'utf-8' });
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
// Replacing in code so we need to count the number of brackets to find the end of the function in swift
|
|
455
|
+
const lines = txt.split('\n');
|
|
456
|
+
let replaced = '';
|
|
457
|
+
let keep = true;
|
|
458
|
+
let brackets = 0;
|
|
459
|
+
for (const line of lines) {
|
|
460
|
+
if (line.includes(textStart)) {
|
|
461
|
+
keep = false;
|
|
462
|
+
}
|
|
463
|
+
if (!keep) {
|
|
464
|
+
brackets += (line.match(/{/g) || []).length;
|
|
465
|
+
brackets -= (line.match(/}/g) || []).length;
|
|
466
|
+
if (brackets == 0) {
|
|
467
|
+
keep = true;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
replaced += line + '\n';
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
(0, fs_extra_1.writeFileSync)(path, replaced, { encoding: 'utf-8' });
|
|
475
|
+
}
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
else if (!skipIfNotFound) {
|
|
479
|
+
log_1.logger.error(`Unable to find "${textStart}" in ${filename}. Try updating it manually`);
|
|
480
|
+
}
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
function setAllStringIn(data, start, end, replacement) {
|
|
484
|
+
let position = 0;
|
|
485
|
+
let result = data;
|
|
486
|
+
let replaced = true;
|
|
487
|
+
while (replaced) {
|
|
488
|
+
const foundIdx = result.indexOf(start, position);
|
|
489
|
+
if (foundIdx == -1) {
|
|
490
|
+
replaced = false;
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
const idx = foundIdx + start.length;
|
|
494
|
+
position = idx + replacement.length;
|
|
495
|
+
result = result.substring(0, idx) + replacement + result.substring(result.indexOf(end, idx));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
async function updateAndroidManifest(filename) {
|
|
501
|
+
const txt = readFile(filename);
|
|
502
|
+
if (!txt) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (txt.includes('|density') || txt.includes('density|')) {
|
|
506
|
+
return; // Probably already updated
|
|
507
|
+
}
|
|
508
|
+
// Since navigation was an optional change in Capacitor 7, attempting to add density and/or navigation
|
|
509
|
+
const replaced = txt
|
|
510
|
+
.replace('android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation"', 'android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"')
|
|
511
|
+
.replace('android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"', 'android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"');
|
|
512
|
+
if (!replaced.includes('|density')) {
|
|
513
|
+
log_1.logger.error(`Unable to add 'density' to 'android:configChanges' in ${filename}. Try adding it manually`);
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
(0, fs_extra_1.writeFileSync)(filename, replaced, 'utf-8');
|
|
517
|
+
}
|
|
518
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newPluginCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
async function newPluginCommand() {
|
|
8
|
+
(0, errors_1.fatal)(`The plugin:generate command has been removed.\n` + `Use ${colors_1.default.input('npm init @capacitor/plugin')}`);
|
|
9
|
+
}
|
|
10
|
+
exports.newPluginCommand = newPluginCommand;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.open = exports.openCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const open_1 = require("../android/open");
|
|
6
|
+
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
const open_2 = require("../ios/open");
|
|
10
|
+
const log_1 = require("../log");
|
|
11
|
+
async function openCommand(config, selectedPlatformName) {
|
|
12
|
+
var _a;
|
|
13
|
+
if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
|
|
14
|
+
const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
|
|
15
|
+
if (platformDir) {
|
|
16
|
+
await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:open');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
|
24
|
+
let platformName;
|
|
25
|
+
if (platforms.length === 1) {
|
|
26
|
+
platformName = platforms[0];
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
platformName = await (0, common_1.promptForPlatform)(platforms.filter(createOpenablePlatformFilter(config)), `Please choose a platform to open:`);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
await open(config, platformName);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if (!(0, errors_1.isFatal)(e)) {
|
|
36
|
+
(0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
|
37
|
+
}
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.openCommand = openCommand;
|
|
43
|
+
function createOpenablePlatformFilter(config) {
|
|
44
|
+
return (platform) => platform === config.ios.name || platform === config.android.name;
|
|
45
|
+
}
|
|
46
|
+
async function open(config, platformName) {
|
|
47
|
+
if (platformName === config.ios.name) {
|
|
48
|
+
await (0, common_1.runTask)('Opening the Xcode workspace...', () => {
|
|
49
|
+
return (0, open_2.openIOS)(config);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (platformName === config.android.name) {
|
|
53
|
+
return (0, open_1.openAndroid)(config);
|
|
54
|
+
}
|
|
55
|
+
else if (platformName === config.web.name) {
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw `Platform ${platformName} is not valid.`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.open = open;
|