@capgo/cli 4.6.1 → 4.6.3
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 +14 -0
- package/dist/index.js +108 -16
- package/package.json +1 -1
- package/src/bundle/upload.ts +3 -1
- package/src/index.ts +1 -0
- package/src/init.ts +40 -14
- package/src/utils.ts +85 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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.6.3](https://github.com/Cap-go/CLI/compare/v4.6.2...v4.6.3) (2024-05-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* add timeout option ([e8c8890](https://github.com/Cap-go/CLI/commit/e8c8890204bc327443a58b303c5fe8ae132dab2d))
|
|
11
|
+
|
|
12
|
+
### [4.6.2](https://github.com/Cap-go/CLI/compare/v4.6.1...v4.6.2) (2024-05-08)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* better handle nuxt and nextjs ([7f9c0a0](https://github.com/Cap-go/CLI/commit/7f9c0a04ac5097b5ea7b9b9edb0dc815e43ca2e7))
|
|
18
|
+
|
|
5
19
|
### [4.6.1](https://github.com/Cap-go/CLI/compare/v4.6.0...v4.6.1) (2024-05-08)
|
|
6
20
|
|
|
7
21
|
|
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.6.
|
|
92376
|
+
version: "4.6.3",
|
|
92377
92377
|
description: "A CLI to upload to capgo servers",
|
|
92378
92378
|
author: "github.com/riderx",
|
|
92379
92379
|
license: "Apache 2.0",
|
|
@@ -93770,6 +93770,72 @@ async function* getFiles(dir) {
|
|
|
93770
93770
|
yield res;
|
|
93771
93771
|
}
|
|
93772
93772
|
}
|
|
93773
|
+
async function findProjectType() {
|
|
93774
|
+
const pwd = import_node_process8.default.cwd();
|
|
93775
|
+
for await (const f3 of getFiles(pwd)) {
|
|
93776
|
+
if (f3.includes("angular.json")) {
|
|
93777
|
+
f2.info("Found angular project");
|
|
93778
|
+
return "angular";
|
|
93779
|
+
}
|
|
93780
|
+
if (f3.includes("nuxt.config.js")) {
|
|
93781
|
+
f2.info("Found nuxtjs project");
|
|
93782
|
+
return "nuxtjs";
|
|
93783
|
+
}
|
|
93784
|
+
if (f3.includes("next.config.js")) {
|
|
93785
|
+
f2.info("Found nextjs project");
|
|
93786
|
+
return "nextjs";
|
|
93787
|
+
}
|
|
93788
|
+
if (f3.includes("svelte.config.js")) {
|
|
93789
|
+
f2.info("Found sveltekit project");
|
|
93790
|
+
return "sveltekit";
|
|
93791
|
+
}
|
|
93792
|
+
}
|
|
93793
|
+
return "unknown";
|
|
93794
|
+
}
|
|
93795
|
+
async function findMainFileForProjectType(projectType) {
|
|
93796
|
+
if (projectType === "angular")
|
|
93797
|
+
return "src/main.ts";
|
|
93798
|
+
if (projectType === "nuxtjs")
|
|
93799
|
+
return "src/main.ts";
|
|
93800
|
+
if (projectType === "nextjs")
|
|
93801
|
+
return "pages/_app.tsx";
|
|
93802
|
+
if (projectType === "sveltekit")
|
|
93803
|
+
return "src/main.ts";
|
|
93804
|
+
return null;
|
|
93805
|
+
}
|
|
93806
|
+
async function findBuildCommandForProjectType(projectType) {
|
|
93807
|
+
if (projectType === "angular") {
|
|
93808
|
+
f2.info("Angular project detected");
|
|
93809
|
+
return "build";
|
|
93810
|
+
}
|
|
93811
|
+
if (projectType === "nuxtjs") {
|
|
93812
|
+
f2.info("Nuxtjs project detected");
|
|
93813
|
+
return "generate";
|
|
93814
|
+
}
|
|
93815
|
+
if (projectType === "nextjs") {
|
|
93816
|
+
f2.info("Nextjs project detected");
|
|
93817
|
+
f2.warn("Please make sure you have configured static export in your next.config.js: https://nextjs.org/docs/pages/building-your-application/deploying/static-exports");
|
|
93818
|
+
f2.warn("Please make sure you have the output: 'export' and distDir: 'dist' in your next.config.js");
|
|
93819
|
+
const doContinue = await se({ message: "Do you want to continue?" });
|
|
93820
|
+
if (!doContinue) {
|
|
93821
|
+
f2.error("Aborted");
|
|
93822
|
+
program.error("");
|
|
93823
|
+
}
|
|
93824
|
+
return "build";
|
|
93825
|
+
}
|
|
93826
|
+
if (projectType === "sveltekit") {
|
|
93827
|
+
f2.info("Sveltekit project detected");
|
|
93828
|
+
f2.warn("Please make sure you have the adapter-static installed: https://kit.svelte.dev/docs/adapter-static");
|
|
93829
|
+
f2.warn("Please make sure you have the pages: 'dist' and assets: 'dest', in your svelte.config.js adaptater");
|
|
93830
|
+
const doContinue = await se({ message: "Do you want to continue?" });
|
|
93831
|
+
if (!doContinue) {
|
|
93832
|
+
f2.error("Aborted");
|
|
93833
|
+
program.error("");
|
|
93834
|
+
}
|
|
93835
|
+
return "build";
|
|
93836
|
+
}
|
|
93837
|
+
return "build";
|
|
93838
|
+
}
|
|
93773
93839
|
async function findMainFile() {
|
|
93774
93840
|
const mainRegex = /(main|index)\.(ts|tsx|js|jsx)$/;
|
|
93775
93841
|
let mainFile = "";
|
|
@@ -94951,7 +95017,7 @@ The app size is ${mbSize} Mb, this may take a while to download for users
|
|
|
94951
95017
|
}
|
|
94952
95018
|
try {
|
|
94953
95019
|
await distribution_default.put(url, {
|
|
94954
|
-
timeout:
|
|
95020
|
+
timeout: options.timeout || 12e4,
|
|
94955
95021
|
retry: 5,
|
|
94956
95022
|
body: zipped,
|
|
94957
95023
|
headers: !localS3 ? {
|
|
@@ -94961,6 +95027,7 @@ The app size is ${mbSize} Mb, this may take a while to download for users
|
|
|
94961
95027
|
} : void 0
|
|
94962
95028
|
});
|
|
94963
95029
|
} catch (errorUpload) {
|
|
95030
|
+
spinner.stop("Failed to upload bundle");
|
|
94964
95031
|
f2.error(`Cannot upload bundle ${formatError(errorUpload)}`);
|
|
94965
95032
|
await deletedFailedVersion(supabase, appid, bundle2);
|
|
94966
95033
|
program.error("");
|
|
@@ -95419,10 +95486,14 @@ async function step4(userId, snag, apikey, appId) {
|
|
|
95419
95486
|
let coreVersion = pack.dependencies["@capacitor/core"] || pack.devDependencies["@capacitor/core"];
|
|
95420
95487
|
coreVersion = coreVersion?.replace("^", "").replace("~", "");
|
|
95421
95488
|
if (!coreVersion) {
|
|
95422
|
-
s.stop(
|
|
95489
|
+
s.stop("Error");
|
|
95490
|
+
f2.warn(`Cannot find @capacitor/core in package.json, please run \`capgo init\` in a capacitor project`);
|
|
95491
|
+
$e(`Bye \u{1F44B}`);
|
|
95423
95492
|
import_node_process16.default.exit();
|
|
95424
95493
|
} else if (import_semver.default.lt(coreVersion, "5.0.0")) {
|
|
95425
|
-
s.stop(
|
|
95494
|
+
s.stop("Error");
|
|
95495
|
+
f2.warn(`@capacitor/core version is ${coreVersion}, please update to Capacitor v5 first: ${urlMigrateV5}`);
|
|
95496
|
+
$e(`Bye \u{1F44B}`);
|
|
95426
95497
|
import_node_process16.default.exit();
|
|
95427
95498
|
} else if (import_semver.default.lt(coreVersion, "6.0.0")) {
|
|
95428
95499
|
s.stop(`@capacitor/core version is ${coreVersion}, please update to Capacitor v6: ${urlMigrateV6} to access the best features of Capgo`);
|
|
@@ -95430,7 +95501,9 @@ async function step4(userId, snag, apikey, appId) {
|
|
|
95430
95501
|
}
|
|
95431
95502
|
const pm = findPackageManagerType();
|
|
95432
95503
|
if (pm === "unknown") {
|
|
95433
|
-
s.stop(
|
|
95504
|
+
s.stop("Error");
|
|
95505
|
+
f2.warn(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm or yarn`);
|
|
95506
|
+
$e(`Bye \u{1F44B}`);
|
|
95434
95507
|
import_node_process16.default.exit();
|
|
95435
95508
|
}
|
|
95436
95509
|
const installCmd = pm === "yarn" ? "add" : "install";
|
|
@@ -95451,9 +95524,16 @@ async function step5(userId, snag, apikey, appId) {
|
|
|
95451
95524
|
if (doAddCode) {
|
|
95452
95525
|
const s = de();
|
|
95453
95526
|
s.start(`Adding @capacitor-updater to your main file`);
|
|
95454
|
-
const
|
|
95527
|
+
const projectType = await findProjectType();
|
|
95528
|
+
let mainFilePath;
|
|
95529
|
+
if (projectType === "unknown")
|
|
95530
|
+
mainFilePath = await findMainFile();
|
|
95531
|
+
else
|
|
95532
|
+
mainFilePath = await findMainFileForProjectType(projectType);
|
|
95455
95533
|
if (!mainFilePath) {
|
|
95456
|
-
s.stop("
|
|
95534
|
+
s.stop("Error");
|
|
95535
|
+
f2.warn("Cannot find main file, You need to add @capgo/capacitor-updater manually");
|
|
95536
|
+
$e(`Bye \u{1F44B}`);
|
|
95457
95537
|
import_node_process16.default.exit();
|
|
95458
95538
|
}
|
|
95459
95539
|
const mainFile = (0, import_node_fs11.readFileSync)(mainFilePath);
|
|
@@ -95461,7 +95541,9 @@ async function step5(userId, snag, apikey, appId) {
|
|
|
95461
95541
|
const matches = mainFileContent.match(regexImport);
|
|
95462
95542
|
const last = matches?.pop();
|
|
95463
95543
|
if (!last) {
|
|
95464
|
-
s.stop(
|
|
95544
|
+
s.stop("Error");
|
|
95545
|
+
f2.warn(`Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/`);
|
|
95546
|
+
$e(`Bye \u{1F44B}`);
|
|
95465
95547
|
import_node_process16.default.exit();
|
|
95466
95548
|
}
|
|
95467
95549
|
if (mainFileContent.includes(codeInject)) {
|
|
@@ -95493,7 +95575,9 @@ async function step6(userId, snag, apikey, appId) {
|
|
|
95493
95575
|
s.start(`Running: npx @capgo/cli@latest key create`);
|
|
95494
95576
|
const keyRes = await createKey({ force: true }, false);
|
|
95495
95577
|
if (!keyRes) {
|
|
95496
|
-
s.stop(
|
|
95578
|
+
s.stop("Error");
|
|
95579
|
+
f2.warn(`Cannot create key \u274C`);
|
|
95580
|
+
$e(`Bye \u{1F44B}`);
|
|
95497
95581
|
import_node_process16.default.exit(1);
|
|
95498
95582
|
} else {
|
|
95499
95583
|
s.stop(`key created \u{1F511}`);
|
|
@@ -95507,13 +95591,17 @@ async function step7(userId, snag, apikey, appId) {
|
|
|
95507
95591
|
await cancelCommand2(doBuild, userId, snag);
|
|
95508
95592
|
if (doBuild) {
|
|
95509
95593
|
const s = de();
|
|
95510
|
-
|
|
95594
|
+
const projectType = await findProjectType();
|
|
95595
|
+
const buildCommand = await findBuildCommandForProjectType(projectType);
|
|
95596
|
+
s.start(`Running: npm run ${buildCommand} && npx cap sync`);
|
|
95511
95597
|
const pack = JSON.parse((0, import_node_fs11.readFileSync)("package.json").toString());
|
|
95512
|
-
if (!pack.scripts
|
|
95513
|
-
s.stop(
|
|
95598
|
+
if (!pack.scripts[buildCommand]) {
|
|
95599
|
+
s.stop("Error");
|
|
95600
|
+
f2.warn(`Cannot find ${buildCommand} script in package.json, please add it and run \`capgo init\` again`);
|
|
95601
|
+
$e(`Bye \u{1F44B}`);
|
|
95514
95602
|
import_node_process16.default.exit();
|
|
95515
95603
|
}
|
|
95516
|
-
(0, import_node_child_process6.execSync)(`npm run
|
|
95604
|
+
(0, import_node_child_process6.execSync)(`npm run ${buildCommand} && npx cap sync`, execOption);
|
|
95517
95605
|
s.stop(`Build & Sync Done \u2705`);
|
|
95518
95606
|
} else {
|
|
95519
95607
|
f2.info(`Build yourself with command: npm run build && npx cap sync`);
|
|
@@ -95531,7 +95619,9 @@ async function step8(userId, snag, apikey, appId) {
|
|
|
95531
95619
|
apikey
|
|
95532
95620
|
}, false);
|
|
95533
95621
|
if (!uploadRes) {
|
|
95534
|
-
s.stop(
|
|
95622
|
+
s.stop("Error");
|
|
95623
|
+
f2.warn(`Upload failed \u274C`);
|
|
95624
|
+
$e(`Bye \u{1F44B}`);
|
|
95535
95625
|
import_node_process16.default.exit();
|
|
95536
95626
|
} else {
|
|
95537
95627
|
s.stop(`Upload Done \u2705`);
|
|
@@ -95552,8 +95642,10 @@ async function step9(userId, snag) {
|
|
|
95552
95642
|
{ value: "android", label: "Android" }
|
|
95553
95643
|
]
|
|
95554
95644
|
});
|
|
95555
|
-
if (eD(plaformType))
|
|
95645
|
+
if (eD(plaformType)) {
|
|
95646
|
+
$e(`Bye \u{1F44B}`);
|
|
95556
95647
|
import_node_process16.default.exit();
|
|
95648
|
+
}
|
|
95557
95649
|
const platform2 = plaformType;
|
|
95558
95650
|
const s = de();
|
|
95559
95651
|
s.start(`Running: npx cap run ${platform2}`);
|
|
@@ -96475,7 +96567,7 @@ var bundle = program.command("bundle").description("Manage bundle");
|
|
|
96475
96567
|
bundle.command("upload [appId]").alias("u").description("Upload a new bundle in Capgo Cloud").action(uploadCommand).option("-a, --apikey <apikey>", "apikey to link to your account").option("-p, --path <path>", "path of the folder to upload").option("-c, --channel <channel>", "channel to link to").option("-e, --external <url>", "link to external url intead of upload to Capgo Cloud").option("--iv-session-key <key>", "Set the iv and session key for bundle url external").option("--s3-region <region>", "Region for your AWS S3 bucket").option("--s3-apikey <apikey>", "apikey for your AWS S3 account").option("--s3-apisecret <apisecret>", "api secret for your AWS S3 account").option("--s3-bucket-name <bucketName>", "Name for your AWS S3 bucket").option("--key <key>", "custom path for public signing key").option("--key-data <keyData>", "base64 public signing key").option("--bundle-url", "prints bundle url into stdout").option("--no-key", "ignore signing key and send clear update").option("--no-code-check", "Ignore checking if notifyAppReady() is called in soure code and index present in root folder").option("--display-iv-session", "Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>", "bundle version number of the bundle to upload").option(
|
|
96476
96568
|
"--min-update-version <minUpdateVersion>",
|
|
96477
96569
|
"Minimal version required to update to this version. Used only if the disable auto update is set to metadata in channel"
|
|
96478
|
-
).option("--auto-min-update-version", "Set the min update version based on native packages").option("--ignore-metadata-check", "Ignores the metadata (node_modules) check when uploading");
|
|
96570
|
+
).option("--auto-min-update-version", "Set the min update version based on native packages").option("--ignore-metadata-check", "Ignores the metadata (node_modules) check when uploading").option("--timeout <timeout>", "Timeout for the upload process in seconds");
|
|
96479
96571
|
bundle.command("compatibility [appId]").action(checkCompatibilityCommand).option("-a, --apikey <apikey>", "apikey to link to your account").option("-c, --channel <channel>", "channel to check the compatibility with").option("--text", "output text instead of emojis");
|
|
96480
96572
|
bundle.command("delete [bundleId] [appId]").alias("d").description("Delete a bundle in Capgo Cloud").action(deleteBundle).option("-a, --apikey <apikey>", "apikey to link to your account");
|
|
96481
96573
|
bundle.command("list [appId]").alias("l").description("List bundle in Capgo Cloud").action(listBundle).option("-a, --apikey <apikey>", "apikey to link to your account");
|
package/package.json
CHANGED
package/src/bundle/upload.ts
CHANGED
|
@@ -63,6 +63,7 @@ interface Options extends OptionsBase {
|
|
|
63
63
|
minUpdateVersion?: string
|
|
64
64
|
autoMinUpdateVersion?: boolean
|
|
65
65
|
ignoreMetadataCheck?: boolean
|
|
66
|
+
timeout?: number
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
export async function uploadBundle(appid: string, options: Options, shouldExit = true) {
|
|
@@ -385,7 +386,7 @@ It will be also visible in your dashboard\n`)
|
|
|
385
386
|
}
|
|
386
387
|
try {
|
|
387
388
|
await ky.put(url, {
|
|
388
|
-
timeout:
|
|
389
|
+
timeout: options.timeout || 120000,
|
|
389
390
|
retry: 5,
|
|
390
391
|
body: zipped,
|
|
391
392
|
headers: (!localS3
|
|
@@ -398,6 +399,7 @@ It will be also visible in your dashboard\n`)
|
|
|
398
399
|
})
|
|
399
400
|
}
|
|
400
401
|
catch (errorUpload) {
|
|
402
|
+
spinner.stop('Failed to upload bundle')
|
|
401
403
|
p.log.error(`Cannot upload bundle ${formatError(errorUpload)}`)
|
|
402
404
|
// call delete version on path /delete_failed_version to delete the version
|
|
403
405
|
await deletedFailedVersion(supabase, appid, bundle)
|
package/src/index.ts
CHANGED
|
@@ -130,6 +130,7 @@ bundle
|
|
|
130
130
|
)
|
|
131
131
|
.option('--auto-min-update-version', 'Set the min update version based on native packages')
|
|
132
132
|
.option('--ignore-metadata-check', 'Ignores the metadata (node_modules) check when uploading')
|
|
133
|
+
.option('--timeout <timeout>', 'Timeout for the upload process in seconds')
|
|
133
134
|
|
|
134
135
|
bundle
|
|
135
136
|
.command('compatibility [appId]')
|
package/src/init.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { login } from './login'
|
|
|
16
16
|
import { addApp } from './app/add'
|
|
17
17
|
import { checkLatest } from './api/update'
|
|
18
18
|
import type { Options } from './api/app'
|
|
19
|
-
import { convertAppName, createSupabaseClient, findMainFile, findSavedKey, getConfig, useLogSnag, verifyUser } from './utils'
|
|
19
|
+
import { convertAppName, createSupabaseClient, findBuildCommandForProjectType, findMainFile, findMainFileForProjectType, findProjectType, findSavedKey, getConfig, useLogSnag, verifyUser } from './utils'
|
|
20
20
|
|
|
21
21
|
interface SuperOptions extends Options {
|
|
22
22
|
local: boolean
|
|
@@ -92,11 +92,15 @@ async function step4(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
92
92
|
let coreVersion = pack.dependencies['@capacitor/core'] || pack.devDependencies['@capacitor/core']
|
|
93
93
|
coreVersion = coreVersion?.replace('^', '').replace('~', '')
|
|
94
94
|
if (!coreVersion) {
|
|
95
|
-
s.stop(
|
|
95
|
+
s.stop('Error')
|
|
96
|
+
p.log.warn(`Cannot find @capacitor/core in package.json, please run \`capgo init\` in a capacitor project`)
|
|
97
|
+
p.outro(`Bye 👋`)
|
|
96
98
|
process.exit()
|
|
97
99
|
}
|
|
98
100
|
else if (semver.lt(coreVersion, '5.0.0')) {
|
|
99
|
-
s.stop(
|
|
101
|
+
s.stop('Error')
|
|
102
|
+
p.log.warn(`@capacitor/core version is ${coreVersion}, please update to Capacitor v5 first: ${urlMigrateV5}`)
|
|
103
|
+
p.outro(`Bye 👋`)
|
|
100
104
|
process.exit()
|
|
101
105
|
}
|
|
102
106
|
else if (semver.lt(coreVersion, '6.0.0')) {
|
|
@@ -105,7 +109,9 @@ async function step4(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
105
109
|
}
|
|
106
110
|
const pm = findPackageManagerType()
|
|
107
111
|
if (pm === 'unknown') {
|
|
108
|
-
s.stop(
|
|
112
|
+
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.outro(`Bye 👋`)
|
|
109
115
|
process.exit()
|
|
110
116
|
}
|
|
111
117
|
// // use pm to install capgo
|
|
@@ -132,9 +138,17 @@ async function step5(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
132
138
|
if (doAddCode) {
|
|
133
139
|
const s = p.spinner()
|
|
134
140
|
s.start(`Adding @capacitor-updater to your main file`)
|
|
135
|
-
const
|
|
141
|
+
const projectType = await findProjectType()
|
|
142
|
+
let mainFilePath
|
|
143
|
+
if (projectType === 'unknown')
|
|
144
|
+
mainFilePath = await findMainFile()
|
|
145
|
+
else
|
|
146
|
+
mainFilePath = await findMainFileForProjectType(projectType)
|
|
147
|
+
|
|
136
148
|
if (!mainFilePath) {
|
|
137
|
-
s.stop('
|
|
149
|
+
s.stop('Error')
|
|
150
|
+
p.log.warn('Cannot find main file, You need to add @capgo/capacitor-updater manually')
|
|
151
|
+
p.outro(`Bye 👋`)
|
|
138
152
|
process.exit()
|
|
139
153
|
}
|
|
140
154
|
// open main file and inject codeInject
|
|
@@ -144,7 +158,9 @@ async function step5(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
144
158
|
const matches = mainFileContent.match(regexImport)
|
|
145
159
|
const last = matches?.pop()
|
|
146
160
|
if (!last) {
|
|
147
|
-
s.stop(
|
|
161
|
+
s.stop('Error')
|
|
162
|
+
p.log.warn(`Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/`)
|
|
163
|
+
p.outro(`Bye 👋`)
|
|
148
164
|
process.exit()
|
|
149
165
|
}
|
|
150
166
|
|
|
@@ -171,7 +187,9 @@ async function step6(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
171
187
|
s.start(`Running: npx @capgo/cli@latest key create`)
|
|
172
188
|
const keyRes = await createKey({ force: true }, false)
|
|
173
189
|
if (!keyRes) {
|
|
174
|
-
s.stop(
|
|
190
|
+
s.stop('Error')
|
|
191
|
+
p.log.warn(`Cannot create key ❌`)
|
|
192
|
+
p.outro(`Bye 👋`)
|
|
175
193
|
process.exit(1)
|
|
176
194
|
}
|
|
177
195
|
else {
|
|
@@ -187,14 +205,18 @@ async function step7(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
187
205
|
await cancelCommand(doBuild, userId, snag)
|
|
188
206
|
if (doBuild) {
|
|
189
207
|
const s = p.spinner()
|
|
190
|
-
|
|
208
|
+
const projectType = await findProjectType()
|
|
209
|
+
const buildCommand = await findBuildCommandForProjectType(projectType)
|
|
210
|
+
s.start(`Running: npm run ${buildCommand} && npx cap sync`)
|
|
191
211
|
const pack = JSON.parse(readFileSync('package.json').toString())
|
|
192
212
|
// check in script build exist
|
|
193
|
-
if (!pack.scripts
|
|
194
|
-
s.stop(
|
|
213
|
+
if (!pack.scripts[buildCommand]) {
|
|
214
|
+
s.stop('Error')
|
|
215
|
+
p.log.warn(`Cannot find ${buildCommand} script in package.json, please add it and run \`capgo init\` again`)
|
|
216
|
+
p.outro(`Bye 👋`)
|
|
195
217
|
process.exit()
|
|
196
218
|
}
|
|
197
|
-
execSync(`npm run
|
|
219
|
+
execSync(`npm run ${buildCommand} && npx cap sync`, execOption as ExecSyncOptions)
|
|
198
220
|
s.stop(`Build & Sync Done ✅`)
|
|
199
221
|
}
|
|
200
222
|
else {
|
|
@@ -214,7 +236,9 @@ async function step8(userId: string, snag: LogSnag, apikey: string, appId: strin
|
|
|
214
236
|
apikey,
|
|
215
237
|
}, false)
|
|
216
238
|
if (!uploadRes) {
|
|
217
|
-
s.stop(
|
|
239
|
+
s.stop('Error')
|
|
240
|
+
p.log.warn(`Upload failed ❌`)
|
|
241
|
+
p.outro(`Bye 👋`)
|
|
218
242
|
process.exit()
|
|
219
243
|
}
|
|
220
244
|
else {
|
|
@@ -238,8 +262,10 @@ async function step9(userId: string, snag: LogSnag) {
|
|
|
238
262
|
{ value: 'android', label: 'Android' },
|
|
239
263
|
],
|
|
240
264
|
})
|
|
241
|
-
if (p.isCancel(plaformType))
|
|
265
|
+
if (p.isCancel(plaformType)) {
|
|
266
|
+
p.outro(`Bye 👋`)
|
|
242
267
|
process.exit()
|
|
268
|
+
}
|
|
243
269
|
|
|
244
270
|
const platform = plaformType as 'ios' | 'android'
|
|
245
271
|
const s = p.spinner()
|
package/src/utils.ts
CHANGED
|
@@ -324,6 +324,91 @@ async function* getFiles(dir: string): AsyncGenerator<string> {
|
|
|
324
324
|
yield res
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
+
|
|
328
|
+
export async function findProjectType() {
|
|
329
|
+
// for nuxtjs check if nuxt.config.js exists
|
|
330
|
+
// for nextjs check if next.config.js exists
|
|
331
|
+
// for angular check if angular.json exists
|
|
332
|
+
// for sveltekit check if svelte.config.js exists
|
|
333
|
+
const pwd = process.cwd()
|
|
334
|
+
for await (const f of getFiles(pwd)) {
|
|
335
|
+
// find number of folder in path after pwd
|
|
336
|
+
if (f.includes('angular.json')) {
|
|
337
|
+
p.log.info('Found angular project')
|
|
338
|
+
return 'angular'
|
|
339
|
+
}
|
|
340
|
+
if (f.includes('nuxt.config.js')) {
|
|
341
|
+
p.log.info('Found nuxtjs project')
|
|
342
|
+
return 'nuxtjs'
|
|
343
|
+
}
|
|
344
|
+
if (f.includes('next.config.js')) {
|
|
345
|
+
p.log.info('Found nextjs project')
|
|
346
|
+
return 'nextjs'
|
|
347
|
+
}
|
|
348
|
+
if (f.includes('svelte.config.js')) {
|
|
349
|
+
p.log.info('Found sveltekit project')
|
|
350
|
+
return 'sveltekit'
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return 'unknown'
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export async function findMainFileForProjectType(projectType: string) {
|
|
357
|
+
if (projectType === 'angular')
|
|
358
|
+
return 'src/main.ts'
|
|
359
|
+
|
|
360
|
+
if (projectType === 'nuxtjs')
|
|
361
|
+
return 'src/main.ts'
|
|
362
|
+
|
|
363
|
+
if (projectType === 'nextjs')
|
|
364
|
+
return 'pages/_app.tsx'
|
|
365
|
+
|
|
366
|
+
if (projectType === 'sveltekit')
|
|
367
|
+
return 'src/main.ts'
|
|
368
|
+
|
|
369
|
+
return null
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// create a function to find the right command to build the project in static mode depending on the project type
|
|
373
|
+
|
|
374
|
+
export async function findBuildCommandForProjectType(projectType: string) {
|
|
375
|
+
if (projectType === 'angular') {
|
|
376
|
+
p.log.info('Angular project detected')
|
|
377
|
+
return 'build'
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (projectType === 'nuxtjs') {
|
|
381
|
+
p.log.info('Nuxtjs project detected')
|
|
382
|
+
return 'generate'
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (projectType === 'nextjs') {
|
|
386
|
+
p.log.info('Nextjs project detected')
|
|
387
|
+
p.log.warn('Please make sure you have configured static export in your next.config.js: https://nextjs.org/docs/pages/building-your-application/deploying/static-exports')
|
|
388
|
+
p.log.warn('Please make sure you have the output: \'export\' and distDir: \'dist\' in your next.config.js')
|
|
389
|
+
const doContinue = await p.confirm({ message: 'Do you want to continue?' })
|
|
390
|
+
if (!doContinue) {
|
|
391
|
+
p.log.error('Aborted')
|
|
392
|
+
program.error('')
|
|
393
|
+
}
|
|
394
|
+
return 'build'
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (projectType === 'sveltekit') {
|
|
398
|
+
p.log.info('Sveltekit project detected')
|
|
399
|
+
p.log.warn('Please make sure you have the adapter-static installed: https://kit.svelte.dev/docs/adapter-static')
|
|
400
|
+
p.log.warn('Please make sure you have the pages: \'dist\' and assets: \'dest\', in your svelte.config.js adaptater')
|
|
401
|
+
const doContinue = await p.confirm({ message: 'Do you want to continue?' })
|
|
402
|
+
if (!doContinue) {
|
|
403
|
+
p.log.error('Aborted')
|
|
404
|
+
program.error('')
|
|
405
|
+
}
|
|
406
|
+
return 'build'
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return 'build'
|
|
410
|
+
}
|
|
411
|
+
|
|
327
412
|
export async function findMainFile() {
|
|
328
413
|
const mainRegex = /(main|index)\.(ts|tsx|js|jsx)$/
|
|
329
414
|
// search for main.ts or main.js in local dir and subdirs
|