@strapi/cloud-cli 0.0.0-next.7466630056657c483fb286557dda890490597807 → 0.0.0-next.7f1333f1967e625c57ab16648c057aea08c9dddb

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/index.js CHANGED
@@ -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)
@@ -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.0.2-beta.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,8 +263,8 @@ 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
270
  node: ">=18.0.0 <=20.x.x",
@@ -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,20 @@ async function cloudApiFactory({ logger }, token) {
389
388
  throw error;
390
389
  }
391
390
  },
391
+ async getProject({ name: name2 }) {
392
+ try {
393
+ const response = await axiosCloudAPI.get(`/projects/${name2}`);
394
+ if (response.status !== 200) {
395
+ throw new Error("Error fetching project's details.");
396
+ }
397
+ return response;
398
+ } catch (error) {
399
+ logger.debug(
400
+ "🥲 Oops! There was a problem retrieving your project's details. Please try again."
401
+ );
402
+ throw error;
403
+ }
404
+ },
392
405
  track(event, payload = {}) {
393
406
  return axiosCloudAPI.post("/track", {
394
407
  event,
@@ -662,21 +675,24 @@ yup__namespace.object({
662
675
  name: yup__namespace.string().required(),
663
676
  exports: yup__namespace.lazy(
664
677
  (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
678
+ typeof value === "object" ? Object.entries(value).reduce(
679
+ (acc, [key, value2]) => {
680
+ if (typeof value2 === "object") {
681
+ acc[key] = yup__namespace.object({
682
+ types: yup__namespace.string().optional(),
683
+ source: yup__namespace.string().required(),
684
+ module: yup__namespace.string().optional(),
685
+ import: yup__namespace.string().required(),
686
+ require: yup__namespace.string().required(),
687
+ default: yup__namespace.string().required()
688
+ }).noUnknown(true);
689
+ } else {
690
+ acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
691
+ }
692
+ return acc;
693
+ },
694
+ {}
695
+ ) : void 0
680
696
  ).optional()
681
697
  )
682
698
  });
@@ -698,18 +714,6 @@ async function getProjectNameFromPackageJson(ctx) {
698
714
  return "my-strapi-project";
699
715
  }
700
716
  }
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
717
  const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
714
718
  try {
715
719
  await cloudApiService.track(eventName, eventData);
@@ -873,6 +877,45 @@ async function loginAction(ctx) {
873
877
  await authenticate();
874
878
  return isAuthenticated;
875
879
  }
880
+ function questionDefaultValuesMapper(questionsMap) {
881
+ return (questions) => {
882
+ return questions.map((question) => {
883
+ const questionName = question.name;
884
+ if (questionName in questionsMap) {
885
+ const questionDefault = questionsMap[questionName];
886
+ if (typeof questionDefault === "function") {
887
+ return {
888
+ ...question,
889
+ default: questionDefault(question)
890
+ };
891
+ }
892
+ return {
893
+ ...question,
894
+ default: questionDefault
895
+ };
896
+ }
897
+ return question;
898
+ });
899
+ };
900
+ }
901
+ function getDefaultsFromQuestions(questions) {
902
+ return questions.reduce((acc, question) => {
903
+ if (question.default && question.name) {
904
+ return { ...acc, [question.name]: question.default };
905
+ }
906
+ return acc;
907
+ }, {});
908
+ }
909
+ function getProjectNodeVersionDefault(question) {
910
+ const currentNodeVersion = process.versions.node.split(".")[0];
911
+ if (question.type === "list" && Array.isArray(question.choices)) {
912
+ const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
913
+ if (choice) {
914
+ return choice.value;
915
+ }
916
+ }
917
+ return question.default;
918
+ }
876
919
  async function handleError(ctx, error) {
877
920
  const { logger } = ctx;
878
921
  logger.debug(error);
@@ -926,11 +969,16 @@ const action$4 = async (ctx) => {
926
969
  }
927
970
  const cloudApi = await cloudApiFactory(ctx, token);
928
971
  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
- );
972
+ const projectName = await getProjectNameFromPackageJson(ctx);
973
+ const defaultAnswersMapper = questionDefaultValuesMapper({
974
+ name: projectName,
975
+ nodeVersion: getProjectNodeVersionDefault
976
+ });
977
+ const questions = defaultAnswersMapper(config.projectCreation.questions);
978
+ const defaultValues = {
979
+ ...config.projectCreation.defaults,
980
+ ...getDefaultsFromQuestions(questions)
981
+ };
934
982
  const projectAnswersDefaulted = fp.defaults(defaultValues);
935
983
  const projectAnswers = await inquirer__default.default.prompt(questions);
936
984
  const projectInput = projectAnswersDefaulted(projectAnswers);
@@ -1107,17 +1155,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1107
1155
  return data.build_id;
1108
1156
  } catch (e) {
1109
1157
  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
- }
1158
+ ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1121
1159
  ctx.logger.debug(e);
1122
1160
  } finally {
1123
1161
  await fse__namespace.default.remove(tarFilePath);
@@ -1164,7 +1202,39 @@ const action$3 = async (ctx) => {
1164
1202
  if (!project) {
1165
1203
  return;
1166
1204
  }
1167
- const cloudApiService = await cloudApiFactory(ctx);
1205
+ const cloudApiService = await cloudApiFactory(ctx, token);
1206
+ try {
1207
+ const {
1208
+ data: { data: projectData, metadata }
1209
+ } = await cloudApiService.getProject({ name: project.name });
1210
+ const isProjectSuspended = projectData.suspendedAt;
1211
+ if (isProjectSuspended) {
1212
+ ctx.logger.log(
1213
+ "\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
1214
+ );
1215
+ ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
1216
+ return;
1217
+ }
1218
+ } catch (e) {
1219
+ if (e instanceof axios.AxiosError && e.response?.data) {
1220
+ if (e.response.status === 404) {
1221
+ ctx.logger.warn(
1222
+ `The project associated with this folder does not exist in Strapi Cloud.
1223
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1224
+ "link"
1225
+ )} command before deploying.`
1226
+ );
1227
+ } else {
1228
+ ctx.logger.error(e.response.data);
1229
+ }
1230
+ } else {
1231
+ ctx.logger.error(
1232
+ "An error occurred while retrieving the project's information. Please try again later."
1233
+ );
1234
+ }
1235
+ ctx.logger.debug(e);
1236
+ return;
1237
+ }
1168
1238
  await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
1169
1239
  projectInternalName: project.name
1170
1240
  });
@@ -1173,7 +1243,7 @@ const action$3 = async (ctx) => {
1173
1243
  const cliConfig2 = await getConfig({ ctx, cloudApiService });
1174
1244
  if (!cliConfig2) {
1175
1245
  ctx.logger.error(
1176
- "An error occurred while retrieving data from Strapi Cloud. Please try check your network or again later."
1246
+ "An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
1177
1247
  );
1178
1248
  return;
1179
1249
  }
@@ -1233,8 +1303,8 @@ const runAction = (name2, action2) => (...args) => {
1233
1303
  process.exit(1);
1234
1304
  });
1235
1305
  };
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));
1306
+ const command$5 = ({ ctx }) => {
1307
+ 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").action(() => runAction("deploy", action$3)(ctx));
1238
1308
  };
1239
1309
  const deployProject = {
1240
1310
  name: "deploy-project",
@@ -1388,8 +1458,8 @@ const link = {
1388
1458
  action: action$2,
1389
1459
  command: command$4
1390
1460
  };
1391
- const command$3 = ({ command: command2, ctx }) => {
1392
- command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1461
+ const command$3 = ({ ctx }) => {
1462
+ return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1393
1463
  "after",
1394
1464
  "\nAfter running this command, you will be prompted to enter your authentication information."
1395
1465
  ).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
@@ -1433,8 +1503,8 @@ const action$1 = async (ctx) => {
1433
1503
  }
1434
1504
  await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
1435
1505
  };
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));
1506
+ const command$2 = ({ ctx }) => {
1507
+ 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$1)(ctx));
1438
1508
  };
1439
1509
  const logout = {
1440
1510
  name: "logout",
@@ -1442,8 +1512,8 @@ const logout = {
1442
1512
  action: action$1,
1443
1513
  command: command$2
1444
1514
  };
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));
1515
+ const command$1 = ({ ctx }) => {
1516
+ 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$4)(ctx));
1447
1517
  };
1448
1518
  const createProject = {
1449
1519
  name: "create-project",
@@ -1504,7 +1574,10 @@ async function buildStrapiCloudCommands({
1504
1574
  await initCloudCLIConfig();
1505
1575
  for (const cloudCommand of cloudCommands) {
1506
1576
  try {
1507
- await cloudCommand.command({ command: command2, ctx, argv });
1577
+ const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
1578
+ if (subCommand) {
1579
+ command2.addCommand(subCommand);
1580
+ }
1508
1581
  } catch (e) {
1509
1582
  console.error(`Failed to load command ${cloudCommand.name}`, e);
1510
1583
  }