@capgo/cli 4.7.0 → 4.8.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/CHANGELOG.md +7 -0
- package/bun.lockb +0 -0
- package/dist/index.js +97 -51
- package/package.json +2 -2
- package/src/api/app.ts +3 -23
- package/src/app/add.ts +1 -1
- package/src/bundle/upload.ts +9 -8
- package/src/init.ts +35 -31
- package/src/login.ts +4 -0
- package/src/utils.ts +18 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [4.8.0](https://github.com/Cap-go/CLI/compare/v4.7.0...v4.8.0) (2024-05-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* auto select package manager and runner ([94f8bef](https://github.com/Cap-go/CLI/commit/94f8bef06efeafbd5cff1979f5ed75de2a523caa))
|
|
11
|
+
|
|
5
12
|
## [4.7.0](https://github.com/Cap-go/CLI/compare/v4.6.3...v4.7.0) (2024-05-10)
|
|
6
13
|
|
|
7
14
|
|
package/bun.lockb
CHANGED
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -92373,7 +92373,7 @@ var {
|
|
|
92373
92373
|
// package.json
|
|
92374
92374
|
var package_default = {
|
|
92375
92375
|
name: "@capgo/cli",
|
|
92376
|
-
version: "4.
|
|
92376
|
+
version: "4.8.0",
|
|
92377
92377
|
description: "A CLI to upload to capgo servers",
|
|
92378
92378
|
author: "github.com/riderx",
|
|
92379
92379
|
license: "Apache 2.0",
|
|
@@ -92418,7 +92418,7 @@ var package_default = {
|
|
|
92418
92418
|
dependencies: {
|
|
92419
92419
|
"@aws-sdk/client-s3": "^3.563.0",
|
|
92420
92420
|
"@capacitor/cli": "6.0.0",
|
|
92421
|
-
"@capgo/find-package-manager": "^0.0.
|
|
92421
|
+
"@capgo/find-package-manager": "^0.0.16",
|
|
92422
92422
|
"@clack/prompts": "^0.7.0",
|
|
92423
92423
|
"@supabase/supabase-js": "^2.42.7",
|
|
92424
92424
|
"@tomasklaen/checksum": "^1.1.0",
|
|
@@ -93558,20 +93558,41 @@ var findPackageManagerType = (path3 = ".", defaultPackageManager = "unknown") =>
|
|
|
93558
93558
|
}
|
|
93559
93559
|
return defaultPm;
|
|
93560
93560
|
};
|
|
93561
|
-
var findInstallCommand = (packageManagerType = findPackageManagerType()) => {
|
|
93561
|
+
var findInstallCommand = (packageManagerType = findPackageManagerType(), prefix = false) => {
|
|
93562
93562
|
switch (packageManagerType) {
|
|
93563
93563
|
case "bun":
|
|
93564
|
-
return "install";
|
|
93564
|
+
return prefix ? "bun install" : "install";
|
|
93565
93565
|
case "pnpm":
|
|
93566
|
-
return "install";
|
|
93566
|
+
return prefix ? "pnpm install" : "install";
|
|
93567
93567
|
case "yarn":
|
|
93568
|
-
return "
|
|
93568
|
+
return prefix ? "yarn install" : "install";
|
|
93569
93569
|
case "npm":
|
|
93570
|
-
return "install";
|
|
93570
|
+
return prefix ? "npm install" : "install";
|
|
93571
|
+
case "unknown":
|
|
93572
|
+
return prefix ? "unknown unknown" : "unknown";
|
|
93571
93573
|
default:
|
|
93572
|
-
return "install";
|
|
93574
|
+
return prefix ? "npm install" : "install";
|
|
93573
93575
|
}
|
|
93574
93576
|
};
|
|
93577
|
+
var findPackageManagerRunner = (path3 = ".", defaultPackageManagerRunner = "npx") => {
|
|
93578
|
+
const bunPath = `${path3}/bun.lockb`;
|
|
93579
|
+
const pnpmPath = `${path3}/pnpm-lock.yaml`;
|
|
93580
|
+
const yarnPath = `${path3}/yarn.lock`;
|
|
93581
|
+
const npmPath = `${path3}/package-lock.json`;
|
|
93582
|
+
if ((0, import_fs.existsSync)(bunPath)) {
|
|
93583
|
+
return "bunx";
|
|
93584
|
+
}
|
|
93585
|
+
if ((0, import_fs.existsSync)(pnpmPath)) {
|
|
93586
|
+
return "pnpm exec";
|
|
93587
|
+
}
|
|
93588
|
+
if ((0, import_fs.existsSync)(yarnPath)) {
|
|
93589
|
+
return "yarn dlx";
|
|
93590
|
+
}
|
|
93591
|
+
if ((0, import_fs.existsSync)(npmPath)) {
|
|
93592
|
+
return "npx";
|
|
93593
|
+
}
|
|
93594
|
+
return defaultPackageManagerRunner;
|
|
93595
|
+
};
|
|
93575
93596
|
|
|
93576
93597
|
// src/utils.ts
|
|
93577
93598
|
var baseKey = ".capgo_key";
|
|
@@ -93592,7 +93613,7 @@ async function getConfig() {
|
|
|
93592
93613
|
try {
|
|
93593
93614
|
config = await (0, import_config.loadConfig)();
|
|
93594
93615
|
} catch (err) {
|
|
93595
|
-
f2.error(
|
|
93616
|
+
f2.error(`No capacitor config file found, run \`cap init\` first ${formatError(err)}`);
|
|
93596
93617
|
program.error("");
|
|
93597
93618
|
}
|
|
93598
93619
|
return config;
|
|
@@ -93793,7 +93814,7 @@ function findSavedKey(quiet = false) {
|
|
|
93793
93814
|
key2 = (0, import_node_fs4.readFileSync)(keyPath, "utf8").trim();
|
|
93794
93815
|
}
|
|
93795
93816
|
if (!key2) {
|
|
93796
|
-
f2.error(`Cannot find API key in local folder or global, please login first with
|
|
93817
|
+
f2.error(`Cannot find API key in local folder or global, please login first with ${getPMAndCommand().runner} @capacitor/cli login`);
|
|
93797
93818
|
program.error("");
|
|
93798
93819
|
}
|
|
93799
93820
|
return key2;
|
|
@@ -93986,6 +94007,19 @@ function getHumanDate(createdA) {
|
|
|
93986
94007
|
const date = new Date(createdA || "");
|
|
93987
94008
|
return date.toLocaleString();
|
|
93988
94009
|
}
|
|
94010
|
+
var pmFetched = false;
|
|
94011
|
+
var pm = "npm";
|
|
94012
|
+
var pmCommand = "install";
|
|
94013
|
+
var pmRunner = "npx";
|
|
94014
|
+
function getPMAndCommand() {
|
|
94015
|
+
if (pmFetched)
|
|
94016
|
+
return { pm, command: pmCommand, installCommand: `${pm} ${pmCommand}`, runner: pmRunner };
|
|
94017
|
+
pm = findPackageManagerType(".", "npm");
|
|
94018
|
+
pmCommand = findInstallCommand(pm);
|
|
94019
|
+
pmFetched = true;
|
|
94020
|
+
pmRunner = findPackageManagerRunner();
|
|
94021
|
+
return { pm, command: pmCommand, installCommand: `${pm} ${pmCommand}`, runner: pmRunner };
|
|
94022
|
+
}
|
|
93989
94023
|
async function getLocalDepenencies() {
|
|
93990
94024
|
if (!(0, import_node_fs4.existsSync)("./package.json")) {
|
|
93991
94025
|
f2.error("Missing package.json, you need to be in a capacitor project");
|
|
@@ -94011,9 +94045,9 @@ async function getLocalDepenencies() {
|
|
|
94011
94045
|
}
|
|
94012
94046
|
}
|
|
94013
94047
|
if (!(0, import_node_fs4.existsSync)("./node_modules/")) {
|
|
94014
|
-
const
|
|
94015
|
-
const installCmd = findInstallCommand(
|
|
94016
|
-
f2.error(`Missing node_modules folder, please run ${
|
|
94048
|
+
const pm2 = findPackageManagerType(".", "npm");
|
|
94049
|
+
const installCmd = findInstallCommand(pm2);
|
|
94050
|
+
f2.error(`Missing node_modules folder, please run ${pm2} ${installCmd}`);
|
|
94017
94051
|
program.error("");
|
|
94018
94052
|
}
|
|
94019
94053
|
let anyInvalid = false;
|
|
@@ -94021,9 +94055,9 @@ async function getLocalDepenencies() {
|
|
|
94021
94055
|
const dependencyFolderExists = (0, import_node_fs4.existsSync)(`./node_modules/${key2}`);
|
|
94022
94056
|
if (!dependencyFolderExists) {
|
|
94023
94057
|
anyInvalid = true;
|
|
94024
|
-
const
|
|
94025
|
-
const installCmd = findInstallCommand(
|
|
94026
|
-
f2.error(`Missing dependency ${key2}, please run ${
|
|
94058
|
+
const pm2 = findPackageManagerType(".", "npm");
|
|
94059
|
+
const installCmd = findInstallCommand(pm2);
|
|
94060
|
+
f2.error(`Missing dependency ${key2}, please run ${pm2} ${installCmd}`);
|
|
94027
94061
|
return { name: key2, version: value };
|
|
94028
94062
|
}
|
|
94029
94063
|
let hasNativeFiles = false;
|
|
@@ -94266,6 +94300,7 @@ async function checkAppExists(supabase, appid) {
|
|
|
94266
94300
|
return !!app2;
|
|
94267
94301
|
}
|
|
94268
94302
|
async function checkAppExistsAndHasPermissionOrgErr(supabase, apikey, appid, requiredPermission) {
|
|
94303
|
+
const pm2 = getPMAndCommand();
|
|
94269
94304
|
const permissions = await isAllowedAppOrg(supabase, apikey, appid);
|
|
94270
94305
|
if (!permissions.okay) {
|
|
94271
94306
|
switch (permissions.error) {
|
|
@@ -94275,7 +94310,7 @@ async function checkAppExistsAndHasPermissionOrgErr(supabase, apikey, appid, req
|
|
|
94275
94310
|
break;
|
|
94276
94311
|
}
|
|
94277
94312
|
case "NO_APP": {
|
|
94278
|
-
f2.error(`App ${appid} does not exist`);
|
|
94313
|
+
f2.error(`App ${appid} does not exist, run first \`${pm2.runner} @capgo/cli app add ${appid}\` to create it`);
|
|
94279
94314
|
program.error("");
|
|
94280
94315
|
break;
|
|
94281
94316
|
}
|
|
@@ -94778,6 +94813,7 @@ var import_client_s3 = __toESM(require_dist_cjs71());
|
|
|
94778
94813
|
var alertMb2 = 20;
|
|
94779
94814
|
var UPLOAD_TIMEOUT = 12e4;
|
|
94780
94815
|
async function uploadBundle(appid, options, shouldExit = true) {
|
|
94816
|
+
const pm2 = getPMAndCommand();
|
|
94781
94817
|
oe(`Uploading`);
|
|
94782
94818
|
await checkLatest();
|
|
94783
94819
|
let { bundle: bundle2, path: path3, channel: channel2 } = options;
|
|
@@ -94801,7 +94837,7 @@ async function uploadBundle(appid, options, shouldExit = true) {
|
|
|
94801
94837
|
const snag = useLogSnag();
|
|
94802
94838
|
channel2 = channel2 || "dev";
|
|
94803
94839
|
const config = await getConfig();
|
|
94804
|
-
const localS3 = (config
|
|
94840
|
+
const localS3 = (config?.app?.extConfig?.plugins && config?.app?.extConfig?.plugins?.CapacitorUpdater && config?.app?.extConfig?.plugins?.CapacitorUpdater?.localS3) === true;
|
|
94805
94841
|
const checkNotifyAppReady = options.codeCheck;
|
|
94806
94842
|
appid = appid || config?.app?.appId;
|
|
94807
94843
|
const uuid = (0, import_node_crypto3.randomUUID)().split("-")[0];
|
|
@@ -94815,8 +94851,8 @@ async function uploadBundle(appid, options, shouldExit = true) {
|
|
|
94815
94851
|
f2.error(`Missing API key, you need to provide a API key to upload your bundle`);
|
|
94816
94852
|
program.error("");
|
|
94817
94853
|
}
|
|
94818
|
-
if (!appid || !
|
|
94819
|
-
f2.error("Missing argument, you need to provide a appid and a
|
|
94854
|
+
if (!appid || !path3) {
|
|
94855
|
+
f2.error("Missing argument, you need to provide a appid and a path (--path), or be in a capacitor project");
|
|
94820
94856
|
program.error("");
|
|
94821
94857
|
}
|
|
94822
94858
|
if (s3BucketName || s3Region || s3Apikey || s3Apisecret) {
|
|
@@ -94863,7 +94899,7 @@ async function uploadBundle(appid, options, shouldExit = true) {
|
|
|
94863
94899
|
localDependencies = localDependenciesWithChannel;
|
|
94864
94900
|
if (finalCompatibility.find((x3) => x3.localVersion !== x3.remoteVersion)) {
|
|
94865
94901
|
f2.error(`Your bundle is not compatible with the channel ${channel2}`);
|
|
94866
|
-
f2.warn(`You can check compatibility with "
|
|
94902
|
+
f2.warn(`You can check compatibility with "${pm2.runner} @capgo/cli bundle compatibility"`);
|
|
94867
94903
|
if (autoMinUpdateVersion) {
|
|
94868
94904
|
minUpdateVersion = bundle2;
|
|
94869
94905
|
f2.info(`Auto set min-update-version to ${minUpdateVersion}`);
|
|
@@ -95143,7 +95179,8 @@ async function uploadCommand(apikey, options) {
|
|
|
95143
95179
|
}
|
|
95144
95180
|
}
|
|
95145
95181
|
async function uploadDeprecatedCommand(apikey, options) {
|
|
95146
|
-
|
|
95182
|
+
const pm2 = getPMAndCommand();
|
|
95183
|
+
f2.warn(`\u26A0\uFE0F This command is deprecated, use "${pm2.runner} @capgo/cli bundle upload" instead \u26A0\uFE0F`);
|
|
95147
95184
|
try {
|
|
95148
95185
|
await uploadBundle(apikey, options, true);
|
|
95149
95186
|
} catch (error) {
|
|
@@ -95156,6 +95193,10 @@ async function uploadDeprecatedCommand(apikey, options) {
|
|
|
95156
95193
|
var import_node_fs9 = require("node:fs");
|
|
95157
95194
|
var import_node_os3 = require("node:os");
|
|
95158
95195
|
var import_node_process14 = __toESM(require("node:process"));
|
|
95196
|
+
async function doLoginExists() {
|
|
95197
|
+
const userHomeDir = (0, import_node_os3.homedir)();
|
|
95198
|
+
return (0, import_node_fs9.existsSync)(`${userHomeDir}/.capgo`) || (0, import_node_fs9.existsSync)(".capgo");
|
|
95199
|
+
}
|
|
95159
95200
|
async function login(apikey, options, shouldExit = true) {
|
|
95160
95201
|
if (shouldExit)
|
|
95161
95202
|
oe(`Login to Capgo`);
|
|
@@ -95343,7 +95384,7 @@ async function addApp(appId, options, throwErr = true) {
|
|
|
95343
95384
|
f2.error(`App ${appId} already exist`);
|
|
95344
95385
|
program.error("");
|
|
95345
95386
|
} else if (appExist) {
|
|
95346
|
-
return
|
|
95387
|
+
return false;
|
|
95347
95388
|
}
|
|
95348
95389
|
const { error: orgError, data: allOrganizations } = await supabase.rpc("get_orgs_v5");
|
|
95349
95390
|
if (orgError) {
|
|
@@ -95467,27 +95508,29 @@ async function markStep(userId, snag, step) {
|
|
|
95467
95508
|
return markSnag("onboarding-v2", userId, snag, `onboarding-step-${step}`);
|
|
95468
95509
|
}
|
|
95469
95510
|
async function step2(userId, snag, appId, options) {
|
|
95511
|
+
const pm2 = getPMAndCommand();
|
|
95470
95512
|
const doAdd = await se({ message: `Add ${appId} in Capgo?` });
|
|
95471
95513
|
await cancelCommand2(doAdd, userId, snag);
|
|
95472
95514
|
if (doAdd) {
|
|
95473
95515
|
const s = de();
|
|
95474
|
-
s.start(`Running:
|
|
95516
|
+
s.start(`Running: ${pm2.runner} @capgo/cli@latest app add ${appId}`);
|
|
95475
95517
|
const addRes = await addApp(appId, options, false);
|
|
95476
95518
|
if (!addRes)
|
|
95477
95519
|
s.stop(`App already add \u2705`);
|
|
95478
95520
|
else
|
|
95479
95521
|
s.stop(`App add Done \u2705`);
|
|
95480
95522
|
} else {
|
|
95481
|
-
f2.info(`Run yourself "
|
|
95523
|
+
f2.info(`Run yourself "${pm2.runner} @capgo/cli@latest app add ${appId}"`);
|
|
95482
95524
|
}
|
|
95483
95525
|
await markStep(userId, snag, 2);
|
|
95484
95526
|
}
|
|
95485
95527
|
async function step3(userId, snag, apikey, appId) {
|
|
95528
|
+
const pm2 = getPMAndCommand();
|
|
95486
95529
|
const doChannel = await se({ message: `Create default channel ${defaultChannel} for ${appId} in Capgo?` });
|
|
95487
95530
|
await cancelCommand2(doChannel, userId, snag);
|
|
95488
95531
|
if (doChannel) {
|
|
95489
95532
|
const s = de();
|
|
95490
|
-
s.start(`Running:
|
|
95533
|
+
s.start(`Running: ${pm2.runner} @capgo/cli@latest channel add ${defaultChannel} ${appId} --default`);
|
|
95491
95534
|
const addChannelRes = await addChannel(defaultChannel, appId, {
|
|
95492
95535
|
default: true,
|
|
95493
95536
|
apikey
|
|
@@ -95497,13 +95540,14 @@ async function step3(userId, snag, apikey, appId) {
|
|
|
95497
95540
|
else
|
|
95498
95541
|
s.stop(`Channel add Done \u2705`);
|
|
95499
95542
|
} else {
|
|
95500
|
-
f2.info(`Run yourself "
|
|
95543
|
+
f2.info(`Run yourself "${pm2.runner} @capgo/cli@latest channel add ${defaultChannel} ${appId} --default"`);
|
|
95501
95544
|
}
|
|
95502
95545
|
await markStep(userId, snag, 3);
|
|
95503
95546
|
}
|
|
95504
95547
|
var urlMigrateV6 = "https://capacitorjs.com/docs/updating/6-0";
|
|
95505
95548
|
var urlMigrateV5 = "https://capacitorjs.com/docs/updating/5-0";
|
|
95506
95549
|
async function step4(userId, snag, apikey, appId) {
|
|
95550
|
+
const pm2 = getPMAndCommand();
|
|
95507
95551
|
const doInstall = await se({ message: `Automatic Install "@capgo/capacitor-updater" dependency in ${appId}?` });
|
|
95508
95552
|
await cancelCommand2(doInstall, userId, snag);
|
|
95509
95553
|
if (doInstall) {
|
|
@@ -95527,22 +95571,20 @@ async function step4(userId, snag, apikey, appId) {
|
|
|
95527
95571
|
s.stop(`@capacitor/core version is ${coreVersion}, please update to Capacitor v6: ${urlMigrateV6} to access the best features of Capgo`);
|
|
95528
95572
|
versionToInstall = "^5.0.0";
|
|
95529
95573
|
}
|
|
95530
|
-
|
|
95531
|
-
if (pm === "unknown") {
|
|
95574
|
+
if (pm2.pm === "unknown") {
|
|
95532
95575
|
s.stop("Error");
|
|
95533
|
-
f2.warn(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm or yarn`);
|
|
95576
|
+
f2.warn(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm, bun or yarn`);
|
|
95534
95577
|
$e(`Bye \u{1F44B}`);
|
|
95535
95578
|
import_node_process16.default.exit();
|
|
95536
95579
|
}
|
|
95537
|
-
const installCmd = findInstallCommand(pm);
|
|
95538
95580
|
if (pack.dependencies["@capgo/capacitor-updater"]) {
|
|
95539
95581
|
s.stop(`Capgo already installed \u2705`);
|
|
95540
95582
|
} else {
|
|
95541
|
-
await (0, import_node_child_process6.execSync)(`${
|
|
95583
|
+
await (0, import_node_child_process6.execSync)(`${pm2.installCommand} @capgo/capacitor-updater@${versionToInstall}`, execOption);
|
|
95542
95584
|
s.stop(`Install Done \u2705`);
|
|
95543
95585
|
}
|
|
95544
95586
|
} else {
|
|
95545
|
-
f2.info(`Run yourself "
|
|
95587
|
+
f2.info(`Run yourself "${pm2.installCommand} @capgo/capacitor-updater@latest"`);
|
|
95546
95588
|
}
|
|
95547
95589
|
await markStep(userId, snag, 4);
|
|
95548
95590
|
}
|
|
@@ -95596,11 +95638,12 @@ ${codeInject};
|
|
|
95596
95638
|
}
|
|
95597
95639
|
}
|
|
95598
95640
|
async function step6(userId, snag, apikey, appId) {
|
|
95641
|
+
const pm2 = getPMAndCommand();
|
|
95599
95642
|
const doEncrypt = await se({ message: `Automatic configure end-to-end encryption in ${appId} updates?` });
|
|
95600
95643
|
await cancelCommand2(doEncrypt, userId, snag);
|
|
95601
95644
|
if (doEncrypt) {
|
|
95602
95645
|
const s = de();
|
|
95603
|
-
s.start(`Running:
|
|
95646
|
+
s.start(`Running: ${pm2.runner} @capgo/cli@latest key create`);
|
|
95604
95647
|
const keyRes = await createKey({ force: true }, false);
|
|
95605
95648
|
if (!keyRes) {
|
|
95606
95649
|
s.stop("Error");
|
|
@@ -95615,13 +95658,14 @@ async function step6(userId, snag, apikey, appId) {
|
|
|
95615
95658
|
await markStep(userId, snag, 6);
|
|
95616
95659
|
}
|
|
95617
95660
|
async function step7(userId, snag, apikey, appId) {
|
|
95618
|
-
const
|
|
95661
|
+
const pm2 = getPMAndCommand();
|
|
95662
|
+
const doBuild = await se({ message: `Automatic build ${appId} with "${pm2.pm} run build" ?` });
|
|
95619
95663
|
await cancelCommand2(doBuild, userId, snag);
|
|
95620
95664
|
if (doBuild) {
|
|
95621
95665
|
const s = de();
|
|
95622
95666
|
const projectType = await findProjectType();
|
|
95623
95667
|
const buildCommand = await findBuildCommandForProjectType(projectType);
|
|
95624
|
-
s.start(`Running:
|
|
95668
|
+
s.start(`Running: ${pm2.pm} run ${buildCommand} && ${pm2.runner} cap sync`);
|
|
95625
95669
|
const pack = JSON.parse((0, import_node_fs11.readFileSync)("package.json").toString());
|
|
95626
95670
|
if (!pack.scripts[buildCommand]) {
|
|
95627
95671
|
s.stop("Error");
|
|
@@ -95629,19 +95673,20 @@ async function step7(userId, snag, apikey, appId) {
|
|
|
95629
95673
|
$e(`Bye \u{1F44B}`);
|
|
95630
95674
|
import_node_process16.default.exit();
|
|
95631
95675
|
}
|
|
95632
|
-
(0, import_node_child_process6.execSync)(
|
|
95676
|
+
(0, import_node_child_process6.execSync)(`${pm2.pm} run ${buildCommand} && ${pm2.runner} cap sync`, execOption);
|
|
95633
95677
|
s.stop(`Build & Sync Done \u2705`);
|
|
95634
95678
|
} else {
|
|
95635
|
-
f2.info(`Build yourself with command:
|
|
95679
|
+
f2.info(`Build yourself with command: ${pm2.pm} run build && ${pm2.runner} cap sync`);
|
|
95636
95680
|
}
|
|
95637
95681
|
await markStep(userId, snag, 7);
|
|
95638
95682
|
}
|
|
95639
95683
|
async function step8(userId, snag, apikey, appId) {
|
|
95684
|
+
const pm2 = getPMAndCommand();
|
|
95640
95685
|
const doBundle = await se({ message: `Automatic upload ${appId} bundle to Capgo?` });
|
|
95641
95686
|
await cancelCommand2(doBundle, userId, snag);
|
|
95642
95687
|
if (doBundle) {
|
|
95643
95688
|
const s = de();
|
|
95644
|
-
s.start(`Running:
|
|
95689
|
+
s.start(`Running: ${pm2.runner} @capgo/cli@latest bundle upload`);
|
|
95645
95690
|
const uploadRes = await uploadBundle(appId, {
|
|
95646
95691
|
channel: defaultChannel,
|
|
95647
95692
|
apikey
|
|
@@ -95655,11 +95700,12 @@ async function step8(userId, snag, apikey, appId) {
|
|
|
95655
95700
|
s.stop(`Upload Done \u2705`);
|
|
95656
95701
|
}
|
|
95657
95702
|
} else {
|
|
95658
|
-
f2.info(`Upload yourself with command:
|
|
95703
|
+
f2.info(`Upload yourself with command: ${pm2.runner} @capgo/cli@latest bundle upload`);
|
|
95659
95704
|
}
|
|
95660
95705
|
await markStep(userId, snag, 8);
|
|
95661
95706
|
}
|
|
95662
95707
|
async function step9(userId, snag) {
|
|
95708
|
+
const pm2 = getPMAndCommand();
|
|
95663
95709
|
const doRun = await se({ message: `Run in device now ?` });
|
|
95664
95710
|
await cancelCommand2(doRun, userId, snag);
|
|
95665
95711
|
if (doRun) {
|
|
@@ -95676,11 +95722,11 @@ async function step9(userId, snag) {
|
|
|
95676
95722
|
}
|
|
95677
95723
|
const platform2 = plaformType;
|
|
95678
95724
|
const s = de();
|
|
95679
|
-
s.start(`Running:
|
|
95680
|
-
await (0, import_node_child_process6.spawnSync)(
|
|
95725
|
+
s.start(`Running: ${pm2.runner} cap run ${platform2}`);
|
|
95726
|
+
await (0, import_node_child_process6.spawnSync)(pm2.runner, ["cap", "run", platform2], { stdio: "inherit" });
|
|
95681
95727
|
s.stop(`Started Done \u2705`);
|
|
95682
95728
|
} else {
|
|
95683
|
-
f2.info(`Run yourself with command:
|
|
95729
|
+
f2.info(`Run yourself with command: ${pm2.runner} cap run <ios|android>`);
|
|
95684
95730
|
}
|
|
95685
95731
|
await markStep(userId, snag, 9);
|
|
95686
95732
|
}
|
|
@@ -95697,20 +95743,20 @@ async function step10(userId, snag, supabase, appId) {
|
|
|
95697
95743
|
}
|
|
95698
95744
|
await markStep(userId, snag, 10);
|
|
95699
95745
|
}
|
|
95700
|
-
async function initApp(
|
|
95746
|
+
async function initApp(apikeyCommand, appId, options) {
|
|
95747
|
+
const pm2 = getPMAndCommand();
|
|
95701
95748
|
oe(`Capgo onboarding \u{1F6EB}`);
|
|
95702
95749
|
await checkLatest();
|
|
95703
95750
|
const snag = useLogSnag();
|
|
95704
95751
|
const config = await getConfig();
|
|
95705
95752
|
appId = appId || config?.app?.appId;
|
|
95706
|
-
apikey =
|
|
95753
|
+
const apikey = apikeyCommand || findSavedKey();
|
|
95707
95754
|
const log = de();
|
|
95708
|
-
|
|
95709
|
-
|
|
95710
|
-
|
|
95711
|
-
log.stop("Login already done \u2705");
|
|
95712
|
-
else
|
|
95755
|
+
if (!doLoginExists() || apikeyCommand) {
|
|
95756
|
+
log.start(`Running: ${pm2.runner} @capgo/cli@latest login ***`);
|
|
95757
|
+
await login(apikey, options, false);
|
|
95713
95758
|
log.stop("Login Done \u2705");
|
|
95759
|
+
}
|
|
95714
95760
|
const supabase = await createSupabaseClient(apikey);
|
|
95715
95761
|
const userId = await verifyUser(supabase, apikey, ["upload", "all", "read", "write"]);
|
|
95716
95762
|
await markStep(userId, snag, 1);
|
|
@@ -95726,7 +95772,7 @@ async function initApp(apikey, appId, options) {
|
|
|
95726
95772
|
await markStep(userId, snag, 0);
|
|
95727
95773
|
f2.info(`Welcome onboard \u2708\uFE0F!`);
|
|
95728
95774
|
f2.info(`Your Capgo update system is setup`);
|
|
95729
|
-
f2.info(`Next time use
|
|
95775
|
+
f2.info(`Next time use \`${pm2.runner} @capgo/cli@latest bundle upload\` to only upload your bundle`);
|
|
95730
95776
|
$e(`Bye \u{1F44B}`);
|
|
95731
95777
|
import_node_process16.default.exit();
|
|
95732
95778
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "A CLI to upload to capgo servers",
|
|
5
5
|
"author": "github.com/riderx",
|
|
6
6
|
"license": "Apache 2.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@aws-sdk/client-s3": "^3.563.0",
|
|
47
47
|
"@capacitor/cli": "6.0.0",
|
|
48
|
-
"@capgo/find-package-manager": "^0.0.
|
|
48
|
+
"@capgo/find-package-manager": "^0.0.16",
|
|
49
49
|
"@clack/prompts": "^0.7.0",
|
|
50
50
|
"@supabase/supabase-js": "^2.42.7",
|
|
51
51
|
"@tomasklaen/checksum": "^1.1.0",
|
package/src/api/app.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as p from '@clack/prompts'
|
|
|
3
3
|
import { program } from 'commander'
|
|
4
4
|
import type { Database } from '../types/supabase.types'
|
|
5
5
|
import type { OptionsBase } from '../utils'
|
|
6
|
-
import { OrganizationPerm,
|
|
6
|
+
import { OrganizationPerm, getPMAndCommand, isAllowedAppOrg } from '../utils'
|
|
7
7
|
|
|
8
8
|
export async function checkAppExists(supabase: SupabaseClient<Database>, appid: string) {
|
|
9
9
|
const { data: app } = await supabase
|
|
@@ -12,28 +12,8 @@ export async function checkAppExists(supabase: SupabaseClient<Database>, appid:
|
|
|
12
12
|
return !!app
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export async function checkAppExistsAndHasPermissionErr(supabase: SupabaseClient<Database>, apikey: string, appid: string, shouldExist = true) {
|
|
16
|
-
const appExist = await checkAppExists(supabase, appid)
|
|
17
|
-
const perm = await isAllowedApp(supabase, apikey, appid)
|
|
18
|
-
|
|
19
|
-
if (appExist && !shouldExist) {
|
|
20
|
-
p.log.error(`App ${appid} already exist`)
|
|
21
|
-
program.error('')
|
|
22
|
-
}
|
|
23
|
-
if (!appExist && shouldExist) {
|
|
24
|
-
p.log.error(`App ${appid} does not exist`)
|
|
25
|
-
program.error('')
|
|
26
|
-
}
|
|
27
|
-
if (appExist && !perm) {
|
|
28
|
-
p.log.error(`App ${appid} exist and you don't have permission to access it`)
|
|
29
|
-
if (appid === 'io.ionic.starter')
|
|
30
|
-
p.log.info('Modify your appid in your capacitor.config.json file to something unique, this is a default appid for ionic starter app')
|
|
31
|
-
|
|
32
|
-
program.error('')
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
15
|
export async function checkAppExistsAndHasPermissionOrgErr(supabase: SupabaseClient<Database>, apikey: string, appid: string, requiredPermission: OrganizationPerm) {
|
|
16
|
+
const pm = getPMAndCommand()
|
|
37
17
|
const permissions = await isAllowedAppOrg(supabase, apikey, appid)
|
|
38
18
|
if (!permissions.okay) {
|
|
39
19
|
switch (permissions.error) {
|
|
@@ -43,7 +23,7 @@ export async function checkAppExistsAndHasPermissionOrgErr(supabase: SupabaseCli
|
|
|
43
23
|
break
|
|
44
24
|
}
|
|
45
25
|
case 'NO_APP': {
|
|
46
|
-
p.log.error(`App ${appid} does not exist`)
|
|
26
|
+
p.log.error(`App ${appid} does not exist, run first \`${pm.runner} @capgo/cli app add ${appid}\` to create it`)
|
|
47
27
|
program.error('')
|
|
48
28
|
break
|
|
49
29
|
}
|
package/src/app/add.ts
CHANGED
package/src/bundle/upload.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
getLocalConfig,
|
|
34
34
|
getLocalDepenencies,
|
|
35
35
|
getOrganizationId,
|
|
36
|
+
getPMAndCommand,
|
|
36
37
|
hasOrganizationPerm,
|
|
37
38
|
regexSemver,
|
|
38
39
|
requireUpdateMetadata,
|
|
@@ -70,6 +71,7 @@ interface Options extends OptionsBase {
|
|
|
70
71
|
const UPLOAD_TIMEOUT = 120000
|
|
71
72
|
|
|
72
73
|
export async function uploadBundle(appid: string, options: Options, shouldExit = true) {
|
|
74
|
+
const pm = getPMAndCommand()
|
|
73
75
|
p.intro(`Uploading`)
|
|
74
76
|
await checkLatest()
|
|
75
77
|
let { bundle, path, channel } = options
|
|
@@ -96,8 +98,8 @@ export async function uploadBundle(appid: string, options: Options, shouldExit =
|
|
|
96
98
|
channel = channel || 'dev'
|
|
97
99
|
|
|
98
100
|
const config = await getConfig()
|
|
99
|
-
const localS3: boolean = (config
|
|
100
|
-
&& config
|
|
101
|
+
const localS3: boolean = (config?.app?.extConfig?.plugins && config?.app?.extConfig?.plugins?.CapacitorUpdater
|
|
102
|
+
&& config?.app?.extConfig?.plugins?.CapacitorUpdater?.localS3) === true
|
|
101
103
|
|
|
102
104
|
const checkNotifyAppReady = options.codeCheck
|
|
103
105
|
appid = appid || config?.app?.appId
|
|
@@ -114,8 +116,8 @@ export async function uploadBundle(appid: string, options: Options, shouldExit =
|
|
|
114
116
|
p.log.error(`Missing API key, you need to provide a API key to upload your bundle`)
|
|
115
117
|
program.error('')
|
|
116
118
|
}
|
|
117
|
-
if (!appid || !
|
|
118
|
-
p.log.error('Missing argument, you need to provide a appid and a
|
|
119
|
+
if (!appid || !path) {
|
|
120
|
+
p.log.error('Missing argument, you need to provide a appid and a path (--path), or be in a capacitor project')
|
|
119
121
|
program.error('')
|
|
120
122
|
}
|
|
121
123
|
// if one S3 variable is set, check that all are set
|
|
@@ -150,8 +152,6 @@ export async function uploadBundle(appid: string, options: Options, shouldExit =
|
|
|
150
152
|
const supabase = await createSupabaseClient(options.apikey)
|
|
151
153
|
const userId = await verifyUser(supabase, options.apikey, ['write', 'all', 'upload'])
|
|
152
154
|
// Check we have app access to this appId
|
|
153
|
-
// await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appid);
|
|
154
|
-
|
|
155
155
|
const permissions = await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appid, OrganizationPerm.upload)
|
|
156
156
|
|
|
157
157
|
// Now if it does exist we will fetch the org id
|
|
@@ -186,7 +186,7 @@ export async function uploadBundle(appid: string, options: Options, shouldExit =
|
|
|
186
186
|
|
|
187
187
|
if (finalCompatibility.find(x => x.localVersion !== x.remoteVersion)) {
|
|
188
188
|
p.log.error(`Your bundle is not compatible with the channel ${channel}`)
|
|
189
|
-
p.log.warn(`You can check compatibility with "
|
|
189
|
+
p.log.warn(`You can check compatibility with "${pm.runner} @capgo/cli bundle compatibility"`)
|
|
190
190
|
|
|
191
191
|
if (autoMinUpdateVersion) {
|
|
192
192
|
minUpdateVersion = bundle
|
|
@@ -511,7 +511,8 @@ export async function uploadCommand(apikey: string, options: Options) {
|
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
export async function uploadDeprecatedCommand(apikey: string, options: Options) {
|
|
514
|
-
|
|
514
|
+
const pm = getPMAndCommand()
|
|
515
|
+
p.log.warn(`⚠️ This command is deprecated, use "${pm.runner} @capgo/cli bundle upload" instead ⚠️`)
|
|
515
516
|
try {
|
|
516
517
|
await uploadBundle(apikey, options, true)
|
|
517
518
|
}
|
package/src/init.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { readFileSync, writeFileSync } from 'node:fs'
|
|
|
2
2
|
import type { ExecSyncOptions } from 'node:child_process'
|
|
3
3
|
import { execSync, spawnSync } from 'node:child_process'
|
|
4
4
|
import process from 'node:process'
|
|
5
|
-
import { findInstallCommand, findPackageManagerType } from '@capgo/find-package-manager'
|
|
6
5
|
import * as p from '@clack/prompts'
|
|
7
6
|
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
8
7
|
import type LogSnag from 'logsnag'
|
|
@@ -12,11 +11,11 @@ import { markSnag, waitLog } from './app/debug'
|
|
|
12
11
|
import { createKey } from './key'
|
|
13
12
|
import { addChannel } from './channel/add'
|
|
14
13
|
import { uploadBundle } from './bundle/upload'
|
|
15
|
-
import { login } from './login'
|
|
14
|
+
import { doLoginExists, login } from './login'
|
|
16
15
|
import { addApp } from './app/add'
|
|
17
16
|
import { checkLatest } from './api/update'
|
|
18
17
|
import type { Options } from './api/app'
|
|
19
|
-
import { convertAppName, createSupabaseClient, findBuildCommandForProjectType, findMainFile, findMainFileForProjectType, findProjectType, findSavedKey, getConfig, useLogSnag, verifyUser } from './utils'
|
|
18
|
+
import { convertAppName, createSupabaseClient, findBuildCommandForProjectType, findMainFile, findMainFileForProjectType, findProjectType, findSavedKey, getConfig, getPMAndCommand, useLogSnag, verifyUser } from './utils'
|
|
20
19
|
|
|
21
20
|
interface SuperOptions extends Options {
|
|
22
21
|
local: boolean
|
|
@@ -40,11 +39,12 @@ async function markStep(userId: string, snag: LogSnag, step: number | string) {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
async function step2(userId: string, snag: LogSnag, appId: string, options: SuperOptions) {
|
|
42
|
+
const pm = getPMAndCommand()
|
|
43
43
|
const doAdd = await p.confirm({ message: `Add ${appId} in Capgo?` })
|
|
44
44
|
await cancelCommand(doAdd, userId, snag)
|
|
45
45
|
if (doAdd) {
|
|
46
46
|
const s = p.spinner()
|
|
47
|
-
s.start(`Running:
|
|
47
|
+
s.start(`Running: ${pm.runner} @capgo/cli@latest app add ${appId}`)
|
|
48
48
|
const addRes = await addApp(appId, options, false)
|
|
49
49
|
if (!addRes)
|
|
50
50
|
s.stop(`App already add ✅`)
|
|
@@ -52,18 +52,19 @@ async function step2(userId: string, snag: LogSnag, appId: string, options: Supe
|
|
|
52
52
|
s.stop(`App add Done ✅`)
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
|
-
p.log.info(`Run yourself "
|
|
55
|
+
p.log.info(`Run yourself "${pm.runner} @capgo/cli@latest app add ${appId}"`)
|
|
56
56
|
}
|
|
57
57
|
await markStep(userId, snag, 2)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
async function step3(userId: string, snag: LogSnag, apikey: string, appId: string) {
|
|
61
|
+
const pm = getPMAndCommand()
|
|
61
62
|
const doChannel = await p.confirm({ message: `Create default channel ${defaultChannel} for ${appId} in Capgo?` })
|
|
62
63
|
await cancelCommand(doChannel, userId, snag)
|
|
63
64
|
if (doChannel) {
|
|
64
65
|
const s = p.spinner()
|
|
65
66
|
// create production channel public
|
|
66
|
-
s.start(`Running:
|
|
67
|
+
s.start(`Running: ${pm.runner} @capgo/cli@latest channel add ${defaultChannel} ${appId} --default`)
|
|
67
68
|
const addChannelRes = await addChannel(defaultChannel, appId, {
|
|
68
69
|
default: true,
|
|
69
70
|
apikey,
|
|
@@ -74,7 +75,7 @@ async function step3(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
74
75
|
s.stop(`Channel add Done ✅`)
|
|
75
76
|
}
|
|
76
77
|
else {
|
|
77
|
-
p.log.info(`Run yourself "
|
|
78
|
+
p.log.info(`Run yourself "${pm.runner} @capgo/cli@latest channel add ${defaultChannel} ${appId} --default"`)
|
|
78
79
|
}
|
|
79
80
|
await markStep(userId, snag, 3)
|
|
80
81
|
}
|
|
@@ -82,6 +83,7 @@ async function step3(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
82
83
|
const urlMigrateV6 = 'https://capacitorjs.com/docs/updating/6-0'
|
|
83
84
|
const urlMigrateV5 = 'https://capacitorjs.com/docs/updating/5-0'
|
|
84
85
|
async function step4(userId: string, snag: LogSnag, apikey: string, appId: string) {
|
|
86
|
+
const pm = getPMAndCommand()
|
|
85
87
|
const doInstall = await p.confirm({ message: `Automatic Install "@capgo/capacitor-updater" dependency in ${appId}?` })
|
|
86
88
|
await cancelCommand(doInstall, userId, snag)
|
|
87
89
|
if (doInstall) {
|
|
@@ -107,27 +109,25 @@ async function step4(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
107
109
|
s.stop(`@capacitor/core version is ${coreVersion}, please update to Capacitor v6: ${urlMigrateV6} to access the best features of Capgo`)
|
|
108
110
|
versionToInstall = '^5.0.0'
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
if (pm === 'unknown') {
|
|
112
|
+
if (pm.pm === 'unknown') {
|
|
112
113
|
s.stop('Error')
|
|
113
|
-
p.log.warn(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm or yarn`)
|
|
114
|
+
p.log.warn(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm, bun or yarn`)
|
|
114
115
|
p.outro(`Bye 👋`)
|
|
115
116
|
process.exit()
|
|
116
117
|
}
|
|
117
118
|
// // use pm to install capgo
|
|
118
119
|
// // run command pm install @capgo/capacitor-updater@latest
|
|
119
|
-
const installCmd = findInstallCommand(pm)
|
|
120
120
|
// check if capgo is already installed in package.json
|
|
121
121
|
if (pack.dependencies['@capgo/capacitor-updater']) {
|
|
122
122
|
s.stop(`Capgo already installed ✅`)
|
|
123
123
|
}
|
|
124
124
|
else {
|
|
125
|
-
await execSync(`${pm}
|
|
125
|
+
await execSync(`${pm.installCommand} @capgo/capacitor-updater@${versionToInstall}`, execOption as ExecSyncOptions)
|
|
126
126
|
s.stop(`Install Done ✅`)
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
|
-
p.log.info(`Run yourself "
|
|
130
|
+
p.log.info(`Run yourself "${pm.installCommand} @capgo/capacitor-updater@latest"`)
|
|
131
131
|
}
|
|
132
132
|
await markStep(userId, snag, 4)
|
|
133
133
|
}
|
|
@@ -180,11 +180,12 @@ async function step5(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
async function step6(userId: string, snag: LogSnag, apikey: string, appId: string) {
|
|
183
|
+
const pm = getPMAndCommand()
|
|
183
184
|
const doEncrypt = await p.confirm({ message: `Automatic configure end-to-end encryption in ${appId} updates?` })
|
|
184
185
|
await cancelCommand(doEncrypt, userId, snag)
|
|
185
186
|
if (doEncrypt) {
|
|
186
187
|
const s = p.spinner()
|
|
187
|
-
s.start(`Running:
|
|
188
|
+
s.start(`Running: ${pm.runner} @capgo/cli@latest key create`)
|
|
188
189
|
const keyRes = await createKey({ force: true }, false)
|
|
189
190
|
if (!keyRes) {
|
|
190
191
|
s.stop('Error')
|
|
@@ -201,13 +202,14 @@ async function step6(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
async function step7(userId: string, snag: LogSnag, apikey: string, appId: string) {
|
|
204
|
-
const
|
|
205
|
+
const pm = getPMAndCommand()
|
|
206
|
+
const doBuild = await p.confirm({ message: `Automatic build ${appId} with "${pm.pm} run build" ?` })
|
|
205
207
|
await cancelCommand(doBuild, userId, snag)
|
|
206
208
|
if (doBuild) {
|
|
207
209
|
const s = p.spinner()
|
|
208
210
|
const projectType = await findProjectType()
|
|
209
211
|
const buildCommand = await findBuildCommandForProjectType(projectType)
|
|
210
|
-
s.start(`Running:
|
|
212
|
+
s.start(`Running: ${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`)
|
|
211
213
|
const pack = JSON.parse(readFileSync('package.json').toString())
|
|
212
214
|
// check in script build exist
|
|
213
215
|
if (!pack.scripts[buildCommand]) {
|
|
@@ -216,21 +218,22 @@ async function step7(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
216
218
|
p.outro(`Bye 👋`)
|
|
217
219
|
process.exit()
|
|
218
220
|
}
|
|
219
|
-
execSync(
|
|
221
|
+
execSync(`${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`, execOption as ExecSyncOptions)
|
|
220
222
|
s.stop(`Build & Sync Done ✅`)
|
|
221
223
|
}
|
|
222
224
|
else {
|
|
223
|
-
p.log.info(`Build yourself with command:
|
|
225
|
+
p.log.info(`Build yourself with command: ${pm.pm} run build && ${pm.runner} cap sync`)
|
|
224
226
|
}
|
|
225
227
|
await markStep(userId, snag, 7)
|
|
226
228
|
}
|
|
227
229
|
|
|
228
230
|
async function step8(userId: string, snag: LogSnag, apikey: string, appId: string) {
|
|
231
|
+
const pm = getPMAndCommand()
|
|
229
232
|
const doBundle = await p.confirm({ message: `Automatic upload ${appId} bundle to Capgo?` })
|
|
230
233
|
await cancelCommand(doBundle, userId, snag)
|
|
231
234
|
if (doBundle) {
|
|
232
235
|
const s = p.spinner()
|
|
233
|
-
s.start(`Running:
|
|
236
|
+
s.start(`Running: ${pm.runner} @capgo/cli@latest bundle upload`)
|
|
234
237
|
const uploadRes = await uploadBundle(appId, {
|
|
235
238
|
channel: defaultChannel,
|
|
236
239
|
apikey,
|
|
@@ -246,12 +249,13 @@ async function step8(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
246
249
|
}
|
|
247
250
|
}
|
|
248
251
|
else {
|
|
249
|
-
p.log.info(`Upload yourself with command:
|
|
252
|
+
p.log.info(`Upload yourself with command: ${pm.runner} @capgo/cli@latest bundle upload`)
|
|
250
253
|
}
|
|
251
254
|
await markStep(userId, snag, 8)
|
|
252
255
|
}
|
|
253
256
|
|
|
254
257
|
async function step9(userId: string, snag: LogSnag) {
|
|
258
|
+
const pm = getPMAndCommand()
|
|
255
259
|
const doRun = await p.confirm({ message: `Run in device now ?` })
|
|
256
260
|
await cancelCommand(doRun, userId, snag)
|
|
257
261
|
if (doRun) {
|
|
@@ -269,12 +273,12 @@ async function step9(userId: string, snag: LogSnag) {
|
|
|
269
273
|
|
|
270
274
|
const platform = plaformType as 'ios' | 'android'
|
|
271
275
|
const s = p.spinner()
|
|
272
|
-
s.start(`Running:
|
|
273
|
-
await spawnSync(
|
|
276
|
+
s.start(`Running: ${pm.runner} cap run ${platform}`)
|
|
277
|
+
await spawnSync(pm.runner, ['cap', 'run', platform], { stdio: 'inherit' })
|
|
274
278
|
s.stop(`Started Done ✅`)
|
|
275
279
|
}
|
|
276
280
|
else {
|
|
277
|
-
p.log.info(`Run yourself with command:
|
|
281
|
+
p.log.info(`Run yourself with command: ${pm.runner} cap run <ios|android>`)
|
|
278
282
|
}
|
|
279
283
|
await markStep(userId, snag, 9)
|
|
280
284
|
}
|
|
@@ -294,21 +298,21 @@ async function step10(userId: string, snag: LogSnag, supabase: SupabaseClient<Da
|
|
|
294
298
|
await markStep(userId, snag, 10)
|
|
295
299
|
}
|
|
296
300
|
|
|
297
|
-
export async function initApp(
|
|
301
|
+
export async function initApp(apikeyCommand: string, appId: string, options: SuperOptions) {
|
|
302
|
+
const pm = getPMAndCommand()
|
|
298
303
|
p.intro(`Capgo onboarding 🛫`)
|
|
299
304
|
await checkLatest()
|
|
300
305
|
const snag = useLogSnag()
|
|
301
306
|
const config = await getConfig()
|
|
302
307
|
appId = appId || config?.app?.appId
|
|
303
|
-
apikey =
|
|
308
|
+
const apikey = apikeyCommand || findSavedKey()
|
|
304
309
|
|
|
305
310
|
const log = p.spinner()
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
log.stop('Login already done ✅')
|
|
310
|
-
else
|
|
311
|
+
if (!doLoginExists() || apikeyCommand) {
|
|
312
|
+
log.start(`Running: ${pm.runner} @capgo/cli@latest login ***`)
|
|
313
|
+
await login(apikey, options, false)
|
|
311
314
|
log.stop('Login Done ✅')
|
|
315
|
+
}
|
|
312
316
|
|
|
313
317
|
const supabase = await createSupabaseClient(apikey)
|
|
314
318
|
const userId = await verifyUser(supabase, apikey, ['upload', 'all', 'read', 'write'])
|
|
@@ -327,7 +331,7 @@ export async function initApp(apikey: string, appId: string, options: SuperOptio
|
|
|
327
331
|
await markStep(userId, snag, 0)
|
|
328
332
|
p.log.info(`Welcome onboard ✈️!`)
|
|
329
333
|
p.log.info(`Your Capgo update system is setup`)
|
|
330
|
-
p.log.info(`Next time use
|
|
334
|
+
p.log.info(`Next time use \`${pm.runner} @capgo/cli@latest bundle upload\` to only upload your bundle`)
|
|
331
335
|
p.outro(`Bye 👋`)
|
|
332
336
|
process.exit()
|
|
333
337
|
}
|
package/src/login.ts
CHANGED
|
@@ -9,6 +9,10 @@ import { checkLatest } from './api/update'
|
|
|
9
9
|
interface Options {
|
|
10
10
|
local: boolean
|
|
11
11
|
}
|
|
12
|
+
export async function doLoginExists() {
|
|
13
|
+
const userHomeDir = homedir()
|
|
14
|
+
return existsSync(`${userHomeDir}/.capgo`) || existsSync('.capgo')
|
|
15
|
+
}
|
|
12
16
|
|
|
13
17
|
export async function login(apikey: string, options: Options, shouldExit = true) {
|
|
14
18
|
if (shouldExit)
|
package/src/utils.ts
CHANGED
|
@@ -11,7 +11,8 @@ import { LogSnag } from 'logsnag'
|
|
|
11
11
|
import * as p from '@clack/prompts'
|
|
12
12
|
import ky from 'ky'
|
|
13
13
|
import { promiseFiles } from 'node-dir'
|
|
14
|
-
import {
|
|
14
|
+
import type { InstallCommand, PackageManagerRunner, PackageManagerType } from '@capgo/find-package-manager'
|
|
15
|
+
import { findInstallCommand, findPackageManagerRunner, findPackageManagerType } from '@capgo/find-package-manager'
|
|
15
16
|
import type { Database } from './types/supabase.types'
|
|
16
17
|
|
|
17
18
|
export const baseKey = '.capgo_key'
|
|
@@ -39,7 +40,7 @@ export async function getConfig() {
|
|
|
39
40
|
config = await loadConfig()
|
|
40
41
|
}
|
|
41
42
|
catch (err) {
|
|
42
|
-
p.log.error(
|
|
43
|
+
p.log.error(`No capacitor config file found, run \`cap init\` first ${formatError(err)}`)
|
|
43
44
|
program.error('')
|
|
44
45
|
}
|
|
45
46
|
return config
|
|
@@ -306,7 +307,7 @@ export function findSavedKey(quiet = false) {
|
|
|
306
307
|
key = readFileSync(keyPath, 'utf8').trim()
|
|
307
308
|
}
|
|
308
309
|
if (!key) {
|
|
309
|
-
p.log.error(`Cannot find API key in local folder or global, please login first with
|
|
310
|
+
p.log.error(`Cannot find API key in local folder or global, please login first with ${getPMAndCommand().runner} @capacitor/cli login`)
|
|
310
311
|
program.error('')
|
|
311
312
|
}
|
|
312
313
|
return key
|
|
@@ -625,6 +626,20 @@ export function getHumanDate(createdA: string | null) {
|
|
|
625
626
|
return date.toLocaleString()
|
|
626
627
|
}
|
|
627
628
|
|
|
629
|
+
let pmFetched = false
|
|
630
|
+
let pm: PackageManagerType = 'npm'
|
|
631
|
+
let pmCommand: InstallCommand = 'install'
|
|
632
|
+
let pmRunner: PackageManagerRunner = 'npx'
|
|
633
|
+
export function getPMAndCommand() {
|
|
634
|
+
if (pmFetched)
|
|
635
|
+
return { pm, command: pmCommand, installCommand: `${pm} ${pmCommand}`, runner: pmRunner }
|
|
636
|
+
pm = findPackageManagerType('.', 'npm')
|
|
637
|
+
pmCommand = findInstallCommand(pm)
|
|
638
|
+
pmFetched = true
|
|
639
|
+
pmRunner = findPackageManagerRunner()
|
|
640
|
+
return { pm, command: pmCommand, installCommand: `${pm} ${pmCommand}`, runner: pmRunner }
|
|
641
|
+
}
|
|
642
|
+
|
|
628
643
|
export async function getLocalDepenencies() {
|
|
629
644
|
if (!existsSync('./package.json')) {
|
|
630
645
|
p.log.error('Missing package.json, you need to be in a capacitor project')
|