@strapi/cloud-cli 0.0.0-next.7466630056657c483fb286557dda890490597807 → 0.0.0-next.77e66829c8c9c19a6fd9c80944bb2395c7d7f714

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 (35) hide show
  1. package/dist/index.js +300 -91
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +299 -89
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/src/cloud/command.d.ts +3 -0
  6. package/dist/src/cloud/command.d.ts.map +1 -0
  7. package/dist/src/create-project/action.d.ts.map +1 -1
  8. package/dist/src/create-project/command.d.ts.map +1 -1
  9. package/dist/src/create-project/utils/project-questions.utils.d.ts +20 -0
  10. package/dist/src/create-project/utils/project-questions.utils.d.ts.map +1 -0
  11. package/dist/src/deploy-project/action.d.ts +4 -1
  12. package/dist/src/deploy-project/action.d.ts.map +1 -1
  13. package/dist/src/deploy-project/command.d.ts.map +1 -1
  14. package/dist/src/environment/command.d.ts +3 -0
  15. package/dist/src/environment/command.d.ts.map +1 -0
  16. package/dist/src/environment/list/action.d.ts +4 -0
  17. package/dist/src/environment/list/action.d.ts.map +1 -0
  18. package/dist/src/environment/list/command.d.ts +4 -0
  19. package/dist/src/environment/list/command.d.ts.map +1 -0
  20. package/dist/src/environment/list/index.d.ts +7 -0
  21. package/dist/src/environment/list/index.d.ts.map +1 -0
  22. package/dist/src/index.d.ts +1 -0
  23. package/dist/src/index.d.ts.map +1 -1
  24. package/dist/src/login/command.d.ts.map +1 -1
  25. package/dist/src/logout/command.d.ts.map +1 -1
  26. package/dist/src/services/cli-api.d.ts +28 -0
  27. package/dist/src/services/cli-api.d.ts.map +1 -1
  28. package/dist/src/types.d.ts +4 -1
  29. package/dist/src/types.d.ts.map +1 -1
  30. package/dist/src/utils/pkg.d.ts.map +1 -1
  31. package/dist/src/utils/tests/compress-files.test.d.ts +2 -0
  32. package/dist/src/utils/tests/compress-files.test.d.ts.map +1 -0
  33. package/package.json +9 -9
  34. package/dist/src/create-project/utils/apply-default-name.d.ts +0 -7
  35. package/dist/src/create-project/utils/apply-default-name.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ 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");
27
28
  const path = require("path");
28
29
  const chalk = require("chalk");
29
30
  const axios = require("axios");
@@ -31,7 +32,6 @@ const crypto = require("node:crypto");
31
32
  const utils = require("@strapi/utils");
32
33
  const tar = require("tar");
33
34
  const minimatch = require("minimatch");
34
- const inquirer = require("inquirer");
35
35
  const fp = require("lodash/fp");
36
36
  const os = require("os");
37
37
  const XDGAppPaths = require("xdg-app-paths");
@@ -42,8 +42,8 @@ const ora = require("ora");
42
42
  const cliProgress = require("cli-progress");
43
43
  const pkgUp = require("pkg-up");
44
44
  const yup = require("yup");
45
- const _ = require("lodash");
46
45
  const EventSource = require("eventsource");
46
+ const commander = require("commander");
47
47
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
48
48
  function _interopNamespace(e) {
49
49
  if (e && e.__esModule)
@@ -65,12 +65,12 @@ function _interopNamespace(e) {
65
65
  }
66
66
  const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
67
67
  const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
68
+ const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
68
69
  const path__namespace = /* @__PURE__ */ _interopNamespace(path);
69
70
  const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
70
71
  const axios__default = /* @__PURE__ */ _interopDefault(axios);
71
72
  const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
72
73
  const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
73
- const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
74
74
  const os__default = /* @__PURE__ */ _interopDefault(os);
75
75
  const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
76
76
  const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
@@ -80,7 +80,6 @@ const ora__default = /* @__PURE__ */ _interopDefault(ora);
80
80
  const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
81
81
  const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
82
82
  const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
83
- const ___default = /* @__PURE__ */ _interopDefault(_);
84
83
  const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
85
84
  const apiConfig = {
86
85
  apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
@@ -194,7 +193,7 @@ async function saveLocalConfig(data) {
194
193
  await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
195
194
  }
196
195
  const name = "@strapi/cloud-cli";
197
- const version = "4.25.7";
196
+ const version = "5.2.0";
198
197
  const description = "Commands to interact with the Strapi Cloud";
199
198
  const keywords = [
200
199
  "strapi",
@@ -239,14 +238,14 @@ const scripts = {
239
238
  watch: "pack-up watch"
240
239
  };
241
240
  const dependencies = {
242
- "@strapi/utils": "4.25.7",
243
- axios: "1.6.0",
241
+ "@strapi/utils": "workspace:*",
242
+ axios: "1.7.4",
244
243
  chalk: "4.1.2",
245
244
  "cli-progress": "3.12.0",
246
245
  commander: "8.3.0",
247
246
  eventsource: "2.0.2",
248
247
  "fast-safe-stringify": "2.1.1",
249
- "fs-extra": "10.0.0",
248
+ "fs-extra": "11.2.0",
250
249
  inquirer: "8.2.5",
251
250
  jsonwebtoken: "9.0.0",
252
251
  "jwks-rsa": "3.1.0",
@@ -255,7 +254,7 @@ const dependencies = {
255
254
  open: "8.4.0",
256
255
  ora: "5.4.1",
257
256
  "pkg-up": "3.1.0",
258
- tar: "6.1.13",
257
+ tar: "6.2.1",
259
258
  "xdg-app-paths": "8.3.0",
260
259
  yup: "0.32.9"
261
260
  };
@@ -264,11 +263,11 @@ const devDependencies = {
264
263
  "@types/cli-progress": "3.11.5",
265
264
  "@types/eventsource": "1.1.15",
266
265
  "@types/lodash": "^4.14.191",
267
- "eslint-config-custom": "4.25.7",
268
- tsconfig: "4.25.7"
266
+ "eslint-config-custom": "workspace:*",
267
+ tsconfig: "workspace:*"
269
268
  };
270
269
  const engines = {
271
- node: ">=18.0.0 <=20.x.x",
270
+ node: ">=18.0.0 <=22.x.x",
272
271
  npm: ">=6.0.0"
273
272
  };
274
273
  const packageJson = {
@@ -318,7 +317,7 @@ async function cloudApiFactory({ logger }, token) {
318
317
  deploy({ filePath, project }, { onUploadProgress }) {
319
318
  return axiosCloudAPI.post(
320
319
  `/deploy/${project.name}`,
321
- { file: fse__namespace.default.createReadStream(filePath) },
320
+ { file: fse__namespace.default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
322
321
  {
323
322
  headers: {
324
323
  "Content-Type": "multipart/form-data"
@@ -377,7 +376,7 @@ async function cloudApiFactory({ logger }, token) {
377
376
  },
378
377
  async listLinkProjects() {
379
378
  try {
380
- const response = await axiosCloudAPI.get("/projects/linkable");
379
+ const response = await axiosCloudAPI.get("/projects-linkable");
381
380
  if (response.status !== 200) {
382
381
  throw new Error("Error fetching cloud projects from the server.");
383
382
  }
@@ -389,6 +388,34 @@ async function cloudApiFactory({ logger }, token) {
389
388
  throw error;
390
389
  }
391
390
  },
391
+ async listEnvironments({ name: name2 }) {
392
+ try {
393
+ const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
394
+ if (response.status !== 200) {
395
+ throw new Error("Error fetching cloud environments from the server.");
396
+ }
397
+ return response;
398
+ } catch (error) {
399
+ logger.debug(
400
+ "🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
401
+ );
402
+ throw error;
403
+ }
404
+ },
405
+ async getProject({ name: name2 }) {
406
+ try {
407
+ const response = await axiosCloudAPI.get(`/projects/${name2}`);
408
+ if (response.status !== 200) {
409
+ throw new Error("Error fetching project's details.");
410
+ }
411
+ return response;
412
+ } catch (error) {
413
+ logger.debug(
414
+ "🥲 Oops! There was a problem retrieving your project's details. Please try again."
415
+ );
416
+ throw error;
417
+ }
418
+ },
392
419
  track(event, payload = {}) {
393
420
  return axiosCloudAPI.post("/track", {
394
421
  event,
@@ -662,21 +689,24 @@ yup__namespace.object({
662
689
  name: yup__namespace.string().required(),
663
690
  exports: yup__namespace.lazy(
664
691
  (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
692
+ typeof value === "object" ? Object.entries(value).reduce(
693
+ (acc, [key, value2]) => {
694
+ if (typeof value2 === "object") {
695
+ acc[key] = yup__namespace.object({
696
+ types: yup__namespace.string().optional(),
697
+ source: yup__namespace.string().required(),
698
+ module: yup__namespace.string().optional(),
699
+ import: yup__namespace.string().required(),
700
+ require: yup__namespace.string().required(),
701
+ default: yup__namespace.string().required()
702
+ }).noUnknown(true);
703
+ } else {
704
+ acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
705
+ }
706
+ return acc;
707
+ },
708
+ {}
709
+ ) : void 0
680
710
  ).optional()
681
711
  )
682
712
  });
@@ -698,18 +728,6 @@ async function getProjectNameFromPackageJson(ctx) {
698
728
  return "my-strapi-project";
699
729
  }
700
730
  }
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
731
  const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
714
732
  try {
715
733
  await cloudApiService.track(eventName, eventData);
@@ -873,6 +891,45 @@ async function loginAction(ctx) {
873
891
  await authenticate();
874
892
  return isAuthenticated;
875
893
  }
894
+ function questionDefaultValuesMapper(questionsMap) {
895
+ return (questions) => {
896
+ return questions.map((question) => {
897
+ const questionName = question.name;
898
+ if (questionName in questionsMap) {
899
+ const questionDefault = questionsMap[questionName];
900
+ if (typeof questionDefault === "function") {
901
+ return {
902
+ ...question,
903
+ default: questionDefault(question)
904
+ };
905
+ }
906
+ return {
907
+ ...question,
908
+ default: questionDefault
909
+ };
910
+ }
911
+ return question;
912
+ });
913
+ };
914
+ }
915
+ function getDefaultsFromQuestions(questions) {
916
+ return questions.reduce((acc, question) => {
917
+ if (question.default && question.name) {
918
+ return { ...acc, [question.name]: question.default };
919
+ }
920
+ return acc;
921
+ }, {});
922
+ }
923
+ function getProjectNodeVersionDefault(question) {
924
+ const currentNodeVersion = process.versions.node.split(".")[0];
925
+ if (question.type === "list" && Array.isArray(question.choices)) {
926
+ const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
927
+ if (choice) {
928
+ return choice.value;
929
+ }
930
+ }
931
+ return question.default;
932
+ }
876
933
  async function handleError(ctx, error) {
877
934
  const { logger } = ctx;
878
935
  logger.debug(error);
@@ -917,7 +974,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
917
974
  throw e;
918
975
  }
919
976
  }
920
- const action$4 = async (ctx) => {
977
+ const action$5 = async (ctx) => {
921
978
  const { logger } = ctx;
922
979
  const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
923
980
  const token = await getValidToken(ctx, promptLogin);
@@ -926,11 +983,16 @@ const action$4 = async (ctx) => {
926
983
  }
927
984
  const cloudApi = await cloudApiFactory(ctx, token);
928
985
  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
- );
986
+ const projectName = await getProjectNameFromPackageJson(ctx);
987
+ const defaultAnswersMapper = questionDefaultValuesMapper({
988
+ name: projectName,
989
+ nodeVersion: getProjectNodeVersionDefault
990
+ });
991
+ const questions = defaultAnswersMapper(config.projectCreation.questions);
992
+ const defaultValues = {
993
+ ...config.projectCreation.defaults,
994
+ ...getDefaultsFromQuestions(questions)
995
+ };
934
996
  const projectAnswersDefaulted = fp.defaults(defaultValues);
935
997
  const projectAnswers = await inquirer__default.default.prompt(questions);
936
998
  const projectInput = projectAnswersDefaulted(projectAnswers);
@@ -1041,6 +1103,32 @@ const buildLogsServiceFactory = ({ logger }) => {
1041
1103
  });
1042
1104
  };
1043
1105
  };
1106
+ const QUIT_OPTION$1 = "Quit";
1107
+ async function promptForEnvironment(environments) {
1108
+ const choices = environments.map((env) => ({ name: env, value: env }));
1109
+ const { selectedEnvironment } = await inquirer__default.default.prompt([
1110
+ {
1111
+ type: "list",
1112
+ name: "selectedEnvironment",
1113
+ message: "Select the environment to deploy:",
1114
+ choices: [...choices, { name: chalk__default.default.grey(`(${QUIT_OPTION$1})`), value: null }]
1115
+ }
1116
+ ]);
1117
+ if (selectedEnvironment === null) {
1118
+ process.exit(1);
1119
+ }
1120
+ const { confirm } = await inquirer__default.default.prompt([
1121
+ {
1122
+ type: "confirm",
1123
+ name: "confirm",
1124
+ message: `Do you want to proceed with deployment to ${chalk__default.default.cyan(selectedEnvironment)}?`
1125
+ }
1126
+ ]);
1127
+ if (!confirm) {
1128
+ process.exit(1);
1129
+ }
1130
+ return selectedEnvironment;
1131
+ }
1044
1132
  async function upload(ctx, project, token, maxProjectFileSize) {
1045
1133
  const cloudApi = await cloudApiFactory(ctx, token);
1046
1134
  try {
@@ -1107,17 +1195,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1107
1195
  return data.build_id;
1108
1196
  } catch (e) {
1109
1197
  progressBar.stop();
1110
- if (e instanceof axios.AxiosError && e.response?.data) {
1111
- if (e.response.status === 404) {
1112
- ctx.logger.warn(
1113
- `The project does not exist. Please link your local project to a Strapi Cloud project using the link command.`
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
- }
1198
+ ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1121
1199
  ctx.logger.debug(e);
1122
1200
  } finally {
1123
1201
  await fse__namespace.default.remove(tarFilePath);
@@ -1129,11 +1207,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1129
1207
  process.exit(1);
1130
1208
  }
1131
1209
  }
1132
- async function getProject(ctx) {
1210
+ async function getProject$1(ctx) {
1133
1211
  const { project } = await retrieve();
1134
1212
  if (!project) {
1135
1213
  try {
1136
- return await action$4(ctx);
1214
+ return await action$5(ctx);
1137
1215
  } catch (e) {
1138
1216
  ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1139
1217
  ctx.logger.debug(e);
@@ -1154,17 +1232,51 @@ async function getConfig({
1154
1232
  return null;
1155
1233
  }
1156
1234
  }
1157
- const action$3 = async (ctx) => {
1235
+ const action$4 = async (ctx, opts) => {
1158
1236
  const { getValidToken } = await tokenServiceFactory(ctx);
1159
1237
  const token = await getValidToken(ctx, promptLogin);
1160
1238
  if (!token) {
1161
1239
  return;
1162
1240
  }
1163
- const project = await getProject(ctx);
1241
+ const project = await getProject$1(ctx);
1164
1242
  if (!project) {
1165
1243
  return;
1166
1244
  }
1167
- const cloudApiService = await cloudApiFactory(ctx);
1245
+ const cloudApiService = await cloudApiFactory(ctx, token);
1246
+ let environments;
1247
+ try {
1248
+ const {
1249
+ data: { data: projectData, metadata }
1250
+ } = await cloudApiService.getProject({ name: project.name });
1251
+ const isProjectSuspended = projectData.suspendedAt;
1252
+ environments = projectData.environments;
1253
+ if (isProjectSuspended) {
1254
+ ctx.logger.log(
1255
+ "\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
1256
+ );
1257
+ ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
1258
+ return;
1259
+ }
1260
+ } catch (e) {
1261
+ if (e instanceof axios.AxiosError && e.response?.data) {
1262
+ if (e.response.status === 404) {
1263
+ ctx.logger.warn(
1264
+ `The project associated with this folder does not exist in Strapi Cloud.
1265
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1266
+ "link"
1267
+ )} command before deploying.`
1268
+ );
1269
+ } else {
1270
+ ctx.logger.error(e.response.data);
1271
+ }
1272
+ } else {
1273
+ ctx.logger.error(
1274
+ "An error occurred while retrieving the project's information. Please try again later."
1275
+ );
1276
+ }
1277
+ ctx.logger.debug(e);
1278
+ return;
1279
+ }
1168
1280
  await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
1169
1281
  projectInternalName: project.name
1170
1282
  });
@@ -1173,7 +1285,7 @@ const action$3 = async (ctx) => {
1173
1285
  const cliConfig2 = await getConfig({ ctx, cloudApiService });
1174
1286
  if (!cliConfig2) {
1175
1287
  ctx.logger.error(
1176
- "An error occurred while retrieving data from Strapi Cloud. Please try check your network or again later."
1288
+ "An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
1177
1289
  );
1178
1290
  return;
1179
1291
  }
@@ -1184,6 +1296,17 @@ const action$3 = async (ctx) => {
1184
1296
  );
1185
1297
  maxSize = 1e8;
1186
1298
  }
1299
+ let targetEnvironment;
1300
+ if (opts.environment) {
1301
+ if (!environments.includes(opts.environment)) {
1302
+ ctx.logger.error(`Environment ${opts.environment} does not exist.`);
1303
+ return;
1304
+ }
1305
+ targetEnvironment = opts.environment;
1306
+ } else {
1307
+ targetEnvironment = environments.length > 1 ? await promptForEnvironment(environments) : environments[0];
1308
+ }
1309
+ project.targetEnvironment = targetEnvironment;
1187
1310
  const buildId = await upload(ctx, project, token, maxSize);
1188
1311
  if (!buildId) {
1189
1312
  return;
@@ -1233,14 +1356,14 @@ const runAction = (name2, action2) => (...args) => {
1233
1356
  process.exit(1);
1234
1357
  });
1235
1358
  };
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));
1359
+ const command$6 = ({ ctx }) => {
1360
+ 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("-e, --environment <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$4)(ctx, opts));
1238
1361
  };
1239
1362
  const deployProject = {
1240
1363
  name: "deploy-project",
1241
1364
  description: "Deploy a Strapi Cloud project",
1242
- action: action$3,
1243
- command: command$5
1365
+ action: action$4,
1366
+ command: command$6
1244
1367
  };
1245
1368
  const QUIT_OPTION = "Quit";
1246
1369
  async function getExistingConfig(ctx) {
@@ -1324,7 +1447,7 @@ async function getUserSelection(ctx, projects) {
1324
1447
  return null;
1325
1448
  }
1326
1449
  }
1327
- const action$2 = async (ctx) => {
1450
+ const action$3 = async (ctx) => {
1328
1451
  const { getValidToken } = await tokenServiceFactory(ctx);
1329
1452
  const token = await getValidToken(ctx, promptLogin);
1330
1453
  const { logger } = ctx;
@@ -1379,17 +1502,17 @@ const action$2 = async (ctx) => {
1379
1502
  });
1380
1503
  }
1381
1504
  };
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));
1505
+ const command$5 = ({ command: command2, ctx }) => {
1506
+ 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$3)(ctx));
1384
1507
  };
1385
1508
  const link = {
1386
1509
  name: "link-project",
1387
1510
  description: "Link a local directory to a Strapi Cloud project",
1388
- action: action$2,
1389
- command: command$4
1511
+ action: action$3,
1512
+ command: command$5
1390
1513
  };
1391
- const command$3 = ({ command: command2, ctx }) => {
1392
- command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1514
+ const command$4 = ({ ctx }) => {
1515
+ return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1393
1516
  "after",
1394
1517
  "\nAfter running this command, you will be prompted to enter your authentication information."
1395
1518
  ).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
@@ -1398,10 +1521,10 @@ const login = {
1398
1521
  name: "login",
1399
1522
  description: "Strapi Cloud Login",
1400
1523
  action: loginAction,
1401
- command: command$3
1524
+ command: command$4
1402
1525
  };
1403
1526
  const openModule = import("open");
1404
- const action$1 = async (ctx) => {
1527
+ const action$2 = async (ctx) => {
1405
1528
  const { logger } = ctx;
1406
1529
  const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
1407
1530
  const token = await retrieveToken();
@@ -1433,25 +1556,25 @@ const action$1 = async (ctx) => {
1433
1556
  }
1434
1557
  await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
1435
1558
  };
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));
1559
+ const command$3 = ({ ctx }) => {
1560
+ 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$2)(ctx));
1438
1561
  };
1439
1562
  const logout = {
1440
1563
  name: "logout",
1441
1564
  description: "Strapi Cloud Logout",
1442
- action: action$1,
1443
- command: command$2
1565
+ action: action$2,
1566
+ command: command$3
1444
1567
  };
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));
1568
+ const command$2 = ({ ctx }) => {
1569
+ 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$5)(ctx));
1447
1570
  };
1448
1571
  const createProject = {
1449
1572
  name: "create-project",
1450
1573
  description: "Create a new project",
1451
- action: action$4,
1452
- command: command$1
1574
+ action: action$5,
1575
+ command: command$2
1453
1576
  };
1454
- const action = async (ctx) => {
1577
+ const action$1 = async (ctx) => {
1455
1578
  const { getValidToken } = await tokenServiceFactory(ctx);
1456
1579
  const token = await getValidToken(ctx, promptLogin);
1457
1580
  const { logger } = ctx;
@@ -1471,12 +1594,94 @@ const action = async (ctx) => {
1471
1594
  spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
1472
1595
  }
1473
1596
  };
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));
1597
+ const command$1 = ({ command: command2, ctx }) => {
1598
+ 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$1)(ctx));
1476
1599
  };
1477
1600
  const listProjects = {
1478
1601
  name: "list-projects",
1479
1602
  description: "List Strapi Cloud projects",
1603
+ action: action$1,
1604
+ command: command$1
1605
+ };
1606
+ async function getProject(ctx) {
1607
+ const { project } = await retrieve();
1608
+ if (!project) {
1609
+ ctx.logger.warn(
1610
+ `
1611
+ We couldn't find a valid local project config.
1612
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1613
+ "link"
1614
+ )} command`
1615
+ );
1616
+ process.exit(1);
1617
+ }
1618
+ return project;
1619
+ }
1620
+ const action = async (ctx) => {
1621
+ const { getValidToken } = await tokenServiceFactory(ctx);
1622
+ const token = await getValidToken(ctx, promptLogin);
1623
+ const { logger } = ctx;
1624
+ if (!token) {
1625
+ return;
1626
+ }
1627
+ const project = await getProject(ctx);
1628
+ if (!project) {
1629
+ ctx.logger.debug(`No valid local project configuration was found.`);
1630
+ return;
1631
+ }
1632
+ const cloudApiService = await cloudApiFactory(ctx, token);
1633
+ const spinner = logger.spinner("Fetching environments...").start();
1634
+ await trackEvent(ctx, cloudApiService, "willListEnvironment", {
1635
+ projectInternalName: project.name
1636
+ });
1637
+ try {
1638
+ const {
1639
+ data: { data: environmentsList }
1640
+ } = await cloudApiService.listEnvironments({ name: project.name });
1641
+ spinner.succeed();
1642
+ logger.log(environmentsList);
1643
+ await trackEvent(ctx, cloudApiService, "didListEnvironment", {
1644
+ projectInternalName: project.name
1645
+ });
1646
+ } catch (e) {
1647
+ if (e.response && e.response.status === 404) {
1648
+ spinner.succeed();
1649
+ logger.warn(
1650
+ `
1651
+ The project associated with this folder does not exist in Strapi Cloud.
1652
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1653
+ "link"
1654
+ )} command`
1655
+ );
1656
+ } else {
1657
+ spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
1658
+ logger.debug("Failed to list environments", e);
1659
+ }
1660
+ await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
1661
+ projectInternalName: project.name
1662
+ });
1663
+ }
1664
+ };
1665
+ function defineCloudNamespace(command2, ctx) {
1666
+ const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
1667
+ cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
1668
+ return cloud;
1669
+ }
1670
+ let environmentCmd = null;
1671
+ const initializeEnvironmentCommand = (command2, ctx) => {
1672
+ if (!environmentCmd) {
1673
+ const cloud = defineCloudNamespace(command2, ctx);
1674
+ environmentCmd = cloud.command("environment").description("Manage environments");
1675
+ }
1676
+ return environmentCmd;
1677
+ };
1678
+ const command = ({ command: command2, ctx }) => {
1679
+ const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
1680
+ 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)(ctx));
1681
+ };
1682
+ const listEnvironments = {
1683
+ name: "list-environments",
1684
+ description: "List Strapi Cloud environments",
1480
1685
  action,
1481
1686
  command
1482
1687
  };
@@ -1486,9 +1691,10 @@ const cli = {
1486
1691
  login,
1487
1692
  logout,
1488
1693
  createProject,
1489
- listProjects
1694
+ listProjects,
1695
+ listEnvironments
1490
1696
  };
1491
- const cloudCommands = [deployProject, link, login, logout, listProjects];
1697
+ const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
1492
1698
  async function initCloudCLIConfig() {
1493
1699
  const localConfig = await getLocalConfig();
1494
1700
  if (!localConfig.deviceId) {
@@ -1504,7 +1710,10 @@ async function buildStrapiCloudCommands({
1504
1710
  await initCloudCLIConfig();
1505
1711
  for (const cloudCommand of cloudCommands) {
1506
1712
  try {
1507
- await cloudCommand.command({ command: command2, ctx, argv });
1713
+ const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
1714
+ if (subCommand) {
1715
+ command2.addCommand(subCommand);
1716
+ }
1508
1717
  } catch (e) {
1509
1718
  console.error(`Failed to load command ${cloudCommand.name}`, e);
1510
1719
  }