@strapi/cloud-cli 0.0.0-next.9b0c43700e0ad92b33a4c97f1507f9f3243f2b6a → 0.0.0-next.a4bb06d54b493ab973659d0200e0e42937988850
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/dist/bin.js +2 -2
- package/dist/bin.js.map +1 -1
- package/dist/index.js +700 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +697 -124
- package/dist/index.mjs.map +1 -1
- package/dist/src/cloud/command.d.ts +3 -0
- package/dist/src/cloud/command.d.ts.map +1 -0
- 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/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 +5 -1
- 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/environment/command.d.ts +3 -0
- package/dist/src/environment/command.d.ts.map +1 -0
- package/dist/src/environment/link/action.d.ts +4 -0
- package/dist/src/environment/link/action.d.ts.map +1 -0
- package/dist/src/environment/link/command.d.ts +4 -0
- package/dist/src/environment/link/command.d.ts.map +1 -0
- package/dist/src/environment/link/index.d.ts +7 -0
- package/dist/src/environment/link/index.d.ts.map +1 -0
- package/dist/src/environment/list/action.d.ts +4 -0
- package/dist/src/environment/list/action.d.ts.map +1 -0
- package/dist/src/environment/list/command.d.ts +4 -0
- package/dist/src/environment/list/command.d.ts.map +1 -0
- package/dist/src/environment/list/index.d.ts +7 -0
- package/dist/src/environment/list/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -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/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 +58 -8
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/services/strapi-info-save.d.ts +15 -2
- package/dist/src/services/strapi-info-save.d.ts.map +1 -1
- package/dist/src/services/token.d.ts.map +1 -1
- package/dist/src/types.d.ts +8 -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/get-local-config.d.ts +6 -0
- package/dist/src/utils/get-local-config.d.ts.map +1 -0
- package/dist/src/utils/helpers.d.ts.map +1 -1
- package/dist/src/utils/pkg.d.ts.map +1 -1
- package/dist/src/utils/tests/compress-files.test.d.ts +2 -0
- package/dist/src/utils/tests/compress-files.test.d.ts.map +1 -0
- package/package.json +11 -11
- package/dist/src/create-project/utils/apply-default-name.d.ts +0 -7
- package/dist/src/create-project/utils/apply-default-name.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -24,6 +24,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
25
|
const crypto$1 = require("crypto");
|
|
26
26
|
const fse = require("fs-extra");
|
|
27
|
+
const inquirer = require("inquirer");
|
|
28
|
+
const boxen = require("boxen");
|
|
27
29
|
const path = require("path");
|
|
28
30
|
const chalk = require("chalk");
|
|
29
31
|
const axios = require("axios");
|
|
@@ -31,10 +33,10 @@ const crypto = require("node:crypto");
|
|
|
31
33
|
const utils = require("@strapi/utils");
|
|
32
34
|
const tar = require("tar");
|
|
33
35
|
const minimatch = require("minimatch");
|
|
34
|
-
const inquirer = require("inquirer");
|
|
35
36
|
const fp = require("lodash/fp");
|
|
36
37
|
const os = require("os");
|
|
37
38
|
const XDGAppPaths = require("xdg-app-paths");
|
|
39
|
+
const lodash = require("lodash");
|
|
38
40
|
const jwksClient = require("jwks-rsa");
|
|
39
41
|
const jwt = require("jsonwebtoken");
|
|
40
42
|
const stringify = require("fast-safe-stringify");
|
|
@@ -42,12 +44,11 @@ const ora = require("ora");
|
|
|
42
44
|
const cliProgress = require("cli-progress");
|
|
43
45
|
const pkgUp = require("pkg-up");
|
|
44
46
|
const yup = require("yup");
|
|
45
|
-
const _ = require("lodash");
|
|
46
47
|
const EventSource = require("eventsource");
|
|
48
|
+
const commander = require("commander");
|
|
47
49
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
48
50
|
function _interopNamespace(e) {
|
|
49
|
-
if (e && e.__esModule)
|
|
50
|
-
return e;
|
|
51
|
+
if (e && e.__esModule) return e;
|
|
51
52
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
52
53
|
if (e) {
|
|
53
54
|
for (const k in e) {
|
|
@@ -65,12 +66,13 @@ function _interopNamespace(e) {
|
|
|
65
66
|
}
|
|
66
67
|
const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
|
|
67
68
|
const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
|
|
69
|
+
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
70
|
+
const boxen__default = /* @__PURE__ */ _interopDefault(boxen);
|
|
68
71
|
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
69
72
|
const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
70
73
|
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
71
74
|
const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
|
|
72
75
|
const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
|
|
73
|
-
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
74
76
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
75
77
|
const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
|
|
76
78
|
const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
|
|
@@ -80,7 +82,6 @@ const ora__default = /* @__PURE__ */ _interopDefault(ora);
|
|
|
80
82
|
const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
|
|
81
83
|
const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
|
|
82
84
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
83
|
-
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
84
85
|
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
85
86
|
const apiConfig = {
|
|
86
87
|
apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
@@ -138,8 +139,7 @@ const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
|
138
139
|
const readGitignore = async (folderPath) => {
|
|
139
140
|
const gitignorePath = path__namespace.resolve(folderPath, ".gitignore");
|
|
140
141
|
const pathExist = await fse__namespace.pathExists(gitignorePath);
|
|
141
|
-
if (!pathExist)
|
|
142
|
-
return [];
|
|
142
|
+
if (!pathExist) return [];
|
|
143
143
|
const gitignoreContent = await fse__namespace.readFile(gitignorePath, "utf8");
|
|
144
144
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
145
145
|
};
|
|
@@ -178,7 +178,7 @@ async function getConfigPath() {
|
|
|
178
178
|
}
|
|
179
179
|
return configPath;
|
|
180
180
|
}
|
|
181
|
-
async function getLocalConfig() {
|
|
181
|
+
async function getLocalConfig$1() {
|
|
182
182
|
const configPath = await getConfigPath();
|
|
183
183
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
184
184
|
await fse__namespace.default.ensureFile(configFilePath);
|
|
@@ -194,7 +194,7 @@ async function saveLocalConfig(data) {
|
|
|
194
194
|
await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
195
195
|
}
|
|
196
196
|
const name = "@strapi/cloud-cli";
|
|
197
|
-
const version = "
|
|
197
|
+
const version = "5.7.0";
|
|
198
198
|
const description = "Commands to interact with the Strapi Cloud";
|
|
199
199
|
const keywords = [
|
|
200
200
|
"strapi",
|
|
@@ -239,14 +239,15 @@ const scripts = {
|
|
|
239
239
|
watch: "pack-up watch"
|
|
240
240
|
};
|
|
241
241
|
const dependencies = {
|
|
242
|
-
"@strapi/utils": "
|
|
243
|
-
axios: "1.
|
|
242
|
+
"@strapi/utils": "5.7.0",
|
|
243
|
+
axios: "1.7.4",
|
|
244
|
+
boxen: "5.1.2",
|
|
244
245
|
chalk: "4.1.2",
|
|
245
246
|
"cli-progress": "3.12.0",
|
|
246
247
|
commander: "8.3.0",
|
|
247
248
|
eventsource: "2.0.2",
|
|
248
249
|
"fast-safe-stringify": "2.1.1",
|
|
249
|
-
"fs-extra": "
|
|
250
|
+
"fs-extra": "11.2.0",
|
|
250
251
|
inquirer: "8.2.5",
|
|
251
252
|
jsonwebtoken: "9.0.0",
|
|
252
253
|
"jwks-rsa": "3.1.0",
|
|
@@ -255,20 +256,20 @@ const dependencies = {
|
|
|
255
256
|
open: "8.4.0",
|
|
256
257
|
ora: "5.4.1",
|
|
257
258
|
"pkg-up": "3.1.0",
|
|
258
|
-
tar: "6.1
|
|
259
|
+
tar: "6.2.1",
|
|
259
260
|
"xdg-app-paths": "8.3.0",
|
|
260
261
|
yup: "0.32.9"
|
|
261
262
|
};
|
|
262
263
|
const devDependencies = {
|
|
263
|
-
"@strapi/pack-up": "
|
|
264
|
+
"@strapi/pack-up": "5.0.2",
|
|
264
265
|
"@types/cli-progress": "3.11.5",
|
|
265
266
|
"@types/eventsource": "1.1.15",
|
|
266
267
|
"@types/lodash": "^4.14.191",
|
|
267
|
-
"eslint-config-custom": "
|
|
268
|
-
tsconfig: "
|
|
268
|
+
"eslint-config-custom": "5.7.0",
|
|
269
|
+
tsconfig: "5.7.0"
|
|
269
270
|
};
|
|
270
271
|
const engines = {
|
|
271
|
-
node: ">=18.0.0 <=
|
|
272
|
+
node: ">=18.0.0 <=22.x.x",
|
|
272
273
|
npm: ">=6.0.0"
|
|
273
274
|
};
|
|
274
275
|
const packageJson = {
|
|
@@ -295,7 +296,7 @@ const packageJson = {
|
|
|
295
296
|
};
|
|
296
297
|
const VERSION = "v1";
|
|
297
298
|
async function cloudApiFactory({ logger }, token) {
|
|
298
|
-
const localConfig = await getLocalConfig();
|
|
299
|
+
const localConfig = await getLocalConfig$1();
|
|
299
300
|
const customHeaders = {
|
|
300
301
|
"x-device-id": localConfig.deviceId,
|
|
301
302
|
"x-app-version": packageJson.version,
|
|
@@ -318,7 +319,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
318
319
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
319
320
|
return axiosCloudAPI.post(
|
|
320
321
|
`/deploy/${project.name}`,
|
|
321
|
-
{ file: fse__namespace.default.createReadStream(filePath) },
|
|
322
|
+
{ file: fse__namespace.default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
322
323
|
{
|
|
323
324
|
headers: {
|
|
324
325
|
"Content-Type": "multipart/form-data"
|
|
@@ -375,6 +376,62 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
375
376
|
throw error;
|
|
376
377
|
}
|
|
377
378
|
},
|
|
379
|
+
async listLinkProjects() {
|
|
380
|
+
try {
|
|
381
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
382
|
+
if (response.status !== 200) {
|
|
383
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
384
|
+
}
|
|
385
|
+
return response;
|
|
386
|
+
} catch (error) {
|
|
387
|
+
logger.debug(
|
|
388
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
389
|
+
);
|
|
390
|
+
throw error;
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
async listEnvironments({ name: name2 }) {
|
|
394
|
+
try {
|
|
395
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
396
|
+
if (response.status !== 200) {
|
|
397
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
398
|
+
}
|
|
399
|
+
return response;
|
|
400
|
+
} catch (error) {
|
|
401
|
+
logger.debug(
|
|
402
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
403
|
+
);
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
408
|
+
try {
|
|
409
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
410
|
+
if (response.status !== 200) {
|
|
411
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
412
|
+
}
|
|
413
|
+
return response;
|
|
414
|
+
} catch (error) {
|
|
415
|
+
logger.debug(
|
|
416
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
417
|
+
);
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
async getProject({ name: name2 }) {
|
|
422
|
+
try {
|
|
423
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
424
|
+
if (response.status !== 200) {
|
|
425
|
+
throw new Error("Error fetching project's details.");
|
|
426
|
+
}
|
|
427
|
+
return response;
|
|
428
|
+
} catch (error) {
|
|
429
|
+
logger.debug(
|
|
430
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
431
|
+
);
|
|
432
|
+
throw error;
|
|
433
|
+
}
|
|
434
|
+
},
|
|
378
435
|
track(event, payload = {}) {
|
|
379
436
|
return axiosCloudAPI.post("/track", {
|
|
380
437
|
event,
|
|
@@ -384,26 +441,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
384
441
|
};
|
|
385
442
|
}
|
|
386
443
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
444
|
+
const getFilePath = (directoryPath) => path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
387
445
|
async function save(data, { directoryPath } = {}) {
|
|
388
|
-
const
|
|
389
|
-
const storedData = { ...alreadyInFileData, ...data };
|
|
390
|
-
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
446
|
+
const pathToFile = getFilePath(directoryPath);
|
|
391
447
|
await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
392
|
-
await fse__namespace.default.writeJson(pathToFile,
|
|
448
|
+
await fse__namespace.default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
393
449
|
}
|
|
394
450
|
async function retrieve({
|
|
395
451
|
directoryPath
|
|
396
452
|
} = {}) {
|
|
397
|
-
const pathToFile =
|
|
453
|
+
const pathToFile = getFilePath(directoryPath);
|
|
398
454
|
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
399
455
|
if (!pathExists) {
|
|
400
456
|
return {};
|
|
401
457
|
}
|
|
402
458
|
return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
|
|
403
459
|
}
|
|
460
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
461
|
+
const pathToFile = getFilePath(directoryPath);
|
|
462
|
+
const existingData = await retrieve({ directoryPath });
|
|
463
|
+
if (!existingData) {
|
|
464
|
+
throw new Error("No configuration data found to patch.");
|
|
465
|
+
}
|
|
466
|
+
const newData = lodash.merge(existingData, patchData);
|
|
467
|
+
await fse__namespace.default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
468
|
+
}
|
|
469
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
470
|
+
const pathToFile = getFilePath(directoryPath);
|
|
471
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
472
|
+
if (pathExists) {
|
|
473
|
+
await fse__namespace.default.remove(pathToFile);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
404
476
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
405
477
|
__proto__: null,
|
|
406
478
|
LOCAL_SAVE_FILENAME,
|
|
479
|
+
deleteConfig,
|
|
480
|
+
patch,
|
|
407
481
|
retrieve,
|
|
408
482
|
save
|
|
409
483
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -411,7 +485,7 @@ let cliConfig;
|
|
|
411
485
|
async function tokenServiceFactory({ logger }) {
|
|
412
486
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
413
487
|
async function saveToken(str) {
|
|
414
|
-
const appConfig = await getLocalConfig();
|
|
488
|
+
const appConfig = await getLocalConfig$1();
|
|
415
489
|
if (!appConfig) {
|
|
416
490
|
logger.error("There was a problem saving your token. Please try again.");
|
|
417
491
|
return;
|
|
@@ -425,7 +499,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
425
499
|
}
|
|
426
500
|
}
|
|
427
501
|
async function retrieveToken() {
|
|
428
|
-
const appConfig = await getLocalConfig();
|
|
502
|
+
const appConfig = await getLocalConfig$1();
|
|
429
503
|
if (appConfig.token) {
|
|
430
504
|
if (await isTokenValid(appConfig.token)) {
|
|
431
505
|
return appConfig.token;
|
|
@@ -487,7 +561,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
487
561
|
}
|
|
488
562
|
}
|
|
489
563
|
async function eraseToken() {
|
|
490
|
-
const appConfig = await getLocalConfig();
|
|
564
|
+
const appConfig = await getLocalConfig$1();
|
|
491
565
|
if (!appConfig) {
|
|
492
566
|
return;
|
|
493
567
|
}
|
|
@@ -508,8 +582,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
508
582
|
logger.log(
|
|
509
583
|
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."
|
|
510
584
|
);
|
|
511
|
-
if (!await loginAction2(ctx))
|
|
512
|
-
return null;
|
|
585
|
+
if (!await loginAction2(ctx)) return null;
|
|
513
586
|
token = await retrieveToken();
|
|
514
587
|
}
|
|
515
588
|
return token;
|
|
@@ -648,21 +721,24 @@ yup__namespace.object({
|
|
|
648
721
|
name: yup__namespace.string().required(),
|
|
649
722
|
exports: yup__namespace.lazy(
|
|
650
723
|
(value) => yup__namespace.object(
|
|
651
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
724
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
725
|
+
(acc, [key, value2]) => {
|
|
726
|
+
if (typeof value2 === "object") {
|
|
727
|
+
acc[key] = yup__namespace.object({
|
|
728
|
+
types: yup__namespace.string().optional(),
|
|
729
|
+
source: yup__namespace.string().required(),
|
|
730
|
+
module: yup__namespace.string().optional(),
|
|
731
|
+
import: yup__namespace.string().required(),
|
|
732
|
+
require: yup__namespace.string().required(),
|
|
733
|
+
default: yup__namespace.string().required()
|
|
734
|
+
}).noUnknown(true);
|
|
735
|
+
} else {
|
|
736
|
+
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
737
|
+
}
|
|
738
|
+
return acc;
|
|
739
|
+
},
|
|
740
|
+
{}
|
|
741
|
+
) : void 0
|
|
666
742
|
).optional()
|
|
667
743
|
)
|
|
668
744
|
});
|
|
@@ -684,18 +760,13 @@ async function getProjectNameFromPackageJson(ctx) {
|
|
|
684
760
|
return "my-strapi-project";
|
|
685
761
|
}
|
|
686
762
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
return questionCopy;
|
|
696
|
-
});
|
|
697
|
-
return { newQuestions, newDefaultValues };
|
|
698
|
-
}
|
|
763
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
764
|
+
try {
|
|
765
|
+
await cloudApiService.track(eventName, eventData);
|
|
766
|
+
} catch (e) {
|
|
767
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
768
|
+
}
|
|
769
|
+
};
|
|
699
770
|
const openModule$1 = import("open");
|
|
700
771
|
async function promptLogin(ctx) {
|
|
701
772
|
const response = await inquirer__default.default.prompt([
|
|
@@ -716,13 +787,6 @@ async function loginAction(ctx) {
|
|
|
716
787
|
const tokenService = await tokenServiceFactory(ctx);
|
|
717
788
|
const existingToken = await tokenService.retrieveToken();
|
|
718
789
|
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
719
|
-
const trackFailedLogin = async () => {
|
|
720
|
-
try {
|
|
721
|
-
await cloudApiService.track("didNotLogin", { loginMethod: "cli" });
|
|
722
|
-
} catch (e) {
|
|
723
|
-
logger.debug("Failed to track failed login", e);
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
790
|
if (existingToken) {
|
|
727
791
|
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
728
792
|
if (isTokenValid) {
|
|
@@ -754,11 +818,7 @@ async function loginAction(ctx) {
|
|
|
754
818
|
logger.debug(e);
|
|
755
819
|
return false;
|
|
756
820
|
}
|
|
757
|
-
|
|
758
|
-
await cloudApiService.track("willLoginAttempt", {});
|
|
759
|
-
} catch (e) {
|
|
760
|
-
logger.debug("Failed to track login attempt", e);
|
|
761
|
-
}
|
|
821
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
762
822
|
logger.debug("🔐 Creating device authentication request...", {
|
|
763
823
|
client_id: cliConfig2.clientId,
|
|
764
824
|
scope: cliConfig2.scope,
|
|
@@ -838,13 +898,13 @@ async function loginAction(ctx) {
|
|
|
838
898
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
839
899
|
);
|
|
840
900
|
spinnerFail();
|
|
841
|
-
await
|
|
901
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
842
902
|
return false;
|
|
843
903
|
}
|
|
844
904
|
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
845
905
|
logger.debug(e);
|
|
846
906
|
spinnerFail();
|
|
847
|
-
await
|
|
907
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
848
908
|
return false;
|
|
849
909
|
}
|
|
850
910
|
await new Promise((resolve) => {
|
|
@@ -858,15 +918,50 @@ async function loginAction(ctx) {
|
|
|
858
918
|
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
859
919
|
);
|
|
860
920
|
logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
861
|
-
|
|
862
|
-
await cloudApiService.track("didLogin", { loginMethod: "cli" });
|
|
863
|
-
} catch (e) {
|
|
864
|
-
logger.debug("Failed to track login", e);
|
|
865
|
-
}
|
|
921
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
866
922
|
};
|
|
867
923
|
await authenticate();
|
|
868
924
|
return isAuthenticated;
|
|
869
925
|
}
|
|
926
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
927
|
+
return (questions) => {
|
|
928
|
+
return questions.map((question) => {
|
|
929
|
+
const questionName = question.name;
|
|
930
|
+
if (questionName in questionsMap) {
|
|
931
|
+
const questionDefault = questionsMap[questionName];
|
|
932
|
+
if (typeof questionDefault === "function") {
|
|
933
|
+
return {
|
|
934
|
+
...question,
|
|
935
|
+
default: questionDefault(question)
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
return {
|
|
939
|
+
...question,
|
|
940
|
+
default: questionDefault
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
return question;
|
|
944
|
+
});
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
function getDefaultsFromQuestions(questions) {
|
|
948
|
+
return questions.reduce((acc, question) => {
|
|
949
|
+
if (question.default && question.name) {
|
|
950
|
+
return { ...acc, [question.name]: question.default };
|
|
951
|
+
}
|
|
952
|
+
return acc;
|
|
953
|
+
}, {});
|
|
954
|
+
}
|
|
955
|
+
function getProjectNodeVersionDefault(question) {
|
|
956
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
957
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
958
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
959
|
+
if (choice) {
|
|
960
|
+
return choice.value;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return question.default;
|
|
964
|
+
}
|
|
870
965
|
async function handleError(ctx, error) {
|
|
871
966
|
const { logger } = ctx;
|
|
872
967
|
logger.debug(error);
|
|
@@ -911,7 +1006,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
911
1006
|
throw e;
|
|
912
1007
|
}
|
|
913
1008
|
}
|
|
914
|
-
const action$
|
|
1009
|
+
const action$6 = async (ctx) => {
|
|
915
1010
|
const { logger } = ctx;
|
|
916
1011
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
917
1012
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -920,11 +1015,16 @@ const action$3 = async (ctx) => {
|
|
|
920
1015
|
}
|
|
921
1016
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
922
1017
|
const { data: config } = await cloudApi.config();
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
);
|
|
1018
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
1019
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
1020
|
+
name: projectName,
|
|
1021
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
1022
|
+
});
|
|
1023
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
1024
|
+
const defaultValues = {
|
|
1025
|
+
...config.projectCreation.defaults,
|
|
1026
|
+
...getDefaultsFromQuestions(questions)
|
|
1027
|
+
};
|
|
928
1028
|
const projectAnswersDefaulted = fp.defaults(defaultValues);
|
|
929
1029
|
const projectAnswers = await inquirer__default.default.prompt(questions);
|
|
930
1030
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -1026,6 +1126,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1026
1126
|
if (retries > MAX_RETRIES) {
|
|
1027
1127
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
1028
1128
|
es.close();
|
|
1129
|
+
clearExistingTimeout();
|
|
1029
1130
|
reject(new Error("Max retries reached"));
|
|
1030
1131
|
}
|
|
1031
1132
|
};
|
|
@@ -1034,6 +1135,29 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1034
1135
|
});
|
|
1035
1136
|
};
|
|
1036
1137
|
};
|
|
1138
|
+
const boxenOptions = {
|
|
1139
|
+
padding: 1,
|
|
1140
|
+
margin: 1,
|
|
1141
|
+
align: "center",
|
|
1142
|
+
borderColor: "yellow",
|
|
1143
|
+
borderStyle: "round"
|
|
1144
|
+
};
|
|
1145
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1146
|
+
async function promptForEnvironment(environments) {
|
|
1147
|
+
const choices = environments.map((env) => ({ name: env, value: env }));
|
|
1148
|
+
const { selectedEnvironment } = await inquirer__default.default.prompt([
|
|
1149
|
+
{
|
|
1150
|
+
type: "list",
|
|
1151
|
+
name: "selectedEnvironment",
|
|
1152
|
+
message: "Select the environment to deploy:",
|
|
1153
|
+
choices: [...choices, { name: chalk__default.default.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1154
|
+
}
|
|
1155
|
+
]);
|
|
1156
|
+
if (selectedEnvironment === null) {
|
|
1157
|
+
process.exit(1);
|
|
1158
|
+
}
|
|
1159
|
+
return selectedEnvironment;
|
|
1160
|
+
}
|
|
1037
1161
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1038
1162
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1039
1163
|
try {
|
|
@@ -1100,17 +1224,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1100
1224
|
return data.build_id;
|
|
1101
1225
|
} catch (e) {
|
|
1102
1226
|
progressBar.stop();
|
|
1103
|
-
|
|
1104
|
-
if (e.response.status === 404) {
|
|
1105
|
-
ctx.logger.error(
|
|
1106
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
1107
|
-
);
|
|
1108
|
-
} else {
|
|
1109
|
-
ctx.logger.error(e.response.data);
|
|
1110
|
-
}
|
|
1111
|
-
} else {
|
|
1112
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1113
|
-
}
|
|
1227
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1114
1228
|
ctx.logger.debug(e);
|
|
1115
1229
|
} finally {
|
|
1116
1230
|
await fse__namespace.default.remove(tarFilePath);
|
|
@@ -1126,7 +1240,7 @@ async function getProject(ctx) {
|
|
|
1126
1240
|
const { project } = await retrieve();
|
|
1127
1241
|
if (!project) {
|
|
1128
1242
|
try {
|
|
1129
|
-
return await action$
|
|
1243
|
+
return await action$6(ctx);
|
|
1130
1244
|
} catch (e) {
|
|
1131
1245
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1132
1246
|
ctx.logger.debug(e);
|
|
@@ -1135,7 +1249,45 @@ async function getProject(ctx) {
|
|
|
1135
1249
|
}
|
|
1136
1250
|
return project;
|
|
1137
1251
|
}
|
|
1138
|
-
|
|
1252
|
+
async function getConfig({
|
|
1253
|
+
ctx,
|
|
1254
|
+
cloudApiService
|
|
1255
|
+
}) {
|
|
1256
|
+
try {
|
|
1257
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1258
|
+
return cliConfig2;
|
|
1259
|
+
} catch (e) {
|
|
1260
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1261
|
+
return null;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1265
|
+
if (!environments.includes(environment)) {
|
|
1266
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1267
|
+
process.exit(1);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1271
|
+
if (opts.env) {
|
|
1272
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1273
|
+
return opts.env;
|
|
1274
|
+
}
|
|
1275
|
+
if (project.targetEnvironment) {
|
|
1276
|
+
return project.targetEnvironment;
|
|
1277
|
+
}
|
|
1278
|
+
if (environments.length > 1) {
|
|
1279
|
+
return promptForEnvironment(environments);
|
|
1280
|
+
}
|
|
1281
|
+
return environments[0];
|
|
1282
|
+
}
|
|
1283
|
+
function hasPendingOrLiveDeployment(environments, targetEnvironment) {
|
|
1284
|
+
const environment = environments.find((env) => env.name === targetEnvironment);
|
|
1285
|
+
if (!environment) {
|
|
1286
|
+
throw new Error(`Environment details ${targetEnvironment} not found.`);
|
|
1287
|
+
}
|
|
1288
|
+
return environment.hasPendingDeployment || environment.hasLiveDeployment || false;
|
|
1289
|
+
}
|
|
1290
|
+
const action$5 = async (ctx, opts) => {
|
|
1139
1291
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1140
1292
|
const token = await getValidToken(ctx, promptLogin);
|
|
1141
1293
|
if (!token) {
|
|
@@ -1145,15 +1297,57 @@ const action$2 = async (ctx) => {
|
|
|
1145
1297
|
if (!project) {
|
|
1146
1298
|
return;
|
|
1147
1299
|
}
|
|
1148
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1300
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1301
|
+
let projectData;
|
|
1302
|
+
let environments;
|
|
1303
|
+
let environmentsDetails;
|
|
1149
1304
|
try {
|
|
1150
|
-
|
|
1305
|
+
const {
|
|
1306
|
+
data: { data, metadata }
|
|
1307
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1308
|
+
projectData = data;
|
|
1309
|
+
environments = projectData.environments;
|
|
1310
|
+
environmentsDetails = projectData.environmentsDetails;
|
|
1311
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1312
|
+
if (isProjectSuspended) {
|
|
1313
|
+
ctx.logger.log(
|
|
1314
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1315
|
+
);
|
|
1316
|
+
ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1151
1319
|
} catch (e) {
|
|
1152
|
-
|
|
1320
|
+
if (e instanceof axios.AxiosError && e.response?.data) {
|
|
1321
|
+
if (e.response.status === 404) {
|
|
1322
|
+
ctx.logger.warn(
|
|
1323
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1324
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1325
|
+
"link"
|
|
1326
|
+
)} command before deploying.`
|
|
1327
|
+
);
|
|
1328
|
+
} else {
|
|
1329
|
+
ctx.logger.error(e.response.data);
|
|
1330
|
+
}
|
|
1331
|
+
} else {
|
|
1332
|
+
ctx.logger.error(
|
|
1333
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
ctx.logger.debug(e);
|
|
1337
|
+
return;
|
|
1153
1338
|
}
|
|
1339
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1340
|
+
projectInternalName: project.name
|
|
1341
|
+
});
|
|
1154
1342
|
const notificationService = notificationServiceFactory(ctx);
|
|
1155
1343
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
1156
|
-
const
|
|
1344
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1345
|
+
if (!cliConfig2) {
|
|
1346
|
+
ctx.logger.error(
|
|
1347
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1348
|
+
);
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1157
1351
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
1158
1352
|
if (Number.isNaN(maxSize)) {
|
|
1159
1353
|
ctx.logger.debug(
|
|
@@ -1161,11 +1355,34 @@ const action$2 = async (ctx) => {
|
|
|
1161
1355
|
);
|
|
1162
1356
|
maxSize = 1e8;
|
|
1163
1357
|
}
|
|
1358
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1359
|
+
if (!opts.force) {
|
|
1360
|
+
const shouldDisplayWarning = hasPendingOrLiveDeployment(
|
|
1361
|
+
environmentsDetails,
|
|
1362
|
+
project.targetEnvironment
|
|
1363
|
+
);
|
|
1364
|
+
if (shouldDisplayWarning) {
|
|
1365
|
+
ctx.logger.log(boxen__default.default(cliConfig2.projectDeployment.confirmationText, boxenOptions));
|
|
1366
|
+
const { confirm } = await inquirer__default.default.prompt([
|
|
1367
|
+
{
|
|
1368
|
+
type: "confirm",
|
|
1369
|
+
name: "confirm",
|
|
1370
|
+
message: `Do you want to proceed with deployment to ${chalk__default.default.cyan(projectData.displayName)} on ${chalk__default.default.cyan(project.targetEnvironment)} environment?`
|
|
1371
|
+
}
|
|
1372
|
+
]);
|
|
1373
|
+
if (!confirm) {
|
|
1374
|
+
process.exit(1);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1164
1378
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1165
1379
|
if (!buildId) {
|
|
1166
1380
|
return;
|
|
1167
1381
|
}
|
|
1168
1382
|
try {
|
|
1383
|
+
ctx.logger.log(
|
|
1384
|
+
`🚀 Deploying project to ${chalk__default.default.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1385
|
+
);
|
|
1169
1386
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1170
1387
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1171
1388
|
ctx.logger.log(
|
|
@@ -1175,10 +1392,11 @@ const action$2 = async (ctx) => {
|
|
|
1175
1392
|
chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
1176
1393
|
);
|
|
1177
1394
|
} catch (e) {
|
|
1395
|
+
ctx.logger.debug(e);
|
|
1178
1396
|
if (e instanceof Error) {
|
|
1179
1397
|
ctx.logger.error(e.message);
|
|
1180
1398
|
} else {
|
|
1181
|
-
|
|
1399
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1182
1400
|
}
|
|
1183
1401
|
}
|
|
1184
1402
|
};
|
|
@@ -1209,17 +1427,179 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1209
1427
|
process.exit(1);
|
|
1210
1428
|
});
|
|
1211
1429
|
};
|
|
1212
|
-
const command$
|
|
1213
|
-
|
|
1430
|
+
const command$7 = ({ ctx }) => {
|
|
1431
|
+
return commander.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").option("-f, --force", "Skip confirmation to deploy").option("-e, --env <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$5)(ctx, opts));
|
|
1214
1432
|
};
|
|
1215
1433
|
const deployProject = {
|
|
1216
1434
|
name: "deploy-project",
|
|
1217
1435
|
description: "Deploy a Strapi Cloud project",
|
|
1218
|
-
action: action$
|
|
1219
|
-
command: command$
|
|
1436
|
+
action: action$5,
|
|
1437
|
+
command: command$7
|
|
1438
|
+
};
|
|
1439
|
+
async function getLocalConfig(ctx) {
|
|
1440
|
+
try {
|
|
1441
|
+
return await retrieve();
|
|
1442
|
+
} catch (e) {
|
|
1443
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1444
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1445
|
+
return null;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
async function getLocalProject(ctx) {
|
|
1449
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1450
|
+
if (!localConfig || !localConfig.project) {
|
|
1451
|
+
ctx.logger.warn(
|
|
1452
|
+
`
|
|
1453
|
+
We couldn't find a valid local project config.
|
|
1454
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1455
|
+
"link"
|
|
1456
|
+
)} command.`
|
|
1457
|
+
);
|
|
1458
|
+
process.exit(1);
|
|
1459
|
+
}
|
|
1460
|
+
return localConfig.project;
|
|
1461
|
+
}
|
|
1462
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1463
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1464
|
+
if (existingConfig && existingConfig.project) {
|
|
1465
|
+
const { shouldRelink } = await inquirer__default.default.prompt([
|
|
1466
|
+
{
|
|
1467
|
+
type: "confirm",
|
|
1468
|
+
name: "shouldRelink",
|
|
1469
|
+
message: `A project named ${chalk__default.default.cyan(
|
|
1470
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1471
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1472
|
+
default: false
|
|
1473
|
+
}
|
|
1474
|
+
]);
|
|
1475
|
+
if (!shouldRelink) {
|
|
1476
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1477
|
+
currentProjectName: existingConfig.project?.name
|
|
1478
|
+
});
|
|
1479
|
+
return false;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return true;
|
|
1483
|
+
}
|
|
1484
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1485
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
1486
|
+
try {
|
|
1487
|
+
const {
|
|
1488
|
+
data: { data: projectList }
|
|
1489
|
+
} = await cloudApiService.listLinkProjects();
|
|
1490
|
+
spinner.succeed();
|
|
1491
|
+
if (!Array.isArray(projectList)) {
|
|
1492
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1495
|
+
const projects = projectList.filter(
|
|
1496
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1497
|
+
).map((project) => {
|
|
1498
|
+
return {
|
|
1499
|
+
name: project.displayName,
|
|
1500
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1501
|
+
};
|
|
1502
|
+
});
|
|
1503
|
+
if (projects.length === 0) {
|
|
1504
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1505
|
+
return null;
|
|
1506
|
+
}
|
|
1507
|
+
return projects;
|
|
1508
|
+
} catch (e) {
|
|
1509
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1510
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1511
|
+
return null;
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
async function getUserSelection(ctx, projects) {
|
|
1515
|
+
const { logger } = ctx;
|
|
1516
|
+
try {
|
|
1517
|
+
const answer = await inquirer__default.default.prompt([
|
|
1518
|
+
{
|
|
1519
|
+
type: "list",
|
|
1520
|
+
name: "linkProject",
|
|
1521
|
+
message: "Which project do you want to link?",
|
|
1522
|
+
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1523
|
+
}
|
|
1524
|
+
]);
|
|
1525
|
+
if (!answer.linkProject) {
|
|
1526
|
+
return null;
|
|
1527
|
+
}
|
|
1528
|
+
return answer;
|
|
1529
|
+
} catch (e) {
|
|
1530
|
+
logger.debug("Failed to get user input", e);
|
|
1531
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1532
|
+
return null;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
const action$4 = async (ctx) => {
|
|
1536
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1537
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1538
|
+
const { logger } = ctx;
|
|
1539
|
+
if (!token) {
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1543
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1544
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1545
|
+
if (!shouldRelink) {
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1549
|
+
const projects = await getProjectsList(
|
|
1550
|
+
ctx,
|
|
1551
|
+
cloudApiService,
|
|
1552
|
+
existingConfig
|
|
1553
|
+
);
|
|
1554
|
+
if (!projects) {
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1558
|
+
if (!answer) {
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
try {
|
|
1562
|
+
const { confirmAction } = await inquirer__default.default.prompt([
|
|
1563
|
+
{
|
|
1564
|
+
type: "confirm",
|
|
1565
|
+
name: "confirmAction",
|
|
1566
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1567
|
+
default: false
|
|
1568
|
+
}
|
|
1569
|
+
]);
|
|
1570
|
+
if (!confirmAction) {
|
|
1571
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1572
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1573
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1574
|
+
});
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
await save({ project: answer.linkProject });
|
|
1578
|
+
logger.log(
|
|
1579
|
+
` You have successfully linked your project to ${chalk__default.default.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1580
|
+
);
|
|
1581
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1582
|
+
projectInternalName: answer.linkProject
|
|
1583
|
+
});
|
|
1584
|
+
} catch (e) {
|
|
1585
|
+
logger.debug("Failed to link project", e);
|
|
1586
|
+
logger.error("An error occurred while linking the project.");
|
|
1587
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1588
|
+
projectInternalName: answer.linkProject
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1220
1591
|
};
|
|
1221
|
-
const command$
|
|
1222
|
-
command2.command("cloud:
|
|
1592
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1593
|
+
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$4)(ctx));
|
|
1594
|
+
};
|
|
1595
|
+
const link = {
|
|
1596
|
+
name: "link-project",
|
|
1597
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1598
|
+
action: action$4,
|
|
1599
|
+
command: command$6
|
|
1600
|
+
};
|
|
1601
|
+
const command$5 = ({ ctx }) => {
|
|
1602
|
+
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1223
1603
|
"after",
|
|
1224
1604
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1225
1605
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1228,10 +1608,10 @@ const login = {
|
|
|
1228
1608
|
name: "login",
|
|
1229
1609
|
description: "Strapi Cloud Login",
|
|
1230
1610
|
action: loginAction,
|
|
1231
|
-
command: command$
|
|
1611
|
+
command: command$5
|
|
1232
1612
|
};
|
|
1233
1613
|
const openModule = import("open");
|
|
1234
|
-
const action$
|
|
1614
|
+
const action$3 = async (ctx) => {
|
|
1235
1615
|
const { logger } = ctx;
|
|
1236
1616
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1237
1617
|
const token = await retrieveToken();
|
|
@@ -1261,31 +1641,27 @@ const action$1 = async (ctx) => {
|
|
|
1261
1641
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1262
1642
|
logger.debug(e);
|
|
1263
1643
|
}
|
|
1264
|
-
|
|
1265
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1266
|
-
} catch (e) {
|
|
1267
|
-
logger.debug("Failed to track logout event", e);
|
|
1268
|
-
}
|
|
1644
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1269
1645
|
};
|
|
1270
|
-
const command$
|
|
1271
|
-
|
|
1646
|
+
const command$4 = ({ ctx }) => {
|
|
1647
|
+
return commander.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$3)(ctx));
|
|
1272
1648
|
};
|
|
1273
1649
|
const logout = {
|
|
1274
1650
|
name: "logout",
|
|
1275
1651
|
description: "Strapi Cloud Logout",
|
|
1276
|
-
action: action$
|
|
1277
|
-
command: command$
|
|
1652
|
+
action: action$3,
|
|
1653
|
+
command: command$4
|
|
1278
1654
|
};
|
|
1279
|
-
const command$
|
|
1280
|
-
|
|
1655
|
+
const command$3 = ({ ctx }) => {
|
|
1656
|
+
return commander.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$6)(ctx));
|
|
1281
1657
|
};
|
|
1282
1658
|
const createProject = {
|
|
1283
1659
|
name: "create-project",
|
|
1284
1660
|
description: "Create a new project",
|
|
1285
|
-
action: action$
|
|
1286
|
-
command: command$
|
|
1661
|
+
action: action$6,
|
|
1662
|
+
command: command$3
|
|
1287
1663
|
};
|
|
1288
|
-
const action = async (ctx) => {
|
|
1664
|
+
const action$2 = async (ctx) => {
|
|
1289
1665
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1290
1666
|
const token = await getValidToken(ctx, promptLogin);
|
|
1291
1667
|
const { logger } = ctx;
|
|
@@ -1305,25 +1681,218 @@ const action = async (ctx) => {
|
|
|
1305
1681
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1306
1682
|
}
|
|
1307
1683
|
};
|
|
1308
|
-
const command = ({ command: command2, ctx }) => {
|
|
1309
|
-
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("
|
|
1684
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1685
|
+
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$2)(ctx));
|
|
1310
1686
|
};
|
|
1311
1687
|
const listProjects = {
|
|
1312
1688
|
name: "list-projects",
|
|
1313
1689
|
description: "List Strapi Cloud projects",
|
|
1690
|
+
action: action$2,
|
|
1691
|
+
command: command$2
|
|
1692
|
+
};
|
|
1693
|
+
const action$1 = async (ctx) => {
|
|
1694
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1695
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1696
|
+
const { logger } = ctx;
|
|
1697
|
+
if (!token) {
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
const project = await getLocalProject(ctx);
|
|
1701
|
+
if (!project) {
|
|
1702
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1706
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1707
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1708
|
+
projectInternalName: project.name
|
|
1709
|
+
});
|
|
1710
|
+
try {
|
|
1711
|
+
const {
|
|
1712
|
+
data: { data: environmentsList }
|
|
1713
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1714
|
+
spinner.succeed();
|
|
1715
|
+
logger.log(environmentsList);
|
|
1716
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1717
|
+
projectInternalName: project.name
|
|
1718
|
+
});
|
|
1719
|
+
} catch (e) {
|
|
1720
|
+
if (e.response && e.response.status === 404) {
|
|
1721
|
+
spinner.succeed();
|
|
1722
|
+
logger.warn(
|
|
1723
|
+
`
|
|
1724
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1725
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1726
|
+
"link"
|
|
1727
|
+
)} command`
|
|
1728
|
+
);
|
|
1729
|
+
} else {
|
|
1730
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1731
|
+
logger.debug("Failed to list environments", e);
|
|
1732
|
+
}
|
|
1733
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1734
|
+
projectInternalName: project.name
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1739
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1740
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1741
|
+
return cloud;
|
|
1742
|
+
}
|
|
1743
|
+
let environmentCmd = null;
|
|
1744
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1745
|
+
if (!environmentCmd) {
|
|
1746
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1747
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1748
|
+
}
|
|
1749
|
+
return environmentCmd;
|
|
1750
|
+
};
|
|
1751
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1752
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1753
|
+
environmentCmd2.command("list").description("List Strapi Cloud project environments").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("list", action$1)(ctx));
|
|
1754
|
+
};
|
|
1755
|
+
const listEnvironments = {
|
|
1756
|
+
name: "list-environments",
|
|
1757
|
+
description: "List Strapi Cloud environments",
|
|
1758
|
+
action: action$1,
|
|
1759
|
+
command: command$1
|
|
1760
|
+
};
|
|
1761
|
+
const QUIT_OPTION = "Quit";
|
|
1762
|
+
const action = async (ctx) => {
|
|
1763
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1764
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1765
|
+
const { logger } = ctx;
|
|
1766
|
+
if (!token) {
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1769
|
+
const project = await getLocalProject(ctx);
|
|
1770
|
+
if (!project) {
|
|
1771
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1775
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1776
|
+
if (!environments) {
|
|
1777
|
+
logger.debug(`Fetching environments failed.`);
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
if (environments.length === 0) {
|
|
1781
|
+
logger.log(
|
|
1782
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1783
|
+
);
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1787
|
+
if (!answer) {
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1791
|
+
projectName: project.name,
|
|
1792
|
+
environmentName: answer.targetEnvironment
|
|
1793
|
+
});
|
|
1794
|
+
try {
|
|
1795
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1796
|
+
} catch (e) {
|
|
1797
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1798
|
+
projectName: project.name,
|
|
1799
|
+
environmentName: answer.targetEnvironment
|
|
1800
|
+
});
|
|
1801
|
+
logger.debug("Failed to link environment", e);
|
|
1802
|
+
logger.error(
|
|
1803
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1804
|
+
);
|
|
1805
|
+
process.exit(1);
|
|
1806
|
+
}
|
|
1807
|
+
logger.log(
|
|
1808
|
+
` You have successfully linked your project to ${chalk__default.default.cyan(answer.targetEnvironment)}, on ${chalk__default.default.cyan(project.displayName)}. You are now able to deploy your project.`
|
|
1809
|
+
);
|
|
1810
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1811
|
+
projectName: project.name,
|
|
1812
|
+
environmentName: answer.targetEnvironment
|
|
1813
|
+
});
|
|
1814
|
+
};
|
|
1815
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1816
|
+
const { logger } = ctx;
|
|
1817
|
+
try {
|
|
1818
|
+
const answer = await inquirer__default.default.prompt([
|
|
1819
|
+
{
|
|
1820
|
+
type: "list",
|
|
1821
|
+
name: "targetEnvironment",
|
|
1822
|
+
message: "Which environment do you want to link?",
|
|
1823
|
+
choices: [...environments, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1824
|
+
}
|
|
1825
|
+
]);
|
|
1826
|
+
if (!answer.targetEnvironment) {
|
|
1827
|
+
return null;
|
|
1828
|
+
}
|
|
1829
|
+
return answer;
|
|
1830
|
+
} catch (e) {
|
|
1831
|
+
logger.debug("Failed to get user input", e);
|
|
1832
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1833
|
+
return null;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1837
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1838
|
+
try {
|
|
1839
|
+
const {
|
|
1840
|
+
data: { data: environmentsList }
|
|
1841
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1842
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1843
|
+
throw new Error("Environments not found in server response");
|
|
1844
|
+
}
|
|
1845
|
+
spinner.succeed();
|
|
1846
|
+
return environmentsList.filter(
|
|
1847
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1848
|
+
);
|
|
1849
|
+
} catch (e) {
|
|
1850
|
+
if (e.response && e.response.status === 404) {
|
|
1851
|
+
spinner.succeed();
|
|
1852
|
+
ctx.logger.warn(
|
|
1853
|
+
`
|
|
1854
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1855
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1856
|
+
"link"
|
|
1857
|
+
)} command.`
|
|
1858
|
+
);
|
|
1859
|
+
} else {
|
|
1860
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1861
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
const command = ({ command: command2, ctx }) => {
|
|
1866
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1867
|
+
environmentCmd2.command("link").description("Link project to a specific Strapi Cloud project environment").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("link", action)(ctx));
|
|
1868
|
+
};
|
|
1869
|
+
const linkEnvironment = {
|
|
1870
|
+
name: "link-environment",
|
|
1871
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1314
1872
|
action,
|
|
1315
1873
|
command
|
|
1316
1874
|
};
|
|
1317
1875
|
const cli = {
|
|
1318
1876
|
deployProject,
|
|
1877
|
+
link,
|
|
1319
1878
|
login,
|
|
1320
1879
|
logout,
|
|
1321
1880
|
createProject,
|
|
1322
|
-
|
|
1881
|
+
linkEnvironment,
|
|
1882
|
+
listProjects,
|
|
1883
|
+
listEnvironments
|
|
1323
1884
|
};
|
|
1324
|
-
const cloudCommands = [
|
|
1885
|
+
const cloudCommands = [
|
|
1886
|
+
deployProject,
|
|
1887
|
+
link,
|
|
1888
|
+
login,
|
|
1889
|
+
logout,
|
|
1890
|
+
linkEnvironment,
|
|
1891
|
+
listProjects,
|
|
1892
|
+
listEnvironments
|
|
1893
|
+
];
|
|
1325
1894
|
async function initCloudCLIConfig() {
|
|
1326
|
-
const localConfig = await getLocalConfig();
|
|
1895
|
+
const localConfig = await getLocalConfig$1();
|
|
1327
1896
|
if (!localConfig.deviceId) {
|
|
1328
1897
|
localConfig.deviceId = crypto__default.default.randomUUID();
|
|
1329
1898
|
}
|
|
@@ -1337,7 +1906,10 @@ async function buildStrapiCloudCommands({
|
|
|
1337
1906
|
await initCloudCLIConfig();
|
|
1338
1907
|
for (const cloudCommand of cloudCommands) {
|
|
1339
1908
|
try {
|
|
1340
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1909
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1910
|
+
if (subCommand) {
|
|
1911
|
+
command2.addCommand(subCommand);
|
|
1912
|
+
}
|
|
1341
1913
|
} catch (e) {
|
|
1342
1914
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1343
1915
|
}
|