@strapi/cloud-cli 4.25.7 → 4.25.9

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.mjs CHANGED
@@ -20,7 +20,6 @@ import ora from "ora";
20
20
  import * as cliProgress from "cli-progress";
21
21
  import pkgUp from "pkg-up";
22
22
  import * as yup from "yup";
23
- import _ from "lodash";
24
23
  import EventSource from "eventsource";
25
24
  const apiConfig = {
26
25
  apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
@@ -134,7 +133,7 @@ async function saveLocalConfig(data) {
134
133
  await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
135
134
  }
136
135
  const name = "@strapi/cloud-cli";
137
- const version = "4.25.6";
136
+ const version = "4.25.8";
138
137
  const description = "Commands to interact with the Strapi Cloud";
139
138
  const keywords = [
140
139
  "strapi",
@@ -179,8 +178,8 @@ const scripts = {
179
178
  watch: "pack-up watch"
180
179
  };
181
180
  const dependencies = {
182
- "@strapi/utils": "4.25.6",
183
- axios: "1.6.0",
181
+ "@strapi/utils": "4.25.8",
182
+ axios: "1.7.4",
184
183
  chalk: "4.1.2",
185
184
  "cli-progress": "3.12.0",
186
185
  commander: "8.3.0",
@@ -204,8 +203,8 @@ const devDependencies = {
204
203
  "@types/cli-progress": "3.11.5",
205
204
  "@types/eventsource": "1.1.15",
206
205
  "@types/lodash": "^4.14.191",
207
- "eslint-config-custom": "4.25.6",
208
- tsconfig: "4.25.6"
206
+ "eslint-config-custom": "4.25.8",
207
+ tsconfig: "4.25.8"
209
208
  };
210
209
  const engines = {
211
210
  node: ">=18.0.0 <=20.x.x",
@@ -317,7 +316,7 @@ async function cloudApiFactory({ logger }, token) {
317
316
  },
318
317
  async listLinkProjects() {
319
318
  try {
320
- const response = await axiosCloudAPI.get("/projects/linkable");
319
+ const response = await axiosCloudAPI.get("/projects-linkable");
321
320
  if (response.status !== 200) {
322
321
  throw new Error("Error fetching cloud projects from the server.");
323
322
  }
@@ -329,6 +328,20 @@ async function cloudApiFactory({ logger }, token) {
329
328
  throw error;
330
329
  }
331
330
  },
331
+ async getProject({ name: name2 }) {
332
+ try {
333
+ const response = await axiosCloudAPI.get(`/projects/${name2}`);
334
+ if (response.status !== 200) {
335
+ throw new Error("Error fetching project's details.");
336
+ }
337
+ return response;
338
+ } catch (error) {
339
+ logger.debug(
340
+ "🥲 Oops! There was a problem retrieving your project's details. Please try again."
341
+ );
342
+ throw error;
343
+ }
344
+ },
332
345
  track(event, payload = {}) {
333
346
  return axiosCloudAPI.post("/track", {
334
347
  event,
@@ -638,18 +651,6 @@ async function getProjectNameFromPackageJson(ctx) {
638
651
  return "my-strapi-project";
639
652
  }
640
653
  }
641
- function applyDefaultName(newDefaultName, questions, defaultValues) {
642
- const newDefaultValues = _.cloneDeep(defaultValues);
643
- newDefaultValues.name = newDefaultName;
644
- const newQuestions = questions.map((question) => {
645
- const questionCopy = _.cloneDeep(question);
646
- if (questionCopy.name === "name") {
647
- questionCopy.default = newDefaultName;
648
- }
649
- return questionCopy;
650
- });
651
- return { newQuestions, newDefaultValues };
652
- }
653
654
  const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
654
655
  try {
655
656
  await cloudApiService.track(eventName, eventData);
@@ -813,6 +814,45 @@ async function loginAction(ctx) {
813
814
  await authenticate();
814
815
  return isAuthenticated;
815
816
  }
817
+ function questionDefaultValuesMapper(questionsMap) {
818
+ return (questions) => {
819
+ return questions.map((question) => {
820
+ const questionName = question.name;
821
+ if (questionName in questionsMap) {
822
+ const questionDefault = questionsMap[questionName];
823
+ if (typeof questionDefault === "function") {
824
+ return {
825
+ ...question,
826
+ default: questionDefault(question)
827
+ };
828
+ }
829
+ return {
830
+ ...question,
831
+ default: questionDefault
832
+ };
833
+ }
834
+ return question;
835
+ });
836
+ };
837
+ }
838
+ function getDefaultsFromQuestions(questions) {
839
+ return questions.reduce((acc, question) => {
840
+ if (question.default && question.name) {
841
+ return { ...acc, [question.name]: question.default };
842
+ }
843
+ return acc;
844
+ }, {});
845
+ }
846
+ function getProjectNodeVersionDefault(question) {
847
+ const currentNodeVersion = process.versions.node.split(".")[0];
848
+ if (question.type === "list" && Array.isArray(question.choices)) {
849
+ const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
850
+ if (choice) {
851
+ return choice.value;
852
+ }
853
+ }
854
+ return question.default;
855
+ }
816
856
  async function handleError(ctx, error) {
817
857
  const { logger } = ctx;
818
858
  logger.debug(error);
@@ -866,11 +906,16 @@ const action$4 = async (ctx) => {
866
906
  }
867
907
  const cloudApi = await cloudApiFactory(ctx, token);
868
908
  const { data: config } = await cloudApi.config();
869
- const { newQuestions: questions, newDefaultValues: defaultValues } = applyDefaultName(
870
- await getProjectNameFromPackageJson(ctx),
871
- config.projectCreation.questions,
872
- config.projectCreation.defaults
873
- );
909
+ const projectName = await getProjectNameFromPackageJson(ctx);
910
+ const defaultAnswersMapper = questionDefaultValuesMapper({
911
+ name: projectName,
912
+ nodeVersion: getProjectNodeVersionDefault
913
+ });
914
+ const questions = defaultAnswersMapper(config.projectCreation.questions);
915
+ const defaultValues = {
916
+ ...config.projectCreation.defaults,
917
+ ...getDefaultsFromQuestions(questions)
918
+ };
874
919
  const projectAnswersDefaulted = defaults(defaultValues);
875
920
  const projectAnswers = await inquirer.prompt(questions);
876
921
  const projectInput = projectAnswersDefaulted(projectAnswers);
@@ -1047,17 +1092,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1047
1092
  return data.build_id;
1048
1093
  } catch (e) {
1049
1094
  progressBar.stop();
1050
- if (e instanceof AxiosError && e.response?.data) {
1051
- if (e.response.status === 404) {
1052
- ctx.logger.warn(
1053
- `The project does not exist. Please link your local project to a Strapi Cloud project using the link command.`
1054
- );
1055
- } else {
1056
- ctx.logger.error(e.response.data);
1057
- }
1058
- } else {
1059
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1060
- }
1095
+ ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1061
1096
  ctx.logger.debug(e);
1062
1097
  } finally {
1063
1098
  await fse__default.remove(tarFilePath);
@@ -1104,7 +1139,39 @@ const action$3 = async (ctx) => {
1104
1139
  if (!project) {
1105
1140
  return;
1106
1141
  }
1107
- const cloudApiService = await cloudApiFactory(ctx);
1142
+ const cloudApiService = await cloudApiFactory(ctx, token);
1143
+ try {
1144
+ const {
1145
+ data: { data: projectData, metadata }
1146
+ } = await cloudApiService.getProject({ name: project.name });
1147
+ const isProjectSuspended = projectData.suspendedAt;
1148
+ if (isProjectSuspended) {
1149
+ ctx.logger.log(
1150
+ "\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
1151
+ );
1152
+ ctx.logger.log(chalk.underline(`${metadata.dashboardUrls.project}`));
1153
+ return;
1154
+ }
1155
+ } catch (e) {
1156
+ if (e instanceof AxiosError && e.response?.data) {
1157
+ if (e.response.status === 404) {
1158
+ ctx.logger.warn(
1159
+ `The project associated with this folder does not exist in Strapi Cloud.
1160
+ Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
1161
+ "link"
1162
+ )} command before deploying.`
1163
+ );
1164
+ } else {
1165
+ ctx.logger.error(e.response.data);
1166
+ }
1167
+ } else {
1168
+ ctx.logger.error(
1169
+ "An error occurred while retrieving the project's information. Please try again later."
1170
+ );
1171
+ }
1172
+ ctx.logger.debug(e);
1173
+ return;
1174
+ }
1108
1175
  await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
1109
1176
  projectInternalName: project.name
1110
1177
  });
@@ -1113,7 +1180,7 @@ const action$3 = async (ctx) => {
1113
1180
  const cliConfig2 = await getConfig({ ctx, cloudApiService });
1114
1181
  if (!cliConfig2) {
1115
1182
  ctx.logger.error(
1116
- "An error occurred while retrieving data from Strapi Cloud. Please try check your network or again later."
1183
+ "An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
1117
1184
  );
1118
1185
  return;
1119
1186
  }