This commit is contained in:
parent
55470c090d
commit
6947a1adba
1260 changed files with 111297 additions and 0 deletions
122
@capacitor/cli/dist/tasks/add.js
vendored
Normal file
122
@capacitor/cli/dist/tasks/add.js
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.addCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const utils_fs_1 = require("@ionic/utils-fs");
|
||||
const utils_terminal_1 = require("@ionic/utils-terminal");
|
||||
const add_1 = require("../android/add");
|
||||
const common_1 = require("../android/common");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_2 = require("../common");
|
||||
const errors_1 = require("../errors");
|
||||
const add_2 = require("../ios/add");
|
||||
const common_3 = require("../ios/common");
|
||||
const log_1 = require("../log");
|
||||
const sync_1 = require("./sync");
|
||||
async function addCommand(config, selectedPlatformName) {
|
||||
var _a;
|
||||
if (selectedPlatformName && !(await (0, common_2.isValidPlatform)(selectedPlatformName))) {
|
||||
const platformDir = (0, common_2.resolvePlatform)(config, selectedPlatformName);
|
||||
if (platformDir) {
|
||||
await (0, common_2.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:add');
|
||||
}
|
||||
else {
|
||||
let msg = `Platform ${colors_1.default.input(selectedPlatformName)} not found.`;
|
||||
if (await (0, common_2.isValidCommunityPlatform)(selectedPlatformName)) {
|
||||
msg += `\nTry installing ${colors_1.default.strong(`@capacitor-community/${selectedPlatformName}`)} and adding the platform again.`;
|
||||
}
|
||||
if (await (0, common_2.isValidEnterprisePlatform)(selectedPlatformName)) {
|
||||
msg +=
|
||||
`\nThis is an enterprise platform and @ionic-enterprise/capacitor-${selectedPlatformName} is not installed.\n` +
|
||||
`To learn how to use this platform, visit https://ionic.io/docs/${selectedPlatformName}`;
|
||||
}
|
||||
log_1.logger.error(msg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const knownPlatforms = await (0, common_2.getKnownPlatforms)();
|
||||
const platformName = await (0, common_2.promptForPlatform)(knownPlatforms, `Please choose a platform to add:`, selectedPlatformName);
|
||||
if (platformName === config.web.name) {
|
||||
webWarning();
|
||||
return;
|
||||
}
|
||||
const existingPlatformDir = await (0, common_2.getProjectPlatformDirectory)(config, platformName);
|
||||
if (existingPlatformDir) {
|
||||
(0, errors_1.fatal)(`${colors_1.default.input(platformName)} platform already exists.\n` +
|
||||
`To re-add this platform, first remove ${colors_1.default.strong((0, utils_terminal_1.prettyPath)(existingPlatformDir))}, then run this command again.\n` +
|
||||
`${colors_1.default.strong('WARNING')}: Your native project will be completely removed.`);
|
||||
}
|
||||
try {
|
||||
await (0, common_2.check)([
|
||||
() => (0, common_2.checkPackage)(),
|
||||
() => (0, common_2.checkAppConfig)(config),
|
||||
...addChecks(config, platformName),
|
||||
]);
|
||||
await doAdd(config, platformName);
|
||||
await editPlatforms(config, platformName);
|
||||
if (await (0, utils_fs_1.pathExists)(config.app.webDirAbs)) {
|
||||
await (0, sync_1.sync)(config, platformName, false, false);
|
||||
if (platformName === config.android.name) {
|
||||
await (0, common_2.runTask)('Syncing Gradle', async () => {
|
||||
return (0, add_1.createLocalProperties)(config.android.platformDirAbs);
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
log_1.logger.warn(`${colors_1.default.success(colors_1.default.strong('sync'))} could not run--missing ${colors_1.default.strong(config.app.webDir)} directory.`);
|
||||
}
|
||||
printNextSteps(platformName);
|
||||
}
|
||||
catch (e) {
|
||||
if (!(0, errors_1.isFatal)(e)) {
|
||||
(0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.addCommand = addCommand;
|
||||
function printNextSteps(platformName) {
|
||||
(0, log_1.logSuccess)(`${colors_1.default.strong(platformName)} platform added!`);
|
||||
log_1.output.write(`Follow the Developer Workflow guide to get building:\n${colors_1.default.strong(`https://capacitorjs.com/docs/basics/workflow`)}\n`);
|
||||
}
|
||||
function addChecks(config, platformName) {
|
||||
if (platformName === config.ios.name) {
|
||||
return [
|
||||
() => (0, common_3.checkIOSPackage)(config),
|
||||
() => (0, common_3.checkBundler)(config) || (0, common_3.checkCocoaPods)(config),
|
||||
];
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
return [() => (0, common_1.checkAndroidPackage)(config)];
|
||||
}
|
||||
else if (platformName === config.web.name) {
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
throw `Platform ${platformName} is not valid.`;
|
||||
}
|
||||
}
|
||||
async function doAdd(config, platformName) {
|
||||
await (0, common_2.runTask)(colors_1.default.success(colors_1.default.strong('add')), async () => {
|
||||
if (platformName === config.ios.name) {
|
||||
await (0, add_2.addIOS)(config);
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
await (0, add_1.addAndroid)(config);
|
||||
}
|
||||
});
|
||||
}
|
||||
async function editPlatforms(config, platformName) {
|
||||
if (platformName === config.ios.name) {
|
||||
await (0, common_3.editProjectSettingsIOS)(config);
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
await (0, common_1.editProjectSettingsAndroid)(config);
|
||||
}
|
||||
}
|
||||
function webWarning() {
|
||||
log_1.logger.error(`Not adding platform ${colors_1.default.strong('web')}.\n` +
|
||||
`In Capacitor, the web platform is just your web app! For example, if you have a React or Angular project, the web platform is that project.\n` +
|
||||
`To add Capacitor functionality to your web app, follow the Web Getting Started Guide: ${colors_1.default.strong('https://capacitorjs.com/docs/web')}`);
|
||||
}
|
62
@capacitor/cli/dist/tasks/build.js
vendored
Normal file
62
@capacitor/cli/dist/tasks/build.js
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.build = exports.buildCommand = void 0;
|
||||
const build_1 = require("../android/build");
|
||||
const common_1 = require("../common");
|
||||
const errors_1 = require("../errors");
|
||||
const build_2 = require("../ios/build");
|
||||
async function buildCommand(config, selectedPlatformName, buildOptions) {
|
||||
var _a;
|
||||
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
||||
let platformName;
|
||||
if (platforms.length === 1) {
|
||||
platformName = platforms[0];
|
||||
}
|
||||
else {
|
||||
platformName = await (0, common_1.promptForPlatform)(platforms.filter(createBuildablePlatformFilter(config)), `Please choose a platform to build for:`);
|
||||
}
|
||||
const buildCommandOptions = {
|
||||
scheme: buildOptions.scheme || config.ios.scheme,
|
||||
flavor: buildOptions.flavor || config.android.flavor,
|
||||
keystorepath: buildOptions.keystorepath || config.android.buildOptions.keystorePath,
|
||||
keystorepass: buildOptions.keystorepass || config.android.buildOptions.keystorePassword,
|
||||
keystorealias: buildOptions.keystorealias || config.android.buildOptions.keystoreAlias,
|
||||
keystorealiaspass: buildOptions.keystorealiaspass ||
|
||||
config.android.buildOptions.keystoreAliasPassword,
|
||||
androidreleasetype: buildOptions.androidreleasetype ||
|
||||
config.android.buildOptions.releaseType ||
|
||||
'AAB',
|
||||
signingtype: buildOptions.signingtype ||
|
||||
config.android.buildOptions.signingType ||
|
||||
'jarsigner',
|
||||
configuration: buildOptions.configuration || 'Release',
|
||||
};
|
||||
try {
|
||||
await build(config, platformName, buildCommandOptions);
|
||||
}
|
||||
catch (e) {
|
||||
if (!(0, errors_1.isFatal)(e)) {
|
||||
(0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
exports.buildCommand = buildCommand;
|
||||
async function build(config, platformName, buildOptions) {
|
||||
if (platformName == config.ios.name) {
|
||||
await (0, build_2.buildiOS)(config, buildOptions);
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
await (0, build_1.buildAndroid)(config, buildOptions);
|
||||
}
|
||||
else if (platformName === config.web.name) {
|
||||
throw `Platform "${platformName}" is not available in the build command.`;
|
||||
}
|
||||
else {
|
||||
throw `Platform "${platformName}" is not valid.`;
|
||||
}
|
||||
}
|
||||
exports.build = build;
|
||||
function createBuildablePlatformFilter(config) {
|
||||
return platform => platform === config.ios.name || platform === config.android.name;
|
||||
}
|
31
@capacitor/cli/dist/tasks/config.js
vendored
Normal file
31
@capacitor/cli/dist/tasks/config.js
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.configCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const util_1 = tslib_1.__importDefault(require("util"));
|
||||
const log_1 = require("../log");
|
||||
async function configCommand(config, json) {
|
||||
const evaluatedConfig = await deepAwait(config);
|
||||
if (json) {
|
||||
process.stdout.write(`${JSON.stringify(evaluatedConfig)}\n`);
|
||||
}
|
||||
else {
|
||||
log_1.output.write(`${util_1.default.inspect(evaluatedConfig, { depth: Infinity, colors: true })}\n`);
|
||||
}
|
||||
}
|
||||
exports.configCommand = configCommand;
|
||||
async function deepAwait(obj) {
|
||||
if (obj &&
|
||||
!Array.isArray(obj) &&
|
||||
typeof obj === 'object' &&
|
||||
obj.constructor === Object) {
|
||||
const o = {};
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
o[k] = await deepAwait(v);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
else {
|
||||
return await obj;
|
||||
}
|
||||
}
|
216
@capacitor/cli/dist/tasks/copy.js
vendored
Normal file
216
@capacitor/cli/dist/tasks/copy.js
vendored
Normal file
|
@ -0,0 +1,216 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.copy = exports.copyCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const utils_fs_1 = require("@ionic/utils-fs");
|
||||
const path_1 = require("path");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_1 = require("../common");
|
||||
const cordova_1 = require("../cordova");
|
||||
const errors_1 = require("../errors");
|
||||
const common_2 = require("../ios/common");
|
||||
const log_1 = require("../log");
|
||||
const plugin_1 = require("../plugin");
|
||||
const iosplugin_1 = require("../util/iosplugin");
|
||||
const promise_1 = require("../util/promise");
|
||||
const copy_1 = require("../web/copy");
|
||||
const sourcemaps_1 = require("./sourcemaps");
|
||||
async function copyCommand(config, selectedPlatformName, inline = false) {
|
||||
var _a;
|
||||
if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
|
||||
const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
|
||||
if (platformDir) {
|
||||
await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:copy');
|
||||
}
|
||||
else {
|
||||
log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
||||
try {
|
||||
await (0, promise_1.allSerial)(platforms.map(platformName => () => copy(config, platformName, inline)));
|
||||
}
|
||||
catch (e) {
|
||||
if ((0, errors_1.isFatal)(e)) {
|
||||
throw e;
|
||||
}
|
||||
log_1.logger.error((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.copyCommand = copyCommand;
|
||||
async function copy(config, platformName, inline = false) {
|
||||
await (0, common_1.runTask)(colors_1.default.success(colors_1.default.strong(`copy ${platformName}`)), async () => {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
||||
const result = await (0, common_1.checkWebDir)(config);
|
||||
if (result) {
|
||||
throw result;
|
||||
}
|
||||
await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:copy:before');
|
||||
const allPlugins = await (0, plugin_1.getPlugins)(config, platformName);
|
||||
let usesFederatedCapacitor = false;
|
||||
if (allPlugins.filter(plugin => plugin.id === '@ionic-enterprise/federated-capacitor').length > 0) {
|
||||
usesFederatedCapacitor = true;
|
||||
}
|
||||
let usesLiveUpdates = false;
|
||||
if (allPlugins.filter(plugin => plugin.id === '@capacitor/live-updates')
|
||||
.length > 0) {
|
||||
usesLiveUpdates = true;
|
||||
}
|
||||
let usesSSLPinning = false;
|
||||
if (allPlugins.filter(plugin => plugin.id === '@ionic-enterprise/ssl-pinning')
|
||||
.length > 0) {
|
||||
usesSSLPinning = true;
|
||||
}
|
||||
if (platformName === config.ios.name) {
|
||||
if (usesFederatedCapacitor) {
|
||||
await copyFederatedWebDirs(config, await config.ios.webDirAbs);
|
||||
if ((_c = (_b = (_a = config.app.extConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.FederatedCapacitor) === null || _c === void 0 ? void 0 : _c.liveUpdatesKey) {
|
||||
await copySecureLiveUpdatesKey(config.app.extConfig.plugins.FederatedCapacitor.liveUpdatesKey, config.app.rootDir, config.ios.nativeTargetDirAbs);
|
||||
}
|
||||
}
|
||||
else {
|
||||
await copyWebDir(config, await config.ios.webDirAbs, config.app.webDirAbs);
|
||||
}
|
||||
if (usesLiveUpdates && ((_f = (_e = (_d = config.app.extConfig) === null || _d === void 0 ? void 0 : _d.plugins) === null || _e === void 0 ? void 0 : _e.LiveUpdates) === null || _f === void 0 ? void 0 : _f.key)) {
|
||||
await copySecureLiveUpdatesKey(config.app.extConfig.plugins.LiveUpdates.key, config.app.rootDir, config.ios.nativeTargetDirAbs);
|
||||
}
|
||||
if (usesSSLPinning && ((_j = (_h = (_g = config.app.extConfig) === null || _g === void 0 ? void 0 : _g.plugins) === null || _h === void 0 ? void 0 : _h.SSLPinning) === null || _j === void 0 ? void 0 : _j.certs)) {
|
||||
await copySSLCert((_k = config.app.extConfig.plugins.SSLPinning) === null || _k === void 0 ? void 0 : _k.certs, config.app.rootDir, await config.ios.webDirAbs);
|
||||
}
|
||||
await copyCapacitorConfig(config, config.ios.nativeTargetDirAbs);
|
||||
const cordovaPlugins = await (0, cordova_1.getCordovaPlugins)(config, platformName);
|
||||
await (0, cordova_1.handleCordovaPluginsJS)(cordovaPlugins, config, platformName);
|
||||
const iosPlugins = await (0, common_2.getIOSPlugins)(allPlugins);
|
||||
await (0, iosplugin_1.generateIOSPackageJSON)(config, iosPlugins);
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
if (usesFederatedCapacitor) {
|
||||
await copyFederatedWebDirs(config, config.android.webDirAbs);
|
||||
if ((_o = (_m = (_l = config.app.extConfig) === null || _l === void 0 ? void 0 : _l.plugins) === null || _m === void 0 ? void 0 : _m.FederatedCapacitor) === null || _o === void 0 ? void 0 : _o.liveUpdatesKey) {
|
||||
await copySecureLiveUpdatesKey(config.app.extConfig.plugins.FederatedCapacitor.liveUpdatesKey, config.app.rootDir, config.android.assetsDirAbs);
|
||||
}
|
||||
}
|
||||
else {
|
||||
await copyWebDir(config, config.android.webDirAbs, config.app.webDirAbs);
|
||||
}
|
||||
if (usesLiveUpdates && ((_r = (_q = (_p = config.app.extConfig) === null || _p === void 0 ? void 0 : _p.plugins) === null || _q === void 0 ? void 0 : _q.LiveUpdates) === null || _r === void 0 ? void 0 : _r.key)) {
|
||||
await copySecureLiveUpdatesKey(config.app.extConfig.plugins.LiveUpdates.key, config.app.rootDir, config.android.assetsDirAbs);
|
||||
}
|
||||
if (usesSSLPinning && ((_u = (_t = (_s = config.app.extConfig) === null || _s === void 0 ? void 0 : _s.plugins) === null || _t === void 0 ? void 0 : _t.SSLPinning) === null || _u === void 0 ? void 0 : _u.certs)) {
|
||||
await copySSLCert((_v = config.app.extConfig.plugins.SSLPinning) === null || _v === void 0 ? void 0 : _v.certs, config.app.rootDir, config.android.assetsDirAbs);
|
||||
}
|
||||
await copyCapacitorConfig(config, config.android.assetsDirAbs);
|
||||
const cordovaPlugins = await (0, cordova_1.getCordovaPlugins)(config, platformName);
|
||||
await (0, cordova_1.handleCordovaPluginsJS)(cordovaPlugins, config, platformName);
|
||||
await (0, cordova_1.writeCordovaAndroidManifest)(cordovaPlugins, config, platformName);
|
||||
}
|
||||
else if (platformName === config.web.name) {
|
||||
if (usesFederatedCapacitor) {
|
||||
log_1.logger.info('FederatedCapacitor Plugin installed, skipping web bundling...');
|
||||
}
|
||||
else {
|
||||
await (0, copy_1.copyWeb)(config);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw `Platform ${platformName} is not valid.`;
|
||||
}
|
||||
if (inline) {
|
||||
await (0, sourcemaps_1.inlineSourceMaps)(config, platformName);
|
||||
}
|
||||
});
|
||||
await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:copy:after');
|
||||
}
|
||||
exports.copy = copy;
|
||||
async function copyCapacitorConfig(config, nativeAbsDir) {
|
||||
const nativeRelDir = (0, path_1.relative)(config.app.rootDir, nativeAbsDir);
|
||||
const nativeConfigFile = 'capacitor.config.json';
|
||||
const nativeConfigFilePath = (0, path_1.join)(nativeAbsDir, nativeConfigFile);
|
||||
await (0, common_1.runTask)(`Creating ${colors_1.default.strong(nativeConfigFile)} in ${nativeRelDir}`, async () => {
|
||||
var _a;
|
||||
(_a = config.app.extConfig.android) === null || _a === void 0 ? true : delete _a.buildOptions;
|
||||
await (0, utils_fs_1.writeJSON)(nativeConfigFilePath, config.app.extConfig, {
|
||||
spaces: '\t',
|
||||
});
|
||||
});
|
||||
}
|
||||
async function copyWebDir(config, nativeAbsDir, webAbsDir) {
|
||||
var _a;
|
||||
const webRelDir = (0, path_1.basename)(webAbsDir);
|
||||
const nativeRelDir = (0, path_1.relative)(config.app.rootDir, nativeAbsDir);
|
||||
if (((_a = config.app.extConfig.server) === null || _a === void 0 ? void 0 : _a.url) && !(await (0, utils_fs_1.pathExists)(webAbsDir))) {
|
||||
log_1.logger.warn(`Cannot copy web assets from ${colors_1.default.strong(webRelDir)} to ${nativeRelDir}\n` +
|
||||
`Web asset directory specified by ${colors_1.default.input('webDir')} does not exist. This is not an error because ${colors_1.default.input('server.url')} is set in config.`);
|
||||
return;
|
||||
}
|
||||
await (0, common_1.runTask)(`Copying web assets from ${colors_1.default.strong(webRelDir)} to ${nativeRelDir}`, async () => {
|
||||
await (0, utils_fs_1.remove)(nativeAbsDir);
|
||||
return (0, utils_fs_1.copy)(webAbsDir, nativeAbsDir);
|
||||
});
|
||||
}
|
||||
async function copyFederatedWebDirs(config, nativeAbsDir) {
|
||||
var _a, _b;
|
||||
log_1.logger.info('FederatedCapacitor Plugin Loaded - Copying Web Assets');
|
||||
if (!((_b = (_a = config.app.extConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.FederatedCapacitor)) {
|
||||
throw `FederatedCapacitor plugin is present but no valid config is defined.`;
|
||||
}
|
||||
const federatedConfig = config.app.extConfig.plugins.FederatedCapacitor;
|
||||
if (federatedConfig) {
|
||||
if (federatedConfig.shell.name === undefined) {
|
||||
throw `FederatedCapacitor plugin is present but no valid Shell application is defined in the config.`;
|
||||
}
|
||||
if (!federatedConfig.apps.every(isFederatedApp)) {
|
||||
throw `FederatedCapacitor plugin is present but there is a problem with the apps defined in the config.`;
|
||||
}
|
||||
const copyApps = () => {
|
||||
return federatedConfig.apps.map(app => {
|
||||
const appDir = (0, path_1.resolve)(config.app.rootDir, app.webDir);
|
||||
return copyWebDir(config, (0, path_1.resolve)(nativeAbsDir, app.name), appDir);
|
||||
});
|
||||
};
|
||||
const copyShell = () => {
|
||||
return copyWebDir(config, (0, path_1.resolve)(nativeAbsDir, federatedConfig.shell.name), config.app.webDirAbs);
|
||||
};
|
||||
await Promise.all([...copyApps(), copyShell()]);
|
||||
}
|
||||
}
|
||||
function isFederatedApp(config) {
|
||||
return (config.webDir !== undefined &&
|
||||
config.name !== undefined);
|
||||
}
|
||||
async function copySecureLiveUpdatesKey(secureLiveUpdatesKeyFile, rootDir, nativeAbsDir) {
|
||||
const keyAbsFromPath = (0, path_1.join)(rootDir, secureLiveUpdatesKeyFile);
|
||||
const keyAbsToPath = (0, path_1.join)(nativeAbsDir, (0, path_1.basename)(keyAbsFromPath));
|
||||
const keyRelToDir = (0, path_1.relative)(rootDir, nativeAbsDir);
|
||||
if (!(await (0, utils_fs_1.pathExists)(keyAbsFromPath))) {
|
||||
log_1.logger.warn(`Cannot copy Secure Live Updates signature file from ${colors_1.default.strong(keyAbsFromPath)} to ${keyRelToDir}\n` +
|
||||
`Signature file does not exist at specified key path.`);
|
||||
return;
|
||||
}
|
||||
await (0, common_1.runTask)(`Copying Secure Live Updates key from ${colors_1.default.strong(secureLiveUpdatesKeyFile)} to ${keyRelToDir}`, async () => {
|
||||
return (0, utils_fs_1.copy)(keyAbsFromPath, keyAbsToPath);
|
||||
});
|
||||
}
|
||||
async function copySSLCert(sslCertPaths, rootDir, targetDir) {
|
||||
const validCertPaths = [];
|
||||
for (const sslCertPath of sslCertPaths) {
|
||||
const certAbsFromPath = (0, path_1.join)(rootDir, sslCertPath);
|
||||
if (!(await (0, utils_fs_1.pathExists)(certAbsFromPath))) {
|
||||
log_1.logger.warn(`Cannot copy SSL Certificate file from ${colors_1.default.strong(certAbsFromPath)}\n` +
|
||||
`SSL Certificate does not exist at specified path.`);
|
||||
return;
|
||||
}
|
||||
validCertPaths.push(certAbsFromPath);
|
||||
}
|
||||
const certsDirAbsToPath = (0, path_1.join)(targetDir, 'certs');
|
||||
const certsDirRelToDir = (0, path_1.relative)(rootDir, targetDir);
|
||||
await (0, common_1.runTask)(`Copying SSL Certificates from to ${certsDirRelToDir}`, async () => {
|
||||
const promises = [];
|
||||
for (const certPath of validCertPaths) {
|
||||
promises.push((0, utils_fs_1.copy)(certPath, (0, path_1.join)(certsDirAbsToPath, (0, path_1.basename)(certPath))));
|
||||
}
|
||||
return Promise.all(promises);
|
||||
});
|
||||
}
|
11
@capacitor/cli/dist/tasks/create.js
vendored
Normal file
11
@capacitor/cli/dist/tasks/create.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const errors_1 = require("../errors");
|
||||
async function createCommand() {
|
||||
(0, errors_1.fatal)(`The create command has been removed.\n` +
|
||||
`Use ${colors_1.default.input('npm init @capacitor/app')}`);
|
||||
}
|
||||
exports.createCommand = createCommand;
|
73
@capacitor/cli/dist/tasks/doctor.js
vendored
Normal file
73
@capacitor/cli/dist/tasks/doctor.js
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.doctor = exports.doctorCore = exports.doctorCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const utils_fs_1 = require("@ionic/utils-fs");
|
||||
const doctor_1 = require("../android/doctor");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_1 = require("../common");
|
||||
const doctor_2 = require("../ios/doctor");
|
||||
const log_1 = require("../log");
|
||||
const emoji_1 = require("../util/emoji");
|
||||
const node_1 = require("../util/node");
|
||||
const subprocess_1 = require("../util/subprocess");
|
||||
async function doctorCommand(config, selectedPlatformName) {
|
||||
log_1.output.write(`${(0, emoji_1.emoji)('💊', '')} ${colors_1.default.strong('Capacitor Doctor')} ${(0, emoji_1.emoji)('💊', '')} \n\n`);
|
||||
await doctorCore(config);
|
||||
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
||||
await Promise.all(platforms.map(platformName => {
|
||||
return doctor(config, platformName);
|
||||
}));
|
||||
}
|
||||
exports.doctorCommand = doctorCommand;
|
||||
async function doctorCore(config) {
|
||||
const [cliVersion, coreVersion, androidVersion, iosVersion] = await Promise.all([
|
||||
(0, subprocess_1.getCommandOutput)('npm', ['info', '@capacitor/cli', 'version']),
|
||||
(0, subprocess_1.getCommandOutput)('npm', ['info', '@capacitor/core', 'version']),
|
||||
(0, subprocess_1.getCommandOutput)('npm', ['info', '@capacitor/android', 'version']),
|
||||
(0, subprocess_1.getCommandOutput)('npm', ['info', '@capacitor/ios', 'version']),
|
||||
]);
|
||||
log_1.output.write(`${colors_1.default.strong('Latest Dependencies:')}\n\n` +
|
||||
` @capacitor/cli: ${colors_1.default.weak(cliVersion !== null && cliVersion !== void 0 ? cliVersion : 'unknown')}\n` +
|
||||
` @capacitor/core: ${colors_1.default.weak(coreVersion !== null && coreVersion !== void 0 ? coreVersion : 'unknown')}\n` +
|
||||
` @capacitor/android: ${colors_1.default.weak(androidVersion !== null && androidVersion !== void 0 ? androidVersion : 'unknown')}\n` +
|
||||
` @capacitor/ios: ${colors_1.default.weak(iosVersion !== null && iosVersion !== void 0 ? iosVersion : 'unknown')}\n\n` +
|
||||
`${colors_1.default.strong('Installed Dependencies:')}\n\n`);
|
||||
await printInstalledPackages(config);
|
||||
log_1.output.write('\n');
|
||||
}
|
||||
exports.doctorCore = doctorCore;
|
||||
async function printInstalledPackages(config) {
|
||||
const packageNames = [
|
||||
'@capacitor/cli',
|
||||
'@capacitor/core',
|
||||
'@capacitor/android',
|
||||
'@capacitor/ios',
|
||||
];
|
||||
await Promise.all(packageNames.map(async (packageName) => {
|
||||
const packagePath = (0, node_1.resolveNode)(config.app.rootDir, packageName, 'package.json');
|
||||
await printPackageVersion(packageName, packagePath);
|
||||
}));
|
||||
}
|
||||
async function printPackageVersion(packageName, packagePath) {
|
||||
let version;
|
||||
if (packagePath) {
|
||||
version = (await (0, utils_fs_1.readJSON)(packagePath)).version;
|
||||
}
|
||||
log_1.output.write(` ${packageName}: ${colors_1.default.weak(version || 'not installed')}\n`);
|
||||
}
|
||||
async function doctor(config, platformName) {
|
||||
if (platformName === config.ios.name) {
|
||||
await (0, doctor_2.doctorIOS)(config);
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
await (0, doctor_1.doctorAndroid)(config);
|
||||
}
|
||||
else if (platformName === config.web.name) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
else {
|
||||
throw `Platform ${platformName} is not valid.`;
|
||||
}
|
||||
}
|
||||
exports.doctor = doctor;
|
139
@capacitor/cli/dist/tasks/init.js
vendored
Normal file
139
@capacitor/cli/dist/tasks/init.js
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const open_1 = tslib_1.__importDefault(require("open"));
|
||||
const path_1 = require("path");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_1 = require("../common");
|
||||
const config_1 = require("../config");
|
||||
const cordova_1 = require("../cordova");
|
||||
const errors_1 = require("../errors");
|
||||
const framework_configs_1 = require("../framework-configs");
|
||||
const log_1 = require("../log");
|
||||
const sysconfig_1 = require("../sysconfig");
|
||||
const node_1 = require("../util/node");
|
||||
const term_1 = require("../util/term");
|
||||
async function initCommand(config, name, id, webDirFromCLI) {
|
||||
var _a, _b;
|
||||
try {
|
||||
if (!(0, term_1.checkInteractive)(name, id)) {
|
||||
return;
|
||||
}
|
||||
if (config.app.extConfigType !== 'json') {
|
||||
(0, errors_1.fatal)(`Cannot run ${colors_1.default.input('init')} for a project using a non-JSON configuration file.\n` +
|
||||
`Delete ${colors_1.default.strong(config.app.extConfigName)} and try again.`);
|
||||
}
|
||||
const isNewConfig = Object.keys(config.app.extConfig).length === 0;
|
||||
const tsInstalled = !!(0, node_1.resolveNode)(config.app.rootDir, 'typescript');
|
||||
const appName = await getName(config, name);
|
||||
const appId = await getAppId(config, id);
|
||||
const webDir = (0, term_1.isInteractive)()
|
||||
? await getWebDir(config, webDirFromCLI)
|
||||
: (_a = webDirFromCLI !== null && webDirFromCLI !== void 0 ? webDirFromCLI : config.app.extConfig.webDir) !== null && _a !== void 0 ? _a : 'www';
|
||||
await (0, common_1.check)([
|
||||
() => (0, common_1.checkAppName)(config, appName),
|
||||
() => (0, common_1.checkAppId)(config, appId),
|
||||
]);
|
||||
const cordova = await (0, cordova_1.getCordovaPreferences)(config);
|
||||
await runMergeConfig(config, {
|
||||
appId,
|
||||
appName,
|
||||
webDir,
|
||||
cordova,
|
||||
}, isNewConfig && tsInstalled ? 'ts' : 'json');
|
||||
}
|
||||
catch (e) {
|
||||
if (!(0, errors_1.isFatal)(e)) {
|
||||
log_1.output.write('Usage: npx cap init appName appId\n' +
|
||||
'Example: npx cap init "My App" "com.example.myapp"\n\n');
|
||||
(0, errors_1.fatal)((_b = e.stack) !== null && _b !== void 0 ? _b : e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
exports.initCommand = initCommand;
|
||||
async function getName(config, name) {
|
||||
var _a;
|
||||
if (!name) {
|
||||
const answers = await (0, log_1.logPrompt)(`${colors_1.default.strong(`What is the name of your app?`)}\n` +
|
||||
`This should be a human-friendly app name, like what you'd see in the App Store.`, {
|
||||
type: 'text',
|
||||
name: 'name',
|
||||
message: `Name`,
|
||||
initial: config.app.appName
|
||||
? config.app.appName
|
||||
: (_a = config.app.package.name) !== null && _a !== void 0 ? _a : 'App',
|
||||
});
|
||||
return answers.name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
async function getAppId(config, id) {
|
||||
if (!id) {
|
||||
const answers = await (0, log_1.logPrompt)(`${colors_1.default.strong(`What should be the Package ID for your app?`)}\n` +
|
||||
`Package IDs (aka Bundle ID in iOS and Application ID in Android) are unique identifiers for apps. They must be in reverse domain name notation, generally representing a domain name that you or your company owns.`, {
|
||||
type: 'text',
|
||||
name: 'id',
|
||||
message: `Package ID`,
|
||||
initial: config.app.appId ? config.app.appId : 'com.example.app',
|
||||
});
|
||||
return answers.id;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
async function getWebDir(config, webDir) {
|
||||
if (!webDir) {
|
||||
const framework = (0, framework_configs_1.detectFramework)(config);
|
||||
if (framework === null || framework === void 0 ? void 0 : framework.webDir) {
|
||||
return framework.webDir;
|
||||
}
|
||||
const answers = await (0, log_1.logPrompt)(`${colors_1.default.strong(`What is the web asset directory for your app?`)}\n` +
|
||||
`This directory should contain the final ${colors_1.default.strong('index.html')} of your app.`, {
|
||||
type: 'text',
|
||||
name: 'webDir',
|
||||
message: `Web asset directory`,
|
||||
initial: config.app.webDir ? config.app.webDir : 'www',
|
||||
});
|
||||
return answers.webDir;
|
||||
}
|
||||
return webDir;
|
||||
}
|
||||
async function runMergeConfig(config, extConfig, type) {
|
||||
const configDirectory = (0, path_1.dirname)(config.app.extConfigFilePath);
|
||||
const newConfigPath = (0, path_1.resolve)(configDirectory, type === 'ts' ? config_1.CONFIG_FILE_NAME_TS : config_1.CONFIG_FILE_NAME_JSON);
|
||||
await (0, common_1.runTask)(`Creating ${colors_1.default.strong((0, path_1.basename)(newConfigPath))} in ${colors_1.default.input(config.app.rootDir)}`, async () => {
|
||||
await mergeConfig(config, extConfig, newConfigPath);
|
||||
});
|
||||
printNextSteps((0, path_1.basename)(newConfigPath));
|
||||
if ((0, term_1.isInteractive)()) {
|
||||
let sysconfig = await (0, sysconfig_1.readConfig)();
|
||||
if (typeof sysconfig.signup === 'undefined') {
|
||||
const signup = await promptToSignup();
|
||||
sysconfig = { ...sysconfig, signup };
|
||||
await (0, sysconfig_1.writeConfig)(sysconfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
async function mergeConfig(config, extConfig, newConfigPath) {
|
||||
const oldConfig = { ...config.app.extConfig };
|
||||
const newConfig = { ...oldConfig, ...extConfig };
|
||||
await (0, config_1.writeConfig)(newConfig, newConfigPath);
|
||||
}
|
||||
function printNextSteps(newConfigName) {
|
||||
(0, log_1.logSuccess)(`${colors_1.default.strong(newConfigName)} created!`);
|
||||
log_1.output.write(`\nNext steps: \n${colors_1.default.strong(`https://capacitorjs.com/docs/getting-started#where-to-go-next`)}\n`);
|
||||
}
|
||||
async function promptToSignup() {
|
||||
const answers = await (0, log_1.logPrompt)(`Join the Ionic Community! 💙\n` +
|
||||
`Connect with millions of developers on the Ionic Forum and get access to live events, news updates, and more.`, {
|
||||
type: 'confirm',
|
||||
name: 'create',
|
||||
message: `Create free Ionic account?`,
|
||||
initial: true,
|
||||
});
|
||||
if (answers.create) {
|
||||
(0, open_1.default)(`http://ionicframework.com/signup?source=capacitor`);
|
||||
}
|
||||
return answers.create;
|
||||
}
|
50
@capacitor/cli/dist/tasks/list.js
vendored
Normal file
50
@capacitor/cli/dist/tasks/list.js
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.list = exports.listCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const common_1 = require("../android/common");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_2 = require("../common");
|
||||
const errors_1 = require("../errors");
|
||||
const common_3 = require("../ios/common");
|
||||
const log_1 = require("../log");
|
||||
const plugin_1 = require("../plugin");
|
||||
const promise_1 = require("../util/promise");
|
||||
async function listCommand(config, selectedPlatformName) {
|
||||
var _a;
|
||||
const platforms = await (0, common_2.selectPlatforms)(config, selectedPlatformName);
|
||||
try {
|
||||
await (0, promise_1.allSerial)(platforms.map(platformName => () => list(config, platformName)));
|
||||
}
|
||||
catch (e) {
|
||||
if ((0, errors_1.isFatal)(e)) {
|
||||
throw e;
|
||||
}
|
||||
log_1.logger.error((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
}
|
||||
exports.listCommand = listCommand;
|
||||
async function list(config, platform) {
|
||||
const allPlugins = await (0, plugin_1.getPlugins)(config, platform);
|
||||
let plugins = [];
|
||||
if (platform === config.ios.name) {
|
||||
plugins = await (0, common_3.getIOSPlugins)(allPlugins);
|
||||
}
|
||||
else if (platform === config.android.name) {
|
||||
plugins = await (0, common_1.getAndroidPlugins)(allPlugins);
|
||||
}
|
||||
else if (platform === config.web.name) {
|
||||
log_1.logger.info(`Listing plugins for ${colors_1.default.input(platform)} is not possible.`);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw `Platform ${colors_1.default.input(platform)} is not valid.`;
|
||||
}
|
||||
const capacitorPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
|
||||
(0, plugin_1.printPlugins)(capacitorPlugins, platform);
|
||||
const cordovaPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
|
||||
(0, plugin_1.printPlugins)(cordovaPlugins, platform, 'cordova');
|
||||
const incompatibleCordovaPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 2 /* PluginType.Incompatible */);
|
||||
(0, plugin_1.printPlugins)(incompatibleCordovaPlugins, platform, 'incompatible');
|
||||
}
|
||||
exports.list = list;
|
575
@capacitor/cli/dist/tasks/migrate.js
vendored
Normal file
575
@capacitor/cli/dist/tasks/migrate.js
vendored
Normal file
|
@ -0,0 +1,575 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.patchOldCapacitorPlugins = exports.migrateCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const utils_fs_1 = require("@ionic/utils-fs");
|
||||
const path_1 = require("path");
|
||||
const rimraf_1 = tslib_1.__importDefault(require("rimraf"));
|
||||
const semver_1 = require("semver");
|
||||
const common_1 = require("../android/common");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_2 = require("../common");
|
||||
const errors_1 = require("../errors");
|
||||
const log_1 = require("../log");
|
||||
const plugin_1 = require("../plugin");
|
||||
const fs_1 = require("../util/fs");
|
||||
const node_1 = require("../util/node");
|
||||
const subprocess_1 = require("../util/subprocess");
|
||||
const template_1 = require("../util/template");
|
||||
// eslint-disable-next-line prefer-const
|
||||
let allDependencies = {};
|
||||
const libs = [
|
||||
'@capacitor/core',
|
||||
'@capacitor/cli',
|
||||
'@capacitor/ios',
|
||||
'@capacitor/android',
|
||||
];
|
||||
const plugins = [
|
||||
'@capacitor/action-sheet',
|
||||
'@capacitor/app',
|
||||
'@capacitor/app-launcher',
|
||||
'@capacitor/browser',
|
||||
'@capacitor/camera',
|
||||
'@capacitor/clipboard',
|
||||
'@capacitor/device',
|
||||
'@capacitor/dialog',
|
||||
'@capacitor/filesystem',
|
||||
'@capacitor/geolocation',
|
||||
'@capacitor/haptics',
|
||||
'@capacitor/keyboard',
|
||||
'@capacitor/local-notifications',
|
||||
'@capacitor/motion',
|
||||
'@capacitor/network',
|
||||
'@capacitor/preferences',
|
||||
'@capacitor/push-notifications',
|
||||
'@capacitor/screen-reader',
|
||||
'@capacitor/screen-orientation',
|
||||
'@capacitor/share',
|
||||
'@capacitor/splash-screen',
|
||||
'@capacitor/status-bar',
|
||||
'@capacitor/text-zoom',
|
||||
'@capacitor/toast',
|
||||
];
|
||||
const coreVersion = '^6.0.0';
|
||||
const pluginVersion = '^6.0.0';
|
||||
const gradleVersion = '8.2.1';
|
||||
let installFailed = false;
|
||||
async function migrateCommand(config, noprompt, packagemanager) {
|
||||
if (config === null) {
|
||||
(0, errors_1.fatal)('Config data missing');
|
||||
}
|
||||
const capMajor = await checkCapacitorMajorVersion(config);
|
||||
if (capMajor < 5) {
|
||||
(0, errors_1.fatal)('Migrate can only be used on capacitor 5 and above, please use the CLI in Capacitor 5 to upgrade to 5 first');
|
||||
}
|
||||
const jdkMajor = await (0, common_2.checkJDKMajorVersion)();
|
||||
if (jdkMajor < 17) {
|
||||
log_1.logger.warn('Capacitor 6 requires JDK 17 or higher. Some steps may fail.');
|
||||
}
|
||||
const variablesAndClasspaths = await getAndroidVariablesAndClasspaths(config);
|
||||
if (!variablesAndClasspaths) {
|
||||
(0, errors_1.fatal)('Variable and Classpath info could not be read.');
|
||||
}
|
||||
allDependencies = {
|
||||
...config.app.package.dependencies,
|
||||
...config.app.package.devDependencies,
|
||||
};
|
||||
const monorepoWarning = 'Please note this tool is not intended for use in a mono-repo environment, please check out the Ionic vscode extension for this functionality.';
|
||||
log_1.logger.info(monorepoWarning);
|
||||
const { migrateconfirm } = noprompt
|
||||
? { migrateconfirm: 'y' }
|
||||
: await (0, log_1.logPrompt)(`Capacitor 6 sets a deployment target of iOS 13 and Android 14 (SDK 34). \n`, {
|
||||
type: 'text',
|
||||
name: 'migrateconfirm',
|
||||
message: `Are you sure you want to migrate? (Y/n)`,
|
||||
initial: 'y',
|
||||
});
|
||||
if (typeof migrateconfirm === 'string' &&
|
||||
migrateconfirm.toLowerCase() === 'y') {
|
||||
try {
|
||||
const { depInstallConfirm } = noprompt
|
||||
? { depInstallConfirm: 'y' }
|
||||
: 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)`, {
|
||||
type: 'text',
|
||||
name: 'depInstallConfirm',
|
||||
message: `Run Dependency Install? (Y/n)`,
|
||||
initial: 'y',
|
||||
});
|
||||
const runNpmInstall = typeof depInstallConfirm === 'string' &&
|
||||
depInstallConfirm.toLowerCase() === 'y';
|
||||
let installerType = 'npm';
|
||||
if (runNpmInstall) {
|
||||
const { manager } = packagemanager
|
||||
? { manager: packagemanager }
|
||||
: await (0, log_1.logPrompt)('What dependency manager do you use?', {
|
||||
type: 'select',
|
||||
name: 'manager',
|
||||
message: `Dependency Management Tool`,
|
||||
choices: [
|
||||
{ title: 'NPM', value: 'npm' },
|
||||
{ title: 'Yarn', value: 'yarn' },
|
||||
{ title: 'PNPM', value: 'pnpm' },
|
||||
{ title: 'Bun', value: 'bun' },
|
||||
],
|
||||
initial: 0,
|
||||
});
|
||||
installerType = manager;
|
||||
}
|
||||
try {
|
||||
await (0, common_2.runTask)(`Installing Latest Modules using ${installerType}.`, () => {
|
||||
return installLatestLibs(installerType, runNpmInstall, config);
|
||||
});
|
||||
}
|
||||
catch (ex) {
|
||||
log_1.logger.error(`${installerType} install failed. Try deleting node_modules folder and running ${colors_1.default.input(`${installerType} install --force`)} manually.`);
|
||||
installFailed = true;
|
||||
}
|
||||
// Update iOS Projects
|
||||
if (allDependencies['@capacitor/ios'] &&
|
||||
(0, utils_fs_1.existsSync)(config.ios.platformDirAbs)) {
|
||||
// ios template changes
|
||||
// Remove NSLocationAlwaysUsageDescription
|
||||
await (0, common_2.runTask)(`Migrating Info.plist by removing NSLocationAlwaysUsageDescription key.`, () => {
|
||||
return removeKey((0, path_1.join)(config.ios.nativeTargetDirAbs, 'Info.plist'), 'NSLocationAlwaysUsageDescription');
|
||||
});
|
||||
}
|
||||
if (!installFailed) {
|
||||
await (0, common_2.runTask)(`Running cap sync.`, () => {
|
||||
return (0, subprocess_1.runCommand)('npx', ['cap', 'sync']);
|
||||
});
|
||||
}
|
||||
else {
|
||||
log_1.logger.warn('Skipped Running cap sync.');
|
||||
}
|
||||
if (allDependencies['@capacitor/android'] &&
|
||||
(0, utils_fs_1.existsSync)(config.android.platformDirAbs)) {
|
||||
const gradleWrapperVersion = getGradleWrapperVersion((0, path_1.join)(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
|
||||
if (!installFailed && (0, semver_1.gt)(gradleVersion, gradleWrapperVersion)) {
|
||||
try {
|
||||
await (0, common_2.runTask)(`Upgrading gradle wrapper files`, () => {
|
||||
return updateGradleWrapperFiles(config.android.platformDirAbs);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
if (e.includes('EACCES')) {
|
||||
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`);
|
||||
}
|
||||
else {
|
||||
log_1.logger.error(`gradle wrapper files were not updated`);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log_1.logger.warn('Skipped upgrading gradle wrapper files');
|
||||
}
|
||||
await (0, common_2.runTask)(`Migrating build.gradle file.`, () => {
|
||||
return updateBuildGradle((0, path_1.join)(config.android.platformDirAbs, 'build.gradle'), variablesAndClasspaths);
|
||||
});
|
||||
// Replace deprecated compileSdkVersion
|
||||
await (0, common_2.runTask)('Replacing deprecated compileSdkVersion from build.gradle', () => {
|
||||
return (async () => {
|
||||
const buildGradleFilename = (0, path_1.join)(config.android.platformDirAbs, 'app', 'build.gradle');
|
||||
const buildGradleText = readFile(buildGradleFilename);
|
||||
if (!buildGradleText) {
|
||||
log_1.logger.error(`Could not read ${buildGradleFilename}. Check its permissions and if it exists.`);
|
||||
return;
|
||||
}
|
||||
const compileSdk = `compileSdkVersion rootProject.ext.compileSdkVersion`;
|
||||
if (buildGradleText.includes(compileSdk)) {
|
||||
const buildGradleReplaced = buildGradleText.replace(compileSdk, `compileSdk rootProject.ext.compileSdkVersion`);
|
||||
(0, utils_fs_1.writeFileSync)(buildGradleFilename, buildGradleReplaced, 'utf-8');
|
||||
}
|
||||
})();
|
||||
});
|
||||
// Variables gradle
|
||||
await (0, common_2.runTask)(`Migrating variables.gradle file.`, () => {
|
||||
return (async () => {
|
||||
const variablesPath = (0, path_1.join)(config.android.platformDirAbs, 'variables.gradle');
|
||||
let txt = readFile(variablesPath);
|
||||
if (!txt) {
|
||||
return;
|
||||
}
|
||||
txt = txt.replace(/= {2}'/g, `= '`);
|
||||
(0, utils_fs_1.writeFileSync)(variablesPath, txt, { encoding: 'utf-8' });
|
||||
for (const variable of Object.keys(variablesAndClasspaths.variables)) {
|
||||
let replaceStart = `${variable} = '`;
|
||||
let replaceEnd = `'\n`;
|
||||
if (typeof variablesAndClasspaths.variables[variable] === 'number') {
|
||||
replaceStart = `${variable} = `;
|
||||
replaceEnd = `\n`;
|
||||
}
|
||||
if (txt.includes(replaceStart)) {
|
||||
const first = txt.indexOf(replaceStart) + replaceStart.length;
|
||||
const value = txt.substring(first, txt.indexOf(replaceEnd, first));
|
||||
if ((typeof variablesAndClasspaths.variables[variable] ===
|
||||
'number' &&
|
||||
value <= variablesAndClasspaths.variables[variable]) ||
|
||||
(typeof variablesAndClasspaths.variables[variable] ===
|
||||
'string' &&
|
||||
(0, semver_1.lt)(value, variablesAndClasspaths.variables[variable]))) {
|
||||
await updateFile(config, variablesPath, replaceStart, replaceEnd, variablesAndClasspaths.variables[variable].toString(), true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let file = readFile(variablesPath);
|
||||
if (file) {
|
||||
file = file.replace('}', ` ${replaceStart}${variablesAndClasspaths.variables[variable].toString()}${replaceEnd}}`);
|
||||
(0, utils_fs_1.writeFileSync)(variablesPath, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
const pluginVariables = {
|
||||
firebaseMessagingVersion: '23.3.1',
|
||||
playServicesLocationVersion: '21.1.0',
|
||||
androidxBrowserVersion: '1.7.0',
|
||||
androidxMaterialVersion: '1.10.0',
|
||||
androidxExifInterfaceVersion: '1.3.6',
|
||||
androidxCoreKTXVersion: '1.12.0',
|
||||
googleMapsPlayServicesVersion: '18.2.0',
|
||||
googleMapsUtilsVersion: '3.8.2',
|
||||
googleMapsKtxVersion: '5.0.0',
|
||||
googleMapsUtilsKtxVersion: '5.0.0',
|
||||
kotlinxCoroutinesVersion: '1.7.3',
|
||||
coreSplashScreenVersion: '1.0.1',
|
||||
};
|
||||
for (const variable of Object.keys(pluginVariables)) {
|
||||
await updateFile(config, variablesPath, `${variable} = '`, `'`, pluginVariables[variable], true);
|
||||
}
|
||||
})();
|
||||
});
|
||||
rimraf_1.default.sync((0, path_1.join)(config.android.appDirAbs, 'build'));
|
||||
if (!installFailed) {
|
||||
await (0, common_2.runTask)('Migrating package from Manifest to build.gradle in Capacitor plugins', () => {
|
||||
return patchOldCapacitorPlugins(config);
|
||||
});
|
||||
}
|
||||
else {
|
||||
log_1.logger.warn('Skipped migrating package from Manifest to build.gradle in Capacitor plugins');
|
||||
}
|
||||
}
|
||||
// Write all breaking changes
|
||||
await (0, common_2.runTask)(`Writing breaking changes.`, () => {
|
||||
return writeBreakingChanges();
|
||||
});
|
||||
if (!installFailed) {
|
||||
(0, log_1.logSuccess)(`Migration to Capacitor ${coreVersion} is complete. Run and test your app!`);
|
||||
}
|
||||
else {
|
||||
log_1.logger.warn(`Migration to Capacitor ${coreVersion} is incomplete. Check the log messages for more information.`);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
(0, errors_1.fatal)(`Failed to migrate: ${err}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
(0, errors_1.fatal)(`User canceled migration.`);
|
||||
}
|
||||
}
|
||||
exports.migrateCommand = migrateCommand;
|
||||
async function checkCapacitorMajorVersion(config) {
|
||||
var _a;
|
||||
const capacitorVersion = await (0, common_2.getCoreVersion)(config);
|
||||
const versionArray = (_a = capacitorVersion.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/)) !== null && _a !== void 0 ? _a : [];
|
||||
const majorVersion = parseInt(versionArray[1]);
|
||||
return majorVersion;
|
||||
}
|
||||
async function installLatestLibs(dependencyManager, runInstall, config) {
|
||||
const pkgJsonPath = (0, path_1.join)(config.app.rootDir, 'package.json');
|
||||
const pkgJsonFile = readFile(pkgJsonPath);
|
||||
if (!pkgJsonFile) {
|
||||
return;
|
||||
}
|
||||
const pkgJson = JSON.parse(pkgJsonFile);
|
||||
for (const devDepKey of Object.keys(pkgJson['devDependencies'] || {})) {
|
||||
if (libs.includes(devDepKey)) {
|
||||
pkgJson['devDependencies'][devDepKey] = coreVersion;
|
||||
}
|
||||
else if (plugins.includes(devDepKey)) {
|
||||
pkgJson['devDependencies'][devDepKey] = pluginVersion;
|
||||
}
|
||||
}
|
||||
for (const depKey of Object.keys(pkgJson['dependencies'] || {})) {
|
||||
if (libs.includes(depKey)) {
|
||||
pkgJson['dependencies'][depKey] = coreVersion;
|
||||
}
|
||||
else if (plugins.includes(depKey)) {
|
||||
pkgJson['dependencies'][depKey] = pluginVersion;
|
||||
}
|
||||
}
|
||||
(0, utils_fs_1.writeFileSync)(pkgJsonPath, JSON.stringify(pkgJson, null, 2), {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
if (runInstall) {
|
||||
rimraf_1.default.sync((0, path_1.join)(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
|
||||
await (0, subprocess_1.runCommand)(dependencyManager, ['install']);
|
||||
if (dependencyManager == 'yarn') {
|
||||
await (0, subprocess_1.runCommand)(dependencyManager, ['upgrade']);
|
||||
}
|
||||
else {
|
||||
await (0, subprocess_1.runCommand)(dependencyManager, ['update']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log_1.logger.info(`Please run an install command with your package manager of choice. (ex: yarn install)`);
|
||||
}
|
||||
}
|
||||
async function writeBreakingChanges() {
|
||||
const breaking = [
|
||||
'@capacitor/camera',
|
||||
'@capacitor/filesystem',
|
||||
'@capacitor/geolocation',
|
||||
'@capacitor/google-maps',
|
||||
'@capacitor/local-notifications',
|
||||
];
|
||||
const broken = [];
|
||||
for (const lib of breaking) {
|
||||
if (allDependencies[lib]) {
|
||||
broken.push(lib);
|
||||
}
|
||||
}
|
||||
if (broken.length > 0) {
|
||||
log_1.logger.info(`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/6-0#plugins for breaking changes in these plugins that you use: ${broken.join(', ')}.`);
|
||||
}
|
||||
}
|
||||
async function getAndroidVariablesAndClasspaths(config) {
|
||||
const tempAndroidTemplateFolder = (0, path_1.join)(config.cli.assetsDirAbs, 'tempAndroidTemplate');
|
||||
await (0, template_1.extractTemplate)(config.cli.assets.android.platformTemplateArchiveAbs, tempAndroidTemplateFolder);
|
||||
const variablesGradleFile = readFile((0, path_1.join)(tempAndroidTemplateFolder, 'variables.gradle'));
|
||||
const buildGradleFile = readFile((0, path_1.join)(tempAndroidTemplateFolder, 'build.gradle'));
|
||||
if (!variablesGradleFile || !buildGradleFile) {
|
||||
return;
|
||||
}
|
||||
(0, fs_1.deleteFolderRecursive)(tempAndroidTemplateFolder);
|
||||
const firstIndxOfCATBGV = buildGradleFile.indexOf(`classpath 'com.android.tools.build:gradle:`) + 42;
|
||||
const firstIndxOfCGGGS = buildGradleFile.indexOf(`com.google.gms:google-services:`) + 31;
|
||||
const comAndroidToolsBuildGradleVersion = '' +
|
||||
buildGradleFile.substring(firstIndxOfCATBGV, buildGradleFile.indexOf("'", firstIndxOfCATBGV));
|
||||
const comGoogleGmsGoogleServices = '' +
|
||||
buildGradleFile.substring(firstIndxOfCGGGS, buildGradleFile.indexOf("'", firstIndxOfCGGGS));
|
||||
const variablesGradleAsJSON = JSON.parse(variablesGradleFile
|
||||
.replace('ext ', '')
|
||||
.replace(/=/g, ':')
|
||||
.replace(/\n/g, ',')
|
||||
.replace(/,([^:]+):/g, function (_k, p1) {
|
||||
return `,"${p1}":`;
|
||||
})
|
||||
.replace('{,', '{')
|
||||
.replace(',}', '}')
|
||||
.replace(/\s/g, '')
|
||||
.replace(/'/g, '"'));
|
||||
return {
|
||||
'variables': variablesGradleAsJSON,
|
||||
'com.android.tools.build:gradle': comAndroidToolsBuildGradleVersion,
|
||||
'com.google.gms:google-services': comGoogleGmsGoogleServices,
|
||||
};
|
||||
}
|
||||
function readFile(filename) {
|
||||
try {
|
||||
if (!(0, utils_fs_1.existsSync)(filename)) {
|
||||
log_1.logger.error(`Unable to find ${filename}. Try updating it manually`);
|
||||
return;
|
||||
}
|
||||
return (0, utils_fs_1.readFileSync)(filename, 'utf-8');
|
||||
}
|
||||
catch (err) {
|
||||
log_1.logger.error(`Unable to read ${filename}. Verify it is not already open. ${err}`);
|
||||
}
|
||||
}
|
||||
function getGradleWrapperVersion(filename) {
|
||||
var _a;
|
||||
const txt = readFile(filename);
|
||||
if (!txt) {
|
||||
return '0.0.0';
|
||||
}
|
||||
const version = txt.substring(txt.indexOf('gradle-') + 7, txt.indexOf('-all.zip'));
|
||||
const semverVersion = (_a = (0, semver_1.coerce)(version)) === null || _a === void 0 ? void 0 : _a.version;
|
||||
return semverVersion ? semverVersion : '0.0.0';
|
||||
}
|
||||
async function updateGradleWrapperFiles(platformDir) {
|
||||
await (0, subprocess_1.runCommand)(`./gradlew`, [
|
||||
'wrapper',
|
||||
'--distribution-type',
|
||||
'all',
|
||||
'--gradle-version',
|
||||
gradleVersion,
|
||||
'--warning-mode',
|
||||
'all',
|
||||
], {
|
||||
cwd: platformDir,
|
||||
});
|
||||
}
|
||||
async function movePackageFromManifestToBuildGradle(manifestFilename, buildGradleFilename) {
|
||||
const manifestText = readFile(manifestFilename);
|
||||
const buildGradleText = readFile(buildGradleFilename);
|
||||
if (!manifestText) {
|
||||
log_1.logger.error(`Could not read ${manifestFilename}. Check its permissions and if it exists.`);
|
||||
return;
|
||||
}
|
||||
if (!buildGradleText) {
|
||||
log_1.logger.error(`Could not read ${buildGradleFilename}. Check its permissions and if it exists.`);
|
||||
return;
|
||||
}
|
||||
const namespaceExists = new RegExp(/\s+namespace\s+/).test(buildGradleText);
|
||||
if (namespaceExists) {
|
||||
log_1.logger.error('Found namespace in build.gradle already, skipping migration');
|
||||
return;
|
||||
}
|
||||
let packageName;
|
||||
const manifestRegEx = new RegExp(/package="([^"]+)"/);
|
||||
const manifestResults = manifestRegEx.exec(manifestText);
|
||||
if (manifestResults === null) {
|
||||
log_1.logger.error(`Unable to update Android Manifest. Package not found.`);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
packageName = manifestResults[1];
|
||||
}
|
||||
let manifestReplaced = manifestText;
|
||||
manifestReplaced = manifestReplaced.replace(manifestRegEx, '');
|
||||
if (manifestText == manifestReplaced) {
|
||||
log_1.logger.error(`Unable to update Android Manifest: no changes were detected in Android Manifest file`);
|
||||
return;
|
||||
}
|
||||
let buildGradleReplaced = buildGradleText;
|
||||
buildGradleReplaced = setAllStringIn(buildGradleText, 'android {', '\n', `\n namespace "${packageName}"`);
|
||||
if (buildGradleText == buildGradleReplaced) {
|
||||
log_1.logger.error(`Unable to update buildGradleText: no changes were detected in Android Manifest file`);
|
||||
return;
|
||||
}
|
||||
(0, utils_fs_1.writeFileSync)(manifestFilename, manifestReplaced, 'utf-8');
|
||||
(0, utils_fs_1.writeFileSync)(buildGradleFilename, buildGradleReplaced, 'utf-8');
|
||||
}
|
||||
async function updateBuildGradle(filename, variablesAndClasspaths) {
|
||||
const txt = readFile(filename);
|
||||
if (!txt) {
|
||||
return;
|
||||
}
|
||||
const neededDeps = {
|
||||
'com.android.tools.build:gradle': variablesAndClasspaths['com.android.tools.build:gradle'],
|
||||
'com.google.gms:google-services': variablesAndClasspaths['com.google.gms:google-services'],
|
||||
};
|
||||
let replaced = txt;
|
||||
for (const dep of Object.keys(neededDeps)) {
|
||||
if (replaced.includes(`classpath '${dep}`)) {
|
||||
const firstIndex = replaced.indexOf(dep) + dep.length + 1;
|
||||
const existingVersion = '' + replaced.substring(firstIndex, replaced.indexOf("'", firstIndex));
|
||||
if ((0, semver_1.gte)(neededDeps[dep], existingVersion)) {
|
||||
replaced = setAllStringIn(replaced, `classpath '${dep}:`, `'`, neededDeps[dep]);
|
||||
log_1.logger.info(`Set ${dep} = ${neededDeps[dep]}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
(0, utils_fs_1.writeFileSync)(filename, replaced, 'utf-8');
|
||||
}
|
||||
async function updateFile(config, filename, textStart, textEnd, replacement, skipIfNotFound) {
|
||||
if (config === null) {
|
||||
return false;
|
||||
}
|
||||
const path = filename;
|
||||
let txt = readFile(path);
|
||||
if (!txt) {
|
||||
return false;
|
||||
}
|
||||
if (txt.includes(textStart)) {
|
||||
if (replacement) {
|
||||
txt = setAllStringIn(txt, textStart, textEnd, replacement);
|
||||
(0, utils_fs_1.writeFileSync)(path, txt, { encoding: 'utf-8' });
|
||||
}
|
||||
else {
|
||||
// Replacing in code so we need to count the number of brackets to find the end of the function in swift
|
||||
const lines = txt.split('\n');
|
||||
let replaced = '';
|
||||
let keep = true;
|
||||
let brackets = 0;
|
||||
for (const line of lines) {
|
||||
if (line.includes(textStart)) {
|
||||
keep = false;
|
||||
}
|
||||
if (!keep) {
|
||||
brackets += (line.match(/{/g) || []).length;
|
||||
brackets -= (line.match(/}/g) || []).length;
|
||||
if (brackets == 0) {
|
||||
keep = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
replaced += line + '\n';
|
||||
}
|
||||
}
|
||||
(0, utils_fs_1.writeFileSync)(path, replaced, { encoding: 'utf-8' });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (!skipIfNotFound) {
|
||||
log_1.logger.error(`Unable to find "${textStart}" in ${filename}. Try updating it manually`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function setAllStringIn(data, start, end, replacement) {
|
||||
let position = 0;
|
||||
let result = data;
|
||||
let replaced = true;
|
||||
while (replaced) {
|
||||
const foundIdx = result.indexOf(start, position);
|
||||
if (foundIdx == -1) {
|
||||
replaced = false;
|
||||
}
|
||||
else {
|
||||
const idx = foundIdx + start.length;
|
||||
position = idx + replacement.length;
|
||||
result =
|
||||
result.substring(0, idx) +
|
||||
replacement +
|
||||
result.substring(result.indexOf(end, idx));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async function patchOldCapacitorPlugins(config) {
|
||||
const allPlugins = await (0, plugin_1.getPlugins)(config, 'android');
|
||||
const androidPlugins = await (0, common_1.getAndroidPlugins)(allPlugins);
|
||||
return await Promise.all(androidPlugins.map(async (p) => {
|
||||
var _a, _b;
|
||||
if ((_b = (_a = p.manifest) === null || _a === void 0 ? void 0 : _a.android) === null || _b === void 0 ? void 0 : _b.src) {
|
||||
const buildGradlePath = (0, node_1.resolveNode)(config.app.rootDir, p.id, p.manifest.android.src, 'build.gradle');
|
||||
const manifestPath = (0, node_1.resolveNode)(config.app.rootDir, p.id, p.manifest.android.src, 'src', 'main', 'AndroidManifest.xml');
|
||||
if (buildGradlePath && manifestPath) {
|
||||
const gradleContent = readFile(buildGradlePath);
|
||||
if (!(gradleContent === null || gradleContent === void 0 ? void 0 : gradleContent.includes('namespace'))) {
|
||||
if (plugins.includes(p.id)) {
|
||||
log_1.logger.warn(`You are using an outdated version of ${p.id}, update the plugin to version ${pluginVersion}`);
|
||||
}
|
||||
else {
|
||||
log_1.logger.warn(`${p.id}@${p.version} doesn't officially support Capacitor ${coreVersion} yet, doing our best moving it's package to build.gradle so it builds`);
|
||||
}
|
||||
movePackageFromManifestToBuildGradle(manifestPath, buildGradlePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
exports.patchOldCapacitorPlugins = patchOldCapacitorPlugins;
|
||||
async function removeKey(filename, key) {
|
||||
const txt = readFile(filename);
|
||||
if (!txt) {
|
||||
return;
|
||||
}
|
||||
let lines = txt.split('\n');
|
||||
let removed = false;
|
||||
let removing = false;
|
||||
lines = lines.filter(line => {
|
||||
if (removing && line.includes('</string>')) {
|
||||
removing = false;
|
||||
return false;
|
||||
}
|
||||
if (line.includes(`<key>${key}</key`)) {
|
||||
removing = true;
|
||||
removed = true;
|
||||
}
|
||||
return !removing;
|
||||
});
|
||||
if (removed) {
|
||||
(0, utils_fs_1.writeFileSync)(filename, lines.join('\n'), 'utf-8');
|
||||
}
|
||||
}
|
11
@capacitor/cli/dist/tasks/new-plugin.js
vendored
Normal file
11
@capacitor/cli/dist/tasks/new-plugin.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.newPluginCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const errors_1 = require("../errors");
|
||||
async function newPluginCommand() {
|
||||
(0, errors_1.fatal)(`The plugin:generate command has been removed.\n` +
|
||||
`Use ${colors_1.default.input('npm init @capacitor/plugin')}`);
|
||||
}
|
||||
exports.newPluginCommand = newPluginCommand;
|
62
@capacitor/cli/dist/tasks/open.js
vendored
Normal file
62
@capacitor/cli/dist/tasks/open.js
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.open = exports.openCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const open_1 = require("../android/open");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_1 = require("../common");
|
||||
const errors_1 = require("../errors");
|
||||
const open_2 = require("../ios/open");
|
||||
const log_1 = require("../log");
|
||||
async function openCommand(config, selectedPlatformName) {
|
||||
var _a;
|
||||
if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
|
||||
const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
|
||||
if (platformDir) {
|
||||
await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:open');
|
||||
}
|
||||
else {
|
||||
log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
||||
let platformName;
|
||||
if (platforms.length === 1) {
|
||||
platformName = platforms[0];
|
||||
}
|
||||
else {
|
||||
platformName = await (0, common_1.promptForPlatform)(platforms.filter(createOpenablePlatformFilter(config)), `Please choose a platform to open:`);
|
||||
}
|
||||
try {
|
||||
await open(config, platformName);
|
||||
}
|
||||
catch (e) {
|
||||
if (!(0, errors_1.isFatal)(e)) {
|
||||
(0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.openCommand = openCommand;
|
||||
function createOpenablePlatformFilter(config) {
|
||||
return platform => platform === config.ios.name || platform === config.android.name;
|
||||
}
|
||||
async function open(config, platformName) {
|
||||
if (platformName === config.ios.name) {
|
||||
await (0, common_1.runTask)('Opening the Xcode workspace...', () => {
|
||||
return (0, open_2.openIOS)(config);
|
||||
});
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
return (0, open_1.openAndroid)(config);
|
||||
}
|
||||
else if (platformName === config.web.name) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
else {
|
||||
throw `Platform ${platformName} is not valid.`;
|
||||
}
|
||||
}
|
||||
exports.open = open;
|
114
@capacitor/cli/dist/tasks/run.js
vendored
Normal file
114
@capacitor/cli/dist/tasks/run.js
vendored
Normal file
|
@ -0,0 +1,114 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.run = exports.runCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const utils_process_1 = require("@ionic/utils-process");
|
||||
const utils_terminal_1 = require("@ionic/utils-terminal");
|
||||
const run_1 = require("../android/run");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_1 = require("../common");
|
||||
const cordova_1 = require("../cordova");
|
||||
const errors_1 = require("../errors");
|
||||
const run_2 = require("../ios/run");
|
||||
const log_1 = require("../log");
|
||||
const livereload_1 = require("../util/livereload");
|
||||
const native_run_1 = require("../util/native-run");
|
||||
const sync_1 = require("./sync");
|
||||
async function runCommand(config, selectedPlatformName, options) {
|
||||
var _a, _b, _c, _d;
|
||||
options.host =
|
||||
(_b = (_a = options.host) !== null && _a !== void 0 ? _a : livereload_1.CapLiveReloadHelper.getIpAddress()) !== null && _b !== void 0 ? _b : 'localhost';
|
||||
options.port = (_c = options.port) !== null && _c !== void 0 ? _c : '3000';
|
||||
if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
|
||||
const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
|
||||
if (platformDir) {
|
||||
await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:run');
|
||||
}
|
||||
else {
|
||||
log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
||||
let platformName;
|
||||
if (platforms.length === 1) {
|
||||
platformName = platforms[0];
|
||||
}
|
||||
else {
|
||||
platformName = await (0, common_1.promptForPlatform)(platforms.filter(createRunnablePlatformFilter(config)), `Please choose a platform to run:`);
|
||||
}
|
||||
if (options.list) {
|
||||
const targets = await (0, native_run_1.getPlatformTargets)(platformName);
|
||||
const outputTargets = targets.map(t => {
|
||||
var _a;
|
||||
return ({
|
||||
name: (0, common_1.getPlatformTargetName)(t),
|
||||
api: `${t.platform === 'ios' ? 'iOS' : 'API'} ${t.sdkVersion}`,
|
||||
id: (_a = t.id) !== null && _a !== void 0 ? _a : '?',
|
||||
});
|
||||
});
|
||||
// TODO: make hidden commander option (https://github.com/tj/commander.js/issues/1106)
|
||||
if (process.argv.includes('--json')) {
|
||||
process.stdout.write(`${JSON.stringify(outputTargets)}\n`);
|
||||
}
|
||||
else {
|
||||
const rows = outputTargets.map(t => [t.name, t.api, t.id]);
|
||||
log_1.output.write(`${(0, utils_terminal_1.columnar)(rows, {
|
||||
headers: ['Name', 'API', 'Target ID'],
|
||||
vsep: ' ',
|
||||
})}\n`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (options.sync) {
|
||||
await (0, sync_1.sync)(config, platformName, false, true);
|
||||
}
|
||||
const cordovaPlugins = await (0, cordova_1.getCordovaPlugins)(config, platformName);
|
||||
if (options.liveReload) {
|
||||
await livereload_1.CapLiveReloadHelper.editCapConfigForLiveReload(config, platformName, options);
|
||||
if (platformName === config.android.name) {
|
||||
await await (0, cordova_1.writeCordovaAndroidManifest)(cordovaPlugins, config, platformName, true);
|
||||
}
|
||||
}
|
||||
await run(config, platformName, options);
|
||||
if (options.liveReload) {
|
||||
new Promise(resolve => process.on('SIGINT', resolve))
|
||||
.then(async () => {
|
||||
await livereload_1.CapLiveReloadHelper.revertCapConfigForLiveReload();
|
||||
if (platformName === config.android.name) {
|
||||
await (0, cordova_1.writeCordovaAndroidManifest)(cordovaPlugins, config, platformName, false);
|
||||
}
|
||||
})
|
||||
.then(() => process.exit());
|
||||
log_1.logger.info(`App running with live reload listing for: http://${options.host}:${options.port}. Press Ctrl+C to quit.`);
|
||||
await (0, utils_process_1.sleepForever)();
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (!(0, errors_1.isFatal)(e)) {
|
||||
(0, errors_1.fatal)((_d = e.stack) !== null && _d !== void 0 ? _d : e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.runCommand = runCommand;
|
||||
async function run(config, platformName, options) {
|
||||
if (platformName == config.ios.name) {
|
||||
await (0, run_2.runIOS)(config, options);
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
await (0, run_1.runAndroid)(config, options);
|
||||
}
|
||||
else if (platformName === config.web.name) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw `Platform ${platformName} is not valid.`;
|
||||
}
|
||||
}
|
||||
exports.run = run;
|
||||
function createRunnablePlatformFilter(config) {
|
||||
return platform => platform === config.ios.name || platform === config.android.name;
|
||||
}
|
11
@capacitor/cli/dist/tasks/serve.js
vendored
Normal file
11
@capacitor/cli/dist/tasks/serve.js
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.serveCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const errors_1 = require("../errors");
|
||||
async function serveCommand() {
|
||||
(0, errors_1.fatal)(`The serve command has been removed.\n` +
|
||||
`Use a third-party tool for serving single page apps, such as ${colors_1.default.strong('serve')}: ${colors_1.default.strong('https://www.npmjs.com/package/serve')}`);
|
||||
}
|
||||
exports.serveCommand = serveCommand;
|
40
@capacitor/cli/dist/tasks/sourcemaps.js
vendored
Normal file
40
@capacitor/cli/dist/tasks/sourcemaps.js
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.inlineSourceMaps = void 0;
|
||||
const utils_fs_1 = require("@ionic/utils-fs");
|
||||
const path_1 = require("path");
|
||||
const log_1 = require("../log");
|
||||
function walkDirectory(dirPath) {
|
||||
const files = (0, utils_fs_1.readdirSync)(dirPath);
|
||||
files.forEach(file => {
|
||||
const targetFile = (0, path_1.join)(dirPath, file);
|
||||
if ((0, utils_fs_1.existsSync)(targetFile) && (0, utils_fs_1.lstatSync)(targetFile).isDirectory()) {
|
||||
walkDirectory(targetFile);
|
||||
}
|
||||
else {
|
||||
const mapFile = (0, path_1.join)(dirPath, `${file}.map`);
|
||||
if ((0, path_1.extname)(file) === '.js' && (0, utils_fs_1.existsSync)(mapFile)) {
|
||||
const bufMap = (0, utils_fs_1.readFileSync)(mapFile).toString('base64');
|
||||
const bufFile = (0, utils_fs_1.readFileSync)(targetFile, 'utf8');
|
||||
const result = bufFile.replace(`sourceMappingURL=${file}.map`, 'sourceMappingURL=data:application/json;charset=utf-8;base64,' +
|
||||
bufMap);
|
||||
(0, utils_fs_1.writeFileSync)(targetFile, result);
|
||||
(0, utils_fs_1.unlinkSync)(mapFile);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
async function inlineSourceMaps(config, platformName) {
|
||||
let buildDir = '';
|
||||
if (platformName == config.ios.name) {
|
||||
buildDir = await config.ios.webDirAbs;
|
||||
}
|
||||
if (platformName == config.android.name) {
|
||||
buildDir = await config.android.webDirAbs;
|
||||
}
|
||||
if (buildDir) {
|
||||
log_1.logger.info('Inlining sourcemaps');
|
||||
walkDirectory(buildDir);
|
||||
}
|
||||
}
|
||||
exports.inlineSourceMaps = inlineSourceMaps;
|
59
@capacitor/cli/dist/tasks/sync.js
vendored
Normal file
59
@capacitor/cli/dist/tasks/sync.js
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sync = exports.syncCommand = void 0;
|
||||
const common_1 = require("../common");
|
||||
const errors_1 = require("../errors");
|
||||
const log_1 = require("../log");
|
||||
const promise_1 = require("../util/promise");
|
||||
const copy_1 = require("./copy");
|
||||
const update_1 = require("./update");
|
||||
/**
|
||||
* Sync is a copy and an update in one.
|
||||
*/
|
||||
async function syncCommand(config, selectedPlatformName, deployment, inline = false) {
|
||||
var _a, _b;
|
||||
if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
|
||||
try {
|
||||
await (0, copy_1.copyCommand)(config, selectedPlatformName, inline);
|
||||
}
|
||||
catch (e) {
|
||||
log_1.logger.error((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
await (0, update_1.updateCommand)(config, selectedPlatformName, deployment);
|
||||
}
|
||||
else {
|
||||
const then = +new Date();
|
||||
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
||||
try {
|
||||
await (0, common_1.check)([
|
||||
() => (0, common_1.checkPackage)(),
|
||||
() => (0, common_1.checkWebDir)(config),
|
||||
...(0, update_1.updateChecks)(config, platforms),
|
||||
]);
|
||||
await (0, promise_1.allSerial)(platforms.map(platformName => () => sync(config, platformName, deployment, inline)));
|
||||
const now = +new Date();
|
||||
const diff = (now - then) / 1000;
|
||||
log_1.logger.info(`Sync finished in ${diff}s`);
|
||||
}
|
||||
catch (e) {
|
||||
if (!(0, errors_1.isFatal)(e)) {
|
||||
(0, errors_1.fatal)((_b = e.stack) !== null && _b !== void 0 ? _b : e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.syncCommand = syncCommand;
|
||||
async function sync(config, platformName, deployment, inline = false) {
|
||||
var _a;
|
||||
await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:sync:before');
|
||||
try {
|
||||
await (0, copy_1.copy)(config, platformName, inline);
|
||||
}
|
||||
catch (e) {
|
||||
log_1.logger.error((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
await (0, update_1.update)(config, platformName, deployment);
|
||||
await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:sync:after');
|
||||
}
|
||||
exports.sync = sync;
|
40
@capacitor/cli/dist/tasks/telemetry.js
vendored
Normal file
40
@capacitor/cli/dist/tasks/telemetry.js
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.telemetryCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const errors_1 = require("../errors");
|
||||
const log_1 = require("../log");
|
||||
const sysconfig_1 = require("../sysconfig");
|
||||
const telemetry_1 = require("../telemetry");
|
||||
async function telemetryCommand(onOrOff) {
|
||||
const sysconfig = await (0, sysconfig_1.readConfig)();
|
||||
const enabled = interpretEnabled(onOrOff);
|
||||
if (typeof enabled === 'boolean') {
|
||||
if (sysconfig.telemetry === enabled) {
|
||||
log_1.logger.info(`Telemetry is already ${colors_1.default.strong(enabled ? 'on' : 'off')}`);
|
||||
}
|
||||
else {
|
||||
await (0, sysconfig_1.writeConfig)({ ...sysconfig, telemetry: enabled });
|
||||
(0, log_1.logSuccess)(`You have ${colors_1.default.strong(`opted ${enabled ? 'in' : 'out'}`)} ${enabled ? 'for' : 'of'} telemetry on this machine.`);
|
||||
if (enabled) {
|
||||
log_1.output.write(telemetry_1.THANK_YOU);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log_1.logger.info(`Telemetry is ${colors_1.default.strong(sysconfig.telemetry ? 'on' : 'off')}`);
|
||||
}
|
||||
}
|
||||
exports.telemetryCommand = telemetryCommand;
|
||||
function interpretEnabled(onOrOff) {
|
||||
switch (onOrOff) {
|
||||
case 'on':
|
||||
return true;
|
||||
case 'off':
|
||||
return false;
|
||||
case undefined:
|
||||
return undefined;
|
||||
}
|
||||
(0, errors_1.fatal)(`Argument must be ${colors_1.default.strong('on')} or ${colors_1.default.strong('off')} (or left unspecified)`);
|
||||
}
|
74
@capacitor/cli/dist/tasks/update.js
vendored
Normal file
74
@capacitor/cli/dist/tasks/update.js
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.update = exports.updateChecks = exports.updateCommand = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const update_1 = require("../android/update");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_1 = require("../common");
|
||||
const errors_1 = require("../errors");
|
||||
const common_2 = require("../ios/common");
|
||||
const update_2 = require("../ios/update");
|
||||
const log_1 = require("../log");
|
||||
const promise_1 = require("../util/promise");
|
||||
async function updateCommand(config, selectedPlatformName, deployment) {
|
||||
var _a;
|
||||
if (selectedPlatformName && !(await (0, common_1.isValidPlatform)(selectedPlatformName))) {
|
||||
const platformDir = (0, common_1.resolvePlatform)(config, selectedPlatformName);
|
||||
if (platformDir) {
|
||||
await (0, common_1.runPlatformHook)(config, selectedPlatformName, platformDir, 'capacitor:update');
|
||||
}
|
||||
else {
|
||||
log_1.logger.error(`Platform ${colors_1.default.input(selectedPlatformName)} not found.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const then = +new Date();
|
||||
const platforms = await (0, common_1.selectPlatforms)(config, selectedPlatformName);
|
||||
try {
|
||||
await (0, common_1.check)([() => (0, common_1.checkPackage)(), ...updateChecks(config, platforms)]);
|
||||
await (0, promise_1.allSerial)(platforms.map(platformName => async () => await update(config, platformName, deployment)));
|
||||
const now = +new Date();
|
||||
const diff = (now - then) / 1000;
|
||||
log_1.logger.info(`Update finished in ${diff}s`);
|
||||
}
|
||||
catch (e) {
|
||||
if (!(0, errors_1.isFatal)(e)) {
|
||||
(0, errors_1.fatal)((_a = e.stack) !== null && _a !== void 0 ? _a : e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.updateCommand = updateCommand;
|
||||
function updateChecks(config, platforms) {
|
||||
const checks = [];
|
||||
for (const platformName of platforms) {
|
||||
if (platformName === config.ios.name) {
|
||||
checks.push(() => (0, common_2.checkBundler)(config) || (0, common_2.checkCocoaPods)(config));
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
continue;
|
||||
}
|
||||
else if (platformName === config.web.name) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
throw `Platform ${platformName} is not valid.`;
|
||||
}
|
||||
}
|
||||
return checks;
|
||||
}
|
||||
exports.updateChecks = updateChecks;
|
||||
async function update(config, platformName, deployment) {
|
||||
await (0, common_1.runTask)(colors_1.default.success(colors_1.default.strong(`update ${platformName}`)), async () => {
|
||||
await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:update:before');
|
||||
if (platformName === config.ios.name) {
|
||||
await (0, update_2.updateIOS)(config, deployment);
|
||||
}
|
||||
else if (platformName === config.android.name) {
|
||||
await (0, update_1.updateAndroid)(config);
|
||||
}
|
||||
await (0, common_1.runHooks)(config, platformName, config.app.rootDir, 'capacitor:update:after');
|
||||
});
|
||||
}
|
||||
exports.update = update;
|
Loading…
Add table
Add a link
Reference in a new issue