@strapi/cloud-cli 0.0.0-next.d7fa025a4eacdc27490fb1629b0efb93e3cb58b9 → 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 +251 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +250 -71
- 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 +28 -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 +9 -9
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
|
-
axios: "1.
|
|
241
|
+
"@strapi/utils": "workspace:*",
|
|
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"
|
|
@@ -375,7 +376,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
375
376
|
},
|
|
376
377
|
async listLinkProjects() {
|
|
377
378
|
try {
|
|
378
|
-
const response = await axiosCloudAPI.get("/projects
|
|
379
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
379
380
|
if (response.status !== 200) {
|
|
380
381
|
throw new Error("Error fetching cloud projects from the server.");
|
|
381
382
|
}
|
|
@@ -387,6 +388,34 @@ 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
|
+
},
|
|
405
|
+
async getProject({ name: name2 }) {
|
|
406
|
+
try {
|
|
407
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
408
|
+
if (response.status !== 200) {
|
|
409
|
+
throw new Error("Error fetching project's details.");
|
|
410
|
+
}
|
|
411
|
+
return response;
|
|
412
|
+
} catch (error) {
|
|
413
|
+
logger.debug(
|
|
414
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
415
|
+
);
|
|
416
|
+
throw error;
|
|
417
|
+
}
|
|
418
|
+
},
|
|
390
419
|
track(event, payload = {}) {
|
|
391
420
|
return axiosCloudAPI.post("/track", {
|
|
392
421
|
event,
|
|
@@ -660,21 +689,24 @@ yup__namespace.object({
|
|
|
660
689
|
name: yup__namespace.string().required(),
|
|
661
690
|
exports: yup__namespace.lazy(
|
|
662
691
|
(value) => yup__namespace.object(
|
|
663
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
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
|
|
678
710
|
).optional()
|
|
679
711
|
)
|
|
680
712
|
});
|
|
@@ -942,7 +974,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
942
974
|
throw e;
|
|
943
975
|
}
|
|
944
976
|
}
|
|
945
|
-
const action$
|
|
977
|
+
const action$5 = async (ctx) => {
|
|
946
978
|
const { logger } = ctx;
|
|
947
979
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
948
980
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -1071,6 +1103,32 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1071
1103
|
});
|
|
1072
1104
|
};
|
|
1073
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
|
+
}
|
|
1074
1132
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1075
1133
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1076
1134
|
try {
|
|
@@ -1137,17 +1195,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1137
1195
|
return data.build_id;
|
|
1138
1196
|
} catch (e) {
|
|
1139
1197
|
progressBar.stop();
|
|
1140
|
-
|
|
1141
|
-
if (e.response.status === 404) {
|
|
1142
|
-
ctx.logger.warn(
|
|
1143
|
-
`The project does not exist. Please link your local project to a Strapi Cloud project using the link command.`
|
|
1144
|
-
);
|
|
1145
|
-
} else {
|
|
1146
|
-
ctx.logger.error(e.response.data);
|
|
1147
|
-
}
|
|
1148
|
-
} else {
|
|
1149
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1150
|
-
}
|
|
1198
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1151
1199
|
ctx.logger.debug(e);
|
|
1152
1200
|
} finally {
|
|
1153
1201
|
await fse__namespace.default.remove(tarFilePath);
|
|
@@ -1159,11 +1207,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1159
1207
|
process.exit(1);
|
|
1160
1208
|
}
|
|
1161
1209
|
}
|
|
1162
|
-
async function getProject(ctx) {
|
|
1210
|
+
async function getProject$1(ctx) {
|
|
1163
1211
|
const { project } = await retrieve();
|
|
1164
1212
|
if (!project) {
|
|
1165
1213
|
try {
|
|
1166
|
-
return await action$
|
|
1214
|
+
return await action$5(ctx);
|
|
1167
1215
|
} catch (e) {
|
|
1168
1216
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1169
1217
|
ctx.logger.debug(e);
|
|
@@ -1184,17 +1232,51 @@ async function getConfig({
|
|
|
1184
1232
|
return null;
|
|
1185
1233
|
}
|
|
1186
1234
|
}
|
|
1187
|
-
const action$
|
|
1235
|
+
const action$4 = async (ctx, opts) => {
|
|
1188
1236
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1189
1237
|
const token = await getValidToken(ctx, promptLogin);
|
|
1190
1238
|
if (!token) {
|
|
1191
1239
|
return;
|
|
1192
1240
|
}
|
|
1193
|
-
const project = await getProject(ctx);
|
|
1241
|
+
const project = await getProject$1(ctx);
|
|
1194
1242
|
if (!project) {
|
|
1195
1243
|
return;
|
|
1196
1244
|
}
|
|
1197
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1245
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1246
|
+
let environments;
|
|
1247
|
+
try {
|
|
1248
|
+
const {
|
|
1249
|
+
data: { data: projectData, metadata }
|
|
1250
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1251
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1252
|
+
environments = projectData.environments;
|
|
1253
|
+
if (isProjectSuspended) {
|
|
1254
|
+
ctx.logger.log(
|
|
1255
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1256
|
+
);
|
|
1257
|
+
ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
} catch (e) {
|
|
1261
|
+
if (e instanceof axios.AxiosError && e.response?.data) {
|
|
1262
|
+
if (e.response.status === 404) {
|
|
1263
|
+
ctx.logger.warn(
|
|
1264
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1265
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1266
|
+
"link"
|
|
1267
|
+
)} command before deploying.`
|
|
1268
|
+
);
|
|
1269
|
+
} else {
|
|
1270
|
+
ctx.logger.error(e.response.data);
|
|
1271
|
+
}
|
|
1272
|
+
} else {
|
|
1273
|
+
ctx.logger.error(
|
|
1274
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1277
|
+
ctx.logger.debug(e);
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1198
1280
|
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1199
1281
|
projectInternalName: project.name
|
|
1200
1282
|
});
|
|
@@ -1203,7 +1285,7 @@ const action$3 = async (ctx) => {
|
|
|
1203
1285
|
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1204
1286
|
if (!cliConfig2) {
|
|
1205
1287
|
ctx.logger.error(
|
|
1206
|
-
"An error occurred while retrieving data from Strapi Cloud. Please
|
|
1288
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1207
1289
|
);
|
|
1208
1290
|
return;
|
|
1209
1291
|
}
|
|
@@ -1214,6 +1296,17 @@ const action$3 = async (ctx) => {
|
|
|
1214
1296
|
);
|
|
1215
1297
|
maxSize = 1e8;
|
|
1216
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;
|
|
1217
1310
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1218
1311
|
if (!buildId) {
|
|
1219
1312
|
return;
|
|
@@ -1263,14 +1356,14 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1263
1356
|
process.exit(1);
|
|
1264
1357
|
});
|
|
1265
1358
|
};
|
|
1266
|
-
const command$
|
|
1267
|
-
|
|
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));
|
|
1268
1361
|
};
|
|
1269
1362
|
const deployProject = {
|
|
1270
1363
|
name: "deploy-project",
|
|
1271
1364
|
description: "Deploy a Strapi Cloud project",
|
|
1272
|
-
action: action$
|
|
1273
|
-
command: command$
|
|
1365
|
+
action: action$4,
|
|
1366
|
+
command: command$6
|
|
1274
1367
|
};
|
|
1275
1368
|
const QUIT_OPTION = "Quit";
|
|
1276
1369
|
async function getExistingConfig(ctx) {
|
|
@@ -1354,7 +1447,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1354
1447
|
return null;
|
|
1355
1448
|
}
|
|
1356
1449
|
}
|
|
1357
|
-
const action$
|
|
1450
|
+
const action$3 = async (ctx) => {
|
|
1358
1451
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1359
1452
|
const token = await getValidToken(ctx, promptLogin);
|
|
1360
1453
|
const { logger } = ctx;
|
|
@@ -1409,17 +1502,17 @@ const action$2 = async (ctx) => {
|
|
|
1409
1502
|
});
|
|
1410
1503
|
}
|
|
1411
1504
|
};
|
|
1412
|
-
const command$
|
|
1413
|
-
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));
|
|
1414
1507
|
};
|
|
1415
1508
|
const link = {
|
|
1416
1509
|
name: "link-project",
|
|
1417
1510
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1418
|
-
action: action$
|
|
1419
|
-
command: command$
|
|
1511
|
+
action: action$3,
|
|
1512
|
+
command: command$5
|
|
1420
1513
|
};
|
|
1421
|
-
const command$
|
|
1422
|
-
|
|
1514
|
+
const command$4 = ({ ctx }) => {
|
|
1515
|
+
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1423
1516
|
"after",
|
|
1424
1517
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1425
1518
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1428,10 +1521,10 @@ const login = {
|
|
|
1428
1521
|
name: "login",
|
|
1429
1522
|
description: "Strapi Cloud Login",
|
|
1430
1523
|
action: loginAction,
|
|
1431
|
-
command: command$
|
|
1524
|
+
command: command$4
|
|
1432
1525
|
};
|
|
1433
1526
|
const openModule = import("open");
|
|
1434
|
-
const action$
|
|
1527
|
+
const action$2 = async (ctx) => {
|
|
1435
1528
|
const { logger } = ctx;
|
|
1436
1529
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1437
1530
|
const token = await retrieveToken();
|
|
@@ -1463,25 +1556,25 @@ const action$1 = async (ctx) => {
|
|
|
1463
1556
|
}
|
|
1464
1557
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1465
1558
|
};
|
|
1466
|
-
const command$
|
|
1467
|
-
|
|
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));
|
|
1468
1561
|
};
|
|
1469
1562
|
const logout = {
|
|
1470
1563
|
name: "logout",
|
|
1471
1564
|
description: "Strapi Cloud Logout",
|
|
1472
|
-
action: action$
|
|
1473
|
-
command: command$
|
|
1565
|
+
action: action$2,
|
|
1566
|
+
command: command$3
|
|
1474
1567
|
};
|
|
1475
|
-
const command$
|
|
1476
|
-
|
|
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));
|
|
1477
1570
|
};
|
|
1478
1571
|
const createProject = {
|
|
1479
1572
|
name: "create-project",
|
|
1480
1573
|
description: "Create a new project",
|
|
1481
|
-
action: action$
|
|
1482
|
-
command: command$
|
|
1574
|
+
action: action$5,
|
|
1575
|
+
command: command$2
|
|
1483
1576
|
};
|
|
1484
|
-
const action = async (ctx) => {
|
|
1577
|
+
const action$1 = async (ctx) => {
|
|
1485
1578
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1486
1579
|
const token = await getValidToken(ctx, promptLogin);
|
|
1487
1580
|
const { logger } = ctx;
|
|
@@ -1501,12 +1594,94 @@ const action = async (ctx) => {
|
|
|
1501
1594
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1502
1595
|
}
|
|
1503
1596
|
};
|
|
1504
|
-
const command = ({ command: command2, ctx }) => {
|
|
1505
|
-
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));
|
|
1506
1599
|
};
|
|
1507
1600
|
const listProjects = {
|
|
1508
1601
|
name: "list-projects",
|
|
1509
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",
|
|
1510
1685
|
action,
|
|
1511
1686
|
command
|
|
1512
1687
|
};
|
|
@@ -1516,9 +1691,10 @@ const cli = {
|
|
|
1516
1691
|
login,
|
|
1517
1692
|
logout,
|
|
1518
1693
|
createProject,
|
|
1519
|
-
listProjects
|
|
1694
|
+
listProjects,
|
|
1695
|
+
listEnvironments
|
|
1520
1696
|
};
|
|
1521
|
-
const cloudCommands = [deployProject, link, login, logout, listProjects];
|
|
1697
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
|
|
1522
1698
|
async function initCloudCLIConfig() {
|
|
1523
1699
|
const localConfig = await getLocalConfig();
|
|
1524
1700
|
if (!localConfig.deviceId) {
|
|
@@ -1534,7 +1710,10 @@ async function buildStrapiCloudCommands({
|
|
|
1534
1710
|
await initCloudCLIConfig();
|
|
1535
1711
|
for (const cloudCommand of cloudCommands) {
|
|
1536
1712
|
try {
|
|
1537
|
-
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
|
+
}
|
|
1538
1717
|
} catch (e) {
|
|
1539
1718
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1540
1719
|
}
|