@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,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CapLiveReloadHelper = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const os_1 = require("os");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
class CapLiveReload {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.configJsonToRevertTo = {
|
|
10
|
+
json: null,
|
|
11
|
+
platformPath: null,
|
|
12
|
+
};
|
|
13
|
+
// nothing to do
|
|
14
|
+
}
|
|
15
|
+
getIpAddress(name, family) {
|
|
16
|
+
var _a;
|
|
17
|
+
const interfaces = (_a = (0, os_1.networkInterfaces)()) !== null && _a !== void 0 ? _a : {};
|
|
18
|
+
const _normalizeFamily = (family) => {
|
|
19
|
+
if (family === 4) {
|
|
20
|
+
return 'ipv4';
|
|
21
|
+
}
|
|
22
|
+
if (family === 6) {
|
|
23
|
+
return 'ipv6';
|
|
24
|
+
}
|
|
25
|
+
return family ? family.toLowerCase() : 'ipv4';
|
|
26
|
+
};
|
|
27
|
+
const isLoopback = (addr) => {
|
|
28
|
+
return (/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(addr) ||
|
|
29
|
+
/^fe80::1$/.test(addr) ||
|
|
30
|
+
/^::1$/.test(addr) ||
|
|
31
|
+
/^::$/.test(addr));
|
|
32
|
+
};
|
|
33
|
+
const isPrivate = (addr) => {
|
|
34
|
+
return (/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
|
35
|
+
/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
|
36
|
+
/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
|
37
|
+
/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
|
38
|
+
/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) ||
|
|
39
|
+
/^f[cd][0-9a-f]{2}:/i.test(addr) ||
|
|
40
|
+
/^fe80:/i.test(addr) ||
|
|
41
|
+
/^::1$/.test(addr) ||
|
|
42
|
+
/^::$/.test(addr));
|
|
43
|
+
};
|
|
44
|
+
const isPublic = (addr) => {
|
|
45
|
+
return !isPrivate(addr);
|
|
46
|
+
};
|
|
47
|
+
const loopback = (family) => {
|
|
48
|
+
//
|
|
49
|
+
// Default to `ipv4`
|
|
50
|
+
//
|
|
51
|
+
family = _normalizeFamily(family);
|
|
52
|
+
if (family !== 'ipv4' && family !== 'ipv6') {
|
|
53
|
+
throw new Error('family must be ipv4 or ipv6');
|
|
54
|
+
}
|
|
55
|
+
return family === 'ipv4' ? '127.0.0.1' : 'fe80::1';
|
|
56
|
+
};
|
|
57
|
+
//
|
|
58
|
+
// Default to `ipv4`
|
|
59
|
+
//
|
|
60
|
+
family = _normalizeFamily(family);
|
|
61
|
+
//
|
|
62
|
+
// If a specific network interface has been named,
|
|
63
|
+
// return the address.
|
|
64
|
+
//
|
|
65
|
+
if (name && name !== 'private' && name !== 'public') {
|
|
66
|
+
const res = interfaces[name].filter((details) => {
|
|
67
|
+
const itemFamily = _normalizeFamily(details.family);
|
|
68
|
+
return itemFamily === family;
|
|
69
|
+
});
|
|
70
|
+
if (res.length === 0) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return res[0].address;
|
|
74
|
+
}
|
|
75
|
+
const all = Object.keys(interfaces)
|
|
76
|
+
.map((nic) => {
|
|
77
|
+
//
|
|
78
|
+
// Note: name will only be `public` or `private`
|
|
79
|
+
// when this is called.
|
|
80
|
+
//
|
|
81
|
+
const addresses = interfaces[nic].filter((details) => {
|
|
82
|
+
details.family = _normalizeFamily(details.family);
|
|
83
|
+
if (details.family !== family || isLoopback(details.address)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (!name) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return name === 'public' ? isPrivate(details.address) : isPublic(details.address);
|
|
90
|
+
});
|
|
91
|
+
return addresses.length ? addresses[0].address : undefined;
|
|
92
|
+
})
|
|
93
|
+
.filter(Boolean);
|
|
94
|
+
return !all.length ? loopback(family) : all[0];
|
|
95
|
+
}
|
|
96
|
+
// TODO remove on next major as it's unused
|
|
97
|
+
async editExtConfigForLiveReload(config, platformName, options, rootConfigChange = false) {
|
|
98
|
+
const platformAbsPath = platformName == config.ios.name
|
|
99
|
+
? config.ios.nativeTargetDirAbs
|
|
100
|
+
: platformName == config.android.name
|
|
101
|
+
? config.android.assetsDirAbs
|
|
102
|
+
: null;
|
|
103
|
+
if (platformAbsPath == null)
|
|
104
|
+
throw new Error('Platform not found.');
|
|
105
|
+
const capConfigPath = rootConfigChange
|
|
106
|
+
? config.app.extConfigFilePath
|
|
107
|
+
: (0, path_1.join)(platformAbsPath, 'capacitor.config.json');
|
|
108
|
+
const configJson = { ...config.app.extConfig };
|
|
109
|
+
this.configJsonToRevertTo.json = JSON.stringify(configJson, null, 2);
|
|
110
|
+
this.configJsonToRevertTo.platformPath = capConfigPath;
|
|
111
|
+
const url = `http://${options.host}:${options.port}`;
|
|
112
|
+
configJson.server = {
|
|
113
|
+
url,
|
|
114
|
+
};
|
|
115
|
+
return configJson;
|
|
116
|
+
}
|
|
117
|
+
// TODO remove rootConfigChange param on next major as it's unused
|
|
118
|
+
async editCapConfigForLiveReload(config, platformName, options, rootConfigChange = false) {
|
|
119
|
+
const platformAbsPath = platformName == config.ios.name
|
|
120
|
+
? config.ios.nativeTargetDirAbs
|
|
121
|
+
: platformName == config.android.name
|
|
122
|
+
? config.android.assetsDirAbs
|
|
123
|
+
: null;
|
|
124
|
+
if (platformAbsPath == null)
|
|
125
|
+
throw new Error('Platform not found.');
|
|
126
|
+
const capConfigPath = rootConfigChange
|
|
127
|
+
? config.app.extConfigFilePath
|
|
128
|
+
: (0, path_1.join)(platformAbsPath, 'capacitor.config.json');
|
|
129
|
+
const configJson = (0, fs_extra_1.readJSONSync)(capConfigPath);
|
|
130
|
+
this.configJsonToRevertTo.json = JSON.stringify(configJson, null, 2);
|
|
131
|
+
this.configJsonToRevertTo.platformPath = capConfigPath;
|
|
132
|
+
const url = `http://${options.host}:${options.port}`;
|
|
133
|
+
configJson.server = {
|
|
134
|
+
url,
|
|
135
|
+
};
|
|
136
|
+
(0, fs_extra_1.writeJSONSync)(capConfigPath, configJson, { spaces: '\t' });
|
|
137
|
+
}
|
|
138
|
+
async revertCapConfigForLiveReload() {
|
|
139
|
+
if (this.configJsonToRevertTo.json == null || this.configJsonToRevertTo.platformPath == null)
|
|
140
|
+
return;
|
|
141
|
+
const capConfigPath = this.configJsonToRevertTo.platformPath;
|
|
142
|
+
const configJson = this.configJsonToRevertTo.json;
|
|
143
|
+
(0, fs_extra_1.writeJSONSync)(capConfigPath, JSON.parse(configJson), { spaces: '\t' });
|
|
144
|
+
this.configJsonToRevertTo.json = null;
|
|
145
|
+
this.configJsonToRevertTo.platformPath = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.CapLiveReloadHelper = new CapLiveReload();
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNXMonorepo = exports.isMonorepo = exports.findPackageRelativePathInMonorepo = exports.findPackagePath = exports.findNXMonorepoRoot = exports.findMonorepoRoot = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
/**
|
|
7
|
+
* Finds the monorepo root from the given path.
|
|
8
|
+
* @param currentPath - The current path to start searching from.
|
|
9
|
+
* @returns The path to the monorepo root.
|
|
10
|
+
* @throws An error if the monorepo root is not found.
|
|
11
|
+
*/
|
|
12
|
+
function findMonorepoRoot(currentPath) {
|
|
13
|
+
const packageJsonPath = (0, node_path_1.join)(currentPath, 'package.json');
|
|
14
|
+
const pnpmWorkspacePath = (0, node_path_1.join)(currentPath, 'pnpm-workspace.yaml');
|
|
15
|
+
if ((0, node_fs_1.existsSync)(pnpmWorkspacePath) ||
|
|
16
|
+
((0, node_fs_1.existsSync)(packageJsonPath) && JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, 'utf-8')).workspaces)) {
|
|
17
|
+
return currentPath;
|
|
18
|
+
}
|
|
19
|
+
const parentPath = (0, node_path_1.dirname)(currentPath);
|
|
20
|
+
if (parentPath === currentPath) {
|
|
21
|
+
throw new Error('Monorepo root not found');
|
|
22
|
+
}
|
|
23
|
+
return findMonorepoRoot(parentPath);
|
|
24
|
+
}
|
|
25
|
+
exports.findMonorepoRoot = findMonorepoRoot;
|
|
26
|
+
/**
|
|
27
|
+
* Finds the NX monorepo root from the given path.
|
|
28
|
+
* @param currentPath - The current path to start searching from.
|
|
29
|
+
* @returns The path to the monorepo root.
|
|
30
|
+
* @throws An error if the monorepo root is not found.
|
|
31
|
+
*/
|
|
32
|
+
function findNXMonorepoRoot(currentPath) {
|
|
33
|
+
const nxJsonPath = (0, node_path_1.join)(currentPath, 'nx.json');
|
|
34
|
+
if ((0, node_fs_1.existsSync)(nxJsonPath)) {
|
|
35
|
+
return currentPath;
|
|
36
|
+
}
|
|
37
|
+
const parentPath = (0, node_path_1.dirname)(currentPath);
|
|
38
|
+
if (parentPath === currentPath) {
|
|
39
|
+
throw new Error('Monorepo root not found');
|
|
40
|
+
}
|
|
41
|
+
return findNXMonorepoRoot(parentPath);
|
|
42
|
+
}
|
|
43
|
+
exports.findNXMonorepoRoot = findNXMonorepoRoot;
|
|
44
|
+
/**
|
|
45
|
+
* Finds the path to a package within the node_modules folder,
|
|
46
|
+
* searching up the directory hierarchy until the last possible directory is reached.
|
|
47
|
+
* @param packageName - The name of the package to find.
|
|
48
|
+
* @param currentPath - The current path to start searching from.
|
|
49
|
+
* @param lastPossibleDirectory - The last possible directory to search for the package.
|
|
50
|
+
* @returns The path to the package, or null if not found.
|
|
51
|
+
*/
|
|
52
|
+
function findPackagePath(packageName, currentPath, lastPossibleDirectory) {
|
|
53
|
+
const nodeModulesPath = (0, node_path_1.join)(currentPath, 'node_modules', packageName);
|
|
54
|
+
if ((0, node_fs_1.existsSync)(nodeModulesPath)) {
|
|
55
|
+
return nodeModulesPath;
|
|
56
|
+
}
|
|
57
|
+
if (currentPath === lastPossibleDirectory) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const parentPath = (0, node_path_1.dirname)(currentPath);
|
|
61
|
+
return findPackagePath(packageName, parentPath, lastPossibleDirectory);
|
|
62
|
+
}
|
|
63
|
+
exports.findPackagePath = findPackagePath;
|
|
64
|
+
/**
|
|
65
|
+
* Finds the relative path to a package from the current directory,
|
|
66
|
+
* using the monorepo root as the last possible directory.
|
|
67
|
+
* @param packageName - The name of the package to find.
|
|
68
|
+
* @param currentPath - The current path to start searching from.
|
|
69
|
+
* @returns The relative path to the package, or null if not found.
|
|
70
|
+
*/
|
|
71
|
+
function findPackageRelativePathInMonorepo(packageName, currentPath) {
|
|
72
|
+
const monorepoRoot = findMonorepoRoot(currentPath);
|
|
73
|
+
const packagePath = findPackagePath(packageName, currentPath, monorepoRoot);
|
|
74
|
+
if (packagePath) {
|
|
75
|
+
return (0, node_path_1.relative)(currentPath, packagePath);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
exports.findPackageRelativePathInMonorepo = findPackageRelativePathInMonorepo;
|
|
80
|
+
/**
|
|
81
|
+
* Detects if the current directory is part of a monorepo (npm, yarn, pnpm).
|
|
82
|
+
* @param currentPath - The current path to start searching from.
|
|
83
|
+
* @returns True if the current directory is part of a monorepo, false otherwise.
|
|
84
|
+
*/
|
|
85
|
+
function isMonorepo(currentPath) {
|
|
86
|
+
try {
|
|
87
|
+
findMonorepoRoot(currentPath);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.isMonorepo = isMonorepo;
|
|
95
|
+
/**
|
|
96
|
+
* Detects if the current directory is part of a nx integrated monorepo.
|
|
97
|
+
* @param currentPath - The current path to start searching from.
|
|
98
|
+
* @returns True if the current directory is part of a monorepo, false otherwise.
|
|
99
|
+
*/
|
|
100
|
+
function isNXMonorepo(currentPath) {
|
|
101
|
+
try {
|
|
102
|
+
findNXMonorepoRoot(currentPath);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.isNXMonorepo = isNXMonorepo;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPlatformTargets = exports.runNativeRun = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
const log_1 = require("../log");
|
|
9
|
+
const node_1 = require("./node");
|
|
10
|
+
const subprocess_1 = require("./subprocess");
|
|
11
|
+
async function runNativeRun(args, options = {}) {
|
|
12
|
+
const p = (0, node_1.resolveNode)(__dirname, (0, path_1.dirname)('native-run/package'), 'bin/native-run');
|
|
13
|
+
if (!p) {
|
|
14
|
+
(0, errors_1.fatal)(`${colors_1.default.input('native-run')} not found.`);
|
|
15
|
+
}
|
|
16
|
+
if (process.versions.pnp) {
|
|
17
|
+
return await (0, subprocess_1.runCommand)('yarn', ['node', p, ...args], options);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return await (0, subprocess_1.runCommand)(p, args, options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.runNativeRun = runNativeRun;
|
|
24
|
+
async function getPlatformTargets(platformName) {
|
|
25
|
+
const errors = [];
|
|
26
|
+
try {
|
|
27
|
+
const output = await runNativeRun([platformName, '--list', '--json']);
|
|
28
|
+
const parsedOutput = JSON.parse(output);
|
|
29
|
+
if (parsedOutput.devices.length || parsedOutput.virtualDevices.length) {
|
|
30
|
+
return [
|
|
31
|
+
...parsedOutput.devices.map((t) => ({ ...t, virtual: false })),
|
|
32
|
+
...parsedOutput.virtualDevices.map((t) => ({
|
|
33
|
+
...t,
|
|
34
|
+
virtual: true,
|
|
35
|
+
})),
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
parsedOutput.errors.map((e) => {
|
|
40
|
+
errors.push(e);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
const err = JSON.parse(e);
|
|
46
|
+
errors.push(err);
|
|
47
|
+
}
|
|
48
|
+
if (errors.length === 0) {
|
|
49
|
+
log_1.logger.info('No devices found.');
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
const plural = errors.length > 1 ? 's' : '';
|
|
53
|
+
const errMsg = `${colors_1.default.strong('native-run')} failed with error${plural}\n
|
|
54
|
+
${errors
|
|
55
|
+
.map((e) => {
|
|
56
|
+
return `\t${colors_1.default.strong(e.code)}: ${e.error}`;
|
|
57
|
+
})
|
|
58
|
+
.join('\n')}
|
|
59
|
+
\n\tMore details for this error${plural} may be available online: ${colors_1.default.strong('https://github.com/ionic-team/native-run/wiki/Android-Errors')}
|
|
60
|
+
`;
|
|
61
|
+
throw errMsg;
|
|
62
|
+
}
|
|
63
|
+
exports.getPlatformTargets = getPlatformTargets;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveNode = exports.requireTS = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
/**
|
|
8
|
+
* @see https://github.com/ionic-team/stencil/blob/HEAD/src/compiler/sys/node-require.ts
|
|
9
|
+
*/
|
|
10
|
+
const requireTS = (ts, p) => {
|
|
11
|
+
const id = (0, path_1.resolve)(p);
|
|
12
|
+
delete require.cache[id];
|
|
13
|
+
require.extensions['.ts'] = (module, fileName) => {
|
|
14
|
+
var _a;
|
|
15
|
+
let sourceText = (0, fs_extra_1.readFileSync)(fileName, 'utf8');
|
|
16
|
+
if (fileName.endsWith('.ts')) {
|
|
17
|
+
const tsResults = ts.transpileModule(sourceText, {
|
|
18
|
+
fileName,
|
|
19
|
+
compilerOptions: {
|
|
20
|
+
module: ts.ModuleKind.CommonJS,
|
|
21
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
22
|
+
esModuleInterop: true,
|
|
23
|
+
strict: true,
|
|
24
|
+
target: ts.ScriptTarget.ES2017,
|
|
25
|
+
},
|
|
26
|
+
reportDiagnostics: true,
|
|
27
|
+
});
|
|
28
|
+
sourceText = tsResults.outputText;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// quick hack to turn a modern es module
|
|
32
|
+
// into and old school commonjs module
|
|
33
|
+
sourceText = sourceText.replace(/export\s+\w+\s+(\w+)/gm, 'exports.$1');
|
|
34
|
+
}
|
|
35
|
+
(_a = module._compile) === null || _a === void 0 ? void 0 : _a.call(module, sourceText, fileName);
|
|
36
|
+
};
|
|
37
|
+
const m = require(id); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
38
|
+
delete require.extensions['.ts'];
|
|
39
|
+
return m;
|
|
40
|
+
};
|
|
41
|
+
exports.requireTS = requireTS;
|
|
42
|
+
function resolveNode(root, ...pathSegments) {
|
|
43
|
+
try {
|
|
44
|
+
return require.resolve(pathSegments.join('/'), { paths: [root] });
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
const path = [root, 'node_modules', ...pathSegments].join('/');
|
|
48
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
49
|
+
return path;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.resolveNode = resolveNode;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lazy = exports.LazyPromise = exports.allSerial = void 0;
|
|
4
|
+
function allSerial(funcs) {
|
|
5
|
+
return funcs.reduce((promise, func) => promise.then((result) => func().then((x) => result.concat(x))), Promise.resolve([]));
|
|
6
|
+
}
|
|
7
|
+
exports.allSerial = allSerial;
|
|
8
|
+
class LazyPromise extends Promise {
|
|
9
|
+
constructor(executor) {
|
|
10
|
+
super(() => {
|
|
11
|
+
/* ignore */
|
|
12
|
+
});
|
|
13
|
+
this._executor = executor;
|
|
14
|
+
}
|
|
15
|
+
then(onfulfilled, onrejected) {
|
|
16
|
+
this._promise = this._promise || new Promise(this._executor);
|
|
17
|
+
return this._promise.then(onfulfilled, onrejected);
|
|
18
|
+
}
|
|
19
|
+
catch(onrejected) {
|
|
20
|
+
this._promise = this._promise || new Promise(this._executor);
|
|
21
|
+
return this._promise.catch(onrejected);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.LazyPromise = LazyPromise;
|
|
25
|
+
function lazy(fn) {
|
|
26
|
+
return new LazyPromise(async (resolve, reject) => {
|
|
27
|
+
try {
|
|
28
|
+
resolve(await fn());
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.lazy = lazy;
|
package/dist/util/spm.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addInfoPlistDebugIfNeeded = exports.runCocoapodsDeintegrate = exports.generatePackageText = exports.removeCocoapodsFiles = exports.extractSPMPackageDirectory = exports.checkPluginsForPackageSwift = exports.generatePackageFile = exports.findPackageSwiftFile = exports.checkPackageManager = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const os_1 = require("os");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const plist_1 = require("plist");
|
|
8
|
+
const tar_1 = require("tar");
|
|
9
|
+
const common_1 = require("../common");
|
|
10
|
+
const errors_1 = require("../errors");
|
|
11
|
+
const common_2 = require("../ios/common");
|
|
12
|
+
const log_1 = require("../log");
|
|
13
|
+
const plugin_1 = require("../plugin");
|
|
14
|
+
const subprocess_1 = require("../util/subprocess");
|
|
15
|
+
async function checkPackageManager(config) {
|
|
16
|
+
const iosDirectory = config.ios.nativeProjectDirAbs;
|
|
17
|
+
if ((0, fs_extra_1.existsSync)((0, path_1.resolve)(iosDirectory, 'CapApp-SPM'))) {
|
|
18
|
+
return 'SPM';
|
|
19
|
+
}
|
|
20
|
+
return 'Cocoapods';
|
|
21
|
+
}
|
|
22
|
+
exports.checkPackageManager = checkPackageManager;
|
|
23
|
+
async function findPackageSwiftFile(config) {
|
|
24
|
+
const packageDirectory = (0, path_1.resolve)(config.ios.nativeProjectDirAbs, 'CapApp-SPM');
|
|
25
|
+
return (0, path_1.resolve)(packageDirectory, 'Package.swift');
|
|
26
|
+
}
|
|
27
|
+
exports.findPackageSwiftFile = findPackageSwiftFile;
|
|
28
|
+
async function generatePackageFile(config, plugins) {
|
|
29
|
+
const packageSwiftFile = await findPackageSwiftFile(config);
|
|
30
|
+
try {
|
|
31
|
+
log_1.logger.info('Writing Package.swift');
|
|
32
|
+
const textToWrite = await generatePackageText(config, plugins);
|
|
33
|
+
(0, fs_extra_1.writeFileSync)(packageSwiftFile, textToWrite);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
log_1.logger.error(`Unable to write to ${packageSwiftFile}. Verify it is not already open. \n Error: ${err}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.generatePackageFile = generatePackageFile;
|
|
40
|
+
async function checkPluginsForPackageSwift(config, plugins) {
|
|
41
|
+
const iOSCapacitorPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, 'ios') === 0 /* PluginType.Core */);
|
|
42
|
+
const packageSwiftPluginList = await pluginsWithPackageSwift(iOSCapacitorPlugins);
|
|
43
|
+
if (plugins.length == packageSwiftPluginList.length) {
|
|
44
|
+
log_1.logger.debug(`Found ${plugins.length} iOS plugins, ${packageSwiftPluginList.length} have a Package.swift file`);
|
|
45
|
+
log_1.logger.info('All plugins have a Package.swift file and will be included in Package.swift');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
log_1.logger.warn('Some installed packages are not compatable with SPM');
|
|
49
|
+
}
|
|
50
|
+
return packageSwiftPluginList;
|
|
51
|
+
}
|
|
52
|
+
exports.checkPluginsForPackageSwift = checkPluginsForPackageSwift;
|
|
53
|
+
async function extractSPMPackageDirectory(config) {
|
|
54
|
+
const spmDirectory = (0, path_1.join)(config.ios.nativeProjectDirAbs, 'CapApp-SPM');
|
|
55
|
+
const spmTemplate = (0, path_1.join)(config.cli.assetsDirAbs, 'ios-spm-template.tar.gz');
|
|
56
|
+
const debugConfig = (0, path_1.join)(config.ios.platformDirAbs, 'debug.xcconfig');
|
|
57
|
+
log_1.logger.info('Extracting ' + spmTemplate + ' to ' + spmDirectory);
|
|
58
|
+
try {
|
|
59
|
+
const tempCapDir = await (0, fs_extra_1.mkdtemp)((0, path_1.join)((0, os_1.tmpdir)(), 'cap-'));
|
|
60
|
+
const tempCapSPM = (0, path_1.join)(tempCapDir, 'App', 'CapApp-SPM');
|
|
61
|
+
const tempDebugXCConfig = (0, path_1.join)(tempCapDir, 'debug.xcconfig');
|
|
62
|
+
await (0, tar_1.extract)({ file: spmTemplate, cwd: tempCapDir });
|
|
63
|
+
await (0, fs_extra_1.move)(tempCapSPM, spmDirectory);
|
|
64
|
+
await (0, fs_extra_1.move)(tempDebugXCConfig, debugConfig);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
(0, errors_1.fatal)('Failed to create ' + spmDirectory + ' with error: ' + err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.extractSPMPackageDirectory = extractSPMPackageDirectory;
|
|
71
|
+
async function removeCocoapodsFiles(config) {
|
|
72
|
+
const iosDirectory = config.ios.nativeProjectDirAbs;
|
|
73
|
+
const podFile = (0, path_1.resolve)(iosDirectory, 'Podfile');
|
|
74
|
+
const podlockFile = (0, path_1.resolve)(iosDirectory, 'Podfile.lock');
|
|
75
|
+
const xcworkspaceFile = (0, path_1.resolve)(iosDirectory, 'App.xcworkspace');
|
|
76
|
+
await (0, fs_extra_1.remove)(podFile);
|
|
77
|
+
await (0, fs_extra_1.remove)(podlockFile);
|
|
78
|
+
await (0, fs_extra_1.remove)(xcworkspaceFile);
|
|
79
|
+
}
|
|
80
|
+
exports.removeCocoapodsFiles = removeCocoapodsFiles;
|
|
81
|
+
async function generatePackageText(config, plugins) {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
|
|
84
|
+
const iosVersion = (0, common_2.getMajoriOSVersion)(config);
|
|
85
|
+
let packageSwiftText = `// swift-tools-version: 5.9
|
|
86
|
+
import PackageDescription
|
|
87
|
+
|
|
88
|
+
// DO NOT MODIFY THIS FILE - managed by Capacitor CLI commands
|
|
89
|
+
let package = Package(
|
|
90
|
+
name: "CapApp-SPM",
|
|
91
|
+
platforms: [.iOS(.v${iosVersion})],
|
|
92
|
+
products: [
|
|
93
|
+
.library(
|
|
94
|
+
name: "CapApp-SPM",
|
|
95
|
+
targets: ["CapApp-SPM"])
|
|
96
|
+
],
|
|
97
|
+
dependencies: [
|
|
98
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "${iosPlatformVersion}")`;
|
|
99
|
+
for (const plugin of plugins) {
|
|
100
|
+
if ((0, plugin_1.getPluginType)(plugin, config.ios.name) === 1 /* PluginType.Cordova */) {
|
|
101
|
+
packageSwiftText += `,\n .package(name: "${plugin.name}", path: "../../capacitor-cordova-ios-plugins/sources/${plugin.name}")`;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const relPath = (0, path_1.relative)(config.ios.nativeXcodeProjDirAbs, plugin.rootPath);
|
|
105
|
+
packageSwiftText += `,\n .package(name: "${(_a = plugin.ios) === null || _a === void 0 ? void 0 : _a.name}", path: "${relPath}")`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
packageSwiftText += `
|
|
109
|
+
],
|
|
110
|
+
targets: [
|
|
111
|
+
.target(
|
|
112
|
+
name: "CapApp-SPM",
|
|
113
|
+
dependencies: [
|
|
114
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
115
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")`;
|
|
116
|
+
for (const plugin of plugins) {
|
|
117
|
+
packageSwiftText += `,\n .product(name: "${(_b = plugin.ios) === null || _b === void 0 ? void 0 : _b.name}", package: "${(_c = plugin.ios) === null || _c === void 0 ? void 0 : _c.name}")`;
|
|
118
|
+
}
|
|
119
|
+
packageSwiftText += `
|
|
120
|
+
]
|
|
121
|
+
)
|
|
122
|
+
]
|
|
123
|
+
)
|
|
124
|
+
`;
|
|
125
|
+
return packageSwiftText;
|
|
126
|
+
}
|
|
127
|
+
exports.generatePackageText = generatePackageText;
|
|
128
|
+
async function runCocoapodsDeintegrate(config) {
|
|
129
|
+
const podPath = await config.ios.podPath;
|
|
130
|
+
const projectFileName = config.ios.nativeXcodeProjDirAbs;
|
|
131
|
+
const useBundler = podPath.startsWith('bundle') && (await (0, subprocess_1.isInstalled)('bundle'));
|
|
132
|
+
const podCommandExists = await (0, subprocess_1.isInstalled)('pod');
|
|
133
|
+
if (useBundler)
|
|
134
|
+
log_1.logger.info('Found bundler, using it to run CocoaPods.');
|
|
135
|
+
log_1.logger.info('Running pod deintegrate on project ' + projectFileName);
|
|
136
|
+
if (useBundler || podCommandExists) {
|
|
137
|
+
if (useBundler) {
|
|
138
|
+
await (0, subprocess_1.runCommand)('bundle', ['exec', 'pod', 'deintegrate', projectFileName], {
|
|
139
|
+
cwd: config.ios.nativeProjectDirAbs,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
await (0, subprocess_1.runCommand)(podPath, ['deintegrate', projectFileName], {
|
|
144
|
+
cwd: config.ios.nativeProjectDirAbs,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
log_1.logger.warn('Skipping pod deintegrate because CocoaPods is not installed - migration will be incomplete');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.runCocoapodsDeintegrate = runCocoapodsDeintegrate;
|
|
153
|
+
async function addInfoPlistDebugIfNeeded(config) {
|
|
154
|
+
const infoPlist = (0, path_1.resolve)(config.ios.nativeTargetDirAbs, 'Info.plist');
|
|
155
|
+
log_1.logger.info('Checking ' + infoPlist + ' for CAPACITOR_DEBUG');
|
|
156
|
+
if ((0, fs_extra_1.existsSync)(infoPlist)) {
|
|
157
|
+
const infoPlistContents = (0, fs_extra_1.readFileSync)(infoPlist, 'utf-8');
|
|
158
|
+
const plistEntries = (0, plist_1.parse)(infoPlistContents);
|
|
159
|
+
if (plistEntries['CAPACITOR_DEBUG'] === undefined) {
|
|
160
|
+
log_1.logger.info('Writing CAPACITOR_DEBUG to ' + infoPlist);
|
|
161
|
+
plistEntries['CAPACITOR_DEBUG'] = '$(CAPACITOR_DEBUG)';
|
|
162
|
+
const plistToWrite = (0, plist_1.build)(plistEntries);
|
|
163
|
+
(0, fs_extra_1.writeFileSync)(infoPlist, plistToWrite);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
log_1.logger.warn('Found CAPACITOR_DEBUG set to ' + plistEntries['CAPACITOR_DEBUG'] + ', skipping.');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
log_1.logger.warn(infoPlist + ' not found.');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.addInfoPlistDebugIfNeeded = addInfoPlistDebugIfNeeded;
|
|
174
|
+
// Private Functions
|
|
175
|
+
async function pluginsWithPackageSwift(plugins) {
|
|
176
|
+
const pluginList = [];
|
|
177
|
+
for (const plugin of plugins) {
|
|
178
|
+
const packageSwiftFound = await (0, fs_extra_1.pathExists)((0, path_1.join)(plugin.rootPath, 'Package.swift'));
|
|
179
|
+
if (packageSwiftFound) {
|
|
180
|
+
pluginList.push(plugin);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
log_1.logger.warn(plugin.id + ' does not have a Package.swift');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return pluginList;
|
|
187
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInstalled = exports.getCommandOutput = exports.runCommand = void 0;
|
|
4
|
+
const utils_subprocess_1 = require("@ionic/utils-subprocess");
|
|
5
|
+
async function runCommand(command, args, options = {}) {
|
|
6
|
+
const p = new utils_subprocess_1.Subprocess(command, args, options);
|
|
7
|
+
try {
|
|
8
|
+
return await p.output();
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
if (e instanceof utils_subprocess_1.SubprocessError) {
|
|
12
|
+
// old behavior of just throwing the stdout/stderr strings
|
|
13
|
+
throw e.output ? e.output : e.cause ? `${e.message} ${e.cause.toString()}` : e.code ? e.code : 'Unknown error';
|
|
14
|
+
}
|
|
15
|
+
throw e;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.runCommand = runCommand;
|
|
19
|
+
async function getCommandOutput(command, args, options = {}) {
|
|
20
|
+
try {
|
|
21
|
+
return (await runCommand(command, args, options)).trim();
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.getCommandOutput = getCommandOutput;
|
|
28
|
+
async function isInstalled(command) {
|
|
29
|
+
try {
|
|
30
|
+
await (0, utils_subprocess_1.which)(command);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
exports.isInstalled = isInstalled;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractTemplate = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const tar_1 = tslib_1.__importDefault(require("tar"));
|
|
7
|
+
async function extractTemplate(src, dir) {
|
|
8
|
+
await (0, fs_extra_1.mkdirp)(dir);
|
|
9
|
+
await tar_1.default.extract({ file: src, cwd: dir });
|
|
10
|
+
}
|
|
11
|
+
exports.extractTemplate = extractTemplate;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInteractive = exports.checkInteractive = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const utils_terminal_1 = require("@ionic/utils-terminal");
|
|
6
|
+
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
|
7
|
+
const log_1 = require("../log");
|
|
8
|
+
// Given input variables to a command, make sure all are provided if the terminal
|
|
9
|
+
// is not interactive (because we won't be able to prompt the user)
|
|
10
|
+
const checkInteractive = (...args) => {
|
|
11
|
+
if ((0, exports.isInteractive)()) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
// Fail if no args are provided, treat this as just a check of whether the term is
|
|
15
|
+
// interactive or not.
|
|
16
|
+
if (!args.length) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
// Make sure none of the provided args are empty, otherwise print the interactive
|
|
20
|
+
// warning and return false
|
|
21
|
+
if (args.filter((arg) => !arg).length) {
|
|
22
|
+
log_1.logger.error(`Non-interactive shell detected.\n` +
|
|
23
|
+
`Run the command with ${colors_1.default.input('--help')} to see a list of arguments that must be provided.`);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
exports.checkInteractive = checkInteractive;
|
|
29
|
+
const isInteractive = () => utils_terminal_1.TERMINAL_INFO.tty && !utils_terminal_1.TERMINAL_INFO.ci;
|
|
30
|
+
exports.isInteractive = isInteractive;
|