@strapi/cloud-cli 0.0.0-next.e9b6852d1c05518ff6e37d599321f7aa7aa0683b → 0.0.0-next.f5312617ca16b870c2bf1adcea2c69b676979e29

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
@@ -21,6 +21,7 @@ import * as cliProgress from "cli-progress";
21
21
  import pkgUp from "pkg-up";
22
22
  import * as yup from "yup";
23
23
  import EventSource from "eventsource";
24
+ import { createCommand } from "commander";
24
25
  const apiConfig = {
25
26
  apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
26
27
  dashboardBaseUrl: env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
@@ -133,7 +134,7 @@ async function saveLocalConfig(data) {
133
134
  await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
134
135
  }
135
136
  const name = "@strapi/cloud-cli";
136
- const version = "4.25.9";
137
+ const version = "5.1.1";
137
138
  const description = "Commands to interact with the Strapi Cloud";
138
139
  const keywords = [
139
140
  "strapi",
@@ -178,14 +179,14 @@ const scripts = {
178
179
  watch: "pack-up watch"
179
180
  };
180
181
  const dependencies = {
181
- "@strapi/utils": "4.25.9",
182
+ "@strapi/utils": "workspace:*",
182
183
  axios: "1.7.4",
183
184
  chalk: "4.1.2",
184
185
  "cli-progress": "3.12.0",
185
186
  commander: "8.3.0",
186
187
  eventsource: "2.0.2",
187
188
  "fast-safe-stringify": "2.1.1",
188
- "fs-extra": "10.0.0",
189
+ "fs-extra": "11.2.0",
189
190
  inquirer: "8.2.5",
190
191
  jsonwebtoken: "9.0.0",
191
192
  "jwks-rsa": "3.1.0",
@@ -194,7 +195,7 @@ const dependencies = {
194
195
  open: "8.4.0",
195
196
  ora: "5.4.1",
196
197
  "pkg-up": "3.1.0",
197
- tar: "6.1.13",
198
+ tar: "6.2.1",
198
199
  "xdg-app-paths": "8.3.0",
199
200
  yup: "0.32.9"
200
201
  };
@@ -203,11 +204,11 @@ const devDependencies = {
203
204
  "@types/cli-progress": "3.11.5",
204
205
  "@types/eventsource": "1.1.15",
205
206
  "@types/lodash": "^4.14.191",
206
- "eslint-config-custom": "4.25.9",
207
- tsconfig: "4.25.9"
207
+ "eslint-config-custom": "workspace:*",
208
+ tsconfig: "workspace:*"
208
209
  };
209
210
  const engines = {
210
- node: ">=18.0.0 <=20.x.x",
211
+ node: ">=18.0.0 <=22.x.x",
211
212
  npm: ">=6.0.0"
212
213
  };
213
214
  const packageJson = {
@@ -328,6 +329,20 @@ async function cloudApiFactory({ logger }, token) {
328
329
  throw error;
329
330
  }
330
331
  },
332
+ async listEnvironments({ name: name2 }) {
333
+ try {
334
+ const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
335
+ if (response.status !== 200) {
336
+ throw new Error("Error fetching cloud environments from the server.");
337
+ }
338
+ return response;
339
+ } catch (error) {
340
+ logger.debug(
341
+ "🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
342
+ );
343
+ throw error;
344
+ }
345
+ },
331
346
  async getProject({ name: name2 }) {
332
347
  try {
333
348
  const response = await axiosCloudAPI.get(`/projects/${name2}`);
@@ -615,21 +630,24 @@ yup.object({
615
630
  name: yup.string().required(),
616
631
  exports: yup.lazy(
617
632
  (value) => yup.object(
618
- typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
619
- if (typeof value2 === "object") {
620
- acc[key] = yup.object({
621
- types: yup.string().optional(),
622
- source: yup.string().required(),
623
- module: yup.string().optional(),
624
- import: yup.string().required(),
625
- require: yup.string().required(),
626
- default: yup.string().required()
627
- }).noUnknown(true);
628
- } else {
629
- acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
630
- }
631
- return acc;
632
- }, {}) : void 0
633
+ typeof value === "object" ? Object.entries(value).reduce(
634
+ (acc, [key, value2]) => {
635
+ if (typeof value2 === "object") {
636
+ acc[key] = yup.object({
637
+ types: yup.string().optional(),
638
+ source: yup.string().required(),
639
+ module: yup.string().optional(),
640
+ import: yup.string().required(),
641
+ require: yup.string().required(),
642
+ default: yup.string().required()
643
+ }).noUnknown(true);
644
+ } else {
645
+ acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
646
+ }
647
+ return acc;
648
+ },
649
+ {}
650
+ ) : void 0
633
651
  ).optional()
634
652
  )
635
653
  });
@@ -897,7 +915,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
897
915
  throw e;
898
916
  }
899
917
  }
900
- const action$4 = async (ctx) => {
918
+ const action$5 = async (ctx) => {
901
919
  const { logger } = ctx;
902
920
  const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
903
921
  const token = await getValidToken(ctx, promptLogin);
@@ -1104,11 +1122,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1104
1122
  process.exit(1);
1105
1123
  }
1106
1124
  }
1107
- async function getProject(ctx) {
1125
+ async function getProject$1(ctx) {
1108
1126
  const { project } = await retrieve();
1109
1127
  if (!project) {
1110
1128
  try {
1111
- return await action$4(ctx);
1129
+ return await action$5(ctx);
1112
1130
  } catch (e) {
1113
1131
  ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1114
1132
  ctx.logger.debug(e);
@@ -1129,13 +1147,13 @@ async function getConfig({
1129
1147
  return null;
1130
1148
  }
1131
1149
  }
1132
- const action$3 = async (ctx) => {
1150
+ const action$4 = async (ctx) => {
1133
1151
  const { getValidToken } = await tokenServiceFactory(ctx);
1134
1152
  const token = await getValidToken(ctx, promptLogin);
1135
1153
  if (!token) {
1136
1154
  return;
1137
1155
  }
1138
- const project = await getProject(ctx);
1156
+ const project = await getProject$1(ctx);
1139
1157
  if (!project) {
1140
1158
  return;
1141
1159
  }
@@ -1240,14 +1258,14 @@ const runAction = (name2, action2) => (...args) => {
1240
1258
  process.exit(1);
1241
1259
  });
1242
1260
  };
1243
- const command$5 = ({ command: command2, ctx }) => {
1244
- 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));
1261
+ 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));
1245
1263
  };
1246
1264
  const deployProject = {
1247
1265
  name: "deploy-project",
1248
1266
  description: "Deploy a Strapi Cloud project",
1249
- action: action$3,
1250
- command: command$5
1267
+ action: action$4,
1268
+ command: command$6
1251
1269
  };
1252
1270
  const QUIT_OPTION = "Quit";
1253
1271
  async function getExistingConfig(ctx) {
@@ -1331,7 +1349,7 @@ async function getUserSelection(ctx, projects) {
1331
1349
  return null;
1332
1350
  }
1333
1351
  }
1334
- const action$2 = async (ctx) => {
1352
+ const action$3 = async (ctx) => {
1335
1353
  const { getValidToken } = await tokenServiceFactory(ctx);
1336
1354
  const token = await getValidToken(ctx, promptLogin);
1337
1355
  const { logger } = ctx;
@@ -1386,17 +1404,17 @@ const action$2 = async (ctx) => {
1386
1404
  });
1387
1405
  }
1388
1406
  };
1389
- const command$4 = ({ command: command2, ctx }) => {
1390
- 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));
1407
+ const command$5 = ({ command: command2, ctx }) => {
1408
+ 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));
1391
1409
  };
1392
1410
  const link = {
1393
1411
  name: "link-project",
1394
1412
  description: "Link a local directory to a Strapi Cloud project",
1395
- action: action$2,
1396
- command: command$4
1413
+ action: action$3,
1414
+ command: command$5
1397
1415
  };
1398
- const command$3 = ({ command: command2, ctx }) => {
1399
- command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1416
+ const command$4 = ({ ctx }) => {
1417
+ return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1400
1418
  "after",
1401
1419
  "\nAfter running this command, you will be prompted to enter your authentication information."
1402
1420
  ).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
@@ -1405,10 +1423,10 @@ const login = {
1405
1423
  name: "login",
1406
1424
  description: "Strapi Cloud Login",
1407
1425
  action: loginAction,
1408
- command: command$3
1426
+ command: command$4
1409
1427
  };
1410
1428
  const openModule = import("open");
1411
- const action$1 = async (ctx) => {
1429
+ const action$2 = async (ctx) => {
1412
1430
  const { logger } = ctx;
1413
1431
  const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
1414
1432
  const token = await retrieveToken();
@@ -1440,25 +1458,25 @@ const action$1 = async (ctx) => {
1440
1458
  }
1441
1459
  await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
1442
1460
  };
1443
- const command$2 = ({ command: command2, ctx }) => {
1444
- 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));
1461
+ const command$3 = ({ ctx }) => {
1462
+ return 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));
1445
1463
  };
1446
1464
  const logout = {
1447
1465
  name: "logout",
1448
1466
  description: "Strapi Cloud Logout",
1449
- action: action$1,
1450
- command: command$2
1467
+ action: action$2,
1468
+ command: command$3
1451
1469
  };
1452
- const command$1 = ({ command: command2, ctx }) => {
1453
- 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));
1470
+ const command$2 = ({ ctx }) => {
1471
+ return 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));
1454
1472
  };
1455
1473
  const createProject = {
1456
1474
  name: "create-project",
1457
1475
  description: "Create a new project",
1458
- action: action$4,
1459
- command: command$1
1476
+ action: action$5,
1477
+ command: command$2
1460
1478
  };
1461
- const action = async (ctx) => {
1479
+ const action$1 = async (ctx) => {
1462
1480
  const { getValidToken } = await tokenServiceFactory(ctx);
1463
1481
  const token = await getValidToken(ctx, promptLogin);
1464
1482
  const { logger } = ctx;
@@ -1478,12 +1496,86 @@ const action = async (ctx) => {
1478
1496
  spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
1479
1497
  }
1480
1498
  };
1481
- const command = ({ command: command2, ctx }) => {
1482
- 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));
1499
+ const command$1 = ({ command: command2, ctx }) => {
1500
+ 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));
1483
1501
  };
1484
1502
  const listProjects = {
1485
1503
  name: "list-projects",
1486
1504
  description: "List Strapi Cloud projects",
1505
+ action: action$1,
1506
+ command: command$1
1507
+ };
1508
+ async function getProject(ctx) {
1509
+ const { project } = await retrieve();
1510
+ if (!project) {
1511
+ ctx.logger.warn(
1512
+ `
1513
+ We couldn't find a valid local project config.
1514
+ Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
1515
+ "link"
1516
+ )} command`
1517
+ );
1518
+ process.exit(1);
1519
+ }
1520
+ return project;
1521
+ }
1522
+ const action = async (ctx) => {
1523
+ const { getValidToken } = await tokenServiceFactory(ctx);
1524
+ const token = await getValidToken(ctx, promptLogin);
1525
+ const { logger } = ctx;
1526
+ if (!token) {
1527
+ return;
1528
+ }
1529
+ const project = await getProject(ctx);
1530
+ if (!project) {
1531
+ ctx.logger.debug(`No valid local project configuration was found.`);
1532
+ return;
1533
+ }
1534
+ const cloudApiService = await cloudApiFactory(ctx, token);
1535
+ const spinner = logger.spinner("Fetching environments...").start();
1536
+ await trackEvent(ctx, cloudApiService, "willListEnvironment", {
1537
+ projectInternalName: project.name
1538
+ });
1539
+ try {
1540
+ const {
1541
+ data: { data: environmentsList }
1542
+ } = await cloudApiService.listEnvironments({ name: project.name });
1543
+ spinner.succeed();
1544
+ logger.log(environmentsList);
1545
+ await trackEvent(ctx, cloudApiService, "didListEnvironment", {
1546
+ projectInternalName: project.name
1547
+ });
1548
+ } catch (e) {
1549
+ if (e.response && e.response.status === 404) {
1550
+ spinner.succeed();
1551
+ logger.warn(
1552
+ `
1553
+ The project associated with this folder does not exist in Strapi Cloud.
1554
+ Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
1555
+ "link"
1556
+ )} command`
1557
+ );
1558
+ } else {
1559
+ spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
1560
+ logger.debug("Failed to list environments", e);
1561
+ }
1562
+ await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
1563
+ projectInternalName: project.name
1564
+ });
1565
+ }
1566
+ };
1567
+ function defineCloudNamespace(command2) {
1568
+ return command2.command("cloud").description("Manage Strapi Cloud projects");
1569
+ }
1570
+ 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));
1575
+ };
1576
+ const listEnvironments = {
1577
+ name: "list-environments",
1578
+ description: "List Strapi Cloud environments",
1487
1579
  action,
1488
1580
  command
1489
1581
  };
@@ -1493,9 +1585,10 @@ const cli = {
1493
1585
  login,
1494
1586
  logout,
1495
1587
  createProject,
1496
- listProjects
1588
+ listProjects,
1589
+ listEnvironments
1497
1590
  };
1498
- const cloudCommands = [deployProject, link, login, logout, listProjects];
1591
+ const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
1499
1592
  async function initCloudCLIConfig() {
1500
1593
  const localConfig = await getLocalConfig();
1501
1594
  if (!localConfig.deviceId) {
@@ -1511,7 +1604,10 @@ async function buildStrapiCloudCommands({
1511
1604
  await initCloudCLIConfig();
1512
1605
  for (const cloudCommand of cloudCommands) {
1513
1606
  try {
1514
- await cloudCommand.command({ command: command2, ctx, argv });
1607
+ const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
1608
+ if (subCommand) {
1609
+ command2.addCommand(subCommand);
1610
+ }
1515
1611
  } catch (e) {
1516
1612
  console.error(`Failed to load command ${cloudCommand.name}`, e);
1517
1613
  }