@strapi/cloud-cli 0.0.0-next.b11829e6c6aacb45bc1ec2f341609d04d88080d2 → 0.0.0-next.b558642be856459a3e6c076f5d76fffbfc5fc5a1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -3
- package/dist/index.js +664 -306
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +664 -303
- package/dist/index.mjs.map +1 -1
- package/dist/src/create-project/action.d.ts +1 -1
- package/dist/src/create-project/action.d.ts.map +1 -1
- package/dist/src/create-project/command.d.ts.map +1 -1
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts +3 -0
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts.map +1 -0
- package/dist/src/create-project/utils/project-questions.utils.d.ts +20 -0
- package/dist/src/create-project/utils/project-questions.utils.d.ts.map +1 -0
- package/dist/src/deploy-project/action.d.ts.map +1 -1
- package/dist/src/deploy-project/command.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/link/action.d.ts +4 -0
- package/dist/src/link/action.d.ts.map +1 -0
- package/dist/src/link/command.d.ts +7 -0
- package/dist/src/link/command.d.ts.map +1 -0
- package/dist/src/link/index.d.ts +7 -0
- package/dist/src/link/index.d.ts.map +1 -0
- package/dist/src/list-projects/action.d.ts +4 -0
- package/dist/src/list-projects/action.d.ts.map +1 -0
- package/dist/src/list-projects/command.d.ts +7 -0
- package/dist/src/list-projects/command.d.ts.map +1 -0
- package/dist/src/list-projects/index.d.ts +7 -0
- package/dist/src/list-projects/index.d.ts.map +1 -0
- package/dist/src/login/action.d.ts +2 -2
- package/dist/src/login/action.d.ts.map +1 -1
- package/dist/src/login/command.d.ts.map +1 -1
- package/dist/src/logout/action.d.ts.map +1 -1
- package/dist/src/logout/command.d.ts.map +1 -1
- package/dist/src/services/build-logs.d.ts.map +1 -1
- package/dist/src/services/cli-api.d.ts +38 -8
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/services/strapi-info-save.d.ts +1 -1
- package/dist/src/services/strapi-info-save.d.ts.map +1 -1
- package/dist/src/services/token.d.ts +1 -1
- package/dist/src/services/token.d.ts.map +1 -1
- package/dist/src/types.d.ts +2 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/analytics.d.ts +4 -0
- package/dist/src/utils/analytics.d.ts.map +1 -0
- package/dist/src/utils/compress-files.d.ts.map +1 -1
- package/dist/src/utils/pkg.d.ts.map +1 -1
- package/package.json +9 -8
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import crypto$1 from "crypto";
|
|
2
|
-
import fse from "fs-extra";
|
|
2
|
+
import * as fse from "fs-extra";
|
|
3
|
+
import fse__default from "fs-extra";
|
|
3
4
|
import * as path from "path";
|
|
4
5
|
import path__default from "path";
|
|
5
6
|
import chalk from "chalk";
|
|
6
7
|
import axios, { AxiosError } from "axios";
|
|
7
8
|
import * as crypto from "node:crypto";
|
|
8
9
|
import { env } from "@strapi/utils";
|
|
9
|
-
import * as fs from "fs";
|
|
10
10
|
import * as tar from "tar";
|
|
11
11
|
import { minimatch } from "minimatch";
|
|
12
12
|
import inquirer from "inquirer";
|
|
@@ -18,10 +18,10 @@ import jwt from "jsonwebtoken";
|
|
|
18
18
|
import stringify from "fast-safe-stringify";
|
|
19
19
|
import ora from "ora";
|
|
20
20
|
import * as cliProgress from "cli-progress";
|
|
21
|
-
import EventSource from "eventsource";
|
|
22
|
-
import fs$1 from "fs/promises";
|
|
23
21
|
import pkgUp from "pkg-up";
|
|
24
22
|
import * as yup from "yup";
|
|
23
|
+
import EventSource from "eventsource";
|
|
24
|
+
import { createCommand } from "commander";
|
|
25
25
|
const apiConfig = {
|
|
26
26
|
apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
27
27
|
dashboardBaseUrl: env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -40,23 +40,6 @@ const IGNORED_PATTERNS = [
|
|
|
40
40
|
"**/.idea/**",
|
|
41
41
|
"**/.vscode/**"
|
|
42
42
|
];
|
|
43
|
-
const getFiles = (dirPath, ignorePatterns = [], arrayOfFiles = [], subfolder = "") => {
|
|
44
|
-
const entries = fs.readdirSync(path.join(dirPath, subfolder));
|
|
45
|
-
entries.forEach((entry) => {
|
|
46
|
-
const entryPathFromRoot = path.join(subfolder, entry);
|
|
47
|
-
const entryPath = path.relative(dirPath, entryPathFromRoot);
|
|
48
|
-
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
49
|
-
if (isIgnored) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (fs.statSync(entryPath).isDirectory()) {
|
|
53
|
-
getFiles(dirPath, ignorePatterns, arrayOfFiles, entryPathFromRoot);
|
|
54
|
-
} else {
|
|
55
|
-
arrayOfFiles.push(entryPath);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return arrayOfFiles;
|
|
59
|
-
};
|
|
60
43
|
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
61
44
|
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
62
45
|
const relativeFilePath = path.join(folderPath, file);
|
|
@@ -74,16 +57,35 @@ const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
|
74
57
|
}
|
|
75
58
|
return isIgnored;
|
|
76
59
|
};
|
|
77
|
-
const
|
|
60
|
+
const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
61
|
+
const arrayOfFiles = [];
|
|
62
|
+
const entries = await fse.readdir(path.join(dirPath, subfolder));
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
const entryPathFromRoot = path.join(subfolder, entry);
|
|
65
|
+
const entryPath = path.relative(dirPath, entryPathFromRoot);
|
|
66
|
+
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
67
|
+
if (!isIgnored) {
|
|
68
|
+
if (fse.statSync(entryPath).isDirectory()) {
|
|
69
|
+
const subFiles = await getFiles(dirPath, ignorePatterns, entryPathFromRoot);
|
|
70
|
+
arrayOfFiles.push(...subFiles);
|
|
71
|
+
} else {
|
|
72
|
+
arrayOfFiles.push(entryPath);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return arrayOfFiles;
|
|
77
|
+
};
|
|
78
|
+
const readGitignore = async (folderPath) => {
|
|
78
79
|
const gitignorePath = path.resolve(folderPath, ".gitignore");
|
|
79
|
-
|
|
80
|
+
const pathExist = await fse.pathExists(gitignorePath);
|
|
81
|
+
if (!pathExist)
|
|
80
82
|
return [];
|
|
81
|
-
const gitignoreContent =
|
|
83
|
+
const gitignoreContent = await fse.readFile(gitignorePath, "utf8");
|
|
82
84
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
83
85
|
};
|
|
84
86
|
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
85
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
86
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
87
|
+
const ignorePatterns = await readGitignore(folderToCompress);
|
|
88
|
+
const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
|
|
87
89
|
return tar.c(
|
|
88
90
|
{
|
|
89
91
|
gzip: true,
|
|
@@ -96,7 +98,7 @@ const APP_FOLDER_NAME = "com.strapi.cli";
|
|
|
96
98
|
const CONFIG_FILENAME = "config.json";
|
|
97
99
|
async function checkDirectoryExists(directoryPath) {
|
|
98
100
|
try {
|
|
99
|
-
const fsStat = await
|
|
101
|
+
const fsStat = await fse__default.lstat(directoryPath);
|
|
100
102
|
return fsStat.isDirectory();
|
|
101
103
|
} catch (e) {
|
|
102
104
|
return false;
|
|
@@ -104,14 +106,14 @@ async function checkDirectoryExists(directoryPath) {
|
|
|
104
106
|
}
|
|
105
107
|
async function getTmpStoragePath() {
|
|
106
108
|
const storagePath = path__default.join(os.tmpdir(), APP_FOLDER_NAME);
|
|
107
|
-
await
|
|
109
|
+
await fse__default.ensureDir(storagePath);
|
|
108
110
|
return storagePath;
|
|
109
111
|
}
|
|
110
112
|
async function getConfigPath() {
|
|
111
113
|
const configDirs = XDGAppPaths(APP_FOLDER_NAME).configDirs();
|
|
112
114
|
const configPath = configDirs.find(checkDirectoryExists);
|
|
113
115
|
if (!configPath) {
|
|
114
|
-
await
|
|
116
|
+
await fse__default.ensureDir(configDirs[0]);
|
|
115
117
|
return configDirs[0];
|
|
116
118
|
}
|
|
117
119
|
return configPath;
|
|
@@ -119,9 +121,9 @@ async function getConfigPath() {
|
|
|
119
121
|
async function getLocalConfig() {
|
|
120
122
|
const configPath = await getConfigPath();
|
|
121
123
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
122
|
-
await
|
|
124
|
+
await fse__default.ensureFile(configFilePath);
|
|
123
125
|
try {
|
|
124
|
-
return await
|
|
126
|
+
return await fse__default.readJSON(configFilePath, { encoding: "utf8", throws: true });
|
|
125
127
|
} catch (e) {
|
|
126
128
|
return {};
|
|
127
129
|
}
|
|
@@ -129,10 +131,10 @@ async function getLocalConfig() {
|
|
|
129
131
|
async function saveLocalConfig(data) {
|
|
130
132
|
const configPath = await getConfigPath();
|
|
131
133
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
132
|
-
await
|
|
134
|
+
await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
133
135
|
}
|
|
134
136
|
const name = "@strapi/cloud-cli";
|
|
135
|
-
const version = "
|
|
137
|
+
const version = "5.0.2";
|
|
136
138
|
const description = "Commands to interact with the Strapi Cloud";
|
|
137
139
|
const keywords = [
|
|
138
140
|
"strapi",
|
|
@@ -173,17 +175,18 @@ const scripts = {
|
|
|
173
175
|
build: "pack-up build",
|
|
174
176
|
clean: "run -T rimraf ./dist",
|
|
175
177
|
lint: "run -T eslint .",
|
|
178
|
+
"test:unit": "run -T jest",
|
|
176
179
|
watch: "pack-up watch"
|
|
177
180
|
};
|
|
178
181
|
const dependencies = {
|
|
179
|
-
"@strapi/utils": "
|
|
180
|
-
axios: "1.
|
|
182
|
+
"@strapi/utils": "workspace:*",
|
|
183
|
+
axios: "1.7.4",
|
|
181
184
|
chalk: "4.1.2",
|
|
182
185
|
"cli-progress": "3.12.0",
|
|
183
186
|
commander: "8.3.0",
|
|
184
187
|
eventsource: "2.0.2",
|
|
185
188
|
"fast-safe-stringify": "2.1.1",
|
|
186
|
-
"fs-extra": "
|
|
189
|
+
"fs-extra": "11.2.0",
|
|
187
190
|
inquirer: "8.2.5",
|
|
188
191
|
jsonwebtoken: "9.0.0",
|
|
189
192
|
"jwks-rsa": "3.1.0",
|
|
@@ -192,7 +195,7 @@ const dependencies = {
|
|
|
192
195
|
open: "8.4.0",
|
|
193
196
|
ora: "5.4.1",
|
|
194
197
|
"pkg-up": "3.1.0",
|
|
195
|
-
tar: "6.1
|
|
198
|
+
tar: "6.2.1",
|
|
196
199
|
"xdg-app-paths": "8.3.0",
|
|
197
200
|
yup: "0.32.9"
|
|
198
201
|
};
|
|
@@ -201,8 +204,8 @@ const devDependencies = {
|
|
|
201
204
|
"@types/cli-progress": "3.11.5",
|
|
202
205
|
"@types/eventsource": "1.1.15",
|
|
203
206
|
"@types/lodash": "^4.14.191",
|
|
204
|
-
"eslint-config-custom": "
|
|
205
|
-
tsconfig: "
|
|
207
|
+
"eslint-config-custom": "workspace:*",
|
|
208
|
+
tsconfig: "workspace:*"
|
|
206
209
|
};
|
|
207
210
|
const engines = {
|
|
208
211
|
node: ">=18.0.0 <=20.x.x",
|
|
@@ -231,7 +234,7 @@ const packageJson = {
|
|
|
231
234
|
engines
|
|
232
235
|
};
|
|
233
236
|
const VERSION = "v1";
|
|
234
|
-
async function cloudApiFactory(token) {
|
|
237
|
+
async function cloudApiFactory({ logger }, token) {
|
|
235
238
|
const localConfig = await getLocalConfig();
|
|
236
239
|
const customHeaders = {
|
|
237
240
|
"x-device-id": localConfig.deviceId,
|
|
@@ -255,7 +258,7 @@ async function cloudApiFactory(token) {
|
|
|
255
258
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
256
259
|
return axiosCloudAPI.post(
|
|
257
260
|
`/deploy/${project.name}`,
|
|
258
|
-
{ file:
|
|
261
|
+
{ file: fse__default.createReadStream(filePath) },
|
|
259
262
|
{
|
|
260
263
|
headers: {
|
|
261
264
|
"Content-Type": "multipart/form-data"
|
|
@@ -284,11 +287,61 @@ async function cloudApiFactory(token) {
|
|
|
284
287
|
getUserInfo() {
|
|
285
288
|
return axiosCloudAPI.get("/user");
|
|
286
289
|
},
|
|
287
|
-
config() {
|
|
288
|
-
|
|
290
|
+
async config() {
|
|
291
|
+
try {
|
|
292
|
+
const response = await axiosCloudAPI.get("/config");
|
|
293
|
+
if (response.status !== 200) {
|
|
294
|
+
throw new Error("Error fetching cloud CLI config from the server.");
|
|
295
|
+
}
|
|
296
|
+
return response;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
logger.debug(
|
|
299
|
+
"🥲 Oops! Couldn't retrieve the cloud CLI config from the server. Please try again."
|
|
300
|
+
);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
async listProjects() {
|
|
305
|
+
try {
|
|
306
|
+
const response = await axiosCloudAPI.get("/projects");
|
|
307
|
+
if (response.status !== 200) {
|
|
308
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
309
|
+
}
|
|
310
|
+
return response;
|
|
311
|
+
} catch (error) {
|
|
312
|
+
logger.debug(
|
|
313
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
314
|
+
);
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
async listLinkProjects() {
|
|
319
|
+
try {
|
|
320
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
321
|
+
if (response.status !== 200) {
|
|
322
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
323
|
+
}
|
|
324
|
+
return response;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
logger.debug(
|
|
327
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
328
|
+
);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
289
331
|
},
|
|
290
|
-
|
|
291
|
-
|
|
332
|
+
async getProject({ name: name2 }) {
|
|
333
|
+
try {
|
|
334
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
335
|
+
if (response.status !== 200) {
|
|
336
|
+
throw new Error("Error fetching project's details.");
|
|
337
|
+
}
|
|
338
|
+
return response;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
logger.debug(
|
|
341
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
342
|
+
);
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
292
345
|
},
|
|
293
346
|
track(event, payload = {}) {
|
|
294
347
|
return axiosCloudAPI.post("/track", {
|
|
@@ -303,18 +356,18 @@ async function save(data, { directoryPath } = {}) {
|
|
|
303
356
|
const alreadyInFileData = await retrieve({ directoryPath });
|
|
304
357
|
const storedData = { ...alreadyInFileData, ...data };
|
|
305
358
|
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
306
|
-
await
|
|
307
|
-
await
|
|
359
|
+
await fse__default.ensureDir(path__default.dirname(pathToFile));
|
|
360
|
+
await fse__default.writeJson(pathToFile, storedData, { encoding: "utf8" });
|
|
308
361
|
}
|
|
309
362
|
async function retrieve({
|
|
310
363
|
directoryPath
|
|
311
364
|
} = {}) {
|
|
312
365
|
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
313
|
-
const pathExists = await
|
|
366
|
+
const pathExists = await fse__default.pathExists(pathToFile);
|
|
314
367
|
if (!pathExists) {
|
|
315
368
|
return {};
|
|
316
369
|
}
|
|
317
|
-
return
|
|
370
|
+
return fse__default.readJSON(pathToFile, { encoding: "utf8" });
|
|
318
371
|
}
|
|
319
372
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
320
373
|
__proto__: null,
|
|
@@ -324,7 +377,7 @@ const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defi
|
|
|
324
377
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
325
378
|
let cliConfig;
|
|
326
379
|
async function tokenServiceFactory({ logger }) {
|
|
327
|
-
const cloudApiService = await cloudApiFactory();
|
|
380
|
+
const cloudApiService = await cloudApiFactory({ logger });
|
|
328
381
|
async function saveToken(str) {
|
|
329
382
|
const appConfig = await getLocalConfig();
|
|
330
383
|
if (!appConfig) {
|
|
@@ -373,14 +426,17 @@ async function tokenServiceFactory({ logger }) {
|
|
|
373
426
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
374
427
|
);
|
|
375
428
|
}
|
|
429
|
+
return Promise.reject(new Error("Invalid token"));
|
|
376
430
|
}
|
|
377
431
|
return new Promise((resolve, reject) => {
|
|
378
432
|
jwt.verify(idToken, getKey, (err) => {
|
|
379
433
|
if (err) {
|
|
380
434
|
reject(err);
|
|
381
|
-
} else {
|
|
382
|
-
resolve();
|
|
383
435
|
}
|
|
436
|
+
if (decodedToken.payload.exp < Math.floor(Date.now() / 1e3)) {
|
|
437
|
+
reject(new Error("Token is expired"));
|
|
438
|
+
}
|
|
439
|
+
resolve();
|
|
384
440
|
});
|
|
385
441
|
});
|
|
386
442
|
}
|
|
@@ -414,15 +470,15 @@ async function tokenServiceFactory({ logger }) {
|
|
|
414
470
|
throw e;
|
|
415
471
|
}
|
|
416
472
|
}
|
|
417
|
-
async function getValidToken() {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
logger.log(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
473
|
+
async function getValidToken(ctx, loginAction2) {
|
|
474
|
+
let token = await retrieveToken();
|
|
475
|
+
while (!token || !await isTokenValid(token)) {
|
|
476
|
+
logger.log(
|
|
477
|
+
token ? "Oops! Your token seems expired or invalid. Please login again." : "We couldn't find a valid token. You need to be logged in to use this feature."
|
|
478
|
+
);
|
|
479
|
+
if (!await loginAction2(ctx))
|
|
480
|
+
return null;
|
|
481
|
+
token = await retrieveToken();
|
|
426
482
|
}
|
|
427
483
|
return token;
|
|
428
484
|
}
|
|
@@ -556,17 +612,257 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
556
612
|
local: strapiInfoSave,
|
|
557
613
|
tokenServiceFactory
|
|
558
614
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
559
|
-
|
|
615
|
+
yup.object({
|
|
616
|
+
name: yup.string().required(),
|
|
617
|
+
exports: yup.lazy(
|
|
618
|
+
(value) => yup.object(
|
|
619
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
620
|
+
(acc, [key, value2]) => {
|
|
621
|
+
if (typeof value2 === "object") {
|
|
622
|
+
acc[key] = yup.object({
|
|
623
|
+
types: yup.string().optional(),
|
|
624
|
+
source: yup.string().required(),
|
|
625
|
+
module: yup.string().optional(),
|
|
626
|
+
import: yup.string().required(),
|
|
627
|
+
require: yup.string().required(),
|
|
628
|
+
default: yup.string().required()
|
|
629
|
+
}).noUnknown(true);
|
|
630
|
+
} else {
|
|
631
|
+
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
632
|
+
}
|
|
633
|
+
return acc;
|
|
634
|
+
},
|
|
635
|
+
{}
|
|
636
|
+
) : void 0
|
|
637
|
+
).optional()
|
|
638
|
+
)
|
|
639
|
+
});
|
|
640
|
+
const loadPkg = async ({ cwd, logger }) => {
|
|
641
|
+
const pkgPath = await pkgUp({ cwd });
|
|
642
|
+
if (!pkgPath) {
|
|
643
|
+
throw new Error("Could not find a package.json in the current directory");
|
|
644
|
+
}
|
|
645
|
+
const buffer = await fse.readFile(pkgPath);
|
|
646
|
+
const pkg = JSON.parse(buffer.toString());
|
|
647
|
+
logger.debug("Loaded package.json:", os.EOL, pkg);
|
|
648
|
+
return pkg;
|
|
649
|
+
};
|
|
650
|
+
async function getProjectNameFromPackageJson(ctx) {
|
|
651
|
+
try {
|
|
652
|
+
const packageJson2 = await loadPkg(ctx);
|
|
653
|
+
return packageJson2.name || "my-strapi-project";
|
|
654
|
+
} catch (e) {
|
|
655
|
+
return "my-strapi-project";
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
659
|
+
try {
|
|
660
|
+
await cloudApiService.track(eventName, eventData);
|
|
661
|
+
} catch (e) {
|
|
662
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
const openModule$1 = import("open");
|
|
666
|
+
async function promptLogin(ctx) {
|
|
667
|
+
const response = await inquirer.prompt([
|
|
668
|
+
{
|
|
669
|
+
type: "confirm",
|
|
670
|
+
name: "login",
|
|
671
|
+
message: "Would you like to login?"
|
|
672
|
+
}
|
|
673
|
+
]);
|
|
674
|
+
if (response.login) {
|
|
675
|
+
const loginSuccessful = await loginAction(ctx);
|
|
676
|
+
return loginSuccessful;
|
|
677
|
+
}
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
async function loginAction(ctx) {
|
|
681
|
+
const { logger } = ctx;
|
|
560
682
|
const tokenService = await tokenServiceFactory(ctx);
|
|
683
|
+
const existingToken = await tokenService.retrieveToken();
|
|
684
|
+
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
685
|
+
if (existingToken) {
|
|
686
|
+
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
687
|
+
if (isTokenValid) {
|
|
688
|
+
try {
|
|
689
|
+
const userInfo = await cloudApiService.getUserInfo();
|
|
690
|
+
const { email } = userInfo.data.data;
|
|
691
|
+
if (email) {
|
|
692
|
+
logger.log(`You are already logged into your account (${email}).`);
|
|
693
|
+
} else {
|
|
694
|
+
logger.log("You are already logged in.");
|
|
695
|
+
}
|
|
696
|
+
logger.log(
|
|
697
|
+
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
698
|
+
);
|
|
699
|
+
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
700
|
+
return true;
|
|
701
|
+
} catch (e) {
|
|
702
|
+
logger.debug("Failed to fetch user info", e);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
let cliConfig2;
|
|
707
|
+
try {
|
|
708
|
+
logger.info("🔌 Connecting to the Strapi Cloud API...");
|
|
709
|
+
const config = await cloudApiService.config();
|
|
710
|
+
cliConfig2 = config.data;
|
|
711
|
+
} catch (e) {
|
|
712
|
+
logger.error("🥲 Oops! Something went wrong while logging you in. Please try again.");
|
|
713
|
+
logger.debug(e);
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
717
|
+
logger.debug("🔐 Creating device authentication request...", {
|
|
718
|
+
client_id: cliConfig2.clientId,
|
|
719
|
+
scope: cliConfig2.scope,
|
|
720
|
+
audience: cliConfig2.audience
|
|
721
|
+
});
|
|
722
|
+
const deviceAuthResponse = await axios.post(cliConfig2.deviceCodeAuthUrl, {
|
|
723
|
+
client_id: cliConfig2.clientId,
|
|
724
|
+
scope: cliConfig2.scope,
|
|
725
|
+
audience: cliConfig2.audience
|
|
726
|
+
}).catch((e) => {
|
|
727
|
+
logger.error("There was an issue with the authentication process. Please try again.");
|
|
728
|
+
if (e.message) {
|
|
729
|
+
logger.debug(e.message, e);
|
|
730
|
+
} else {
|
|
731
|
+
logger.debug(e);
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
openModule$1.then((open) => {
|
|
735
|
+
open.default(deviceAuthResponse.data.verification_uri_complete).catch((e) => {
|
|
736
|
+
logger.error("We encountered an issue opening the browser. Please try again later.");
|
|
737
|
+
logger.debug(e.message, e);
|
|
738
|
+
});
|
|
739
|
+
});
|
|
740
|
+
logger.log("If a browser tab does not open automatically, please follow the next steps:");
|
|
741
|
+
logger.log(
|
|
742
|
+
`1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
|
|
743
|
+
);
|
|
744
|
+
logger.log(
|
|
745
|
+
`2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
|
|
746
|
+
`
|
|
747
|
+
);
|
|
748
|
+
const tokenPayload = {
|
|
749
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
750
|
+
device_code: deviceAuthResponse.data.device_code,
|
|
751
|
+
client_id: cliConfig2.clientId
|
|
752
|
+
};
|
|
753
|
+
let isAuthenticated = false;
|
|
754
|
+
const authenticate = async () => {
|
|
755
|
+
const spinner = logger.spinner("Waiting for authentication");
|
|
756
|
+
spinner.start();
|
|
757
|
+
const spinnerFail = () => spinner.fail("Authentication failed!");
|
|
758
|
+
while (!isAuthenticated) {
|
|
759
|
+
try {
|
|
760
|
+
const tokenResponse = await axios.post(cliConfig2.tokenUrl, tokenPayload);
|
|
761
|
+
const authTokenData = tokenResponse.data;
|
|
762
|
+
if (tokenResponse.status === 200) {
|
|
763
|
+
try {
|
|
764
|
+
logger.debug("🔐 Validating token...");
|
|
765
|
+
await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
|
|
766
|
+
logger.debug("🔐 Token validation successful!");
|
|
767
|
+
} catch (e) {
|
|
768
|
+
logger.debug(e);
|
|
769
|
+
spinnerFail();
|
|
770
|
+
throw new Error("Unable to proceed: Token validation failed");
|
|
771
|
+
}
|
|
772
|
+
logger.debug("🔍 Fetching user information...");
|
|
773
|
+
const cloudApiServiceWithToken = await cloudApiFactory(ctx, authTokenData.access_token);
|
|
774
|
+
await cloudApiServiceWithToken.getUserInfo();
|
|
775
|
+
logger.debug("🔍 User information fetched successfully!");
|
|
776
|
+
try {
|
|
777
|
+
logger.debug("📝 Saving login information...");
|
|
778
|
+
await tokenService.saveToken(authTokenData.access_token);
|
|
779
|
+
logger.debug("📝 Login information saved successfully!");
|
|
780
|
+
isAuthenticated = true;
|
|
781
|
+
} catch (e) {
|
|
782
|
+
logger.error(
|
|
783
|
+
"There was a problem saving your login information. Please try logging in again."
|
|
784
|
+
);
|
|
785
|
+
logger.debug(e);
|
|
786
|
+
spinnerFail();
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
} catch (e) {
|
|
791
|
+
if (e.message === "Unable to proceed: Token validation failed") {
|
|
792
|
+
logger.error(
|
|
793
|
+
"There seems to be a problem with your login information. Please try logging in again."
|
|
794
|
+
);
|
|
795
|
+
spinnerFail();
|
|
796
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
800
|
+
logger.debug(e);
|
|
801
|
+
spinnerFail();
|
|
802
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
await new Promise((resolve) => {
|
|
806
|
+
setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
spinner.succeed("Authentication successful!");
|
|
811
|
+
logger.log("You are now logged into Strapi Cloud.");
|
|
812
|
+
logger.log(
|
|
813
|
+
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
814
|
+
);
|
|
815
|
+
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
816
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
817
|
+
};
|
|
818
|
+
await authenticate();
|
|
819
|
+
return isAuthenticated;
|
|
820
|
+
}
|
|
821
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
822
|
+
return (questions) => {
|
|
823
|
+
return questions.map((question) => {
|
|
824
|
+
const questionName = question.name;
|
|
825
|
+
if (questionName in questionsMap) {
|
|
826
|
+
const questionDefault = questionsMap[questionName];
|
|
827
|
+
if (typeof questionDefault === "function") {
|
|
828
|
+
return {
|
|
829
|
+
...question,
|
|
830
|
+
default: questionDefault(question)
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
return {
|
|
834
|
+
...question,
|
|
835
|
+
default: questionDefault
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
return question;
|
|
839
|
+
});
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function getDefaultsFromQuestions(questions) {
|
|
843
|
+
return questions.reduce((acc, question) => {
|
|
844
|
+
if (question.default && question.name) {
|
|
845
|
+
return { ...acc, [question.name]: question.default };
|
|
846
|
+
}
|
|
847
|
+
return acc;
|
|
848
|
+
}, {});
|
|
849
|
+
}
|
|
850
|
+
function getProjectNodeVersionDefault(question) {
|
|
851
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
852
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
853
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
854
|
+
if (choice) {
|
|
855
|
+
return choice.value;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return question.default;
|
|
859
|
+
}
|
|
860
|
+
async function handleError(ctx, error) {
|
|
561
861
|
const { logger } = ctx;
|
|
562
862
|
logger.debug(error);
|
|
563
863
|
if (error instanceof AxiosError) {
|
|
564
864
|
const errorMessage = typeof error.response?.data === "string" ? error.response.data : null;
|
|
565
865
|
switch (error.response?.status) {
|
|
566
|
-
case 401:
|
|
567
|
-
logger.error("Your session has expired. Please log in again.");
|
|
568
|
-
await tokenService.eraseToken();
|
|
569
|
-
return;
|
|
570
866
|
case 403:
|
|
571
867
|
logger.error(
|
|
572
868
|
errorMessage || "You do not have permission to create a project. Please contact support for assistance."
|
|
@@ -592,28 +888,53 @@ async function handleError(ctx, error) {
|
|
|
592
888
|
"We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance."
|
|
593
889
|
);
|
|
594
890
|
}
|
|
595
|
-
|
|
891
|
+
async function createProject$1(ctx, cloudApi, projectInput) {
|
|
596
892
|
const { logger } = ctx;
|
|
597
|
-
const
|
|
598
|
-
|
|
893
|
+
const spinner = logger.spinner("Setting up your project...").start();
|
|
894
|
+
try {
|
|
895
|
+
const { data } = await cloudApi.createProject(projectInput);
|
|
896
|
+
await save({ project: data });
|
|
897
|
+
spinner.succeed("Project created successfully!");
|
|
898
|
+
return data;
|
|
899
|
+
} catch (e) {
|
|
900
|
+
spinner.fail("An error occurred while creating the project on Strapi Cloud.");
|
|
901
|
+
throw e;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
const action$4 = async (ctx) => {
|
|
905
|
+
const { logger } = ctx;
|
|
906
|
+
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
907
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
599
908
|
if (!token) {
|
|
600
909
|
return;
|
|
601
910
|
}
|
|
602
|
-
const cloudApi = await cloudApiFactory(token);
|
|
911
|
+
const cloudApi = await cloudApiFactory(ctx, token);
|
|
603
912
|
const { data: config } = await cloudApi.config();
|
|
604
|
-
const
|
|
913
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
914
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
915
|
+
name: projectName,
|
|
916
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
917
|
+
});
|
|
918
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
919
|
+
const defaultValues = {
|
|
920
|
+
...config.projectCreation.defaults,
|
|
921
|
+
...getDefaultsFromQuestions(questions)
|
|
922
|
+
};
|
|
605
923
|
const projectAnswersDefaulted = defaults(defaultValues);
|
|
606
924
|
const projectAnswers = await inquirer.prompt(questions);
|
|
607
925
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
608
|
-
const spinner = logger.spinner("Setting up your project...").start();
|
|
609
926
|
try {
|
|
610
|
-
|
|
611
|
-
await save({ project: data });
|
|
612
|
-
spinner.succeed("Project created successfully!");
|
|
613
|
-
return data;
|
|
927
|
+
return await createProject$1(ctx, cloudApi, projectInput);
|
|
614
928
|
} catch (e) {
|
|
615
|
-
|
|
616
|
-
|
|
929
|
+
if (e instanceof AxiosError && e.response?.status === 401) {
|
|
930
|
+
logger.warn("Oops! Your session has expired. Please log in again to retry.");
|
|
931
|
+
await eraseToken();
|
|
932
|
+
if (await promptLogin(ctx)) {
|
|
933
|
+
return await createProject$1(ctx, cloudApi, projectInput);
|
|
934
|
+
}
|
|
935
|
+
} else {
|
|
936
|
+
await handleError(ctx, e);
|
|
937
|
+
}
|
|
617
938
|
}
|
|
618
939
|
};
|
|
619
940
|
function notificationServiceFactory({ logger }) {
|
|
@@ -647,38 +968,6 @@ function notificationServiceFactory({ logger }) {
|
|
|
647
968
|
};
|
|
648
969
|
};
|
|
649
970
|
}
|
|
650
|
-
yup.object({
|
|
651
|
-
name: yup.string().required(),
|
|
652
|
-
exports: yup.lazy(
|
|
653
|
-
(value) => yup.object(
|
|
654
|
-
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
655
|
-
if (typeof value2 === "object") {
|
|
656
|
-
acc[key] = yup.object({
|
|
657
|
-
types: yup.string().optional(),
|
|
658
|
-
source: yup.string().required(),
|
|
659
|
-
module: yup.string().optional(),
|
|
660
|
-
import: yup.string().required(),
|
|
661
|
-
require: yup.string().required(),
|
|
662
|
-
default: yup.string().required()
|
|
663
|
-
}).noUnknown(true);
|
|
664
|
-
} else {
|
|
665
|
-
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
666
|
-
}
|
|
667
|
-
return acc;
|
|
668
|
-
}, {}) : void 0
|
|
669
|
-
).optional()
|
|
670
|
-
)
|
|
671
|
-
});
|
|
672
|
-
const loadPkg = async ({ cwd, logger }) => {
|
|
673
|
-
const pkgPath = await pkgUp({ cwd });
|
|
674
|
-
if (!pkgPath) {
|
|
675
|
-
throw new Error("Could not find a package.json in the current directory");
|
|
676
|
-
}
|
|
677
|
-
const buffer = await fs$1.readFile(pkgPath);
|
|
678
|
-
const pkg = JSON.parse(buffer.toString());
|
|
679
|
-
logger.debug("Loaded package.json:", os.EOL, pkg);
|
|
680
|
-
return pkg;
|
|
681
|
-
};
|
|
682
971
|
const buildLogsServiceFactory = ({ logger }) => {
|
|
683
972
|
return async (url, token, cliConfig2) => {
|
|
684
973
|
const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
|
|
@@ -732,6 +1021,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
732
1021
|
if (retries > MAX_RETRIES) {
|
|
733
1022
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
734
1023
|
es.close();
|
|
1024
|
+
clearExistingTimeout();
|
|
735
1025
|
reject(new Error("Max retries reached"));
|
|
736
1026
|
}
|
|
737
1027
|
};
|
|
@@ -741,7 +1031,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
741
1031
|
};
|
|
742
1032
|
};
|
|
743
1033
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
744
|
-
const cloudApi = await cloudApiFactory(token);
|
|
1034
|
+
const cloudApi = await cloudApiFactory(ctx, token);
|
|
745
1035
|
try {
|
|
746
1036
|
const storagePath = await getTmpStoragePath();
|
|
747
1037
|
const projectFolder = path__default.resolve(process.cwd());
|
|
@@ -774,13 +1064,13 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
774
1064
|
process.exit(1);
|
|
775
1065
|
}
|
|
776
1066
|
const tarFilePath = path__default.resolve(storagePath, compressedFilename);
|
|
777
|
-
const fileStats = await
|
|
1067
|
+
const fileStats = await fse__default.stat(tarFilePath);
|
|
778
1068
|
if (fileStats.size > maxProjectFileSize) {
|
|
779
1069
|
ctx.logger.log(
|
|
780
1070
|
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
781
1071
|
);
|
|
782
1072
|
try {
|
|
783
|
-
await
|
|
1073
|
+
await fse__default.remove(tarFilePath);
|
|
784
1074
|
} catch (e) {
|
|
785
1075
|
ctx.logger.log("Unable to remove file: ", tarFilePath);
|
|
786
1076
|
ctx.logger.debug(e);
|
|
@@ -806,20 +1096,10 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
806
1096
|
return data.build_id;
|
|
807
1097
|
} catch (e) {
|
|
808
1098
|
progressBar.stop();
|
|
809
|
-
|
|
810
|
-
if (e.response.status === 404) {
|
|
811
|
-
ctx.logger.error(
|
|
812
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
813
|
-
);
|
|
814
|
-
} else {
|
|
815
|
-
ctx.logger.error(e.response.data);
|
|
816
|
-
}
|
|
817
|
-
} else {
|
|
818
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
819
|
-
}
|
|
1099
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
820
1100
|
ctx.logger.debug(e);
|
|
821
1101
|
} finally {
|
|
822
|
-
await
|
|
1102
|
+
await fse__default.remove(tarFilePath);
|
|
823
1103
|
}
|
|
824
1104
|
process.exit(0);
|
|
825
1105
|
} catch (e) {
|
|
@@ -832,7 +1112,7 @@ async function getProject(ctx) {
|
|
|
832
1112
|
const { project } = await retrieve();
|
|
833
1113
|
if (!project) {
|
|
834
1114
|
try {
|
|
835
|
-
return await action$
|
|
1115
|
+
return await action$4(ctx);
|
|
836
1116
|
} catch (e) {
|
|
837
1117
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
838
1118
|
ctx.logger.debug(e);
|
|
@@ -841,10 +1121,21 @@ async function getProject(ctx) {
|
|
|
841
1121
|
}
|
|
842
1122
|
return project;
|
|
843
1123
|
}
|
|
844
|
-
|
|
1124
|
+
async function getConfig({
|
|
1125
|
+
ctx,
|
|
1126
|
+
cloudApiService
|
|
1127
|
+
}) {
|
|
1128
|
+
try {
|
|
1129
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1130
|
+
return cliConfig2;
|
|
1131
|
+
} catch (e) {
|
|
1132
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1133
|
+
return null;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
const action$3 = async (ctx) => {
|
|
845
1137
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
846
|
-
const
|
|
847
|
-
const token = await getValidToken();
|
|
1138
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
848
1139
|
if (!token) {
|
|
849
1140
|
return;
|
|
850
1141
|
}
|
|
@@ -852,14 +1143,51 @@ const action$2 = async (ctx) => {
|
|
|
852
1143
|
if (!project) {
|
|
853
1144
|
return;
|
|
854
1145
|
}
|
|
1146
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
855
1147
|
try {
|
|
856
|
-
|
|
1148
|
+
const {
|
|
1149
|
+
data: { data: projectData, metadata }
|
|
1150
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1151
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1152
|
+
if (isProjectSuspended) {
|
|
1153
|
+
ctx.logger.log(
|
|
1154
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1155
|
+
);
|
|
1156
|
+
ctx.logger.log(chalk.underline(`${metadata.dashboardUrls.project}`));
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
857
1159
|
} catch (e) {
|
|
858
|
-
|
|
1160
|
+
if (e instanceof AxiosError && e.response?.data) {
|
|
1161
|
+
if (e.response.status === 404) {
|
|
1162
|
+
ctx.logger.warn(
|
|
1163
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1164
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1165
|
+
"link"
|
|
1166
|
+
)} command before deploying.`
|
|
1167
|
+
);
|
|
1168
|
+
} else {
|
|
1169
|
+
ctx.logger.error(e.response.data);
|
|
1170
|
+
}
|
|
1171
|
+
} else {
|
|
1172
|
+
ctx.logger.error(
|
|
1173
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
ctx.logger.debug(e);
|
|
1177
|
+
return;
|
|
859
1178
|
}
|
|
1179
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1180
|
+
projectInternalName: project.name
|
|
1181
|
+
});
|
|
860
1182
|
const notificationService = notificationServiceFactory(ctx);
|
|
861
1183
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
862
|
-
const
|
|
1184
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1185
|
+
if (!cliConfig2) {
|
|
1186
|
+
ctx.logger.error(
|
|
1187
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1188
|
+
);
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
863
1191
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
864
1192
|
if (Number.isNaN(maxSize)) {
|
|
865
1193
|
ctx.logger.debug(
|
|
@@ -881,10 +1209,11 @@ const action$2 = async (ctx) => {
|
|
|
881
1209
|
chalk.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
882
1210
|
);
|
|
883
1211
|
} catch (e) {
|
|
1212
|
+
ctx.logger.debug(e);
|
|
884
1213
|
if (e instanceof Error) {
|
|
885
1214
|
ctx.logger.error(e.message);
|
|
886
1215
|
} else {
|
|
887
|
-
|
|
1216
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
888
1217
|
}
|
|
889
1218
|
}
|
|
890
1219
|
};
|
|
@@ -915,185 +1244,175 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
915
1244
|
process.exit(1);
|
|
916
1245
|
});
|
|
917
1246
|
};
|
|
918
|
-
const command$
|
|
919
|
-
|
|
1247
|
+
const command$5 = ({ ctx }) => {
|
|
1248
|
+
return createCommand("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("deploy", action$3)(ctx));
|
|
920
1249
|
};
|
|
921
1250
|
const deployProject = {
|
|
922
1251
|
name: "deploy-project",
|
|
923
1252
|
description: "Deploy a Strapi Cloud project",
|
|
924
|
-
action: action$
|
|
925
|
-
command: command$
|
|
1253
|
+
action: action$3,
|
|
1254
|
+
command: command$5
|
|
926
1255
|
};
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
logger.log(`You are already logged into your account (${email}).`);
|
|
948
|
-
} else {
|
|
949
|
-
logger.log("You are already logged in.");
|
|
950
|
-
}
|
|
951
|
-
logger.log(
|
|
952
|
-
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
953
|
-
);
|
|
954
|
-
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
955
|
-
return true;
|
|
956
|
-
} catch (e) {
|
|
957
|
-
logger.debug("Failed to fetch user info", e);
|
|
1256
|
+
const QUIT_OPTION = "Quit";
|
|
1257
|
+
async function getExistingConfig(ctx) {
|
|
1258
|
+
try {
|
|
1259
|
+
return await retrieve();
|
|
1260
|
+
} catch (e) {
|
|
1261
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1262
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1267
|
+
if (existingConfig && existingConfig.project) {
|
|
1268
|
+
const { shouldRelink } = await inquirer.prompt([
|
|
1269
|
+
{
|
|
1270
|
+
type: "confirm",
|
|
1271
|
+
name: "shouldRelink",
|
|
1272
|
+
message: `A project named ${chalk.cyan(
|
|
1273
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1274
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1275
|
+
default: false
|
|
958
1276
|
}
|
|
1277
|
+
]);
|
|
1278
|
+
if (!shouldRelink) {
|
|
1279
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1280
|
+
currentProjectName: existingConfig.project?.name
|
|
1281
|
+
});
|
|
1282
|
+
return false;
|
|
959
1283
|
}
|
|
960
1284
|
}
|
|
961
|
-
|
|
1285
|
+
return true;
|
|
1286
|
+
}
|
|
1287
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1288
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
962
1289
|
try {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1290
|
+
const {
|
|
1291
|
+
data: { data: projectList }
|
|
1292
|
+
} = await cloudApiService.listLinkProjects();
|
|
1293
|
+
spinner.succeed();
|
|
1294
|
+
if (!Array.isArray(projectList)) {
|
|
1295
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1296
|
+
return null;
|
|
1297
|
+
}
|
|
1298
|
+
const projects = projectList.filter(
|
|
1299
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1300
|
+
).map((project) => {
|
|
1301
|
+
return {
|
|
1302
|
+
name: project.displayName,
|
|
1303
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1304
|
+
};
|
|
1305
|
+
});
|
|
1306
|
+
if (projects.length === 0) {
|
|
1307
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1308
|
+
return null;
|
|
1309
|
+
}
|
|
1310
|
+
return projects;
|
|
966
1311
|
} catch (e) {
|
|
967
|
-
|
|
968
|
-
logger.debug(e);
|
|
969
|
-
return
|
|
1312
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1313
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1314
|
+
return null;
|
|
970
1315
|
}
|
|
1316
|
+
}
|
|
1317
|
+
async function getUserSelection(ctx, projects) {
|
|
1318
|
+
const { logger } = ctx;
|
|
971
1319
|
try {
|
|
972
|
-
await
|
|
1320
|
+
const answer = await inquirer.prompt([
|
|
1321
|
+
{
|
|
1322
|
+
type: "list",
|
|
1323
|
+
name: "linkProject",
|
|
1324
|
+
message: "Which project do you want to link?",
|
|
1325
|
+
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1326
|
+
}
|
|
1327
|
+
]);
|
|
1328
|
+
if (!answer.linkProject) {
|
|
1329
|
+
return null;
|
|
1330
|
+
}
|
|
1331
|
+
return answer;
|
|
973
1332
|
} catch (e) {
|
|
974
|
-
logger.debug("Failed to
|
|
1333
|
+
logger.debug("Failed to get user input", e);
|
|
1334
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1335
|
+
return null;
|
|
975
1336
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
logger.error("We encountered an issue opening the browser. Please try again later.");
|
|
996
|
-
logger.debug(e.message, e);
|
|
997
|
-
});
|
|
998
|
-
});
|
|
999
|
-
logger.log("If a browser tab does not open automatically, please follow the next steps:");
|
|
1000
|
-
logger.log(
|
|
1001
|
-
`1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
|
|
1002
|
-
);
|
|
1003
|
-
logger.log(
|
|
1004
|
-
`2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
|
|
1005
|
-
`
|
|
1337
|
+
}
|
|
1338
|
+
const action$2 = async (ctx) => {
|
|
1339
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1340
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1341
|
+
const { logger } = ctx;
|
|
1342
|
+
if (!token) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1346
|
+
const existingConfig = await getExistingConfig(ctx);
|
|
1347
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1348
|
+
if (!shouldRelink) {
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1352
|
+
const projects = await getProjectsList(
|
|
1353
|
+
ctx,
|
|
1354
|
+
cloudApiService,
|
|
1355
|
+
existingConfig
|
|
1006
1356
|
);
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
if (tokenResponse.status === 200) {
|
|
1022
|
-
try {
|
|
1023
|
-
logger.debug("🔐 Validating token...");
|
|
1024
|
-
await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
|
|
1025
|
-
logger.debug("🔐 Token validation successful!");
|
|
1026
|
-
} catch (e) {
|
|
1027
|
-
logger.debug(e);
|
|
1028
|
-
spinnerFail();
|
|
1029
|
-
throw new Error("Unable to proceed: Token validation failed");
|
|
1030
|
-
}
|
|
1031
|
-
logger.debug("🔍 Fetching user information...");
|
|
1032
|
-
const cloudApiServiceWithToken = await cloudApiFactory(authTokenData.access_token);
|
|
1033
|
-
await cloudApiServiceWithToken.getUserInfo();
|
|
1034
|
-
logger.debug("🔍 User information fetched successfully!");
|
|
1035
|
-
try {
|
|
1036
|
-
logger.debug("📝 Saving login information...");
|
|
1037
|
-
await tokenService.saveToken(authTokenData.access_token);
|
|
1038
|
-
logger.debug("📝 Login information saved successfully!");
|
|
1039
|
-
isAuthenticated = true;
|
|
1040
|
-
} catch (e) {
|
|
1041
|
-
logger.error(
|
|
1042
|
-
"There was a problem saving your login information. Please try logging in again."
|
|
1043
|
-
);
|
|
1044
|
-
logger.debug(e);
|
|
1045
|
-
spinnerFail();
|
|
1046
|
-
return false;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
} catch (e) {
|
|
1050
|
-
if (e.message === "Unable to proceed: Token validation failed") {
|
|
1051
|
-
logger.error(
|
|
1052
|
-
"There seems to be a problem with your login information. Please try logging in again."
|
|
1053
|
-
);
|
|
1054
|
-
spinnerFail();
|
|
1055
|
-
await trackFailedLogin();
|
|
1056
|
-
return false;
|
|
1057
|
-
}
|
|
1058
|
-
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
1059
|
-
logger.debug(e);
|
|
1060
|
-
spinnerFail();
|
|
1061
|
-
await trackFailedLogin();
|
|
1062
|
-
return false;
|
|
1063
|
-
}
|
|
1064
|
-
await new Promise((resolve) => {
|
|
1065
|
-
setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
|
|
1066
|
-
});
|
|
1357
|
+
if (!projects) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1361
|
+
if (!answer) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
try {
|
|
1365
|
+
const { confirmAction } = await inquirer.prompt([
|
|
1366
|
+
{
|
|
1367
|
+
type: "confirm",
|
|
1368
|
+
name: "confirmAction",
|
|
1369
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1370
|
+
default: false
|
|
1067
1371
|
}
|
|
1372
|
+
]);
|
|
1373
|
+
if (!confirmAction) {
|
|
1374
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1375
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1376
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1377
|
+
});
|
|
1378
|
+
return;
|
|
1068
1379
|
}
|
|
1069
|
-
|
|
1070
|
-
logger.log(
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
);
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1380
|
+
await save({ project: answer.linkProject });
|
|
1381
|
+
logger.log(`Project ${chalk.cyan(answer.linkProject.displayName)} linked successfully.`);
|
|
1382
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1383
|
+
projectInternalName: answer.linkProject
|
|
1384
|
+
});
|
|
1385
|
+
} catch (e) {
|
|
1386
|
+
logger.debug("Failed to link project", e);
|
|
1387
|
+
logger.error("An error occurred while linking the project.");
|
|
1388
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1389
|
+
projectInternalName: answer.linkProject
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
const command$4 = ({ command: command2, ctx }) => {
|
|
1394
|
+
command2.command("cloud:link").alias("link").description("Link a local directory to a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("link", action$2)(ctx));
|
|
1083
1395
|
};
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1396
|
+
const link = {
|
|
1397
|
+
name: "link-project",
|
|
1398
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1399
|
+
action: action$2,
|
|
1400
|
+
command: command$4
|
|
1401
|
+
};
|
|
1402
|
+
const command$3 = ({ ctx }) => {
|
|
1403
|
+
return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1086
1404
|
"after",
|
|
1087
1405
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1088
|
-
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login",
|
|
1406
|
+
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
1089
1407
|
};
|
|
1090
1408
|
const login = {
|
|
1091
1409
|
name: "login",
|
|
1092
1410
|
description: "Strapi Cloud Login",
|
|
1093
|
-
action:
|
|
1094
|
-
command: command$
|
|
1411
|
+
action: loginAction,
|
|
1412
|
+
command: command$3
|
|
1095
1413
|
};
|
|
1096
|
-
const
|
|
1414
|
+
const openModule = import("open");
|
|
1415
|
+
const action$1 = async (ctx) => {
|
|
1097
1416
|
const { logger } = ctx;
|
|
1098
1417
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1099
1418
|
const token = await retrieveToken();
|
|
@@ -1101,9 +1420,21 @@ const action = async (ctx) => {
|
|
|
1101
1420
|
logger.log("You're already logged out.");
|
|
1102
1421
|
return;
|
|
1103
1422
|
}
|
|
1104
|
-
const cloudApiService = await cloudApiFactory(token);
|
|
1423
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1424
|
+
const config = await cloudApiService.config();
|
|
1425
|
+
const cliConfig2 = config.data;
|
|
1105
1426
|
try {
|
|
1106
1427
|
await eraseToken();
|
|
1428
|
+
openModule.then((open) => {
|
|
1429
|
+
open.default(
|
|
1430
|
+
`${cliConfig2.baseUrl}/oidc/logout?client_id=${encodeURIComponent(
|
|
1431
|
+
cliConfig2.clientId
|
|
1432
|
+
)}&logout_hint=${encodeURIComponent(token)}
|
|
1433
|
+
`
|
|
1434
|
+
).catch((e) => {
|
|
1435
|
+
logger.debug(e.message, e);
|
|
1436
|
+
});
|
|
1437
|
+
});
|
|
1107
1438
|
logger.log(
|
|
1108
1439
|
"🔌 You have been logged out from the CLI. If you are on a shared computer, please make sure to log out from the Strapi Cloud Dashboard as well."
|
|
1109
1440
|
);
|
|
@@ -1111,37 +1442,64 @@ const action = async (ctx) => {
|
|
|
1111
1442
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1112
1443
|
logger.debug(e);
|
|
1113
1444
|
}
|
|
1114
|
-
|
|
1115
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1116
|
-
} catch (e) {
|
|
1117
|
-
logger.debug("Failed to track logout event", e);
|
|
1118
|
-
}
|
|
1445
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1119
1446
|
};
|
|
1120
|
-
const command$
|
|
1121
|
-
|
|
1447
|
+
const command$2 = ({ ctx }) => {
|
|
1448
|
+
return createCommand("cloud:logout").alias("logout").description("Strapi Cloud Logout").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("logout", action$1)(ctx));
|
|
1122
1449
|
};
|
|
1123
1450
|
const logout = {
|
|
1124
1451
|
name: "logout",
|
|
1125
1452
|
description: "Strapi Cloud Logout",
|
|
1126
|
-
action,
|
|
1127
|
-
command: command$
|
|
1453
|
+
action: action$1,
|
|
1454
|
+
command: command$2
|
|
1128
1455
|
};
|
|
1129
|
-
const command = ({
|
|
1130
|
-
|
|
1456
|
+
const command$1 = ({ ctx }) => {
|
|
1457
|
+
return createCommand("cloud:create-project").description("Create a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("cloud:create-project", action$4)(ctx));
|
|
1131
1458
|
};
|
|
1132
1459
|
const createProject = {
|
|
1133
1460
|
name: "create-project",
|
|
1134
1461
|
description: "Create a new project",
|
|
1135
|
-
action: action$
|
|
1462
|
+
action: action$4,
|
|
1463
|
+
command: command$1
|
|
1464
|
+
};
|
|
1465
|
+
const action = async (ctx) => {
|
|
1466
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1467
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1468
|
+
const { logger } = ctx;
|
|
1469
|
+
if (!token) {
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1473
|
+
const spinner = logger.spinner("Fetching your projects...").start();
|
|
1474
|
+
try {
|
|
1475
|
+
const {
|
|
1476
|
+
data: { data: projectList }
|
|
1477
|
+
} = await cloudApiService.listProjects();
|
|
1478
|
+
spinner.succeed();
|
|
1479
|
+
logger.log(projectList);
|
|
1480
|
+
} catch (e) {
|
|
1481
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1482
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
const command = ({ command: command2, ctx }) => {
|
|
1486
|
+
command2.command("cloud:projects").alias("projects").description("List Strapi Cloud projects").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("projects", action)(ctx));
|
|
1487
|
+
};
|
|
1488
|
+
const listProjects = {
|
|
1489
|
+
name: "list-projects",
|
|
1490
|
+
description: "List Strapi Cloud projects",
|
|
1491
|
+
action,
|
|
1136
1492
|
command
|
|
1137
1493
|
};
|
|
1138
1494
|
const cli = {
|
|
1139
1495
|
deployProject,
|
|
1496
|
+
link,
|
|
1140
1497
|
login,
|
|
1141
1498
|
logout,
|
|
1142
|
-
createProject
|
|
1499
|
+
createProject,
|
|
1500
|
+
listProjects
|
|
1143
1501
|
};
|
|
1144
|
-
const cloudCommands = [deployProject, login, logout];
|
|
1502
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects];
|
|
1145
1503
|
async function initCloudCLIConfig() {
|
|
1146
1504
|
const localConfig = await getLocalConfig();
|
|
1147
1505
|
if (!localConfig.deviceId) {
|
|
@@ -1157,7 +1515,10 @@ async function buildStrapiCloudCommands({
|
|
|
1157
1515
|
await initCloudCLIConfig();
|
|
1158
1516
|
for (const cloudCommand of cloudCommands) {
|
|
1159
1517
|
try {
|
|
1160
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1518
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1519
|
+
if (subCommand) {
|
|
1520
|
+
command2.addCommand(subCommand);
|
|
1521
|
+
}
|
|
1161
1522
|
} catch (e) {
|
|
1162
1523
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1163
1524
|
}
|