@strapi/cloud-cli 5.2.0 → 5.4.0

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
@@ -1,6 +1,7 @@
1
1
  import crypto$1 from "crypto";
2
2
  import * as fse from "fs-extra";
3
3
  import fse__default from "fs-extra";
4
+ import inquirer from "inquirer";
4
5
  import * as path from "path";
5
6
  import path__default from "path";
6
7
  import chalk from "chalk";
@@ -9,7 +10,6 @@ import * as crypto from "node:crypto";
9
10
  import { env } from "@strapi/utils";
10
11
  import * as tar from "tar";
11
12
  import { minimatch } from "minimatch";
12
- import inquirer from "inquirer";
13
13
  import { defaults, has } from "lodash/fp";
14
14
  import os from "os";
15
15
  import XDGAppPaths from "xdg-app-paths";
@@ -134,7 +134,7 @@ async function saveLocalConfig(data) {
134
134
  await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
135
135
  }
136
136
  const name = "@strapi/cloud-cli";
137
- const version = "5.1.1";
137
+ const version = "5.4.0";
138
138
  const description = "Commands to interact with the Strapi Cloud";
139
139
  const keywords = [
140
140
  "strapi",
@@ -179,7 +179,7 @@ const scripts = {
179
179
  watch: "pack-up watch"
180
180
  };
181
181
  const dependencies = {
182
- "@strapi/utils": "workspace:*",
182
+ "@strapi/utils": "5.4.0",
183
183
  axios: "1.7.4",
184
184
  chalk: "4.1.2",
185
185
  "cli-progress": "3.12.0",
@@ -204,13 +204,14 @@ const devDependencies = {
204
204
  "@types/cli-progress": "3.11.5",
205
205
  "@types/eventsource": "1.1.15",
206
206
  "@types/lodash": "^4.14.191",
207
- "eslint-config-custom": "workspace:*",
208
- tsconfig: "workspace:*"
207
+ "eslint-config-custom": "5.4.0",
208
+ tsconfig: "5.4.0"
209
209
  };
210
210
  const engines = {
211
211
  node: ">=18.0.0 <=22.x.x",
212
212
  npm: ">=6.0.0"
213
213
  };
214
+ const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
214
215
  const packageJson = {
215
216
  name,
216
217
  version,
@@ -231,7 +232,8 @@ const packageJson = {
231
232
  scripts,
232
233
  dependencies,
233
234
  devDependencies,
234
- engines
235
+ engines,
236
+ gitHead
235
237
  };
236
238
  const VERSION = "v1";
237
239
  async function cloudApiFactory({ logger }, token) {
@@ -258,7 +260,7 @@ async function cloudApiFactory({ logger }, token) {
258
260
  deploy({ filePath, project }, { onUploadProgress }) {
259
261
  return axiosCloudAPI.post(
260
262
  `/deploy/${project.name}`,
261
- { file: fse__default.createReadStream(filePath) },
263
+ { file: fse__default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
262
264
  {
263
265
  headers: {
264
266
  "Content-Type": "multipart/form-data"
@@ -1044,6 +1046,32 @@ const buildLogsServiceFactory = ({ logger }) => {
1044
1046
  });
1045
1047
  };
1046
1048
  };
1049
+ const QUIT_OPTION$1 = "Quit";
1050
+ async function promptForEnvironment(environments) {
1051
+ const choices = environments.map((env2) => ({ name: env2, value: env2 }));
1052
+ const { selectedEnvironment } = await inquirer.prompt([
1053
+ {
1054
+ type: "list",
1055
+ name: "selectedEnvironment",
1056
+ message: "Select the environment to deploy:",
1057
+ choices: [...choices, { name: chalk.grey(`(${QUIT_OPTION$1})`), value: null }]
1058
+ }
1059
+ ]);
1060
+ if (selectedEnvironment === null) {
1061
+ process.exit(1);
1062
+ }
1063
+ const { confirm } = await inquirer.prompt([
1064
+ {
1065
+ type: "confirm",
1066
+ name: "confirm",
1067
+ message: `Do you want to proceed with deployment to ${chalk.cyan(selectedEnvironment)}?`
1068
+ }
1069
+ ]);
1070
+ if (!confirm) {
1071
+ process.exit(1);
1072
+ }
1073
+ return selectedEnvironment;
1074
+ }
1047
1075
  async function upload(ctx, project, token, maxProjectFileSize) {
1048
1076
  const cloudApi = await cloudApiFactory(ctx, token);
1049
1077
  try {
@@ -1147,7 +1175,7 @@ async function getConfig({
1147
1175
  return null;
1148
1176
  }
1149
1177
  }
1150
- const action$4 = async (ctx) => {
1178
+ const action$4 = async (ctx, opts) => {
1151
1179
  const { getValidToken } = await tokenServiceFactory(ctx);
1152
1180
  const token = await getValidToken(ctx, promptLogin);
1153
1181
  if (!token) {
@@ -1158,11 +1186,13 @@ const action$4 = async (ctx) => {
1158
1186
  return;
1159
1187
  }
1160
1188
  const cloudApiService = await cloudApiFactory(ctx, token);
1189
+ let environments;
1161
1190
  try {
1162
1191
  const {
1163
1192
  data: { data: projectData, metadata }
1164
1193
  } = await cloudApiService.getProject({ name: project.name });
1165
1194
  const isProjectSuspended = projectData.suspendedAt;
1195
+ environments = projectData.environments;
1166
1196
  if (isProjectSuspended) {
1167
1197
  ctx.logger.log(
1168
1198
  "\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
@@ -1209,6 +1239,17 @@ Please link your local project to an existing Strapi Cloud project using the ${c
1209
1239
  );
1210
1240
  maxSize = 1e8;
1211
1241
  }
1242
+ let targetEnvironment;
1243
+ if (opts.environment) {
1244
+ if (!environments.includes(opts.environment)) {
1245
+ ctx.logger.error(`Environment ${opts.environment} does not exist.`);
1246
+ return;
1247
+ }
1248
+ targetEnvironment = opts.environment;
1249
+ } else {
1250
+ targetEnvironment = environments.length > 1 ? await promptForEnvironment(environments) : environments[0];
1251
+ }
1252
+ project.targetEnvironment = targetEnvironment;
1212
1253
  const buildId = await upload(ctx, project, token, maxSize);
1213
1254
  if (!buildId) {
1214
1255
  return;
@@ -1259,7 +1300,7 @@ const runAction = (name2, action2) => (...args) => {
1259
1300
  });
1260
1301
  };
1261
1302
  const command$6 = ({ ctx }) => {
1262
- return 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$4)(ctx));
1303
+ return 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));
1263
1304
  };
1264
1305
  const deployProject = {
1265
1306
  name: "deploy-project",
@@ -1564,14 +1605,22 @@ Please link your local project to an existing Strapi Cloud project using the ${c
1564
1605
  });
1565
1606
  }
1566
1607
  };
1567
- function defineCloudNamespace(command2) {
1568
- return command2.command("cloud").description("Manage Strapi Cloud projects");
1608
+ function defineCloudNamespace(command2, ctx) {
1609
+ const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
1610
+ cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
1611
+ return cloud;
1569
1612
  }
1613
+ let environmentCmd = null;
1614
+ const initializeEnvironmentCommand = (command2, ctx) => {
1615
+ if (!environmentCmd) {
1616
+ const cloud = defineCloudNamespace(command2, ctx);
1617
+ environmentCmd = cloud.command("environment").description("Manage environments");
1618
+ }
1619
+ return environmentCmd;
1620
+ };
1570
1621
  const command = ({ command: command2, ctx }) => {
1571
- const cloud = defineCloudNamespace(command2);
1572
- cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
1573
- const environment = cloud.command("environment").description("Manage environments for a Strapi Cloud project");
1574
- environment.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));
1622
+ const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
1623
+ 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));
1575
1624
  };
1576
1625
  const listEnvironments = {
1577
1626
  name: "list-environments",