@strapi/cloud-cli 0.0.0-next.e9b6852d1c05518ff6e37d599321f7aa7aa0683b → 0.0.0-next.ea6e3b80ab37f554da4f8bde08dbfe9b57400d31
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 +200 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -56
- package/dist/index.mjs.map +1 -1
- package/dist/src/cloud/command.d.ts +3 -0
- package/dist/src/cloud/command.d.ts.map +1 -0
- package/dist/src/create-project/command.d.ts.map +1 -1
- package/dist/src/deploy-project/action.d.ts +4 -1
- package/dist/src/deploy-project/action.d.ts.map +1 -1
- package/dist/src/deploy-project/command.d.ts.map +1 -1
- package/dist/src/environment/command.d.ts +3 -0
- package/dist/src/environment/command.d.ts.map +1 -0
- package/dist/src/environment/list/action.d.ts +4 -0
- package/dist/src/environment/list/action.d.ts.map +1 -0
- package/dist/src/environment/list/command.d.ts +4 -0
- package/dist/src/environment/list/command.d.ts.map +1 -0
- package/dist/src/environment/list/index.d.ts +7 -0
- package/dist/src/environment/list/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/login/command.d.ts.map +1 -1
- package/dist/src/logout/command.d.ts.map +1 -1
- package/dist/src/services/cli-api.d.ts +12 -0
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/types.d.ts +4 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/pkg.d.ts.map +1 -1
- package/dist/src/utils/tests/compress-files.test.d.ts +2 -0
- package/dist/src/utils/tests/compress-files.test.d.ts.map +1 -0
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
25
|
const crypto$1 = require("crypto");
|
|
26
26
|
const fse = require("fs-extra");
|
|
27
|
+
const inquirer = require("inquirer");
|
|
27
28
|
const path = require("path");
|
|
28
29
|
const chalk = require("chalk");
|
|
29
30
|
const axios = require("axios");
|
|
@@ -31,7 +32,6 @@ const crypto = require("node:crypto");
|
|
|
31
32
|
const utils = require("@strapi/utils");
|
|
32
33
|
const tar = require("tar");
|
|
33
34
|
const minimatch = require("minimatch");
|
|
34
|
-
const inquirer = require("inquirer");
|
|
35
35
|
const fp = require("lodash/fp");
|
|
36
36
|
const os = require("os");
|
|
37
37
|
const XDGAppPaths = require("xdg-app-paths");
|
|
@@ -43,6 +43,7 @@ const cliProgress = require("cli-progress");
|
|
|
43
43
|
const pkgUp = require("pkg-up");
|
|
44
44
|
const yup = require("yup");
|
|
45
45
|
const EventSource = require("eventsource");
|
|
46
|
+
const commander = require("commander");
|
|
46
47
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
47
48
|
function _interopNamespace(e) {
|
|
48
49
|
if (e && e.__esModule)
|
|
@@ -64,12 +65,12 @@ function _interopNamespace(e) {
|
|
|
64
65
|
}
|
|
65
66
|
const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
|
|
66
67
|
const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
|
|
68
|
+
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
67
69
|
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
68
70
|
const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
69
71
|
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
70
72
|
const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
|
|
71
73
|
const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
|
|
72
|
-
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
73
74
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
74
75
|
const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
|
|
75
76
|
const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
|
|
@@ -192,7 +193,7 @@ async function saveLocalConfig(data) {
|
|
|
192
193
|
await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
193
194
|
}
|
|
194
195
|
const name = "@strapi/cloud-cli";
|
|
195
|
-
const version = "
|
|
196
|
+
const version = "5.3.0";
|
|
196
197
|
const description = "Commands to interact with the Strapi Cloud";
|
|
197
198
|
const keywords = [
|
|
198
199
|
"strapi",
|
|
@@ -237,14 +238,14 @@ const scripts = {
|
|
|
237
238
|
watch: "pack-up watch"
|
|
238
239
|
};
|
|
239
240
|
const dependencies = {
|
|
240
|
-
"@strapi/utils": "
|
|
241
|
+
"@strapi/utils": "workspace:*",
|
|
241
242
|
axios: "1.7.4",
|
|
242
243
|
chalk: "4.1.2",
|
|
243
244
|
"cli-progress": "3.12.0",
|
|
244
245
|
commander: "8.3.0",
|
|
245
246
|
eventsource: "2.0.2",
|
|
246
247
|
"fast-safe-stringify": "2.1.1",
|
|
247
|
-
"fs-extra": "
|
|
248
|
+
"fs-extra": "11.2.0",
|
|
248
249
|
inquirer: "8.2.5",
|
|
249
250
|
jsonwebtoken: "9.0.0",
|
|
250
251
|
"jwks-rsa": "3.1.0",
|
|
@@ -253,7 +254,7 @@ const dependencies = {
|
|
|
253
254
|
open: "8.4.0",
|
|
254
255
|
ora: "5.4.1",
|
|
255
256
|
"pkg-up": "3.1.0",
|
|
256
|
-
tar: "6.1
|
|
257
|
+
tar: "6.2.1",
|
|
257
258
|
"xdg-app-paths": "8.3.0",
|
|
258
259
|
yup: "0.32.9"
|
|
259
260
|
};
|
|
@@ -262,11 +263,11 @@ const devDependencies = {
|
|
|
262
263
|
"@types/cli-progress": "3.11.5",
|
|
263
264
|
"@types/eventsource": "1.1.15",
|
|
264
265
|
"@types/lodash": "^4.14.191",
|
|
265
|
-
"eslint-config-custom": "
|
|
266
|
-
tsconfig: "
|
|
266
|
+
"eslint-config-custom": "workspace:*",
|
|
267
|
+
tsconfig: "workspace:*"
|
|
267
268
|
};
|
|
268
269
|
const engines = {
|
|
269
|
-
node: ">=18.0.0 <=
|
|
270
|
+
node: ">=18.0.0 <=22.x.x",
|
|
270
271
|
npm: ">=6.0.0"
|
|
271
272
|
};
|
|
272
273
|
const packageJson = {
|
|
@@ -316,7 +317,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
316
317
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
317
318
|
return axiosCloudAPI.post(
|
|
318
319
|
`/deploy/${project.name}`,
|
|
319
|
-
{ file: fse__namespace.default.createReadStream(filePath) },
|
|
320
|
+
{ file: fse__namespace.default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
320
321
|
{
|
|
321
322
|
headers: {
|
|
322
323
|
"Content-Type": "multipart/form-data"
|
|
@@ -387,6 +388,20 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
387
388
|
throw error;
|
|
388
389
|
}
|
|
389
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
|
+
},
|
|
390
405
|
async getProject({ name: name2 }) {
|
|
391
406
|
try {
|
|
392
407
|
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
@@ -674,21 +689,24 @@ yup__namespace.object({
|
|
|
674
689
|
name: yup__namespace.string().required(),
|
|
675
690
|
exports: yup__namespace.lazy(
|
|
676
691
|
(value) => yup__namespace.object(
|
|
677
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
693
|
+
(acc, [key, value2]) => {
|
|
694
|
+
if (typeof value2 === "object") {
|
|
695
|
+
acc[key] = yup__namespace.object({
|
|
696
|
+
types: yup__namespace.string().optional(),
|
|
697
|
+
source: yup__namespace.string().required(),
|
|
698
|
+
module: yup__namespace.string().optional(),
|
|
699
|
+
import: yup__namespace.string().required(),
|
|
700
|
+
require: yup__namespace.string().required(),
|
|
701
|
+
default: yup__namespace.string().required()
|
|
702
|
+
}).noUnknown(true);
|
|
703
|
+
} else {
|
|
704
|
+
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
705
|
+
}
|
|
706
|
+
return acc;
|
|
707
|
+
},
|
|
708
|
+
{}
|
|
709
|
+
) : void 0
|
|
692
710
|
).optional()
|
|
693
711
|
)
|
|
694
712
|
});
|
|
@@ -956,7 +974,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
956
974
|
throw e;
|
|
957
975
|
}
|
|
958
976
|
}
|
|
959
|
-
const action$
|
|
977
|
+
const action$5 = async (ctx) => {
|
|
960
978
|
const { logger } = ctx;
|
|
961
979
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
962
980
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -1085,6 +1103,32 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1085
1103
|
});
|
|
1086
1104
|
};
|
|
1087
1105
|
};
|
|
1106
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1107
|
+
async function promptForEnvironment(environments) {
|
|
1108
|
+
const choices = environments.map((env) => ({ name: env, value: env }));
|
|
1109
|
+
const { selectedEnvironment } = await inquirer__default.default.prompt([
|
|
1110
|
+
{
|
|
1111
|
+
type: "list",
|
|
1112
|
+
name: "selectedEnvironment",
|
|
1113
|
+
message: "Select the environment to deploy:",
|
|
1114
|
+
choices: [...choices, { name: chalk__default.default.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1115
|
+
}
|
|
1116
|
+
]);
|
|
1117
|
+
if (selectedEnvironment === null) {
|
|
1118
|
+
process.exit(1);
|
|
1119
|
+
}
|
|
1120
|
+
const { confirm } = await inquirer__default.default.prompt([
|
|
1121
|
+
{
|
|
1122
|
+
type: "confirm",
|
|
1123
|
+
name: "confirm",
|
|
1124
|
+
message: `Do you want to proceed with deployment to ${chalk__default.default.cyan(selectedEnvironment)}?`
|
|
1125
|
+
}
|
|
1126
|
+
]);
|
|
1127
|
+
if (!confirm) {
|
|
1128
|
+
process.exit(1);
|
|
1129
|
+
}
|
|
1130
|
+
return selectedEnvironment;
|
|
1131
|
+
}
|
|
1088
1132
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1089
1133
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1090
1134
|
try {
|
|
@@ -1163,11 +1207,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1163
1207
|
process.exit(1);
|
|
1164
1208
|
}
|
|
1165
1209
|
}
|
|
1166
|
-
async function getProject(ctx) {
|
|
1210
|
+
async function getProject$1(ctx) {
|
|
1167
1211
|
const { project } = await retrieve();
|
|
1168
1212
|
if (!project) {
|
|
1169
1213
|
try {
|
|
1170
|
-
return await action$
|
|
1214
|
+
return await action$5(ctx);
|
|
1171
1215
|
} catch (e) {
|
|
1172
1216
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1173
1217
|
ctx.logger.debug(e);
|
|
@@ -1188,22 +1232,24 @@ async function getConfig({
|
|
|
1188
1232
|
return null;
|
|
1189
1233
|
}
|
|
1190
1234
|
}
|
|
1191
|
-
const action$
|
|
1235
|
+
const action$4 = async (ctx, opts) => {
|
|
1192
1236
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1193
1237
|
const token = await getValidToken(ctx, promptLogin);
|
|
1194
1238
|
if (!token) {
|
|
1195
1239
|
return;
|
|
1196
1240
|
}
|
|
1197
|
-
const project = await getProject(ctx);
|
|
1241
|
+
const project = await getProject$1(ctx);
|
|
1198
1242
|
if (!project) {
|
|
1199
1243
|
return;
|
|
1200
1244
|
}
|
|
1201
1245
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1246
|
+
let environments;
|
|
1202
1247
|
try {
|
|
1203
1248
|
const {
|
|
1204
1249
|
data: { data: projectData, metadata }
|
|
1205
1250
|
} = await cloudApiService.getProject({ name: project.name });
|
|
1206
1251
|
const isProjectSuspended = projectData.suspendedAt;
|
|
1252
|
+
environments = projectData.environments;
|
|
1207
1253
|
if (isProjectSuspended) {
|
|
1208
1254
|
ctx.logger.log(
|
|
1209
1255
|
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
@@ -1250,6 +1296,17 @@ Please link your local project to an existing Strapi Cloud project using the ${c
|
|
|
1250
1296
|
);
|
|
1251
1297
|
maxSize = 1e8;
|
|
1252
1298
|
}
|
|
1299
|
+
let targetEnvironment;
|
|
1300
|
+
if (opts.environment) {
|
|
1301
|
+
if (!environments.includes(opts.environment)) {
|
|
1302
|
+
ctx.logger.error(`Environment ${opts.environment} does not exist.`);
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
targetEnvironment = opts.environment;
|
|
1306
|
+
} else {
|
|
1307
|
+
targetEnvironment = environments.length > 1 ? await promptForEnvironment(environments) : environments[0];
|
|
1308
|
+
}
|
|
1309
|
+
project.targetEnvironment = targetEnvironment;
|
|
1253
1310
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1254
1311
|
if (!buildId) {
|
|
1255
1312
|
return;
|
|
@@ -1299,14 +1356,14 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1299
1356
|
process.exit(1);
|
|
1300
1357
|
});
|
|
1301
1358
|
};
|
|
1302
|
-
const command$
|
|
1303
|
-
|
|
1359
|
+
const command$6 = ({ ctx }) => {
|
|
1360
|
+
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").option("-e, --environment <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$4)(ctx, opts));
|
|
1304
1361
|
};
|
|
1305
1362
|
const deployProject = {
|
|
1306
1363
|
name: "deploy-project",
|
|
1307
1364
|
description: "Deploy a Strapi Cloud project",
|
|
1308
|
-
action: action$
|
|
1309
|
-
command: command$
|
|
1365
|
+
action: action$4,
|
|
1366
|
+
command: command$6
|
|
1310
1367
|
};
|
|
1311
1368
|
const QUIT_OPTION = "Quit";
|
|
1312
1369
|
async function getExistingConfig(ctx) {
|
|
@@ -1390,7 +1447,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1390
1447
|
return null;
|
|
1391
1448
|
}
|
|
1392
1449
|
}
|
|
1393
|
-
const action$
|
|
1450
|
+
const action$3 = async (ctx) => {
|
|
1394
1451
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1395
1452
|
const token = await getValidToken(ctx, promptLogin);
|
|
1396
1453
|
const { logger } = ctx;
|
|
@@ -1445,17 +1502,17 @@ const action$2 = async (ctx) => {
|
|
|
1445
1502
|
});
|
|
1446
1503
|
}
|
|
1447
1504
|
};
|
|
1448
|
-
const command$
|
|
1449
|
-
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$
|
|
1505
|
+
const command$5 = ({ command: command2, ctx }) => {
|
|
1506
|
+
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));
|
|
1450
1507
|
};
|
|
1451
1508
|
const link = {
|
|
1452
1509
|
name: "link-project",
|
|
1453
1510
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1454
|
-
action: action$
|
|
1455
|
-
command: command$
|
|
1511
|
+
action: action$3,
|
|
1512
|
+
command: command$5
|
|
1456
1513
|
};
|
|
1457
|
-
const command$
|
|
1458
|
-
|
|
1514
|
+
const command$4 = ({ ctx }) => {
|
|
1515
|
+
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1459
1516
|
"after",
|
|
1460
1517
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1461
1518
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1464,10 +1521,10 @@ const login = {
|
|
|
1464
1521
|
name: "login",
|
|
1465
1522
|
description: "Strapi Cloud Login",
|
|
1466
1523
|
action: loginAction,
|
|
1467
|
-
command: command$
|
|
1524
|
+
command: command$4
|
|
1468
1525
|
};
|
|
1469
1526
|
const openModule = import("open");
|
|
1470
|
-
const action$
|
|
1527
|
+
const action$2 = async (ctx) => {
|
|
1471
1528
|
const { logger } = ctx;
|
|
1472
1529
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1473
1530
|
const token = await retrieveToken();
|
|
@@ -1499,25 +1556,25 @@ const action$1 = async (ctx) => {
|
|
|
1499
1556
|
}
|
|
1500
1557
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1501
1558
|
};
|
|
1502
|
-
const command$
|
|
1503
|
-
|
|
1559
|
+
const command$3 = ({ ctx }) => {
|
|
1560
|
+
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));
|
|
1504
1561
|
};
|
|
1505
1562
|
const logout = {
|
|
1506
1563
|
name: "logout",
|
|
1507
1564
|
description: "Strapi Cloud Logout",
|
|
1508
|
-
action: action$
|
|
1509
|
-
command: command$
|
|
1565
|
+
action: action$2,
|
|
1566
|
+
command: command$3
|
|
1510
1567
|
};
|
|
1511
|
-
const command$
|
|
1512
|
-
|
|
1568
|
+
const command$2 = ({ ctx }) => {
|
|
1569
|
+
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));
|
|
1513
1570
|
};
|
|
1514
1571
|
const createProject = {
|
|
1515
1572
|
name: "create-project",
|
|
1516
1573
|
description: "Create a new project",
|
|
1517
|
-
action: action$
|
|
1518
|
-
command: command$
|
|
1574
|
+
action: action$5,
|
|
1575
|
+
command: command$2
|
|
1519
1576
|
};
|
|
1520
|
-
const action = async (ctx) => {
|
|
1577
|
+
const action$1 = async (ctx) => {
|
|
1521
1578
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1522
1579
|
const token = await getValidToken(ctx, promptLogin);
|
|
1523
1580
|
const { logger } = ctx;
|
|
@@ -1537,12 +1594,94 @@ const action = async (ctx) => {
|
|
|
1537
1594
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1538
1595
|
}
|
|
1539
1596
|
};
|
|
1540
|
-
const command = ({ command: command2, ctx }) => {
|
|
1541
|
-
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));
|
|
1597
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1598
|
+
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));
|
|
1542
1599
|
};
|
|
1543
1600
|
const listProjects = {
|
|
1544
1601
|
name: "list-projects",
|
|
1545
1602
|
description: "List Strapi Cloud projects",
|
|
1603
|
+
action: action$1,
|
|
1604
|
+
command: command$1
|
|
1605
|
+
};
|
|
1606
|
+
async function getProject(ctx) {
|
|
1607
|
+
const { project } = await retrieve();
|
|
1608
|
+
if (!project) {
|
|
1609
|
+
ctx.logger.warn(
|
|
1610
|
+
`
|
|
1611
|
+
We couldn't find a valid local project config.
|
|
1612
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1613
|
+
"link"
|
|
1614
|
+
)} command`
|
|
1615
|
+
);
|
|
1616
|
+
process.exit(1);
|
|
1617
|
+
}
|
|
1618
|
+
return project;
|
|
1619
|
+
}
|
|
1620
|
+
const action = async (ctx) => {
|
|
1621
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1622
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1623
|
+
const { logger } = ctx;
|
|
1624
|
+
if (!token) {
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
const project = await getProject(ctx);
|
|
1628
|
+
if (!project) {
|
|
1629
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1633
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1634
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1635
|
+
projectInternalName: project.name
|
|
1636
|
+
});
|
|
1637
|
+
try {
|
|
1638
|
+
const {
|
|
1639
|
+
data: { data: environmentsList }
|
|
1640
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1641
|
+
spinner.succeed();
|
|
1642
|
+
logger.log(environmentsList);
|
|
1643
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1644
|
+
projectInternalName: project.name
|
|
1645
|
+
});
|
|
1646
|
+
} catch (e) {
|
|
1647
|
+
if (e.response && e.response.status === 404) {
|
|
1648
|
+
spinner.succeed();
|
|
1649
|
+
logger.warn(
|
|
1650
|
+
`
|
|
1651
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1652
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1653
|
+
"link"
|
|
1654
|
+
)} command`
|
|
1655
|
+
);
|
|
1656
|
+
} else {
|
|
1657
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1658
|
+
logger.debug("Failed to list environments", e);
|
|
1659
|
+
}
|
|
1660
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1661
|
+
projectInternalName: project.name
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1666
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1667
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
|
|
1668
|
+
return cloud;
|
|
1669
|
+
}
|
|
1670
|
+
let environmentCmd = null;
|
|
1671
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1672
|
+
if (!environmentCmd) {
|
|
1673
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1674
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1675
|
+
}
|
|
1676
|
+
return environmentCmd;
|
|
1677
|
+
};
|
|
1678
|
+
const command = ({ command: command2, ctx }) => {
|
|
1679
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1680
|
+
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));
|
|
1681
|
+
};
|
|
1682
|
+
const listEnvironments = {
|
|
1683
|
+
name: "list-environments",
|
|
1684
|
+
description: "List Strapi Cloud environments",
|
|
1546
1685
|
action,
|
|
1547
1686
|
command
|
|
1548
1687
|
};
|
|
@@ -1552,9 +1691,10 @@ const cli = {
|
|
|
1552
1691
|
login,
|
|
1553
1692
|
logout,
|
|
1554
1693
|
createProject,
|
|
1555
|
-
listProjects
|
|
1694
|
+
listProjects,
|
|
1695
|
+
listEnvironments
|
|
1556
1696
|
};
|
|
1557
|
-
const cloudCommands = [deployProject, link, login, logout, listProjects];
|
|
1697
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
|
|
1558
1698
|
async function initCloudCLIConfig() {
|
|
1559
1699
|
const localConfig = await getLocalConfig();
|
|
1560
1700
|
if (!localConfig.deviceId) {
|
|
@@ -1570,7 +1710,10 @@ async function buildStrapiCloudCommands({
|
|
|
1570
1710
|
await initCloudCLIConfig();
|
|
1571
1711
|
for (const cloudCommand of cloudCommands) {
|
|
1572
1712
|
try {
|
|
1573
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1713
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1714
|
+
if (subCommand) {
|
|
1715
|
+
command2.addCommand(subCommand);
|
|
1716
|
+
}
|
|
1574
1717
|
} catch (e) {
|
|
1575
1718
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1576
1719
|
}
|