@strapi/cloud-cli 5.0.6 → 5.1.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.js CHANGED
@@ -193,7 +193,7 @@ async function saveLocalConfig(data) {
193
193
  await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
194
194
  }
195
195
  const name = "@strapi/cloud-cli";
196
- const version = "5.0.0";
196
+ const version = "5.0.6";
197
197
  const description = "Commands to interact with the Strapi Cloud";
198
198
  const keywords = [
199
199
  "strapi",
@@ -267,7 +267,7 @@ const devDependencies = {
267
267
  tsconfig: "workspace:*"
268
268
  };
269
269
  const engines = {
270
- node: ">=18.0.0 <=20.x.x",
270
+ node: ">=18.0.0 <=22.x.x",
271
271
  npm: ">=6.0.0"
272
272
  };
273
273
  const packageJson = {
@@ -388,6 +388,20 @@ async function cloudApiFactory({ logger }, token) {
388
388
  throw error;
389
389
  }
390
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
+ },
391
405
  async getProject({ name: name2 }) {
392
406
  try {
393
407
  const response = await axiosCloudAPI.get(`/projects/${name2}`);
@@ -960,7 +974,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
960
974
  throw e;
961
975
  }
962
976
  }
963
- const action$4 = async (ctx) => {
977
+ const action$5 = async (ctx) => {
964
978
  const { logger } = ctx;
965
979
  const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
966
980
  const token = await getValidToken(ctx, promptLogin);
@@ -1167,11 +1181,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1167
1181
  process.exit(1);
1168
1182
  }
1169
1183
  }
1170
- async function getProject(ctx) {
1184
+ async function getProject$1(ctx) {
1171
1185
  const { project } = await retrieve();
1172
1186
  if (!project) {
1173
1187
  try {
1174
- return await action$4(ctx);
1188
+ return await action$5(ctx);
1175
1189
  } catch (e) {
1176
1190
  ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1177
1191
  ctx.logger.debug(e);
@@ -1192,13 +1206,13 @@ async function getConfig({
1192
1206
  return null;
1193
1207
  }
1194
1208
  }
1195
- const action$3 = async (ctx) => {
1209
+ const action$4 = async (ctx) => {
1196
1210
  const { getValidToken } = await tokenServiceFactory(ctx);
1197
1211
  const token = await getValidToken(ctx, promptLogin);
1198
1212
  if (!token) {
1199
1213
  return;
1200
1214
  }
1201
- const project = await getProject(ctx);
1215
+ const project = await getProject$1(ctx);
1202
1216
  if (!project) {
1203
1217
  return;
1204
1218
  }
@@ -1303,14 +1317,14 @@ const runAction = (name2, action2) => (...args) => {
1303
1317
  process.exit(1);
1304
1318
  });
1305
1319
  };
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));
1320
+ const command$6 = ({ ctx }) => {
1321
+ 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$4)(ctx));
1308
1322
  };
1309
1323
  const deployProject = {
1310
1324
  name: "deploy-project",
1311
1325
  description: "Deploy a Strapi Cloud project",
1312
- action: action$3,
1313
- command: command$5
1326
+ action: action$4,
1327
+ command: command$6
1314
1328
  };
1315
1329
  const QUIT_OPTION = "Quit";
1316
1330
  async function getExistingConfig(ctx) {
@@ -1394,7 +1408,7 @@ async function getUserSelection(ctx, projects) {
1394
1408
  return null;
1395
1409
  }
1396
1410
  }
1397
- const action$2 = async (ctx) => {
1411
+ const action$3 = async (ctx) => {
1398
1412
  const { getValidToken } = await tokenServiceFactory(ctx);
1399
1413
  const token = await getValidToken(ctx, promptLogin);
1400
1414
  const { logger } = ctx;
@@ -1449,16 +1463,16 @@ const action$2 = async (ctx) => {
1449
1463
  });
1450
1464
  }
1451
1465
  };
1452
- const command$4 = ({ command: command2, ctx }) => {
1453
- 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));
1466
+ const command$5 = ({ command: command2, ctx }) => {
1467
+ 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));
1454
1468
  };
1455
1469
  const link = {
1456
1470
  name: "link-project",
1457
1471
  description: "Link a local directory to a Strapi Cloud project",
1458
- action: action$2,
1459
- command: command$4
1472
+ action: action$3,
1473
+ command: command$5
1460
1474
  };
1461
- const command$3 = ({ ctx }) => {
1475
+ const command$4 = ({ ctx }) => {
1462
1476
  return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1463
1477
  "after",
1464
1478
  "\nAfter running this command, you will be prompted to enter your authentication information."
@@ -1468,10 +1482,10 @@ const login = {
1468
1482
  name: "login",
1469
1483
  description: "Strapi Cloud Login",
1470
1484
  action: loginAction,
1471
- command: command$3
1485
+ command: command$4
1472
1486
  };
1473
1487
  const openModule = import("open");
1474
- const action$1 = async (ctx) => {
1488
+ const action$2 = async (ctx) => {
1475
1489
  const { logger } = ctx;
1476
1490
  const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
1477
1491
  const token = await retrieveToken();
@@ -1503,25 +1517,25 @@ const action$1 = async (ctx) => {
1503
1517
  }
1504
1518
  await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
1505
1519
  };
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));
1520
+ const command$3 = ({ ctx }) => {
1521
+ 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));
1508
1522
  };
1509
1523
  const logout = {
1510
1524
  name: "logout",
1511
1525
  description: "Strapi Cloud Logout",
1512
- action: action$1,
1513
- command: command$2
1526
+ action: action$2,
1527
+ command: command$3
1514
1528
  };
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));
1529
+ const command$2 = ({ ctx }) => {
1530
+ 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));
1517
1531
  };
1518
1532
  const createProject = {
1519
1533
  name: "create-project",
1520
1534
  description: "Create a new project",
1521
- action: action$4,
1522
- command: command$1
1535
+ action: action$5,
1536
+ command: command$2
1523
1537
  };
1524
- const action = async (ctx) => {
1538
+ const action$1 = async (ctx) => {
1525
1539
  const { getValidToken } = await tokenServiceFactory(ctx);
1526
1540
  const token = await getValidToken(ctx, promptLogin);
1527
1541
  const { logger } = ctx;
@@ -1541,12 +1555,86 @@ const action = async (ctx) => {
1541
1555
  spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
1542
1556
  }
1543
1557
  };
1544
- const command = ({ command: command2, ctx }) => {
1545
- 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));
1558
+ const command$1 = ({ command: command2, ctx }) => {
1559
+ 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));
1546
1560
  };
1547
1561
  const listProjects = {
1548
1562
  name: "list-projects",
1549
1563
  description: "List Strapi Cloud projects",
1564
+ action: action$1,
1565
+ command: command$1
1566
+ };
1567
+ async function getProject(ctx) {
1568
+ const { project } = await retrieve();
1569
+ if (!project) {
1570
+ ctx.logger.warn(
1571
+ `
1572
+ We couldn't find a valid local project config.
1573
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1574
+ "link"
1575
+ )} command`
1576
+ );
1577
+ process.exit(1);
1578
+ }
1579
+ return project;
1580
+ }
1581
+ const action = async (ctx) => {
1582
+ const { getValidToken } = await tokenServiceFactory(ctx);
1583
+ const token = await getValidToken(ctx, promptLogin);
1584
+ const { logger } = ctx;
1585
+ if (!token) {
1586
+ return;
1587
+ }
1588
+ const project = await getProject(ctx);
1589
+ if (!project) {
1590
+ ctx.logger.debug(`No valid local project configuration was found.`);
1591
+ return;
1592
+ }
1593
+ const cloudApiService = await cloudApiFactory(ctx, token);
1594
+ const spinner = logger.spinner("Fetching environments...").start();
1595
+ await trackEvent(ctx, cloudApiService, "willListEnvironment", {
1596
+ projectInternalName: project.name
1597
+ });
1598
+ try {
1599
+ const {
1600
+ data: { data: environmentsList }
1601
+ } = await cloudApiService.listEnvironments({ name: project.name });
1602
+ spinner.succeed();
1603
+ logger.log(environmentsList);
1604
+ await trackEvent(ctx, cloudApiService, "didListEnvironment", {
1605
+ projectInternalName: project.name
1606
+ });
1607
+ } catch (e) {
1608
+ if (e.response && e.response.status === 404) {
1609
+ spinner.succeed();
1610
+ logger.warn(
1611
+ `
1612
+ The project associated with this folder does not exist in Strapi Cloud.
1613
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1614
+ "link"
1615
+ )} command`
1616
+ );
1617
+ } else {
1618
+ spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
1619
+ logger.debug("Failed to list environments", e);
1620
+ }
1621
+ await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
1622
+ projectInternalName: project.name
1623
+ });
1624
+ }
1625
+ };
1626
+ function defineCloudNamespace(command2) {
1627
+ return command2.command("cloud").description("Manage Strapi Cloud projects");
1628
+ }
1629
+ const command = ({ command: command2, ctx }) => {
1630
+ const cloud = defineCloudNamespace(command2);
1631
+ cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
1632
+ const environment = cloud.command("environment").description("Manage environments for a Strapi Cloud project");
1633
+ 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));
1634
+ };
1635
+ const listEnvironments = {
1636
+ name: "list-environments",
1637
+ description: "List Strapi Cloud environments",
1550
1638
  action,
1551
1639
  command
1552
1640
  };
@@ -1556,9 +1644,10 @@ const cli = {
1556
1644
  login,
1557
1645
  logout,
1558
1646
  createProject,
1559
- listProjects
1647
+ listProjects,
1648
+ listEnvironments
1560
1649
  };
1561
- const cloudCommands = [deployProject, link, login, logout, listProjects];
1650
+ const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
1562
1651
  async function initCloudCLIConfig() {
1563
1652
  const localConfig = await getLocalConfig();
1564
1653
  if (!localConfig.deviceId) {