@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.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";
|
|
@@ -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 = "
|
|
137
|
+
const version = "5.3.0";
|
|
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": "
|
|
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": "
|
|
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
|
|
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": "
|
|
207
|
-
tsconfig: "
|
|
207
|
+
"eslint-config-custom": "workspace:*",
|
|
208
|
+
tsconfig: "workspace:*"
|
|
208
209
|
};
|
|
209
210
|
const engines = {
|
|
210
|
-
node: ">=18.0.0 <=
|
|
211
|
+
node: ">=18.0.0 <=22.x.x",
|
|
211
212
|
npm: ">=6.0.0"
|
|
212
213
|
};
|
|
213
214
|
const packageJson = {
|
|
@@ -257,7 +258,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
257
258
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
258
259
|
return axiosCloudAPI.post(
|
|
259
260
|
`/deploy/${project.name}`,
|
|
260
|
-
{ file: fse__default.createReadStream(filePath) },
|
|
261
|
+
{ file: fse__default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
261
262
|
{
|
|
262
263
|
headers: {
|
|
263
264
|
"Content-Type": "multipart/form-data"
|
|
@@ -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(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
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$
|
|
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);
|
|
@@ -1026,6 +1044,32 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1026
1044
|
});
|
|
1027
1045
|
};
|
|
1028
1046
|
};
|
|
1047
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1048
|
+
async function promptForEnvironment(environments) {
|
|
1049
|
+
const choices = environments.map((env2) => ({ name: env2, value: env2 }));
|
|
1050
|
+
const { selectedEnvironment } = await inquirer.prompt([
|
|
1051
|
+
{
|
|
1052
|
+
type: "list",
|
|
1053
|
+
name: "selectedEnvironment",
|
|
1054
|
+
message: "Select the environment to deploy:",
|
|
1055
|
+
choices: [...choices, { name: chalk.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1056
|
+
}
|
|
1057
|
+
]);
|
|
1058
|
+
if (selectedEnvironment === null) {
|
|
1059
|
+
process.exit(1);
|
|
1060
|
+
}
|
|
1061
|
+
const { confirm } = await inquirer.prompt([
|
|
1062
|
+
{
|
|
1063
|
+
type: "confirm",
|
|
1064
|
+
name: "confirm",
|
|
1065
|
+
message: `Do you want to proceed with deployment to ${chalk.cyan(selectedEnvironment)}?`
|
|
1066
|
+
}
|
|
1067
|
+
]);
|
|
1068
|
+
if (!confirm) {
|
|
1069
|
+
process.exit(1);
|
|
1070
|
+
}
|
|
1071
|
+
return selectedEnvironment;
|
|
1072
|
+
}
|
|
1029
1073
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1030
1074
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1031
1075
|
try {
|
|
@@ -1104,11 +1148,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1104
1148
|
process.exit(1);
|
|
1105
1149
|
}
|
|
1106
1150
|
}
|
|
1107
|
-
async function getProject(ctx) {
|
|
1151
|
+
async function getProject$1(ctx) {
|
|
1108
1152
|
const { project } = await retrieve();
|
|
1109
1153
|
if (!project) {
|
|
1110
1154
|
try {
|
|
1111
|
-
return await action$
|
|
1155
|
+
return await action$5(ctx);
|
|
1112
1156
|
} catch (e) {
|
|
1113
1157
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1114
1158
|
ctx.logger.debug(e);
|
|
@@ -1129,22 +1173,24 @@ async function getConfig({
|
|
|
1129
1173
|
return null;
|
|
1130
1174
|
}
|
|
1131
1175
|
}
|
|
1132
|
-
const action$
|
|
1176
|
+
const action$4 = async (ctx, opts) => {
|
|
1133
1177
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1134
1178
|
const token = await getValidToken(ctx, promptLogin);
|
|
1135
1179
|
if (!token) {
|
|
1136
1180
|
return;
|
|
1137
1181
|
}
|
|
1138
|
-
const project = await getProject(ctx);
|
|
1182
|
+
const project = await getProject$1(ctx);
|
|
1139
1183
|
if (!project) {
|
|
1140
1184
|
return;
|
|
1141
1185
|
}
|
|
1142
1186
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1187
|
+
let environments;
|
|
1143
1188
|
try {
|
|
1144
1189
|
const {
|
|
1145
1190
|
data: { data: projectData, metadata }
|
|
1146
1191
|
} = await cloudApiService.getProject({ name: project.name });
|
|
1147
1192
|
const isProjectSuspended = projectData.suspendedAt;
|
|
1193
|
+
environments = projectData.environments;
|
|
1148
1194
|
if (isProjectSuspended) {
|
|
1149
1195
|
ctx.logger.log(
|
|
1150
1196
|
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
@@ -1191,6 +1237,17 @@ Please link your local project to an existing Strapi Cloud project using the ${c
|
|
|
1191
1237
|
);
|
|
1192
1238
|
maxSize = 1e8;
|
|
1193
1239
|
}
|
|
1240
|
+
let targetEnvironment;
|
|
1241
|
+
if (opts.environment) {
|
|
1242
|
+
if (!environments.includes(opts.environment)) {
|
|
1243
|
+
ctx.logger.error(`Environment ${opts.environment} does not exist.`);
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
targetEnvironment = opts.environment;
|
|
1247
|
+
} else {
|
|
1248
|
+
targetEnvironment = environments.length > 1 ? await promptForEnvironment(environments) : environments[0];
|
|
1249
|
+
}
|
|
1250
|
+
project.targetEnvironment = targetEnvironment;
|
|
1194
1251
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1195
1252
|
if (!buildId) {
|
|
1196
1253
|
return;
|
|
@@ -1240,14 +1297,14 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1240
1297
|
process.exit(1);
|
|
1241
1298
|
});
|
|
1242
1299
|
};
|
|
1243
|
-
const command$
|
|
1244
|
-
|
|
1300
|
+
const command$6 = ({ ctx }) => {
|
|
1301
|
+
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));
|
|
1245
1302
|
};
|
|
1246
1303
|
const deployProject = {
|
|
1247
1304
|
name: "deploy-project",
|
|
1248
1305
|
description: "Deploy a Strapi Cloud project",
|
|
1249
|
-
action: action$
|
|
1250
|
-
command: command$
|
|
1306
|
+
action: action$4,
|
|
1307
|
+
command: command$6
|
|
1251
1308
|
};
|
|
1252
1309
|
const QUIT_OPTION = "Quit";
|
|
1253
1310
|
async function getExistingConfig(ctx) {
|
|
@@ -1331,7 +1388,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1331
1388
|
return null;
|
|
1332
1389
|
}
|
|
1333
1390
|
}
|
|
1334
|
-
const action$
|
|
1391
|
+
const action$3 = async (ctx) => {
|
|
1335
1392
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1336
1393
|
const token = await getValidToken(ctx, promptLogin);
|
|
1337
1394
|
const { logger } = ctx;
|
|
@@ -1386,17 +1443,17 @@ const action$2 = async (ctx) => {
|
|
|
1386
1443
|
});
|
|
1387
1444
|
}
|
|
1388
1445
|
};
|
|
1389
|
-
const command$
|
|
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$
|
|
1446
|
+
const command$5 = ({ command: command2, ctx }) => {
|
|
1447
|
+
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
1448
|
};
|
|
1392
1449
|
const link = {
|
|
1393
1450
|
name: "link-project",
|
|
1394
1451
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1395
|
-
action: action$
|
|
1396
|
-
command: command$
|
|
1452
|
+
action: action$3,
|
|
1453
|
+
command: command$5
|
|
1397
1454
|
};
|
|
1398
|
-
const command$
|
|
1399
|
-
|
|
1455
|
+
const command$4 = ({ ctx }) => {
|
|
1456
|
+
return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1400
1457
|
"after",
|
|
1401
1458
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1402
1459
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1405,10 +1462,10 @@ const login = {
|
|
|
1405
1462
|
name: "login",
|
|
1406
1463
|
description: "Strapi Cloud Login",
|
|
1407
1464
|
action: loginAction,
|
|
1408
|
-
command: command$
|
|
1465
|
+
command: command$4
|
|
1409
1466
|
};
|
|
1410
1467
|
const openModule = import("open");
|
|
1411
|
-
const action$
|
|
1468
|
+
const action$2 = async (ctx) => {
|
|
1412
1469
|
const { logger } = ctx;
|
|
1413
1470
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1414
1471
|
const token = await retrieveToken();
|
|
@@ -1440,25 +1497,25 @@ const action$1 = async (ctx) => {
|
|
|
1440
1497
|
}
|
|
1441
1498
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1442
1499
|
};
|
|
1443
|
-
const command$
|
|
1444
|
-
|
|
1500
|
+
const command$3 = ({ ctx }) => {
|
|
1501
|
+
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
1502
|
};
|
|
1446
1503
|
const logout = {
|
|
1447
1504
|
name: "logout",
|
|
1448
1505
|
description: "Strapi Cloud Logout",
|
|
1449
|
-
action: action$
|
|
1450
|
-
command: command$
|
|
1506
|
+
action: action$2,
|
|
1507
|
+
command: command$3
|
|
1451
1508
|
};
|
|
1452
|
-
const command$
|
|
1453
|
-
|
|
1509
|
+
const command$2 = ({ ctx }) => {
|
|
1510
|
+
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
1511
|
};
|
|
1455
1512
|
const createProject = {
|
|
1456
1513
|
name: "create-project",
|
|
1457
1514
|
description: "Create a new project",
|
|
1458
|
-
action: action$
|
|
1459
|
-
command: command$
|
|
1515
|
+
action: action$5,
|
|
1516
|
+
command: command$2
|
|
1460
1517
|
};
|
|
1461
|
-
const action = async (ctx) => {
|
|
1518
|
+
const action$1 = async (ctx) => {
|
|
1462
1519
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1463
1520
|
const token = await getValidToken(ctx, promptLogin);
|
|
1464
1521
|
const { logger } = ctx;
|
|
@@ -1478,12 +1535,94 @@ const action = async (ctx) => {
|
|
|
1478
1535
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1479
1536
|
}
|
|
1480
1537
|
};
|
|
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));
|
|
1538
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1539
|
+
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
1540
|
};
|
|
1484
1541
|
const listProjects = {
|
|
1485
1542
|
name: "list-projects",
|
|
1486
1543
|
description: "List Strapi Cloud projects",
|
|
1544
|
+
action: action$1,
|
|
1545
|
+
command: command$1
|
|
1546
|
+
};
|
|
1547
|
+
async function getProject(ctx) {
|
|
1548
|
+
const { project } = await retrieve();
|
|
1549
|
+
if (!project) {
|
|
1550
|
+
ctx.logger.warn(
|
|
1551
|
+
`
|
|
1552
|
+
We couldn't find a valid local project config.
|
|
1553
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1554
|
+
"link"
|
|
1555
|
+
)} command`
|
|
1556
|
+
);
|
|
1557
|
+
process.exit(1);
|
|
1558
|
+
}
|
|
1559
|
+
return project;
|
|
1560
|
+
}
|
|
1561
|
+
const action = async (ctx) => {
|
|
1562
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1563
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1564
|
+
const { logger } = ctx;
|
|
1565
|
+
if (!token) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
const project = await getProject(ctx);
|
|
1569
|
+
if (!project) {
|
|
1570
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1574
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1575
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1576
|
+
projectInternalName: project.name
|
|
1577
|
+
});
|
|
1578
|
+
try {
|
|
1579
|
+
const {
|
|
1580
|
+
data: { data: environmentsList }
|
|
1581
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1582
|
+
spinner.succeed();
|
|
1583
|
+
logger.log(environmentsList);
|
|
1584
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1585
|
+
projectInternalName: project.name
|
|
1586
|
+
});
|
|
1587
|
+
} catch (e) {
|
|
1588
|
+
if (e.response && e.response.status === 404) {
|
|
1589
|
+
spinner.succeed();
|
|
1590
|
+
logger.warn(
|
|
1591
|
+
`
|
|
1592
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1593
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1594
|
+
"link"
|
|
1595
|
+
)} command`
|
|
1596
|
+
);
|
|
1597
|
+
} else {
|
|
1598
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1599
|
+
logger.debug("Failed to list environments", e);
|
|
1600
|
+
}
|
|
1601
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1602
|
+
projectInternalName: project.name
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1607
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1608
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
|
|
1609
|
+
return cloud;
|
|
1610
|
+
}
|
|
1611
|
+
let environmentCmd = null;
|
|
1612
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1613
|
+
if (!environmentCmd) {
|
|
1614
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1615
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1616
|
+
}
|
|
1617
|
+
return environmentCmd;
|
|
1618
|
+
};
|
|
1619
|
+
const command = ({ command: command2, ctx }) => {
|
|
1620
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1621
|
+
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));
|
|
1622
|
+
};
|
|
1623
|
+
const listEnvironments = {
|
|
1624
|
+
name: "list-environments",
|
|
1625
|
+
description: "List Strapi Cloud environments",
|
|
1487
1626
|
action,
|
|
1488
1627
|
command
|
|
1489
1628
|
};
|
|
@@ -1493,9 +1632,10 @@ const cli = {
|
|
|
1493
1632
|
login,
|
|
1494
1633
|
logout,
|
|
1495
1634
|
createProject,
|
|
1496
|
-
listProjects
|
|
1635
|
+
listProjects,
|
|
1636
|
+
listEnvironments
|
|
1497
1637
|
};
|
|
1498
|
-
const cloudCommands = [deployProject, link, login, logout, listProjects];
|
|
1638
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
|
|
1499
1639
|
async function initCloudCLIConfig() {
|
|
1500
1640
|
const localConfig = await getLocalConfig();
|
|
1501
1641
|
if (!localConfig.deviceId) {
|
|
@@ -1511,7 +1651,10 @@ async function buildStrapiCloudCommands({
|
|
|
1511
1651
|
await initCloudCLIConfig();
|
|
1512
1652
|
for (const cloudCommand of cloudCommands) {
|
|
1513
1653
|
try {
|
|
1514
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1654
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1655
|
+
if (subCommand) {
|
|
1656
|
+
command2.addCommand(subCommand);
|
|
1657
|
+
}
|
|
1515
1658
|
} catch (e) {
|
|
1516
1659
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1517
1660
|
}
|