@capgo/cli 8.0.0-alpha.1 โ 8.0.0-alpha.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/README.md +1 -0
- package/dist/index.js +238 -411
- package/dist/package.json +89 -93
- package/dist/src/api/channels.d.ts +592 -16
- package/dist/src/api/channels.d.ts.map +1 -1
- package/dist/src/api/update.d.ts.map +1 -1
- package/dist/src/app/add.d.ts +2 -8
- package/dist/src/app/add.d.ts.map +1 -1
- package/dist/src/app/debug.d.ts +1 -1
- package/dist/src/app/debug.d.ts.map +1 -1
- package/dist/src/app/delete.d.ts +2 -1
- package/dist/src/app/delete.d.ts.map +1 -1
- package/dist/src/app/info.d.ts +9 -1
- package/dist/src/app/info.d.ts.map +1 -1
- package/dist/src/app/list.d.ts +19 -1
- package/dist/src/app/list.d.ts.map +1 -1
- package/dist/src/app/set.d.ts +2 -1
- package/dist/src/app/set.d.ts.map +1 -1
- package/dist/src/app/setting.d.ts +2 -1
- package/dist/src/app/setting.d.ts.map +1 -1
- package/dist/src/bundle/cleanup.d.ts +5 -1
- package/dist/src/bundle/cleanup.d.ts.map +1 -1
- package/dist/src/bundle/compatibility.d.ts +4 -4
- package/dist/src/bundle/compatibility.d.ts.map +1 -1
- package/dist/src/bundle/delete.d.ts +2 -1
- package/dist/src/bundle/delete.d.ts.map +1 -1
- package/dist/src/bundle/partial.d.ts +2 -2
- package/dist/src/bundle/partial.d.ts.map +1 -1
- package/dist/src/bundle/upload.d.ts +3 -3
- package/dist/src/bundle/upload.d.ts.map +1 -1
- package/dist/src/bundle/upload_interface.d.ts +1 -0
- package/dist/src/bundle/upload_interface.d.ts.map +1 -1
- package/dist/src/bundle/zip.d.ts.map +1 -1
- package/dist/src/channel/add.d.ts +2 -2
- package/dist/src/channel/add.d.ts.map +1 -1
- package/dist/src/channel/currentBundle.d.ts +2 -1
- package/dist/src/channel/currentBundle.d.ts.map +1 -1
- package/dist/src/channel/delete.d.ts +2 -1
- package/dist/src/channel/delete.d.ts.map +1 -1
- package/dist/src/channel/list.d.ts +2 -1
- package/dist/src/channel/list.d.ts.map +1 -1
- package/dist/src/channel/set.d.ts +2 -1
- package/dist/src/channel/set.d.ts.map +1 -1
- package/dist/src/checksum.d.ts +9 -0
- package/dist/src/checksum.d.ts.map +1 -0
- package/dist/src/init.d.ts.map +1 -1
- package/dist/src/keyV2.d.ts +2 -3
- package/dist/src/keyV2.d.ts.map +1 -1
- package/dist/src/login.d.ts +2 -2
- package/dist/src/login.d.ts.map +1 -1
- package/dist/src/organisation/list.d.ts +3 -0
- package/dist/src/organisation/list.d.ts.map +1 -1
- package/dist/src/sdk.d.ts +107 -4
- package/dist/src/sdk.d.ts.map +1 -1
- package/dist/src/sdk.js +247 -310
- package/dist/src/types/supabase.types.d.ts +313 -9
- package/dist/src/types/supabase.types.d.ts.map +1 -1
- package/dist/src/utils/latest-version.d.ts +7 -0
- package/dist/src/utils/latest-version.d.ts.map +1 -0
- package/dist/src/utils.d.ts +302 -21
- package/dist/src/utils.d.ts.map +1 -1
- package/package.json +11 -15
- package/dist/src/api/app.js +0 -45
- package/dist/src/api/app.js.map +0 -1
- package/dist/src/api/channels.js +0 -167
- package/dist/src/api/channels.js.map +0 -1
- package/dist/src/api/cryptoV2.js +0 -102
- package/dist/src/api/cryptoV2.js.map +0 -1
- package/dist/src/api/update.js +0 -14
- package/dist/src/api/update.js.map +0 -1
- package/dist/src/api/versions.js +0 -92
- package/dist/src/api/versions.js.map +0 -1
- package/dist/src/app/add.js +0 -150
- package/dist/src/app/add.js.map +0 -1
- package/dist/src/app/debug.js +0 -222
- package/dist/src/app/debug.js.map +0 -1
- package/dist/src/app/delete.js +0 -89
- package/dist/src/app/delete.js.map +0 -1
- package/dist/src/app/info.js +0 -84
- package/dist/src/app/info.js.map +0 -1
- package/dist/src/app/list.js +0 -48
- package/dist/src/app/list.js.map +0 -1
- package/dist/src/app/set.js +0 -96
- package/dist/src/app/set.js.map +0 -1
- package/dist/src/app/setting.js +0 -50
- package/dist/src/app/setting.js.map +0 -1
- package/dist/src/bundle/check.js +0 -30
- package/dist/src/bundle/check.js.map +0 -1
- package/dist/src/bundle/cleanup.js +0 -105
- package/dist/src/bundle/cleanup.js.map +0 -1
- package/dist/src/bundle/compatibility.js +0 -62
- package/dist/src/bundle/compatibility.js.map +0 -1
- package/dist/src/bundle/decryptV2.js +0 -76
- package/dist/src/bundle/decryptV2.js.map +0 -1
- package/dist/src/bundle/delete.js +0 -40
- package/dist/src/bundle/delete.js.map +0 -1
- package/dist/src/bundle/encryptV2.js +0 -108
- package/dist/src/bundle/encryptV2.js.map +0 -1
- package/dist/src/bundle/list.js +0 -36
- package/dist/src/bundle/list.js.map +0 -1
- package/dist/src/bundle/partial.js +0 -332
- package/dist/src/bundle/partial.js.map +0 -1
- package/dist/src/bundle/unlink.js +0 -70
- package/dist/src/bundle/unlink.js.map +0 -1
- package/dist/src/bundle/upload.js +0 -700
- package/dist/src/bundle/upload.js.map +0 -1
- package/dist/src/bundle/upload_interface.js +0 -2
- package/dist/src/bundle/upload_interface.js.map +0 -1
- package/dist/src/bundle/zip.js +0 -148
- package/dist/src/bundle/zip.js.map +0 -1
- package/dist/src/channel/add.js +0 -68
- package/dist/src/channel/add.js.map +0 -1
- package/dist/src/channel/currentBundle.js +0 -54
- package/dist/src/channel/currentBundle.js.map +0 -1
- package/dist/src/channel/delete.js +0 -77
- package/dist/src/channel/delete.js.map +0 -1
- package/dist/src/channel/list.js +0 -45
- package/dist/src/channel/list.js.map +0 -1
- package/dist/src/channel/set.js +0 -220
- package/dist/src/channel/set.js.map +0 -1
- package/dist/src/config/index.js +0 -31
- package/dist/src/config/index.js.map +0 -1
- package/dist/src/docs.js +0 -280
- package/dist/src/docs.js.map +0 -1
- package/dist/src/index.js +0 -504
- package/dist/src/index.js.map +0 -1
- package/dist/src/init.js +0 -797
- package/dist/src/init.js.map +0 -1
- package/dist/src/keyV2.js +0 -163
- package/dist/src/keyV2.js.map +0 -1
- package/dist/src/login.js +0 -51
- package/dist/src/login.js.map +0 -1
- package/dist/src/organisation/add.js +0 -82
- package/dist/src/organisation/add.js.map +0 -1
- package/dist/src/organisation/delete.js +0 -91
- package/dist/src/organisation/delete.js.map +0 -1
- package/dist/src/organisation/index.js +0 -5
- package/dist/src/organisation/index.js.map +0 -1
- package/dist/src/organisation/list.js +0 -60
- package/dist/src/organisation/list.js.map +0 -1
- package/dist/src/organisation/set.js +0 -95
- package/dist/src/organisation/set.js.map +0 -1
- package/dist/src/sdk.js.map +0 -1
- package/dist/src/types/supabase.types.js +0 -88
- package/dist/src/types/supabase.types.js.map +0 -1
- package/dist/src/user/account.js +0 -31
- package/dist/src/user/account.js.map +0 -1
- package/dist/src/utils.js +0 -1184
- package/dist/src/utils.js.map +0 -1
package/dist/src/init.js
DELETED
|
@@ -1,797 +0,0 @@
|
|
|
1
|
-
import { execSync, spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { cwd, exit } from 'node:process';
|
|
5
|
-
import { cancel as pCancel, confirm as pConfirm, intro as pIntro, isCancel as pIsCancel, log as pLog, outro as pOutro, select as pSelect, spinner as pSpinner, text as pText } from '@clack/prompts';
|
|
6
|
-
import semverInc from 'semver/functions/inc';
|
|
7
|
-
// We only use semver from std for Capgo semver, others connected to package.json need npm one as it's not following the semver spec
|
|
8
|
-
import semverLt from 'semver/functions/lt';
|
|
9
|
-
import tmp from 'tmp';
|
|
10
|
-
import { checkAlerts } from './api/update';
|
|
11
|
-
import { addAppInternal } from './app/add';
|
|
12
|
-
import { markSnag, waitLog } from './app/debug';
|
|
13
|
-
import { uploadBundle } from './bundle/upload';
|
|
14
|
-
import { addChannel } from './channel/add';
|
|
15
|
-
import { createKeyV2 } from './keyV2';
|
|
16
|
-
import { doLoginExists, login } from './login';
|
|
17
|
-
import { createSupabaseClient, findBuildCommandForProjectType, findMainFile, findMainFileForProjectType, findProjectType, findRoot, findSavedKey, getAllPackagesDependencies, getAppId, getBundleVersion, getConfig, getLocalConfig, getOrganization, getPackageScripts, getPMAndCommand, PACKNAME, projectIsMonorepo, updateConfigbyKey, updateConfigUpdater, verifyUser } from './utils';
|
|
18
|
-
const importInject = 'import { CapacitorUpdater } from \'@capgo/capacitor-updater\'';
|
|
19
|
-
const codeInject = 'CapacitorUpdater.notifyAppReady()';
|
|
20
|
-
// create regex to find line who start by 'import ' and end by ' from '
|
|
21
|
-
const regexImport = /import.*from.*/g;
|
|
22
|
-
const defaultChannel = 'production';
|
|
23
|
-
const execOption = { stdio: 'pipe' };
|
|
24
|
-
let tmpObject;
|
|
25
|
-
let globalPathToPackageJson;
|
|
26
|
-
function readTmpObj() {
|
|
27
|
-
tmpObject ??= readdirSync(tmp.tmpdir)
|
|
28
|
-
.map((name) => { return { name, full: `${tmp.tmpdir}/${name}` }; })
|
|
29
|
-
.find(obj => obj.name.startsWith('capgocli'))
|
|
30
|
-
?.full
|
|
31
|
-
?? tmp.fileSync({ prefix: 'capgocli' }).name;
|
|
32
|
-
}
|
|
33
|
-
function markStepDone(step, pathToPackageJson) {
|
|
34
|
-
try {
|
|
35
|
-
readTmpObj();
|
|
36
|
-
writeFileSync(tmpObject, JSON.stringify(pathToPackageJson ? { step_done: step, pathToPackageJson } : { step_done: step, pathToPackageJson: globalPathToPackageJson }));
|
|
37
|
-
if (pathToPackageJson) {
|
|
38
|
-
globalPathToPackageJson = pathToPackageJson;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
pLog.error(`Cannot mark step as done in the CLI, error:\n${err}`);
|
|
43
|
-
pLog.warn('Onboarding will continue but please report it to the capgo team!');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async function readStepsDone(orgId, apikey) {
|
|
47
|
-
try {
|
|
48
|
-
readTmpObj();
|
|
49
|
-
const rawData = readFileSync(tmpObject, 'utf-8');
|
|
50
|
-
if (!rawData || rawData.length === 0)
|
|
51
|
-
return undefined;
|
|
52
|
-
const { step_done, pathToPackageJson } = JSON.parse(rawData);
|
|
53
|
-
pLog.info(`You have already got to the step ${step_done}/10 in the previous session`);
|
|
54
|
-
const skipSteps = await pConfirm({ message: 'Would you like to continue from where you left off?' });
|
|
55
|
-
await cancelCommand(skipSteps, orgId, apikey);
|
|
56
|
-
if (skipSteps) {
|
|
57
|
-
if (pathToPackageJson) {
|
|
58
|
-
globalPathToPackageJson = pathToPackageJson;
|
|
59
|
-
}
|
|
60
|
-
return step_done;
|
|
61
|
-
}
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
pLog.error(`Cannot read which steps have been compleated, error:\n${err}`);
|
|
66
|
-
pLog.warn('Onboarding will continue but please report it to the capgo team!');
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function cleanupStepsDone() {
|
|
71
|
-
if (!tmpObject) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
rmSync(tmpObject);
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
pLog.error(`Cannot delete the tmp steps file.\nError: ${err}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async function cancelCommand(command, orgId, apikey) {
|
|
82
|
-
if (pIsCancel(command)) {
|
|
83
|
-
await markSnag('onboarding-v2', orgId, apikey, 'canceled', '๐คท');
|
|
84
|
-
exit();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function markStep(orgId, apikey, step, appId) {
|
|
88
|
-
return markSnag('onboarding-v2', orgId, apikey, `onboarding-step-${step}`, appId);
|
|
89
|
-
}
|
|
90
|
-
async function addAppStep(organization, apikey, appId, options) {
|
|
91
|
-
const pm = getPMAndCommand();
|
|
92
|
-
const doAdd = await pConfirm({ message: `Add ${appId} in Capgo?` });
|
|
93
|
-
await cancelCommand(doAdd, organization.gid, apikey);
|
|
94
|
-
if (doAdd) {
|
|
95
|
-
const s = pSpinner();
|
|
96
|
-
s.start(`Running: ${pm.runner} @capgo/cli@latest app add ${appId}`);
|
|
97
|
-
const addRes = await addAppInternal(appId, options, organization, true);
|
|
98
|
-
if (!addRes)
|
|
99
|
-
s.stop(`App already add โ
`);
|
|
100
|
-
else
|
|
101
|
-
s.stop(`App add Done โ
`);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
pLog.info(`If you change your mind, run it for yourself with: "${pm.runner} @capgo/cli@latest app add ${appId}"`);
|
|
105
|
-
}
|
|
106
|
-
await markStep(organization.gid, apikey, 'add-app', appId);
|
|
107
|
-
}
|
|
108
|
-
async function addChannelStep(orgId, apikey, appId) {
|
|
109
|
-
const pm = getPMAndCommand();
|
|
110
|
-
const doChannel = await pConfirm({ message: `Create default channel ${defaultChannel} for ${appId} in Capgo?` });
|
|
111
|
-
await cancelCommand(doChannel, orgId, apikey);
|
|
112
|
-
if (doChannel) {
|
|
113
|
-
const s = pSpinner();
|
|
114
|
-
// create production channel public
|
|
115
|
-
s.start(`Running: ${pm.runner} @capgo/cli@latest channel add ${defaultChannel} ${appId} --default`);
|
|
116
|
-
const addChannelRes = await addChannel(defaultChannel, appId, {
|
|
117
|
-
default: true,
|
|
118
|
-
apikey,
|
|
119
|
-
}, true);
|
|
120
|
-
if (!addChannelRes)
|
|
121
|
-
s.stop(`Channel already added โ
`);
|
|
122
|
-
else
|
|
123
|
-
s.stop(`Channel add Done โ
`);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
pLog.info(`If you change your mind, run it for yourself with: "${pm.runner} @capgo/cli@latest channel add ${defaultChannel} ${appId} --default"`);
|
|
127
|
-
}
|
|
128
|
-
await markStep(orgId, apikey, 'add-channel', appId);
|
|
129
|
-
}
|
|
130
|
-
async function getAssistedDependencies(stepsDone) {
|
|
131
|
-
// here we will assume that getAlllPackagesDependencies uses 'findRoot(cwd())' for the first argument
|
|
132
|
-
const root = join(findRoot(cwd()), PACKNAME);
|
|
133
|
-
const dependencies = !globalPathToPackageJson ? await getAllPackagesDependencies(undefined, root) : await getAllPackagesDependencies(undefined, globalPathToPackageJson);
|
|
134
|
-
if (dependencies.size === 0 || !dependencies.has('@capacitor/core')) {
|
|
135
|
-
pLog.warn('No adequate dependencies found');
|
|
136
|
-
const doSelect = await pConfirm({ message: 'Would you like to select the package.json file manually?' });
|
|
137
|
-
if (pIsCancel(doSelect)) {
|
|
138
|
-
pCancel('Operation cancelled.');
|
|
139
|
-
exit(1);
|
|
140
|
-
}
|
|
141
|
-
if (doSelect) {
|
|
142
|
-
const useTreeSelect = await pConfirm({ message: 'Would you like to use a tree selector to choose the package.json file?' });
|
|
143
|
-
if (pIsCancel(useTreeSelect)) {
|
|
144
|
-
pCancel('Operation cancelled.');
|
|
145
|
-
exit(1);
|
|
146
|
-
}
|
|
147
|
-
if (useTreeSelect) {
|
|
148
|
-
let path = cwd();
|
|
149
|
-
let selectedPath = PACKNAME;
|
|
150
|
-
while (true) {
|
|
151
|
-
const options = readdirSync(path)
|
|
152
|
-
.map(dir => ({ value: dir, label: dir }));
|
|
153
|
-
options.push({ value: '..', label: '..' });
|
|
154
|
-
selectedPath = await pSelect({
|
|
155
|
-
message: 'Select package.json file:',
|
|
156
|
-
options,
|
|
157
|
-
});
|
|
158
|
-
if (pIsCancel(selectedPath)) {
|
|
159
|
-
pCancel('Operation cancelled.');
|
|
160
|
-
exit(1);
|
|
161
|
-
}
|
|
162
|
-
if (!statSync(join(path, selectedPath)).isDirectory() && selectedPath !== PACKNAME) {
|
|
163
|
-
pLog.error(`Selected a file that is not a package.json file`);
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
path = join(path, selectedPath);
|
|
167
|
-
if (selectedPath === PACKNAME) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
// write the path of package.json in tmp file
|
|
172
|
-
await markStepDone(stepsDone, path);
|
|
173
|
-
return { dependencies: await getAllPackagesDependencies(undefined, path), path };
|
|
174
|
-
}
|
|
175
|
-
const path = await pText({
|
|
176
|
-
message: 'Enter path to node_modules folder:',
|
|
177
|
-
});
|
|
178
|
-
if (pIsCancel(path)) {
|
|
179
|
-
pCancel('Operation cancelled.');
|
|
180
|
-
exit(1);
|
|
181
|
-
}
|
|
182
|
-
if (!existsSync(path)) {
|
|
183
|
-
pLog.error(`Path ${path} does not exist`);
|
|
184
|
-
exit(1);
|
|
185
|
-
}
|
|
186
|
-
return { dependencies: await getAllPackagesDependencies(undefined, path), path };
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
// even in the default case, let's mark the path to package.json
|
|
190
|
-
// this will help with bundle upload
|
|
191
|
-
await markStepDone(stepsDone, root);
|
|
192
|
-
return { dependencies: await getAllPackagesDependencies(undefined, root), path: root };
|
|
193
|
-
}
|
|
194
|
-
const urlMigrateV6 = 'https://capacitorjs.com/docs/updating/6-0';
|
|
195
|
-
const urlMigrateV7 = 'https://capacitorjs.com/docs/updating/7-0';
|
|
196
|
-
async function addUpdaterStep(orgId, apikey, appId) {
|
|
197
|
-
const pm = getPMAndCommand();
|
|
198
|
-
let pkgVersion = '1.0.0';
|
|
199
|
-
let delta = false;
|
|
200
|
-
const doInstall = await pConfirm({ message: `Automatic Install "@capgo/capacitor-updater" dependency in ${appId}?` });
|
|
201
|
-
await cancelCommand(doInstall, orgId, apikey);
|
|
202
|
-
if (doInstall) {
|
|
203
|
-
const s = pSpinner();
|
|
204
|
-
let versionToInstall = 'latest';
|
|
205
|
-
// 3 because this is the 4th step, ergo 3 steps have already been done
|
|
206
|
-
const { dependencies, path } = await getAssistedDependencies(3);
|
|
207
|
-
s.start(`Checking if @capgo/capacitor-updater is installed`);
|
|
208
|
-
if (!dependencies.has('@capacitor/core')) {
|
|
209
|
-
s.stop('Error');
|
|
210
|
-
pLog.warn(`Cannot find @capacitor/core in package.json`);
|
|
211
|
-
pOutro(`Bye ๐`);
|
|
212
|
-
exit();
|
|
213
|
-
}
|
|
214
|
-
const coreVersion = dependencies.get('@capacitor/core');
|
|
215
|
-
if (!coreVersion) {
|
|
216
|
-
s.stop('Error');
|
|
217
|
-
pLog.warn(`Cannot find @capacitor/core in package.json, please run \`capgo init\` in a capacitor project`);
|
|
218
|
-
pOutro(`Bye ๐`);
|
|
219
|
-
exit();
|
|
220
|
-
}
|
|
221
|
-
if (coreVersion === 'latest') {
|
|
222
|
-
s.stop(`@capacitor/core version is ${coreVersion}, make sure to use a proper version, using Latest as value is not recommended and will lead to unexpected behavior`);
|
|
223
|
-
pOutro(`Bye ๐`);
|
|
224
|
-
exit();
|
|
225
|
-
}
|
|
226
|
-
else if (semverLt(coreVersion, '6.0.0')) {
|
|
227
|
-
s.stop('Error');
|
|
228
|
-
pLog.warn(`@capacitor/core version is ${coreVersion}, Capgo only support 2 last Capacitor versions, please update to Capacitor v6 minimum: ${urlMigrateV6}`);
|
|
229
|
-
pOutro(`Bye ๐`);
|
|
230
|
-
exit();
|
|
231
|
-
}
|
|
232
|
-
else if (semverLt(coreVersion, '7.0.0')) {
|
|
233
|
-
s.stop(`@capacitor/core version is ${coreVersion}, update to Capacitor v7 minimum: ${urlMigrateV7} to get the best features of Capgo`);
|
|
234
|
-
versionToInstall = '^6.0.0';
|
|
235
|
-
}
|
|
236
|
-
if (pm.pm === 'unknown') {
|
|
237
|
-
s.stop('Error');
|
|
238
|
-
pLog.warn(`Cannot reconize package manager, please run \`capgo init\` in a capacitor project with npm, pnpm, bun or yarn`);
|
|
239
|
-
pOutro(`Bye ๐`);
|
|
240
|
-
exit();
|
|
241
|
-
}
|
|
242
|
-
// // use pm to install capgo
|
|
243
|
-
// // run command pm install @capgo/capacitor-updater@latest
|
|
244
|
-
// check if capgo is already installed in package.json
|
|
245
|
-
if (dependencies.get('@capgo/capacitor-updater')) {
|
|
246
|
-
s.stop(`Capgo already installed โ
`);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
await execSync(`${pm.installCommand} --force @capgo/capacitor-updater@${versionToInstall}`, { ...execOption, cwd: path.replace('/package.json', '') });
|
|
250
|
-
s.stop(`Install Done โ
`);
|
|
251
|
-
pkgVersion = getBundleVersion(undefined, path) || '1.0.0';
|
|
252
|
-
let doDirectInstall = false;
|
|
253
|
-
if (versionToInstall === 'latest') {
|
|
254
|
-
doDirectInstall = await pConfirm({ message: `Do you want to set instant updates in ${appId}? Read more about it here: https://capgo.app/docs/live-updates/update-behavior/#applying-updates-immediately` });
|
|
255
|
-
await cancelCommand(doDirectInstall, orgId, apikey);
|
|
256
|
-
}
|
|
257
|
-
s.start(`Updating config file`);
|
|
258
|
-
delta = !!doDirectInstall;
|
|
259
|
-
const directInstall = doDirectInstall
|
|
260
|
-
? {
|
|
261
|
-
directUpdate: 'always',
|
|
262
|
-
autoSplashscreen: true,
|
|
263
|
-
}
|
|
264
|
-
: {};
|
|
265
|
-
if (doDirectInstall) {
|
|
266
|
-
await updateConfigbyKey('SplashScreen', { launchAutoHide: false });
|
|
267
|
-
}
|
|
268
|
-
await updateConfigUpdater({ version: pkgVersion, appId, autoUpdate: true, ...directInstall });
|
|
269
|
-
s.stop(`Config file updated โ
`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
pLog.info(`If you change your mind, run it for yourself with: "${pm.installCommand} @capgo/capacitor-updater@latest"`);
|
|
274
|
-
}
|
|
275
|
-
await markStep(orgId, apikey, 'add-updater', appId);
|
|
276
|
-
return { pkgVersion, delta };
|
|
277
|
-
}
|
|
278
|
-
async function addCodeStep(orgId, apikey, appId) {
|
|
279
|
-
const doAddCode = await pConfirm({ message: `Automatic Add "${codeInject}" code and import in ${appId}?` });
|
|
280
|
-
await cancelCommand(doAddCode, orgId, apikey);
|
|
281
|
-
if (doAddCode) {
|
|
282
|
-
const s = pSpinner();
|
|
283
|
-
s.start(`Adding @capacitor-updater to your main file`);
|
|
284
|
-
const projectType = await findProjectType();
|
|
285
|
-
if (projectType === 'nuxtjs-js' || projectType === 'nuxtjs-ts') {
|
|
286
|
-
// Nuxt.js specific logic
|
|
287
|
-
const nuxtDir = join('plugins');
|
|
288
|
-
if (!existsSync(nuxtDir)) {
|
|
289
|
-
mkdirSync(nuxtDir, { recursive: true });
|
|
290
|
-
}
|
|
291
|
-
let nuxtFilePath;
|
|
292
|
-
if (projectType === 'nuxtjs-ts') {
|
|
293
|
-
nuxtFilePath = join(nuxtDir, 'capacitorUpdater.client.ts');
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
nuxtFilePath = join(nuxtDir, 'capacitorUpdater.client.js');
|
|
297
|
-
}
|
|
298
|
-
const nuxtFileContent = `
|
|
299
|
-
import { CapacitorUpdater } from '@capgo/capacitor-updater'
|
|
300
|
-
|
|
301
|
-
export default defineNuxtPlugin(() => {
|
|
302
|
-
CapacitorUpdater.notifyAppReady()
|
|
303
|
-
})
|
|
304
|
-
`;
|
|
305
|
-
if (existsSync(nuxtFilePath)) {
|
|
306
|
-
const currentContent = readFileSync(nuxtFilePath, 'utf8');
|
|
307
|
-
if (currentContent.includes('CapacitorUpdater.notifyAppReady()')) {
|
|
308
|
-
s.stop('Code already added to capacitorUpdater.client.ts file inside plugins directory โ
');
|
|
309
|
-
pLog.info('Plugins directory and capacitorUpdater.client.ts file already exist with required code');
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
writeFileSync(nuxtFilePath, nuxtFileContent, 'utf8');
|
|
313
|
-
s.stop('Code added to capacitorUpdater.client.ts file inside plugins directory โ
');
|
|
314
|
-
pLog.info('Updated capacitorUpdater.client.ts file with required code');
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
writeFileSync(nuxtFilePath, nuxtFileContent, 'utf8');
|
|
319
|
-
s.stop('Code added to capacitorUpdater.client.ts file inside plugins directory โ
');
|
|
320
|
-
pLog.info('Created plugins directory and capacitorUpdater.client.ts file');
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
// Handle other project types
|
|
325
|
-
let mainFilePath;
|
|
326
|
-
if (projectType === 'unknown') {
|
|
327
|
-
mainFilePath = await findMainFile();
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
const isTypeScript = projectType.endsWith('-ts');
|
|
331
|
-
mainFilePath = await findMainFileForProjectType(projectType, isTypeScript);
|
|
332
|
-
}
|
|
333
|
-
// Open main file and inject codeInject
|
|
334
|
-
if (!mainFilePath || !existsSync(mainFilePath)) {
|
|
335
|
-
s.stop('Cannot find main file to install Updater plugin');
|
|
336
|
-
const userProvidedPath = await pText({
|
|
337
|
-
message: `Provide the correct relative path to your main file (JS or TS):`,
|
|
338
|
-
validate: (value) => {
|
|
339
|
-
if (!existsSync(value))
|
|
340
|
-
return 'File does not exist. Please provide a valid path.';
|
|
341
|
-
},
|
|
342
|
-
});
|
|
343
|
-
if (pIsCancel(userProvidedPath)) {
|
|
344
|
-
pCancel('Operation cancelled.');
|
|
345
|
-
exit(1);
|
|
346
|
-
}
|
|
347
|
-
mainFilePath = userProvidedPath;
|
|
348
|
-
}
|
|
349
|
-
const mainFile = readFileSync(mainFilePath, 'utf8');
|
|
350
|
-
const mainFileContent = mainFile.toString();
|
|
351
|
-
const matches = mainFileContent.match(regexImport);
|
|
352
|
-
const last = matches?.pop();
|
|
353
|
-
if (!last) {
|
|
354
|
-
s.stop('Error');
|
|
355
|
-
pLog.warn(`Cannot find import line in main file, use manual installation: https://capgo.app/docs/getting-started/add-an-app/`);
|
|
356
|
-
pOutro(`Bye ๐`);
|
|
357
|
-
exit();
|
|
358
|
-
}
|
|
359
|
-
if (mainFileContent.includes(codeInject)) {
|
|
360
|
-
s.stop(`Code already added to ${mainFilePath} โ
`);
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
const newMainFileContent = mainFileContent.replace(last, `${last}\n${importInject};\n\n${codeInject};\n`);
|
|
364
|
-
writeFileSync(mainFilePath, newMainFileContent, 'utf8');
|
|
365
|
-
s.stop(`Code added to ${mainFilePath} โ
`);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
await markStep(orgId, apikey, 'add-code', appId);
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
pLog.info(`Add to your main file the following code:\n\n${importInject};\n\n${codeInject};\n`);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
async function addEncryptionStep(orgId, apikey, appId) {
|
|
375
|
-
const dependencies = await getAllPackagesDependencies();
|
|
376
|
-
const coreVersion = dependencies.get('@capacitor/core');
|
|
377
|
-
if (!coreVersion) {
|
|
378
|
-
pLog.warn(`Cannot find @capacitor/core in package.json. It is likely that you are using a monorepo. Please NOTE that encryption is not supported in Capacitor V5.`);
|
|
379
|
-
}
|
|
380
|
-
const pm = getPMAndCommand();
|
|
381
|
-
const doEncrypt = await pConfirm({ message: `Automatic configure end-to-end encryption in ${appId} updates?` });
|
|
382
|
-
await cancelCommand(doEncrypt, orgId, apikey);
|
|
383
|
-
if (doEncrypt) {
|
|
384
|
-
if (coreVersion === 'latest') {
|
|
385
|
-
pLog.error(`@capacitor/core version is ${coreVersion}, make sure to use a proper version, using Latest as value is not recommended and will lead to unexpected behavior`);
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
if (coreVersion && semverLt(coreVersion, '6.0.0')) {
|
|
389
|
-
pLog.warn(`Encryption is not supported in Capacitor V5.`);
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
const s = pSpinner();
|
|
393
|
-
s.start(`Running: ${pm.runner} @capgo/cli@latest key create`);
|
|
394
|
-
const keyRes = await createKeyV2({ force: true }, false);
|
|
395
|
-
if (!keyRes) {
|
|
396
|
-
s.stop('Error');
|
|
397
|
-
pLog.warn(`Cannot create key โ`);
|
|
398
|
-
pOutro(`Bye ๐`);
|
|
399
|
-
exit(1);
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
s.stop(`key created ๐`);
|
|
403
|
-
}
|
|
404
|
-
markSnag('onboarding-v2', orgId, apikey, 'Use encryption v2', appId);
|
|
405
|
-
}
|
|
406
|
-
await markStep(orgId, apikey, 'add-encryption', appId);
|
|
407
|
-
}
|
|
408
|
-
async function buildProjectStep(orgId, apikey, appId) {
|
|
409
|
-
const pm = getPMAndCommand();
|
|
410
|
-
const doBuild = await pConfirm({ message: `Automatic build ${appId} with "${pm.pm} run build" ?` });
|
|
411
|
-
await cancelCommand(doBuild, orgId, apikey);
|
|
412
|
-
if (doBuild) {
|
|
413
|
-
const s = pSpinner();
|
|
414
|
-
s.start(`Checking project type`);
|
|
415
|
-
const projectType = await findProjectType();
|
|
416
|
-
const buildCommand = await findBuildCommandForProjectType(projectType);
|
|
417
|
-
s.message(`Running: ${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`);
|
|
418
|
-
const packScripts = getPackageScripts();
|
|
419
|
-
// check in script build exist
|
|
420
|
-
if (!packScripts[buildCommand]) {
|
|
421
|
-
s.stop('Error');
|
|
422
|
-
pLog.warn(`Cannot find ${buildCommand} script in package.json, please add it and run \`capgo init\` again`);
|
|
423
|
-
pOutro(`Bye ๐`);
|
|
424
|
-
exit();
|
|
425
|
-
}
|
|
426
|
-
execSync(`${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`, execOption);
|
|
427
|
-
s.stop(`Build & Sync Done โ
`);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
pLog.info(`Build yourself with command: ${pm.pm} run build && ${pm.runner} cap sync`);
|
|
431
|
-
}
|
|
432
|
-
await markStep(orgId, apikey, 'build-project', appId);
|
|
433
|
-
}
|
|
434
|
-
async function runDeviceStep(orgId, apikey, appId) {
|
|
435
|
-
const pm = getPMAndCommand();
|
|
436
|
-
const doRun = await pConfirm({ message: `Run ${appId} in device now to test the initial version?` });
|
|
437
|
-
await cancelCommand(doRun, orgId, apikey);
|
|
438
|
-
if (doRun) {
|
|
439
|
-
const plaformType = await pSelect({
|
|
440
|
-
message: 'Pick a platform to run your app',
|
|
441
|
-
options: [
|
|
442
|
-
{ value: 'ios', label: 'IOS' },
|
|
443
|
-
{ value: 'android', label: 'Android' },
|
|
444
|
-
],
|
|
445
|
-
});
|
|
446
|
-
if (pIsCancel(plaformType)) {
|
|
447
|
-
pOutro(`Bye ๐`);
|
|
448
|
-
exit();
|
|
449
|
-
}
|
|
450
|
-
const platform = plaformType;
|
|
451
|
-
const s = pSpinner();
|
|
452
|
-
s.start(`Running: ${pm.runner} cap run ${platform}`);
|
|
453
|
-
await spawnSync(pm.runner, ['cap', 'run', platform], { stdio: 'inherit' });
|
|
454
|
-
s.stop(`App started โ
`);
|
|
455
|
-
pLog.info(`๐ฑ Your app should now be running on your ${platform} device with Capgo integrated`);
|
|
456
|
-
pLog.info(`๐ This is your baseline version - we'll create an update next`);
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
pLog.info(`If you change your mind, run it for yourself with: ${pm.runner} cap run <ios|android>`);
|
|
460
|
-
}
|
|
461
|
-
await markStep(orgId, apikey, 'run-device', appId);
|
|
462
|
-
}
|
|
463
|
-
async function addCodeChangeStep(orgId, apikey, appId, pkgVersion) {
|
|
464
|
-
pLog.info(`๐ฏ Now let's test Capgo by making a visible change and deploying an update!`);
|
|
465
|
-
const modificationType = await pSelect({
|
|
466
|
-
message: 'How would you like to test the update?',
|
|
467
|
-
options: [
|
|
468
|
-
{ value: 'auto', label: 'Auto: Let Capgo CLI make a visible change for you' },
|
|
469
|
-
{ value: 'manual', label: 'Manual: I\'ll make changes myself' },
|
|
470
|
-
],
|
|
471
|
-
});
|
|
472
|
-
if (pIsCancel(modificationType)) {
|
|
473
|
-
await markSnag('onboarding-v2', orgId, apikey, 'canceled', '๐คท');
|
|
474
|
-
exit();
|
|
475
|
-
}
|
|
476
|
-
if (modificationType === 'auto') {
|
|
477
|
-
const s = pSpinner();
|
|
478
|
-
s.start('Making automatic changes to test Capgo updates');
|
|
479
|
-
let changed = false;
|
|
480
|
-
// Try to find and modify ONE file only, prioritizing HTML files
|
|
481
|
-
const possibleFiles = [
|
|
482
|
-
'src/index.html',
|
|
483
|
-
'public/index.html',
|
|
484
|
-
'index.html',
|
|
485
|
-
'src/App.vue',
|
|
486
|
-
'src/app/app.component.html',
|
|
487
|
-
'src/app/home/home.page.html',
|
|
488
|
-
'src/main.css',
|
|
489
|
-
'src/style.css',
|
|
490
|
-
'public/style.css',
|
|
491
|
-
];
|
|
492
|
-
for (const filePath of possibleFiles) {
|
|
493
|
-
if (existsSync(filePath) && !changed) {
|
|
494
|
-
try {
|
|
495
|
-
const content = readFileSync(filePath, 'utf8');
|
|
496
|
-
let newContent = content;
|
|
497
|
-
if (filePath.endsWith('.html')) {
|
|
498
|
-
// Add a visible banner to HTML files
|
|
499
|
-
if (content.includes('<body>') && !content.includes('capgo-test-banner')) {
|
|
500
|
-
newContent = content.replace('<body>', `<body>
|
|
501
|
-
<div id="capgo-test-banner" style="background: linear-gradient(90deg, #4CAF50, #2196F3); color: white; padding: 15px; text-align: center; font-weight: bold; position: fixed; top: env(safe-area-inset-top, 0); left: env(safe-area-inset-left, 0); right: env(safe-area-inset-right, 0); z-index: 9999; box-shadow: 0 2px 10px rgba(0,0,0,0.1); padding-top: calc(15px + env(safe-area-inset-top, 0));">
|
|
502
|
-
๐ Capgo Update Test - This banner shows the update worked!
|
|
503
|
-
</div>
|
|
504
|
-
<style>
|
|
505
|
-
body { padding-top: calc(60px + env(safe-area-inset-top, 0)) !important; }
|
|
506
|
-
</style>`);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
else if (filePath.endsWith('.vue')) {
|
|
510
|
-
// Add a test banner to Vue components
|
|
511
|
-
if (content.includes('<template>') && !content.includes('capgo-test-vue')) {
|
|
512
|
-
newContent = content.replace('<template>', `<template>
|
|
513
|
-
<div class="capgo-test-vue" style="background: linear-gradient(90deg, #4CAF50, #2196F3); color: white; padding: 15px; text-align: center; font-weight: bold; margin-bottom: 20px; padding-top: calc(15px + env(safe-area-inset-top, 0)); padding-left: calc(15px + env(safe-area-inset-left, 0)); padding-right: calc(15px + env(safe-area-inset-right, 0));">
|
|
514
|
-
๐ Capgo Update Test - Vue component updated!
|
|
515
|
-
</div>`);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
else if (filePath.endsWith('.css')) {
|
|
519
|
-
// Add body background change as fallback
|
|
520
|
-
if (!content.includes('capgo-test-background')) {
|
|
521
|
-
newContent = `/* Capgo test modification - background change */
|
|
522
|
-
body {
|
|
523
|
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
|
524
|
-
/* capgo-test-background */
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
${content}`;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (newContent !== content) {
|
|
531
|
-
writeFileSync(filePath, newContent, 'utf8');
|
|
532
|
-
s.stop(`โ
Made test changes to ${filePath}`);
|
|
533
|
-
pLog.info(`๐ Added visible test modification to verify the update works`);
|
|
534
|
-
changed = true;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
catch {
|
|
539
|
-
// Continue to next file
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
if (!changed) {
|
|
544
|
-
s.stop('โ ๏ธ Could not automatically modify files');
|
|
545
|
-
pLog.warn('Please make a visible change manually (like editing a text or color)');
|
|
546
|
-
const continueManual = await pConfirm({ message: 'Continue after making your changes?' });
|
|
547
|
-
await cancelCommand(continueManual, orgId, apikey);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
pLog.info(`โ Please make a visible change to your app now (example: change a text, color, or add an element)`);
|
|
552
|
-
pLog.info(`๐ก This change will help you see that Capgo updates work correctly`);
|
|
553
|
-
const changesReady = await pConfirm({ message: 'Have you made your changes and ready to continue?' });
|
|
554
|
-
await cancelCommand(changesReady, orgId, apikey);
|
|
555
|
-
}
|
|
556
|
-
// Version bump
|
|
557
|
-
const nextVersion = semverInc(pkgVersion, 'patch') || '1.0.1';
|
|
558
|
-
const versionChoice = await pSelect({
|
|
559
|
-
message: 'How do you want to handle the version for this update?',
|
|
560
|
-
options: [
|
|
561
|
-
{ value: 'auto', label: `Auto: Bump patch version (${pkgVersion} โ ${nextVersion})` },
|
|
562
|
-
{ value: 'manual', label: 'Manual: I\'ll provide the version number' },
|
|
563
|
-
],
|
|
564
|
-
});
|
|
565
|
-
if (pIsCancel(versionChoice)) {
|
|
566
|
-
await markSnag('onboarding-v2', orgId, apikey, 'canceled', '๐คท');
|
|
567
|
-
exit();
|
|
568
|
-
}
|
|
569
|
-
let newVersion = pkgVersion;
|
|
570
|
-
if (versionChoice === 'auto') {
|
|
571
|
-
// Auto bump patch version using semver
|
|
572
|
-
const incrementedVersion = semverInc(pkgVersion, 'patch');
|
|
573
|
-
if (incrementedVersion) {
|
|
574
|
-
newVersion = incrementedVersion;
|
|
575
|
-
pLog.info(`๐ข Auto-bumped version from ${pkgVersion} to ${newVersion}`);
|
|
576
|
-
}
|
|
577
|
-
else {
|
|
578
|
-
newVersion = '1.0.1'; // fallback
|
|
579
|
-
pLog.warn(`Could not parse version ${pkgVersion}, using fallback ${newVersion}`);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
else {
|
|
583
|
-
const userVersion = await pText({
|
|
584
|
-
message: `Current version is ${pkgVersion}. Enter new version:`,
|
|
585
|
-
validate: (value) => {
|
|
586
|
-
if (!value.match(/^\d+\.\d+\.\d+/))
|
|
587
|
-
return 'Please enter a valid version (x.y.z)';
|
|
588
|
-
},
|
|
589
|
-
});
|
|
590
|
-
if (pIsCancel(userVersion)) {
|
|
591
|
-
await markSnag('onboarding-v2', orgId, apikey, 'canceled', '๐คท');
|
|
592
|
-
exit();
|
|
593
|
-
}
|
|
594
|
-
newVersion = userVersion;
|
|
595
|
-
}
|
|
596
|
-
// Build after modifications
|
|
597
|
-
const pm = getPMAndCommand();
|
|
598
|
-
const doBuild = await pConfirm({ message: `Build ${appId} with changes before uploading? If you need to build yourself please do it now in other terminal, and then select no` });
|
|
599
|
-
await cancelCommand(doBuild, orgId, apikey);
|
|
600
|
-
if (doBuild) {
|
|
601
|
-
const s = pSpinner();
|
|
602
|
-
s.start(`Checking project type`);
|
|
603
|
-
const projectType = await findProjectType();
|
|
604
|
-
const buildCommand = await findBuildCommandForProjectType(projectType);
|
|
605
|
-
s.message(`Running: ${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`);
|
|
606
|
-
const packScripts = getPackageScripts();
|
|
607
|
-
// check in script build exist
|
|
608
|
-
if (!packScripts[buildCommand]) {
|
|
609
|
-
s.stop('Error');
|
|
610
|
-
pLog.warn(`Cannot find ${buildCommand} script in package.json, please add it and run \`capgo init\` again`);
|
|
611
|
-
pOutro(`Bye ๐`);
|
|
612
|
-
exit();
|
|
613
|
-
}
|
|
614
|
-
execSync(`${pm.pm} run ${buildCommand} && ${pm.runner} cap sync`, execOption);
|
|
615
|
-
s.stop(`โ
Build with changes completed`);
|
|
616
|
-
pLog.info(`๐ฆ Your modifications have been built and synced`);
|
|
617
|
-
}
|
|
618
|
-
else {
|
|
619
|
-
pLog.info(`Build yourself with command: ${pm.pm} run build && ${pm.runner} cap sync`);
|
|
620
|
-
}
|
|
621
|
-
await markStep(orgId, apikey, 'add-code-change', appId);
|
|
622
|
-
return newVersion;
|
|
623
|
-
}
|
|
624
|
-
async function uploadStep(orgId, apikey, appId, newVersion, delta) {
|
|
625
|
-
const pm = getPMAndCommand();
|
|
626
|
-
const doBundle = await pConfirm({ message: `Upload the updated ${appId} bundle (v${newVersion}) to Capgo?` });
|
|
627
|
-
await cancelCommand(doBundle, orgId, apikey);
|
|
628
|
-
if (doBundle) {
|
|
629
|
-
const s = pSpinner();
|
|
630
|
-
let nodeModulesPath;
|
|
631
|
-
s.start(`Running: ${pm.runner} @capgo/cli@latest bundle upload ${delta ? '--delta-only' : ''}`);
|
|
632
|
-
const isMonorepo = projectIsMonorepo(cwd());
|
|
633
|
-
if (globalPathToPackageJson && isMonorepo) {
|
|
634
|
-
pLog.warn(`You are most likely using a monorepo, please provide the path to your package.json file AND node_modules path folder when uploading your bundle`);
|
|
635
|
-
pLog.warn(`Example: ${pm.runner} @capgo/cli@latest bundle upload --package-json ./packages/my-app/package.json --node-modules ./packages/my-app/node_modules ${delta ? '--delta-only' : ''}`);
|
|
636
|
-
nodeModulesPath = join(findRoot(cwd()), 'node_modules');
|
|
637
|
-
pLog.warn(`Guessed node modules path at: ${nodeModulesPath}`);
|
|
638
|
-
if (!existsSync(nodeModulesPath)) {
|
|
639
|
-
pLog.error(`Node modules path does not exist, upload skipped`);
|
|
640
|
-
pOutro(`Bye ๐`);
|
|
641
|
-
exit(1);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
const uploadRes = await uploadBundle(appId, {
|
|
645
|
-
channel: defaultChannel,
|
|
646
|
-
apikey,
|
|
647
|
-
packageJson: isMonorepo ? globalPathToPackageJson : undefined,
|
|
648
|
-
nodeModules: isMonorepo ? nodeModulesPath : undefined,
|
|
649
|
-
deltaOnly: delta,
|
|
650
|
-
bundle: newVersion,
|
|
651
|
-
}, false);
|
|
652
|
-
if (!uploadRes?.success) {
|
|
653
|
-
s.stop('Error');
|
|
654
|
-
pLog.warn(`Upload failed โ`);
|
|
655
|
-
pOutro(`Bye ๐`);
|
|
656
|
-
exit();
|
|
657
|
-
}
|
|
658
|
-
else {
|
|
659
|
-
s.stop(`โ
Update v${newVersion} uploaded successfully!`);
|
|
660
|
-
pLog.info(`๐ Your updated bundle is now available on Capgo`);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
else {
|
|
664
|
-
pLog.info(`Upload yourself with command: ${pm.runner} @capgo/cli@latest bundle upload`);
|
|
665
|
-
}
|
|
666
|
-
await markStep(orgId, apikey, 'upload', appId);
|
|
667
|
-
}
|
|
668
|
-
async function testCapgoUpdateStep(orgId, apikey, appId, hostWeb, delta) {
|
|
669
|
-
pLog.info(`๐งช Time to test the Capgo update system!`);
|
|
670
|
-
pLog.info(`๐ฑ Go to your device where the app is running`);
|
|
671
|
-
if (delta) {
|
|
672
|
-
pLog.info(`๐ IMPORTANT: Background your app (swipe up/press home button) and then reopen it`);
|
|
673
|
-
pLog.info(`โฑ๏ธ The update should be downloaded and applied automatically`);
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
pLog.info(`๐ฑ With standard updates, you will need to:`);
|
|
677
|
-
pLog.info(` 1. Background the app (swipe up/press home button) to start download`);
|
|
678
|
-
pLog.info(` 2. Wait a few seconds for download to complete`);
|
|
679
|
-
pLog.info(` 3. Background and foreground again to see the update`);
|
|
680
|
-
}
|
|
681
|
-
pLog.info(`๐ You should see your changes appear in the app!`);
|
|
682
|
-
const doWaitLogs = await pConfirm({ message: `Monitor Capgo logs to verify the update worked?` });
|
|
683
|
-
await cancelCommand(doWaitLogs, orgId, apikey);
|
|
684
|
-
if (doWaitLogs) {
|
|
685
|
-
pLog.info(`๐ Watching logs from ${appId}...`);
|
|
686
|
-
pLog.info(`๐ Please background and reopen your app now to trigger the update`);
|
|
687
|
-
await waitLog('onboarding-v2', apikey, appId, apikey, orgId);
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
pLog.info(`๐ Check logs manually at ${hostWeb}/app/p/${appId}/logs to verify the update`);
|
|
691
|
-
}
|
|
692
|
-
await markStep(orgId, apikey, 'test-update', appId);
|
|
693
|
-
}
|
|
694
|
-
export async function initApp(apikeyCommand, appId, options) {
|
|
695
|
-
const pm = getPMAndCommand();
|
|
696
|
-
pIntro(`Capgo onboarding ๐ซ`);
|
|
697
|
-
await checkAlerts();
|
|
698
|
-
const extConfig = (!options.supaAnon || !options.supaHost)
|
|
699
|
-
? await getConfig()
|
|
700
|
-
: await updateConfigUpdater({
|
|
701
|
-
statsUrl: `${options.supaHost}/functions/v1/stats`,
|
|
702
|
-
channelUrl: `${options.supaHost}/functions/v1/channel_self`,
|
|
703
|
-
updateUrl: `${options.supaHost}/functions/v1/updates`,
|
|
704
|
-
localApiFiles: `${options.supaHost}/functions/v1`,
|
|
705
|
-
localS3: true,
|
|
706
|
-
localSupa: options.supaHost,
|
|
707
|
-
localSupaAnon: options.supaAnon,
|
|
708
|
-
});
|
|
709
|
-
const localConfig = await getLocalConfig();
|
|
710
|
-
appId = getAppId(appId, extConfig?.config);
|
|
711
|
-
options.apikey = apikeyCommand || findSavedKey();
|
|
712
|
-
if (appId === undefined) {
|
|
713
|
-
// ask for the appId
|
|
714
|
-
appId = await pText({
|
|
715
|
-
message: 'Enter your appId:',
|
|
716
|
-
});
|
|
717
|
-
if (pIsCancel(appId)) {
|
|
718
|
-
pCancel('Operation cancelled.');
|
|
719
|
-
exit(1);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
const log = pSpinner();
|
|
723
|
-
if (!doLoginExists() || apikeyCommand) {
|
|
724
|
-
log.start(`Running: ${pm.runner} @capgo/cli@latest login ***`);
|
|
725
|
-
await login(options.apikey, options, false);
|
|
726
|
-
log.stop('Login Done โ
');
|
|
727
|
-
}
|
|
728
|
-
const supabase = await createSupabaseClient(options.apikey, options.supaHost, options.supaAnon);
|
|
729
|
-
await verifyUser(supabase, options.apikey, ['upload', 'all', 'read', 'write']);
|
|
730
|
-
const organization = await getOrganization(supabase, ['admin', 'super_admin']);
|
|
731
|
-
const orgId = organization.gid;
|
|
732
|
-
const stepToSkip = await readStepsDone(orgId, options.apikey) ?? 0;
|
|
733
|
-
let pkgVersion = getBundleVersion(undefined, globalPathToPackageJson) || '1.0.0';
|
|
734
|
-
let delta = false;
|
|
735
|
-
let currentVersion = pkgVersion;
|
|
736
|
-
try {
|
|
737
|
-
if (stepToSkip < 1)
|
|
738
|
-
await markStep(orgId, options.apikey, 'add-app', appId);
|
|
739
|
-
if (stepToSkip < 2) {
|
|
740
|
-
await addAppStep(organization, options.apikey, appId, options);
|
|
741
|
-
markStepDone(2);
|
|
742
|
-
}
|
|
743
|
-
if (stepToSkip < 3) {
|
|
744
|
-
await addChannelStep(orgId, options.apikey, appId);
|
|
745
|
-
markStepDone(3);
|
|
746
|
-
}
|
|
747
|
-
if (stepToSkip < 4) {
|
|
748
|
-
const res = await addUpdaterStep(orgId, options.apikey, appId);
|
|
749
|
-
pkgVersion = res.pkgVersion;
|
|
750
|
-
currentVersion = pkgVersion;
|
|
751
|
-
delta = res.delta;
|
|
752
|
-
markStepDone(4);
|
|
753
|
-
}
|
|
754
|
-
if (stepToSkip < 5) {
|
|
755
|
-
await addCodeStep(orgId, options.apikey, appId);
|
|
756
|
-
markStepDone(5);
|
|
757
|
-
}
|
|
758
|
-
if (stepToSkip < 6) {
|
|
759
|
-
await addEncryptionStep(orgId, options.apikey, appId);
|
|
760
|
-
markStepDone(6);
|
|
761
|
-
}
|
|
762
|
-
if (stepToSkip < 7) {
|
|
763
|
-
await buildProjectStep(orgId, options.apikey, appId);
|
|
764
|
-
markStepDone(7);
|
|
765
|
-
}
|
|
766
|
-
if (stepToSkip < 8) {
|
|
767
|
-
await runDeviceStep(orgId, options.apikey, appId);
|
|
768
|
-
markStepDone(8);
|
|
769
|
-
}
|
|
770
|
-
if (stepToSkip < 9) {
|
|
771
|
-
currentVersion = await addCodeChangeStep(orgId, options.apikey, appId, pkgVersion);
|
|
772
|
-
markStepDone(9);
|
|
773
|
-
}
|
|
774
|
-
if (stepToSkip < 10) {
|
|
775
|
-
await uploadStep(orgId, options.apikey, appId, currentVersion, delta);
|
|
776
|
-
markStepDone(10);
|
|
777
|
-
}
|
|
778
|
-
if (stepToSkip < 11) {
|
|
779
|
-
await testCapgoUpdateStep(orgId, options.apikey, appId, localConfig.hostWeb, delta);
|
|
780
|
-
markStepDone(11);
|
|
781
|
-
}
|
|
782
|
-
await markStep(orgId, options.apikey, 'done', appId);
|
|
783
|
-
cleanupStepsDone();
|
|
784
|
-
}
|
|
785
|
-
catch (e) {
|
|
786
|
-
console.error(e);
|
|
787
|
-
pLog.error(`Error during onboarding.\n if the error persists please contact support@capgo.app\n Or use manual installation: https://capgo.app/docs/getting-started/add-an-app/`);
|
|
788
|
-
exit(1);
|
|
789
|
-
}
|
|
790
|
-
pLog.info(`Welcome onboard โ๏ธ!`);
|
|
791
|
-
pLog.info(`Your Capgo update system is setup`);
|
|
792
|
-
pLog.info(`Next time use \`${pm.runner} @capgo/cli@latest bundle upload\` to only upload your bundle`);
|
|
793
|
-
pLog.info(`If you have any issue try to use the debug command \`${pm.runner} @capgo/cli@latest app debug\``);
|
|
794
|
-
pOutro(`Bye ๐`);
|
|
795
|
-
exit();
|
|
796
|
-
}
|
|
797
|
-
//# sourceMappingURL=init.js.map
|