@strapi/cloud-cli 0.0.0-next.d54a672641d83234230d3d80d92aaf87f60f8c75 → 0.0.0-next.d65d44102fd32871728c0d74ec4f2519b7cc0a16

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.
Files changed (48) hide show
  1. package/dist/bin.js +1 -0
  2. package/dist/bin.js.map +1 -1
  3. package/dist/index.js +518 -108
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +516 -106
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/src/cloud/command.d.ts +3 -0
  8. package/dist/src/cloud/command.d.ts.map +1 -0
  9. package/dist/src/create-project/action.d.ts.map +1 -1
  10. package/dist/src/create-project/command.d.ts.map +1 -1
  11. package/dist/src/create-project/utils/project-questions.utils.d.ts +20 -0
  12. package/dist/src/create-project/utils/project-questions.utils.d.ts.map +1 -0
  13. package/dist/src/deploy-project/action.d.ts +5 -1
  14. package/dist/src/deploy-project/action.d.ts.map +1 -1
  15. package/dist/src/deploy-project/command.d.ts.map +1 -1
  16. package/dist/src/environment/command.d.ts +3 -0
  17. package/dist/src/environment/command.d.ts.map +1 -0
  18. package/dist/src/environment/link/action.d.ts +4 -0
  19. package/dist/src/environment/link/action.d.ts.map +1 -0
  20. package/dist/src/environment/link/command.d.ts +4 -0
  21. package/dist/src/environment/link/command.d.ts.map +1 -0
  22. package/dist/src/environment/link/index.d.ts +7 -0
  23. package/dist/src/environment/link/index.d.ts.map +1 -0
  24. package/dist/src/environment/list/action.d.ts +4 -0
  25. package/dist/src/environment/list/action.d.ts.map +1 -0
  26. package/dist/src/environment/list/command.d.ts +4 -0
  27. package/dist/src/environment/list/command.d.ts.map +1 -0
  28. package/dist/src/environment/list/index.d.ts +7 -0
  29. package/dist/src/environment/list/index.d.ts.map +1 -0
  30. package/dist/src/index.d.ts +2 -0
  31. package/dist/src/index.d.ts.map +1 -1
  32. package/dist/src/link/action.d.ts.map +1 -1
  33. package/dist/src/login/command.d.ts.map +1 -1
  34. package/dist/src/logout/command.d.ts.map +1 -1
  35. package/dist/src/services/cli-api.d.ts +46 -3
  36. package/dist/src/services/cli-api.d.ts.map +1 -1
  37. package/dist/src/services/strapi-info-save.d.ts +15 -2
  38. package/dist/src/services/strapi-info-save.d.ts.map +1 -1
  39. package/dist/src/types.d.ts +7 -1
  40. package/dist/src/types.d.ts.map +1 -1
  41. package/dist/src/utils/get-local-config.d.ts +6 -0
  42. package/dist/src/utils/get-local-config.d.ts.map +1 -0
  43. package/dist/src/utils/pkg.d.ts.map +1 -1
  44. package/dist/src/utils/tests/compress-files.test.d.ts +2 -0
  45. package/dist/src/utils/tests/compress-files.test.d.ts.map +1 -0
  46. package/package.json +10 -9
  47. package/dist/src/create-project/utils/apply-default-name.d.ts +0 -7
  48. 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,8 +44,8 @@ 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
51
  if (e && e.__esModule)
@@ -65,12 +67,13 @@ function _interopNamespace(e) {
65
67
  }
66
68
  const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
67
69
  const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
70
+ const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
71
+ const boxen__default = /* @__PURE__ */ _interopDefault(boxen);
68
72
  const path__namespace = /* @__PURE__ */ _interopNamespace(path);
69
73
  const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
70
74
  const axios__default = /* @__PURE__ */ _interopDefault(axios);
71
75
  const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
72
76
  const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
73
- const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
74
77
  const os__default = /* @__PURE__ */ _interopDefault(os);
75
78
  const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
76
79
  const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
@@ -80,7 +83,6 @@ const ora__default = /* @__PURE__ */ _interopDefault(ora);
80
83
  const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
81
84
  const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
82
85
  const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
83
- const ___default = /* @__PURE__ */ _interopDefault(_);
84
86
  const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
85
87
  const apiConfig = {
86
88
  apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
@@ -178,7 +180,7 @@ async function getConfigPath() {
178
180
  }
179
181
  return configPath;
180
182
  }
181
- async function getLocalConfig() {
183
+ async function getLocalConfig$1() {
182
184
  const configPath = await getConfigPath();
183
185
  const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
184
186
  await fse__namespace.default.ensureFile(configFilePath);
@@ -194,7 +196,7 @@ async function saveLocalConfig(data) {
194
196
  await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
195
197
  }
196
198
  const name = "@strapi/cloud-cli";
197
- const version = "4.25.5";
199
+ const version = "5.4.1";
198
200
  const description = "Commands to interact with the Strapi Cloud";
199
201
  const keywords = [
200
202
  "strapi",
@@ -239,14 +241,15 @@ const scripts = {
239
241
  watch: "pack-up watch"
240
242
  };
241
243
  const dependencies = {
242
- "@strapi/utils": "4.25.5",
243
- axios: "1.6.0",
244
+ "@strapi/utils": "5.4.1",
245
+ axios: "1.7.4",
246
+ boxen: "5.1.2",
244
247
  chalk: "4.1.2",
245
248
  "cli-progress": "3.12.0",
246
249
  commander: "8.3.0",
247
250
  eventsource: "2.0.2",
248
251
  "fast-safe-stringify": "2.1.1",
249
- "fs-extra": "10.0.0",
252
+ "fs-extra": "11.2.0",
250
253
  inquirer: "8.2.5",
251
254
  jsonwebtoken: "9.0.0",
252
255
  "jwks-rsa": "3.1.0",
@@ -255,7 +258,7 @@ const dependencies = {
255
258
  open: "8.4.0",
256
259
  ora: "5.4.1",
257
260
  "pkg-up": "3.1.0",
258
- tar: "6.1.13",
261
+ tar: "6.2.1",
259
262
  "xdg-app-paths": "8.3.0",
260
263
  yup: "0.32.9"
261
264
  };
@@ -264,13 +267,14 @@ const devDependencies = {
264
267
  "@types/cli-progress": "3.11.5",
265
268
  "@types/eventsource": "1.1.15",
266
269
  "@types/lodash": "^4.14.191",
267
- "eslint-config-custom": "4.25.5",
268
- tsconfig: "4.25.5"
270
+ "eslint-config-custom": "5.4.1",
271
+ tsconfig: "5.4.1"
269
272
  };
270
273
  const engines = {
271
- node: ">=18.0.0 <=20.x.x",
274
+ node: ">=18.0.0 <=22.x.x",
272
275
  npm: ">=6.0.0"
273
276
  };
277
+ const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
274
278
  const packageJson = {
275
279
  name,
276
280
  version,
@@ -291,11 +295,12 @@ const packageJson = {
291
295
  scripts,
292
296
  dependencies,
293
297
  devDependencies,
294
- engines
298
+ engines,
299
+ gitHead
295
300
  };
296
301
  const VERSION = "v1";
297
302
  async function cloudApiFactory({ logger }, token) {
298
- const localConfig = await getLocalConfig();
303
+ const localConfig = await getLocalConfig$1();
299
304
  const customHeaders = {
300
305
  "x-device-id": localConfig.deviceId,
301
306
  "x-app-version": packageJson.version,
@@ -318,7 +323,7 @@ async function cloudApiFactory({ logger }, token) {
318
323
  deploy({ filePath, project }, { onUploadProgress }) {
319
324
  return axiosCloudAPI.post(
320
325
  `/deploy/${project.name}`,
321
- { file: fse__namespace.default.createReadStream(filePath) },
326
+ { file: fse__namespace.default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
322
327
  {
323
328
  headers: {
324
329
  "Content-Type": "multipart/form-data"
@@ -377,7 +382,7 @@ async function cloudApiFactory({ logger }, token) {
377
382
  },
378
383
  async listLinkProjects() {
379
384
  try {
380
- const response = await axiosCloudAPI.get("/projects/linkable");
385
+ const response = await axiosCloudAPI.get("/projects-linkable");
381
386
  if (response.status !== 200) {
382
387
  throw new Error("Error fetching cloud projects from the server.");
383
388
  }
@@ -389,6 +394,48 @@ async function cloudApiFactory({ logger }, token) {
389
394
  throw error;
390
395
  }
391
396
  },
397
+ async listEnvironments({ name: name2 }) {
398
+ try {
399
+ const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
400
+ if (response.status !== 200) {
401
+ throw new Error("Error fetching cloud environments from the server.");
402
+ }
403
+ return response;
404
+ } catch (error) {
405
+ logger.debug(
406
+ "🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
407
+ );
408
+ throw error;
409
+ }
410
+ },
411
+ async listLinkEnvironments({ name: name2 }) {
412
+ try {
413
+ const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
414
+ if (response.status !== 200) {
415
+ throw new Error("Error fetching cloud environments from the server.");
416
+ }
417
+ return response;
418
+ } catch (error) {
419
+ logger.debug(
420
+ "🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
421
+ );
422
+ throw error;
423
+ }
424
+ },
425
+ async getProject({ name: name2 }) {
426
+ try {
427
+ const response = await axiosCloudAPI.get(`/projects/${name2}`);
428
+ if (response.status !== 200) {
429
+ throw new Error("Error fetching project's details.");
430
+ }
431
+ return response;
432
+ } catch (error) {
433
+ logger.debug(
434
+ "🥲 Oops! There was a problem retrieving your project's details. Please try again."
435
+ );
436
+ throw error;
437
+ }
438
+ },
392
439
  track(event, payload = {}) {
393
440
  return axiosCloudAPI.post("/track", {
394
441
  event,
@@ -398,26 +445,43 @@ async function cloudApiFactory({ logger }, token) {
398
445
  };
399
446
  }
400
447
  const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
448
+ const getFilePath = (directoryPath) => path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
401
449
  async function save(data, { directoryPath } = {}) {
402
- const alreadyInFileData = await retrieve({ directoryPath });
403
- const storedData = { ...alreadyInFileData, ...data };
404
- const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
450
+ const pathToFile = getFilePath(directoryPath);
405
451
  await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
406
- await fse__namespace.default.writeJson(pathToFile, storedData, { encoding: "utf8" });
452
+ await fse__namespace.default.writeJson(pathToFile, data, { encoding: "utf8" });
407
453
  }
408
454
  async function retrieve({
409
455
  directoryPath
410
456
  } = {}) {
411
- const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
457
+ const pathToFile = getFilePath(directoryPath);
412
458
  const pathExists = await fse__namespace.default.pathExists(pathToFile);
413
459
  if (!pathExists) {
414
460
  return {};
415
461
  }
416
462
  return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
417
463
  }
464
+ async function patch(patchData, { directoryPath } = {}) {
465
+ const pathToFile = getFilePath(directoryPath);
466
+ const existingData = await retrieve({ directoryPath });
467
+ if (!existingData) {
468
+ throw new Error("No configuration data found to patch.");
469
+ }
470
+ const newData = lodash.merge(existingData, patchData);
471
+ await fse__namespace.default.writeJson(pathToFile, newData, { encoding: "utf8" });
472
+ }
473
+ async function deleteConfig({ directoryPath } = {}) {
474
+ const pathToFile = getFilePath(directoryPath);
475
+ const pathExists = await fse__namespace.default.pathExists(pathToFile);
476
+ if (pathExists) {
477
+ await fse__namespace.default.remove(pathToFile);
478
+ }
479
+ }
418
480
  const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
419
481
  __proto__: null,
420
482
  LOCAL_SAVE_FILENAME,
483
+ deleteConfig,
484
+ patch,
421
485
  retrieve,
422
486
  save
423
487
  }, Symbol.toStringTag, { value: "Module" }));
@@ -425,7 +489,7 @@ let cliConfig;
425
489
  async function tokenServiceFactory({ logger }) {
426
490
  const cloudApiService = await cloudApiFactory({ logger });
427
491
  async function saveToken(str) {
428
- const appConfig = await getLocalConfig();
492
+ const appConfig = await getLocalConfig$1();
429
493
  if (!appConfig) {
430
494
  logger.error("There was a problem saving your token. Please try again.");
431
495
  return;
@@ -439,7 +503,7 @@ async function tokenServiceFactory({ logger }) {
439
503
  }
440
504
  }
441
505
  async function retrieveToken() {
442
- const appConfig = await getLocalConfig();
506
+ const appConfig = await getLocalConfig$1();
443
507
  if (appConfig.token) {
444
508
  if (await isTokenValid(appConfig.token)) {
445
509
  return appConfig.token;
@@ -501,7 +565,7 @@ async function tokenServiceFactory({ logger }) {
501
565
  }
502
566
  }
503
567
  async function eraseToken() {
504
- const appConfig = await getLocalConfig();
568
+ const appConfig = await getLocalConfig$1();
505
569
  if (!appConfig) {
506
570
  return;
507
571
  }
@@ -662,21 +726,24 @@ yup__namespace.object({
662
726
  name: yup__namespace.string().required(),
663
727
  exports: yup__namespace.lazy(
664
728
  (value) => yup__namespace.object(
665
- typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
666
- if (typeof value2 === "object") {
667
- acc[key] = yup__namespace.object({
668
- types: yup__namespace.string().optional(),
669
- source: yup__namespace.string().required(),
670
- module: yup__namespace.string().optional(),
671
- import: yup__namespace.string().required(),
672
- require: yup__namespace.string().required(),
673
- default: yup__namespace.string().required()
674
- }).noUnknown(true);
675
- } else {
676
- acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
677
- }
678
- return acc;
679
- }, {}) : void 0
729
+ typeof value === "object" ? Object.entries(value).reduce(
730
+ (acc, [key, value2]) => {
731
+ if (typeof value2 === "object") {
732
+ acc[key] = yup__namespace.object({
733
+ types: yup__namespace.string().optional(),
734
+ source: yup__namespace.string().required(),
735
+ module: yup__namespace.string().optional(),
736
+ import: yup__namespace.string().required(),
737
+ require: yup__namespace.string().required(),
738
+ default: yup__namespace.string().required()
739
+ }).noUnknown(true);
740
+ } else {
741
+ acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
742
+ }
743
+ return acc;
744
+ },
745
+ {}
746
+ ) : void 0
680
747
  ).optional()
681
748
  )
682
749
  });
@@ -698,18 +765,6 @@ async function getProjectNameFromPackageJson(ctx) {
698
765
  return "my-strapi-project";
699
766
  }
700
767
  }
701
- function applyDefaultName(newDefaultName, questions, defaultValues) {
702
- const newDefaultValues = ___default.default.cloneDeep(defaultValues);
703
- newDefaultValues.name = newDefaultName;
704
- const newQuestions = questions.map((question) => {
705
- const questionCopy = ___default.default.cloneDeep(question);
706
- if (questionCopy.name === "name") {
707
- questionCopy.default = newDefaultName;
708
- }
709
- return questionCopy;
710
- });
711
- return { newQuestions, newDefaultValues };
712
- }
713
768
  const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
714
769
  try {
715
770
  await cloudApiService.track(eventName, eventData);
@@ -873,6 +928,45 @@ async function loginAction(ctx) {
873
928
  await authenticate();
874
929
  return isAuthenticated;
875
930
  }
931
+ function questionDefaultValuesMapper(questionsMap) {
932
+ return (questions) => {
933
+ return questions.map((question) => {
934
+ const questionName = question.name;
935
+ if (questionName in questionsMap) {
936
+ const questionDefault = questionsMap[questionName];
937
+ if (typeof questionDefault === "function") {
938
+ return {
939
+ ...question,
940
+ default: questionDefault(question)
941
+ };
942
+ }
943
+ return {
944
+ ...question,
945
+ default: questionDefault
946
+ };
947
+ }
948
+ return question;
949
+ });
950
+ };
951
+ }
952
+ function getDefaultsFromQuestions(questions) {
953
+ return questions.reduce((acc, question) => {
954
+ if (question.default && question.name) {
955
+ return { ...acc, [question.name]: question.default };
956
+ }
957
+ return acc;
958
+ }, {});
959
+ }
960
+ function getProjectNodeVersionDefault(question) {
961
+ const currentNodeVersion = process.versions.node.split(".")[0];
962
+ if (question.type === "list" && Array.isArray(question.choices)) {
963
+ const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
964
+ if (choice) {
965
+ return choice.value;
966
+ }
967
+ }
968
+ return question.default;
969
+ }
876
970
  async function handleError(ctx, error) {
877
971
  const { logger } = ctx;
878
972
  logger.debug(error);
@@ -917,7 +1011,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
917
1011
  throw e;
918
1012
  }
919
1013
  }
920
- const action$4 = async (ctx) => {
1014
+ const action$6 = async (ctx) => {
921
1015
  const { logger } = ctx;
922
1016
  const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
923
1017
  const token = await getValidToken(ctx, promptLogin);
@@ -926,11 +1020,16 @@ const action$4 = async (ctx) => {
926
1020
  }
927
1021
  const cloudApi = await cloudApiFactory(ctx, token);
928
1022
  const { data: config } = await cloudApi.config();
929
- const { newQuestions: questions, newDefaultValues: defaultValues } = applyDefaultName(
930
- await getProjectNameFromPackageJson(ctx),
931
- config.projectCreation.questions,
932
- config.projectCreation.defaults
933
- );
1023
+ const projectName = await getProjectNameFromPackageJson(ctx);
1024
+ const defaultAnswersMapper = questionDefaultValuesMapper({
1025
+ name: projectName,
1026
+ nodeVersion: getProjectNodeVersionDefault
1027
+ });
1028
+ const questions = defaultAnswersMapper(config.projectCreation.questions);
1029
+ const defaultValues = {
1030
+ ...config.projectCreation.defaults,
1031
+ ...getDefaultsFromQuestions(questions)
1032
+ };
934
1033
  const projectAnswersDefaulted = fp.defaults(defaultValues);
935
1034
  const projectAnswers = await inquirer__default.default.prompt(questions);
936
1035
  const projectInput = projectAnswersDefaulted(projectAnswers);
@@ -1041,6 +1140,29 @@ const buildLogsServiceFactory = ({ logger }) => {
1041
1140
  });
1042
1141
  };
1043
1142
  };
1143
+ const boxenOptions = {
1144
+ padding: 1,
1145
+ margin: 1,
1146
+ align: "center",
1147
+ borderColor: "yellow",
1148
+ borderStyle: "round"
1149
+ };
1150
+ const QUIT_OPTION$2 = "Quit";
1151
+ async function promptForEnvironment(environments) {
1152
+ const choices = environments.map((env) => ({ name: env, value: env }));
1153
+ const { selectedEnvironment } = await inquirer__default.default.prompt([
1154
+ {
1155
+ type: "list",
1156
+ name: "selectedEnvironment",
1157
+ message: "Select the environment to deploy:",
1158
+ choices: [...choices, { name: chalk__default.default.grey(`(${QUIT_OPTION$2})`), value: null }]
1159
+ }
1160
+ ]);
1161
+ if (selectedEnvironment === null) {
1162
+ process.exit(1);
1163
+ }
1164
+ return selectedEnvironment;
1165
+ }
1044
1166
  async function upload(ctx, project, token, maxProjectFileSize) {
1045
1167
  const cloudApi = await cloudApiFactory(ctx, token);
1046
1168
  try {
@@ -1107,17 +1229,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1107
1229
  return data.build_id;
1108
1230
  } catch (e) {
1109
1231
  progressBar.stop();
1110
- if (e instanceof axios.AxiosError && e.response?.data) {
1111
- if (e.response.status === 404) {
1112
- ctx.logger.error(
1113
- `The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
1114
- );
1115
- } else {
1116
- ctx.logger.error(e.response.data);
1117
- }
1118
- } else {
1119
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1120
- }
1232
+ ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1121
1233
  ctx.logger.debug(e);
1122
1234
  } finally {
1123
1235
  await fse__namespace.default.remove(tarFilePath);
@@ -1133,7 +1245,7 @@ async function getProject(ctx) {
1133
1245
  const { project } = await retrieve();
1134
1246
  if (!project) {
1135
1247
  try {
1136
- return await action$4(ctx);
1248
+ return await action$6(ctx);
1137
1249
  } catch (e) {
1138
1250
  ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1139
1251
  ctx.logger.debug(e);
@@ -1154,7 +1266,33 @@ async function getConfig({
1154
1266
  return null;
1155
1267
  }
1156
1268
  }
1157
- const action$3 = async (ctx) => {
1269
+ function validateEnvironment(ctx, environment, environments) {
1270
+ if (!environments.includes(environment)) {
1271
+ ctx.logger.error(`Environment ${environment} does not exist.`);
1272
+ process.exit(1);
1273
+ }
1274
+ }
1275
+ async function getTargetEnvironment(ctx, opts, project, environments) {
1276
+ if (opts.env) {
1277
+ validateEnvironment(ctx, opts.env, environments);
1278
+ return opts.env;
1279
+ }
1280
+ if (project.targetEnvironment) {
1281
+ return project.targetEnvironment;
1282
+ }
1283
+ if (environments.length > 1) {
1284
+ return promptForEnvironment(environments);
1285
+ }
1286
+ return environments[0];
1287
+ }
1288
+ function hasPendingOrLiveDeployment(environments, targetEnvironment) {
1289
+ const environment = environments.find((env) => env.name === targetEnvironment);
1290
+ if (!environment) {
1291
+ throw new Error(`Environment details ${targetEnvironment} not found.`);
1292
+ }
1293
+ return environment.hasPendingDeployment || environment.hasLiveDeployment || false;
1294
+ }
1295
+ const action$5 = async (ctx, opts) => {
1158
1296
  const { getValidToken } = await tokenServiceFactory(ctx);
1159
1297
  const token = await getValidToken(ctx, promptLogin);
1160
1298
  if (!token) {
@@ -1164,7 +1302,45 @@ const action$3 = async (ctx) => {
1164
1302
  if (!project) {
1165
1303
  return;
1166
1304
  }
1167
- const cloudApiService = await cloudApiFactory(ctx);
1305
+ const cloudApiService = await cloudApiFactory(ctx, token);
1306
+ let projectData;
1307
+ let environments;
1308
+ let environmentsDetails;
1309
+ try {
1310
+ const {
1311
+ data: { data, metadata }
1312
+ } = await cloudApiService.getProject({ name: project.name });
1313
+ projectData = data;
1314
+ environments = projectData.environments;
1315
+ environmentsDetails = projectData.environmentsDetails;
1316
+ const isProjectSuspended = projectData.suspendedAt;
1317
+ if (isProjectSuspended) {
1318
+ ctx.logger.log(
1319
+ "\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
1320
+ );
1321
+ ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
1322
+ return;
1323
+ }
1324
+ } catch (e) {
1325
+ if (e instanceof axios.AxiosError && e.response?.data) {
1326
+ if (e.response.status === 404) {
1327
+ ctx.logger.warn(
1328
+ `The project associated with this folder does not exist in Strapi Cloud.
1329
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1330
+ "link"
1331
+ )} command before deploying.`
1332
+ );
1333
+ } else {
1334
+ ctx.logger.error(e.response.data);
1335
+ }
1336
+ } else {
1337
+ ctx.logger.error(
1338
+ "An error occurred while retrieving the project's information. Please try again later."
1339
+ );
1340
+ }
1341
+ ctx.logger.debug(e);
1342
+ return;
1343
+ }
1168
1344
  await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
1169
1345
  projectInternalName: project.name
1170
1346
  });
@@ -1173,7 +1349,7 @@ const action$3 = async (ctx) => {
1173
1349
  const cliConfig2 = await getConfig({ ctx, cloudApiService });
1174
1350
  if (!cliConfig2) {
1175
1351
  ctx.logger.error(
1176
- "An error occurred while retrieving data from Strapi Cloud. Please try check your network or again later."
1352
+ "An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
1177
1353
  );
1178
1354
  return;
1179
1355
  }
@@ -1184,11 +1360,34 @@ const action$3 = async (ctx) => {
1184
1360
  );
1185
1361
  maxSize = 1e8;
1186
1362
  }
1363
+ project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
1364
+ if (!opts.force) {
1365
+ const shouldDisplayWarning = hasPendingOrLiveDeployment(
1366
+ environmentsDetails,
1367
+ project.targetEnvironment
1368
+ );
1369
+ if (shouldDisplayWarning) {
1370
+ ctx.logger.log(boxen__default.default(cliConfig2.projectDeployment.confirmationText, boxenOptions));
1371
+ const { confirm } = await inquirer__default.default.prompt([
1372
+ {
1373
+ type: "confirm",
1374
+ name: "confirm",
1375
+ message: `Do you want to proceed with deployment to ${chalk__default.default.cyan(projectData.displayName)} on ${chalk__default.default.cyan(project.targetEnvironment)} environment?`
1376
+ }
1377
+ ]);
1378
+ if (!confirm) {
1379
+ process.exit(1);
1380
+ }
1381
+ }
1382
+ }
1187
1383
  const buildId = await upload(ctx, project, token, maxSize);
1188
1384
  if (!buildId) {
1189
1385
  return;
1190
1386
  }
1191
1387
  try {
1388
+ ctx.logger.log(
1389
+ `🚀 Deploying project to ${chalk__default.default.cyan(project.targetEnvironment ?? `production`)} environment...`
1390
+ );
1192
1391
  notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
1193
1392
  await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
1194
1393
  ctx.logger.log(
@@ -1233,17 +1432,16 @@ const runAction = (name2, action2) => (...args) => {
1233
1432
  process.exit(1);
1234
1433
  });
1235
1434
  };
1236
- const command$5 = ({ command: command2, ctx }) => {
1237
- command2.command("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));
1435
+ const command$7 = ({ ctx }) => {
1436
+ 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));
1238
1437
  };
1239
1438
  const deployProject = {
1240
1439
  name: "deploy-project",
1241
1440
  description: "Deploy a Strapi Cloud project",
1242
- action: action$3,
1243
- command: command$5
1441
+ action: action$5,
1442
+ command: command$7
1244
1443
  };
1245
- const QUIT_OPTION = "Quit";
1246
- async function getExistingConfig(ctx) {
1444
+ async function getLocalConfig(ctx) {
1247
1445
  try {
1248
1446
  return await retrieve();
1249
1447
  } catch (e) {
@@ -1252,6 +1450,21 @@ async function getExistingConfig(ctx) {
1252
1450
  return null;
1253
1451
  }
1254
1452
  }
1453
+ async function getLocalProject(ctx) {
1454
+ const localConfig = await getLocalConfig(ctx);
1455
+ if (!localConfig || !localConfig.project) {
1456
+ ctx.logger.warn(
1457
+ `
1458
+ We couldn't find a valid local project config.
1459
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1460
+ "link"
1461
+ )} command.`
1462
+ );
1463
+ process.exit(1);
1464
+ }
1465
+ return localConfig.project;
1466
+ }
1467
+ const QUIT_OPTION$1 = "Quit";
1255
1468
  async function promptForRelink(ctx, cloudApiService, existingConfig) {
1256
1469
  if (existingConfig && existingConfig.project) {
1257
1470
  const { shouldRelink } = await inquirer__default.default.prompt([
@@ -1281,7 +1494,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
1281
1494
  } = await cloudApiService.listLinkProjects();
1282
1495
  spinner.succeed();
1283
1496
  if (!Array.isArray(projectList)) {
1284
- ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
1497
+ ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
1285
1498
  return null;
1286
1499
  }
1287
1500
  const projects = projectList.filter(
@@ -1293,7 +1506,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
1293
1506
  };
1294
1507
  });
1295
1508
  if (projects.length === 0) {
1296
- ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
1509
+ ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
1297
1510
  return null;
1298
1511
  }
1299
1512
  return projects;
@@ -1311,7 +1524,7 @@ async function getUserSelection(ctx, projects) {
1311
1524
  type: "list",
1312
1525
  name: "linkProject",
1313
1526
  message: "Which project do you want to link?",
1314
- choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
1527
+ choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION$1})`), value: null }]
1315
1528
  }
1316
1529
  ]);
1317
1530
  if (!answer.linkProject) {
@@ -1324,7 +1537,7 @@ async function getUserSelection(ctx, projects) {
1324
1537
  return null;
1325
1538
  }
1326
1539
  }
1327
- const action$2 = async (ctx) => {
1540
+ const action$4 = async (ctx) => {
1328
1541
  const { getValidToken } = await tokenServiceFactory(ctx);
1329
1542
  const token = await getValidToken(ctx, promptLogin);
1330
1543
  const { logger } = ctx;
@@ -1332,7 +1545,7 @@ const action$2 = async (ctx) => {
1332
1545
  return;
1333
1546
  }
1334
1547
  const cloudApiService = await cloudApiFactory(ctx, token);
1335
- const existingConfig = await getExistingConfig(ctx);
1548
+ const existingConfig = await getLocalConfig(ctx);
1336
1549
  const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
1337
1550
  if (!shouldRelink) {
1338
1551
  return;
@@ -1367,7 +1580,9 @@ const action$2 = async (ctx) => {
1367
1580
  return;
1368
1581
  }
1369
1582
  await save({ project: answer.linkProject });
1370
- logger.log(`Project ${chalk__default.default.cyan(answer.linkProject.displayName)} linked successfully.`);
1583
+ logger.log(
1584
+ ` You have successfully linked your project to ${chalk__default.default.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
1585
+ );
1371
1586
  await trackEvent(ctx, cloudApiService, "didLinkProject", {
1372
1587
  projectInternalName: answer.linkProject
1373
1588
  });
@@ -1379,17 +1594,17 @@ const action$2 = async (ctx) => {
1379
1594
  });
1380
1595
  }
1381
1596
  };
1382
- const command$4 = ({ command: command2, ctx }) => {
1383
- 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));
1597
+ const command$6 = ({ command: command2, ctx }) => {
1598
+ 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));
1384
1599
  };
1385
1600
  const link = {
1386
1601
  name: "link-project",
1387
1602
  description: "Link a local directory to a Strapi Cloud project",
1388
- action: action$2,
1389
- command: command$4
1603
+ action: action$4,
1604
+ command: command$6
1390
1605
  };
1391
- const command$3 = ({ command: command2, ctx }) => {
1392
- command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1606
+ const command$5 = ({ ctx }) => {
1607
+ return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1393
1608
  "after",
1394
1609
  "\nAfter running this command, you will be prompted to enter your authentication information."
1395
1610
  ).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
@@ -1398,10 +1613,10 @@ const login = {
1398
1613
  name: "login",
1399
1614
  description: "Strapi Cloud Login",
1400
1615
  action: loginAction,
1401
- command: command$3
1616
+ command: command$5
1402
1617
  };
1403
1618
  const openModule = import("open");
1404
- const action$1 = async (ctx) => {
1619
+ const action$3 = async (ctx) => {
1405
1620
  const { logger } = ctx;
1406
1621
  const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
1407
1622
  const token = await retrieveToken();
@@ -1433,25 +1648,25 @@ const action$1 = async (ctx) => {
1433
1648
  }
1434
1649
  await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
1435
1650
  };
1436
- const command$2 = ({ command: command2, ctx }) => {
1437
- command2.command("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));
1651
+ const command$4 = ({ ctx }) => {
1652
+ 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));
1438
1653
  };
1439
1654
  const logout = {
1440
1655
  name: "logout",
1441
1656
  description: "Strapi Cloud Logout",
1442
- action: action$1,
1443
- command: command$2
1657
+ action: action$3,
1658
+ command: command$4
1444
1659
  };
1445
- const command$1 = ({ command: command2, ctx }) => {
1446
- command2.command("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));
1660
+ const command$3 = ({ ctx }) => {
1661
+ 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));
1447
1662
  };
1448
1663
  const createProject = {
1449
1664
  name: "create-project",
1450
1665
  description: "Create a new project",
1451
- action: action$4,
1452
- command: command$1
1666
+ action: action$6,
1667
+ command: command$3
1453
1668
  };
1454
- const action = async (ctx) => {
1669
+ const action$2 = async (ctx) => {
1455
1670
  const { getValidToken } = await tokenServiceFactory(ctx);
1456
1671
  const token = await getValidToken(ctx, promptLogin);
1457
1672
  const { logger } = ctx;
@@ -1471,12 +1686,194 @@ const action = async (ctx) => {
1471
1686
  spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
1472
1687
  }
1473
1688
  };
1474
- const command = ({ command: command2, ctx }) => {
1475
- 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));
1689
+ const command$2 = ({ command: command2, ctx }) => {
1690
+ 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));
1476
1691
  };
1477
1692
  const listProjects = {
1478
1693
  name: "list-projects",
1479
1694
  description: "List Strapi Cloud projects",
1695
+ action: action$2,
1696
+ command: command$2
1697
+ };
1698
+ const action$1 = async (ctx) => {
1699
+ const { getValidToken } = await tokenServiceFactory(ctx);
1700
+ const token = await getValidToken(ctx, promptLogin);
1701
+ const { logger } = ctx;
1702
+ if (!token) {
1703
+ return;
1704
+ }
1705
+ const project = await getLocalProject(ctx);
1706
+ if (!project) {
1707
+ ctx.logger.debug(`No valid local project configuration was found.`);
1708
+ return;
1709
+ }
1710
+ const cloudApiService = await cloudApiFactory(ctx, token);
1711
+ const spinner = logger.spinner("Fetching environments...").start();
1712
+ await trackEvent(ctx, cloudApiService, "willListEnvironment", {
1713
+ projectInternalName: project.name
1714
+ });
1715
+ try {
1716
+ const {
1717
+ data: { data: environmentsList }
1718
+ } = await cloudApiService.listEnvironments({ name: project.name });
1719
+ spinner.succeed();
1720
+ logger.log(environmentsList);
1721
+ await trackEvent(ctx, cloudApiService, "didListEnvironment", {
1722
+ projectInternalName: project.name
1723
+ });
1724
+ } catch (e) {
1725
+ if (e.response && e.response.status === 404) {
1726
+ spinner.succeed();
1727
+ logger.warn(
1728
+ `
1729
+ The project associated with this folder does not exist in Strapi Cloud.
1730
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1731
+ "link"
1732
+ )} command`
1733
+ );
1734
+ } else {
1735
+ spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
1736
+ logger.debug("Failed to list environments", e);
1737
+ }
1738
+ await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
1739
+ projectInternalName: project.name
1740
+ });
1741
+ }
1742
+ };
1743
+ function defineCloudNamespace(command2, ctx) {
1744
+ const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
1745
+ cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
1746
+ return cloud;
1747
+ }
1748
+ let environmentCmd = null;
1749
+ const initializeEnvironmentCommand = (command2, ctx) => {
1750
+ if (!environmentCmd) {
1751
+ const cloud = defineCloudNamespace(command2, ctx);
1752
+ environmentCmd = cloud.command("environment").description("Manage environments");
1753
+ }
1754
+ return environmentCmd;
1755
+ };
1756
+ const command$1 = ({ command: command2, ctx }) => {
1757
+ const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
1758
+ 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));
1759
+ };
1760
+ const listEnvironments = {
1761
+ name: "list-environments",
1762
+ description: "List Strapi Cloud environments",
1763
+ action: action$1,
1764
+ command: command$1
1765
+ };
1766
+ const QUIT_OPTION = "Quit";
1767
+ const action = async (ctx) => {
1768
+ const { getValidToken } = await tokenServiceFactory(ctx);
1769
+ const token = await getValidToken(ctx, promptLogin);
1770
+ const { logger } = ctx;
1771
+ if (!token) {
1772
+ return;
1773
+ }
1774
+ const project = await getLocalProject(ctx);
1775
+ if (!project) {
1776
+ logger.debug(`No valid local project configuration was found.`);
1777
+ return;
1778
+ }
1779
+ const cloudApiService = await cloudApiFactory(ctx, token);
1780
+ const environments = await getEnvironmentsList(ctx, cloudApiService, project);
1781
+ if (!environments) {
1782
+ logger.debug(`Fetching environments failed.`);
1783
+ return;
1784
+ }
1785
+ if (environments.length === 0) {
1786
+ logger.log(
1787
+ `The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
1788
+ );
1789
+ return;
1790
+ }
1791
+ const answer = await promptUserForEnvironment(ctx, environments);
1792
+ if (!answer) {
1793
+ return;
1794
+ }
1795
+ await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
1796
+ projectName: project.name,
1797
+ environmentName: answer.targetEnvironment
1798
+ });
1799
+ try {
1800
+ await patch({ project: { targetEnvironment: answer.targetEnvironment } });
1801
+ } catch (e) {
1802
+ await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
1803
+ projectName: project.name,
1804
+ environmentName: answer.targetEnvironment
1805
+ });
1806
+ logger.debug("Failed to link environment", e);
1807
+ logger.error(
1808
+ "Failed to link the environment. If this issue persists, try re-linking your project or contact support."
1809
+ );
1810
+ process.exit(1);
1811
+ }
1812
+ logger.log(
1813
+ ` 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.`
1814
+ );
1815
+ await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
1816
+ projectName: project.name,
1817
+ environmentName: answer.targetEnvironment
1818
+ });
1819
+ };
1820
+ async function promptUserForEnvironment(ctx, environments) {
1821
+ const { logger } = ctx;
1822
+ try {
1823
+ const answer = await inquirer__default.default.prompt([
1824
+ {
1825
+ type: "list",
1826
+ name: "targetEnvironment",
1827
+ message: "Which environment do you want to link?",
1828
+ choices: [...environments, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
1829
+ }
1830
+ ]);
1831
+ if (!answer.targetEnvironment) {
1832
+ return null;
1833
+ }
1834
+ return answer;
1835
+ } catch (e) {
1836
+ logger.debug("Failed to get user input", e);
1837
+ logger.error("An error occurred while trying to get your environment selection.");
1838
+ return null;
1839
+ }
1840
+ }
1841
+ async function getEnvironmentsList(ctx, cloudApiService, project) {
1842
+ const spinner = ctx.logger.spinner("Fetching environments...\n").start();
1843
+ try {
1844
+ const {
1845
+ data: { data: environmentsList }
1846
+ } = await cloudApiService.listLinkEnvironments({ name: project.name });
1847
+ if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
1848
+ throw new Error("Environments not found in server response");
1849
+ }
1850
+ spinner.succeed();
1851
+ return environmentsList.filter(
1852
+ (environment) => environment.name !== project.targetEnvironment
1853
+ );
1854
+ } catch (e) {
1855
+ if (e.response && e.response.status === 404) {
1856
+ spinner.succeed();
1857
+ ctx.logger.warn(
1858
+ `
1859
+ The project associated with this folder does not exist in Strapi Cloud.
1860
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1861
+ "link"
1862
+ )} command.`
1863
+ );
1864
+ } else {
1865
+ spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
1866
+ ctx.logger.debug("Failed to list environments", e);
1867
+ }
1868
+ }
1869
+ }
1870
+ const command = ({ command: command2, ctx }) => {
1871
+ const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
1872
+ 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));
1873
+ };
1874
+ const linkEnvironment = {
1875
+ name: "link-environment",
1876
+ description: "Link Strapi Cloud environment to a local project",
1480
1877
  action,
1481
1878
  command
1482
1879
  };
@@ -1486,11 +1883,21 @@ const cli = {
1486
1883
  login,
1487
1884
  logout,
1488
1885
  createProject,
1489
- listProjects
1886
+ linkEnvironment,
1887
+ listProjects,
1888
+ listEnvironments
1490
1889
  };
1491
- const cloudCommands = [deployProject, link, login, logout, listProjects];
1890
+ const cloudCommands = [
1891
+ deployProject,
1892
+ link,
1893
+ login,
1894
+ logout,
1895
+ linkEnvironment,
1896
+ listProjects,
1897
+ listEnvironments
1898
+ ];
1492
1899
  async function initCloudCLIConfig() {
1493
- const localConfig = await getLocalConfig();
1900
+ const localConfig = await getLocalConfig$1();
1494
1901
  if (!localConfig.deviceId) {
1495
1902
  localConfig.deviceId = crypto__default.default.randomUUID();
1496
1903
  }
@@ -1504,7 +1911,10 @@ async function buildStrapiCloudCommands({
1504
1911
  await initCloudCLIConfig();
1505
1912
  for (const cloudCommand of cloudCommands) {
1506
1913
  try {
1507
- await cloudCommand.command({ command: command2, ctx, argv });
1914
+ const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
1915
+ if (subCommand) {
1916
+ command2.addCommand(subCommand);
1917
+ }
1508
1918
  } catch (e) {
1509
1919
  console.error(`Failed to load command ${cloudCommand.name}`, e);
1510
1920
  }