@strapi/cloud-cli 0.0.0-next.c81cadaa87436c4661a7ec61cdda96a5540b2b42 → 0.0.0-next.c9f32f6f0c2be1b88323373117f12eb33219d20e
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/bin.js +1 -0
- package/dist/bin.js.map +1 -1
- package/dist/index.js +469 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +467 -88
- 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 +5 -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/link/action.d.ts +4 -0
- package/dist/src/environment/link/action.d.ts.map +1 -0
- package/dist/src/environment/link/command.d.ts +4 -0
- package/dist/src/environment/link/command.d.ts.map +1 -0
- package/dist/src/environment/link/index.d.ts +7 -0
- package/dist/src/environment/link/index.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 +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/link/action.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 +46 -3
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/services/strapi-info-save.d.ts +15 -2
- package/dist/src/services/strapi-info-save.d.ts.map +1 -1
- package/dist/src/types.d.ts +7 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/get-local-config.d.ts +6 -0
- package/dist/src/utils/get-local-config.d.ts.map +1 -0
- 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 +10 -9
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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";
|
|
5
|
+
import boxen from "boxen";
|
|
4
6
|
import * as path from "path";
|
|
5
7
|
import path__default from "path";
|
|
6
8
|
import chalk from "chalk";
|
|
@@ -9,10 +11,10 @@ import * as crypto from "node:crypto";
|
|
|
9
11
|
import { env } from "@strapi/utils";
|
|
10
12
|
import * as tar from "tar";
|
|
11
13
|
import { minimatch } from "minimatch";
|
|
12
|
-
import inquirer from "inquirer";
|
|
13
14
|
import { defaults, has } from "lodash/fp";
|
|
14
15
|
import os from "os";
|
|
15
16
|
import XDGAppPaths from "xdg-app-paths";
|
|
17
|
+
import { merge } from "lodash";
|
|
16
18
|
import jwksClient from "jwks-rsa";
|
|
17
19
|
import jwt from "jsonwebtoken";
|
|
18
20
|
import stringify from "fast-safe-stringify";
|
|
@@ -21,6 +23,7 @@ import * as cliProgress from "cli-progress";
|
|
|
21
23
|
import pkgUp from "pkg-up";
|
|
22
24
|
import * as yup from "yup";
|
|
23
25
|
import EventSource from "eventsource";
|
|
26
|
+
import { createCommand } from "commander";
|
|
24
27
|
const apiConfig = {
|
|
25
28
|
apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
26
29
|
dashboardBaseUrl: env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -117,7 +120,7 @@ async function getConfigPath() {
|
|
|
117
120
|
}
|
|
118
121
|
return configPath;
|
|
119
122
|
}
|
|
120
|
-
async function getLocalConfig() {
|
|
123
|
+
async function getLocalConfig$1() {
|
|
121
124
|
const configPath = await getConfigPath();
|
|
122
125
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
123
126
|
await fse__default.ensureFile(configFilePath);
|
|
@@ -133,7 +136,7 @@ async function saveLocalConfig(data) {
|
|
|
133
136
|
await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
134
137
|
}
|
|
135
138
|
const name = "@strapi/cloud-cli";
|
|
136
|
-
const version = "4.
|
|
139
|
+
const version = "5.4.1";
|
|
137
140
|
const description = "Commands to interact with the Strapi Cloud";
|
|
138
141
|
const keywords = [
|
|
139
142
|
"strapi",
|
|
@@ -178,14 +181,15 @@ const scripts = {
|
|
|
178
181
|
watch: "pack-up watch"
|
|
179
182
|
};
|
|
180
183
|
const dependencies = {
|
|
181
|
-
"@strapi/utils": "4.
|
|
182
|
-
axios: "1.
|
|
184
|
+
"@strapi/utils": "5.4.1",
|
|
185
|
+
axios: "1.7.4",
|
|
186
|
+
boxen: "5.1.2",
|
|
183
187
|
chalk: "4.1.2",
|
|
184
188
|
"cli-progress": "3.12.0",
|
|
185
189
|
commander: "8.3.0",
|
|
186
190
|
eventsource: "2.0.2",
|
|
187
191
|
"fast-safe-stringify": "2.1.1",
|
|
188
|
-
"fs-extra": "
|
|
192
|
+
"fs-extra": "11.2.0",
|
|
189
193
|
inquirer: "8.2.5",
|
|
190
194
|
jsonwebtoken: "9.0.0",
|
|
191
195
|
"jwks-rsa": "3.1.0",
|
|
@@ -194,7 +198,7 @@ const dependencies = {
|
|
|
194
198
|
open: "8.4.0",
|
|
195
199
|
ora: "5.4.1",
|
|
196
200
|
"pkg-up": "3.1.0",
|
|
197
|
-
tar: "6.1
|
|
201
|
+
tar: "6.2.1",
|
|
198
202
|
"xdg-app-paths": "8.3.0",
|
|
199
203
|
yup: "0.32.9"
|
|
200
204
|
};
|
|
@@ -203,13 +207,14 @@ const devDependencies = {
|
|
|
203
207
|
"@types/cli-progress": "3.11.5",
|
|
204
208
|
"@types/eventsource": "1.1.15",
|
|
205
209
|
"@types/lodash": "^4.14.191",
|
|
206
|
-
"eslint-config-custom": "4.
|
|
207
|
-
tsconfig: "4.
|
|
210
|
+
"eslint-config-custom": "5.4.1",
|
|
211
|
+
tsconfig: "5.4.1"
|
|
208
212
|
};
|
|
209
213
|
const engines = {
|
|
210
|
-
node: ">=18.0.0 <=
|
|
214
|
+
node: ">=18.0.0 <=22.x.x",
|
|
211
215
|
npm: ">=6.0.0"
|
|
212
216
|
};
|
|
217
|
+
const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
|
|
213
218
|
const packageJson = {
|
|
214
219
|
name,
|
|
215
220
|
version,
|
|
@@ -230,11 +235,12 @@ const packageJson = {
|
|
|
230
235
|
scripts,
|
|
231
236
|
dependencies,
|
|
232
237
|
devDependencies,
|
|
233
|
-
engines
|
|
238
|
+
engines,
|
|
239
|
+
gitHead
|
|
234
240
|
};
|
|
235
241
|
const VERSION = "v1";
|
|
236
242
|
async function cloudApiFactory({ logger }, token) {
|
|
237
|
-
const localConfig = await getLocalConfig();
|
|
243
|
+
const localConfig = await getLocalConfig$1();
|
|
238
244
|
const customHeaders = {
|
|
239
245
|
"x-device-id": localConfig.deviceId,
|
|
240
246
|
"x-app-version": packageJson.version,
|
|
@@ -257,7 +263,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
257
263
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
258
264
|
return axiosCloudAPI.post(
|
|
259
265
|
`/deploy/${project.name}`,
|
|
260
|
-
{ file: fse__default.createReadStream(filePath) },
|
|
266
|
+
{ file: fse__default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
261
267
|
{
|
|
262
268
|
headers: {
|
|
263
269
|
"Content-Type": "multipart/form-data"
|
|
@@ -316,7 +322,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
316
322
|
},
|
|
317
323
|
async listLinkProjects() {
|
|
318
324
|
try {
|
|
319
|
-
const response = await axiosCloudAPI.get("/projects
|
|
325
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
320
326
|
if (response.status !== 200) {
|
|
321
327
|
throw new Error("Error fetching cloud projects from the server.");
|
|
322
328
|
}
|
|
@@ -328,6 +334,48 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
328
334
|
throw error;
|
|
329
335
|
}
|
|
330
336
|
},
|
|
337
|
+
async listEnvironments({ name: name2 }) {
|
|
338
|
+
try {
|
|
339
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
340
|
+
if (response.status !== 200) {
|
|
341
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
342
|
+
}
|
|
343
|
+
return response;
|
|
344
|
+
} catch (error) {
|
|
345
|
+
logger.debug(
|
|
346
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
347
|
+
);
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
352
|
+
try {
|
|
353
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
354
|
+
if (response.status !== 200) {
|
|
355
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
356
|
+
}
|
|
357
|
+
return response;
|
|
358
|
+
} catch (error) {
|
|
359
|
+
logger.debug(
|
|
360
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
361
|
+
);
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
async getProject({ name: name2 }) {
|
|
366
|
+
try {
|
|
367
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
368
|
+
if (response.status !== 200) {
|
|
369
|
+
throw new Error("Error fetching project's details.");
|
|
370
|
+
}
|
|
371
|
+
return response;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
logger.debug(
|
|
374
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
375
|
+
);
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
},
|
|
331
379
|
track(event, payload = {}) {
|
|
332
380
|
return axiosCloudAPI.post("/track", {
|
|
333
381
|
event,
|
|
@@ -337,26 +385,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
337
385
|
};
|
|
338
386
|
}
|
|
339
387
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
388
|
+
const getFilePath = (directoryPath) => path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
340
389
|
async function save(data, { directoryPath } = {}) {
|
|
341
|
-
const
|
|
342
|
-
const storedData = { ...alreadyInFileData, ...data };
|
|
343
|
-
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
390
|
+
const pathToFile = getFilePath(directoryPath);
|
|
344
391
|
await fse__default.ensureDir(path__default.dirname(pathToFile));
|
|
345
|
-
await fse__default.writeJson(pathToFile,
|
|
392
|
+
await fse__default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
346
393
|
}
|
|
347
394
|
async function retrieve({
|
|
348
395
|
directoryPath
|
|
349
396
|
} = {}) {
|
|
350
|
-
const pathToFile =
|
|
397
|
+
const pathToFile = getFilePath(directoryPath);
|
|
351
398
|
const pathExists = await fse__default.pathExists(pathToFile);
|
|
352
399
|
if (!pathExists) {
|
|
353
400
|
return {};
|
|
354
401
|
}
|
|
355
402
|
return fse__default.readJSON(pathToFile, { encoding: "utf8" });
|
|
356
403
|
}
|
|
404
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
405
|
+
const pathToFile = getFilePath(directoryPath);
|
|
406
|
+
const existingData = await retrieve({ directoryPath });
|
|
407
|
+
if (!existingData) {
|
|
408
|
+
throw new Error("No configuration data found to patch.");
|
|
409
|
+
}
|
|
410
|
+
const newData = merge(existingData, patchData);
|
|
411
|
+
await fse__default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
412
|
+
}
|
|
413
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
414
|
+
const pathToFile = getFilePath(directoryPath);
|
|
415
|
+
const pathExists = await fse__default.pathExists(pathToFile);
|
|
416
|
+
if (pathExists) {
|
|
417
|
+
await fse__default.remove(pathToFile);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
357
420
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
358
421
|
__proto__: null,
|
|
359
422
|
LOCAL_SAVE_FILENAME,
|
|
423
|
+
deleteConfig,
|
|
424
|
+
patch,
|
|
360
425
|
retrieve,
|
|
361
426
|
save
|
|
362
427
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -364,7 +429,7 @@ let cliConfig;
|
|
|
364
429
|
async function tokenServiceFactory({ logger }) {
|
|
365
430
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
366
431
|
async function saveToken(str) {
|
|
367
|
-
const appConfig = await getLocalConfig();
|
|
432
|
+
const appConfig = await getLocalConfig$1();
|
|
368
433
|
if (!appConfig) {
|
|
369
434
|
logger.error("There was a problem saving your token. Please try again.");
|
|
370
435
|
return;
|
|
@@ -378,7 +443,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
378
443
|
}
|
|
379
444
|
}
|
|
380
445
|
async function retrieveToken() {
|
|
381
|
-
const appConfig = await getLocalConfig();
|
|
446
|
+
const appConfig = await getLocalConfig$1();
|
|
382
447
|
if (appConfig.token) {
|
|
383
448
|
if (await isTokenValid(appConfig.token)) {
|
|
384
449
|
return appConfig.token;
|
|
@@ -440,7 +505,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
440
505
|
}
|
|
441
506
|
}
|
|
442
507
|
async function eraseToken() {
|
|
443
|
-
const appConfig = await getLocalConfig();
|
|
508
|
+
const appConfig = await getLocalConfig$1();
|
|
444
509
|
if (!appConfig) {
|
|
445
510
|
return;
|
|
446
511
|
}
|
|
@@ -601,21 +666,24 @@ yup.object({
|
|
|
601
666
|
name: yup.string().required(),
|
|
602
667
|
exports: yup.lazy(
|
|
603
668
|
(value) => yup.object(
|
|
604
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
669
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
670
|
+
(acc, [key, value2]) => {
|
|
671
|
+
if (typeof value2 === "object") {
|
|
672
|
+
acc[key] = yup.object({
|
|
673
|
+
types: yup.string().optional(),
|
|
674
|
+
source: yup.string().required(),
|
|
675
|
+
module: yup.string().optional(),
|
|
676
|
+
import: yup.string().required(),
|
|
677
|
+
require: yup.string().required(),
|
|
678
|
+
default: yup.string().required()
|
|
679
|
+
}).noUnknown(true);
|
|
680
|
+
} else {
|
|
681
|
+
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
682
|
+
}
|
|
683
|
+
return acc;
|
|
684
|
+
},
|
|
685
|
+
{}
|
|
686
|
+
) : void 0
|
|
619
687
|
).optional()
|
|
620
688
|
)
|
|
621
689
|
});
|
|
@@ -883,7 +951,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
883
951
|
throw e;
|
|
884
952
|
}
|
|
885
953
|
}
|
|
886
|
-
const action$
|
|
954
|
+
const action$6 = async (ctx) => {
|
|
887
955
|
const { logger } = ctx;
|
|
888
956
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
889
957
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -1012,6 +1080,29 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1012
1080
|
});
|
|
1013
1081
|
};
|
|
1014
1082
|
};
|
|
1083
|
+
const boxenOptions = {
|
|
1084
|
+
padding: 1,
|
|
1085
|
+
margin: 1,
|
|
1086
|
+
align: "center",
|
|
1087
|
+
borderColor: "yellow",
|
|
1088
|
+
borderStyle: "round"
|
|
1089
|
+
};
|
|
1090
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1091
|
+
async function promptForEnvironment(environments) {
|
|
1092
|
+
const choices = environments.map((env2) => ({ name: env2, value: env2 }));
|
|
1093
|
+
const { selectedEnvironment } = await inquirer.prompt([
|
|
1094
|
+
{
|
|
1095
|
+
type: "list",
|
|
1096
|
+
name: "selectedEnvironment",
|
|
1097
|
+
message: "Select the environment to deploy:",
|
|
1098
|
+
choices: [...choices, { name: chalk.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1099
|
+
}
|
|
1100
|
+
]);
|
|
1101
|
+
if (selectedEnvironment === null) {
|
|
1102
|
+
process.exit(1);
|
|
1103
|
+
}
|
|
1104
|
+
return selectedEnvironment;
|
|
1105
|
+
}
|
|
1015
1106
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1016
1107
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1017
1108
|
try {
|
|
@@ -1078,17 +1169,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1078
1169
|
return data.build_id;
|
|
1079
1170
|
} catch (e) {
|
|
1080
1171
|
progressBar.stop();
|
|
1081
|
-
|
|
1082
|
-
if (e.response.status === 404) {
|
|
1083
|
-
ctx.logger.warn(
|
|
1084
|
-
`The project does not exist. Please link your local project to a Strapi Cloud project using the link command.`
|
|
1085
|
-
);
|
|
1086
|
-
} else {
|
|
1087
|
-
ctx.logger.error(e.response.data);
|
|
1088
|
-
}
|
|
1089
|
-
} else {
|
|
1090
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1091
|
-
}
|
|
1172
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1092
1173
|
ctx.logger.debug(e);
|
|
1093
1174
|
} finally {
|
|
1094
1175
|
await fse__default.remove(tarFilePath);
|
|
@@ -1104,7 +1185,7 @@ async function getProject(ctx) {
|
|
|
1104
1185
|
const { project } = await retrieve();
|
|
1105
1186
|
if (!project) {
|
|
1106
1187
|
try {
|
|
1107
|
-
return await action$
|
|
1188
|
+
return await action$6(ctx);
|
|
1108
1189
|
} catch (e) {
|
|
1109
1190
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1110
1191
|
ctx.logger.debug(e);
|
|
@@ -1125,7 +1206,33 @@ async function getConfig({
|
|
|
1125
1206
|
return null;
|
|
1126
1207
|
}
|
|
1127
1208
|
}
|
|
1128
|
-
|
|
1209
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1210
|
+
if (!environments.includes(environment)) {
|
|
1211
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1212
|
+
process.exit(1);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1216
|
+
if (opts.env) {
|
|
1217
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1218
|
+
return opts.env;
|
|
1219
|
+
}
|
|
1220
|
+
if (project.targetEnvironment) {
|
|
1221
|
+
return project.targetEnvironment;
|
|
1222
|
+
}
|
|
1223
|
+
if (environments.length > 1) {
|
|
1224
|
+
return promptForEnvironment(environments);
|
|
1225
|
+
}
|
|
1226
|
+
return environments[0];
|
|
1227
|
+
}
|
|
1228
|
+
function hasPendingOrLiveDeployment(environments, targetEnvironment) {
|
|
1229
|
+
const environment = environments.find((env2) => env2.name === targetEnvironment);
|
|
1230
|
+
if (!environment) {
|
|
1231
|
+
throw new Error(`Environment details ${targetEnvironment} not found.`);
|
|
1232
|
+
}
|
|
1233
|
+
return environment.hasPendingDeployment || environment.hasLiveDeployment || false;
|
|
1234
|
+
}
|
|
1235
|
+
const action$5 = async (ctx, opts) => {
|
|
1129
1236
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1130
1237
|
const token = await getValidToken(ctx, promptLogin);
|
|
1131
1238
|
if (!token) {
|
|
@@ -1135,7 +1242,45 @@ const action$3 = async (ctx) => {
|
|
|
1135
1242
|
if (!project) {
|
|
1136
1243
|
return;
|
|
1137
1244
|
}
|
|
1138
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1245
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1246
|
+
let projectData;
|
|
1247
|
+
let environments;
|
|
1248
|
+
let environmentsDetails;
|
|
1249
|
+
try {
|
|
1250
|
+
const {
|
|
1251
|
+
data: { data, metadata }
|
|
1252
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1253
|
+
projectData = data;
|
|
1254
|
+
environments = projectData.environments;
|
|
1255
|
+
environmentsDetails = projectData.environmentsDetails;
|
|
1256
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1257
|
+
if (isProjectSuspended) {
|
|
1258
|
+
ctx.logger.log(
|
|
1259
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1260
|
+
);
|
|
1261
|
+
ctx.logger.log(chalk.underline(`${metadata.dashboardUrls.project}`));
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
} catch (e) {
|
|
1265
|
+
if (e instanceof AxiosError && e.response?.data) {
|
|
1266
|
+
if (e.response.status === 404) {
|
|
1267
|
+
ctx.logger.warn(
|
|
1268
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1269
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1270
|
+
"link"
|
|
1271
|
+
)} command before deploying.`
|
|
1272
|
+
);
|
|
1273
|
+
} else {
|
|
1274
|
+
ctx.logger.error(e.response.data);
|
|
1275
|
+
}
|
|
1276
|
+
} else {
|
|
1277
|
+
ctx.logger.error(
|
|
1278
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
ctx.logger.debug(e);
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1139
1284
|
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1140
1285
|
projectInternalName: project.name
|
|
1141
1286
|
});
|
|
@@ -1144,7 +1289,7 @@ const action$3 = async (ctx) => {
|
|
|
1144
1289
|
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1145
1290
|
if (!cliConfig2) {
|
|
1146
1291
|
ctx.logger.error(
|
|
1147
|
-
"An error occurred while retrieving data from Strapi Cloud. Please
|
|
1292
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1148
1293
|
);
|
|
1149
1294
|
return;
|
|
1150
1295
|
}
|
|
@@ -1155,11 +1300,34 @@ const action$3 = async (ctx) => {
|
|
|
1155
1300
|
);
|
|
1156
1301
|
maxSize = 1e8;
|
|
1157
1302
|
}
|
|
1303
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1304
|
+
if (!opts.force) {
|
|
1305
|
+
const shouldDisplayWarning = hasPendingOrLiveDeployment(
|
|
1306
|
+
environmentsDetails,
|
|
1307
|
+
project.targetEnvironment
|
|
1308
|
+
);
|
|
1309
|
+
if (shouldDisplayWarning) {
|
|
1310
|
+
ctx.logger.log(boxen(cliConfig2.projectDeployment.confirmationText, boxenOptions));
|
|
1311
|
+
const { confirm } = await inquirer.prompt([
|
|
1312
|
+
{
|
|
1313
|
+
type: "confirm",
|
|
1314
|
+
name: "confirm",
|
|
1315
|
+
message: `Do you want to proceed with deployment to ${chalk.cyan(projectData.displayName)} on ${chalk.cyan(project.targetEnvironment)} environment?`
|
|
1316
|
+
}
|
|
1317
|
+
]);
|
|
1318
|
+
if (!confirm) {
|
|
1319
|
+
process.exit(1);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1158
1323
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1159
1324
|
if (!buildId) {
|
|
1160
1325
|
return;
|
|
1161
1326
|
}
|
|
1162
1327
|
try {
|
|
1328
|
+
ctx.logger.log(
|
|
1329
|
+
`🚀 Deploying project to ${chalk.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1330
|
+
);
|
|
1163
1331
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1164
1332
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1165
1333
|
ctx.logger.log(
|
|
@@ -1204,17 +1372,16 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1204
1372
|
process.exit(1);
|
|
1205
1373
|
});
|
|
1206
1374
|
};
|
|
1207
|
-
const command$
|
|
1208
|
-
|
|
1375
|
+
const command$7 = ({ ctx }) => {
|
|
1376
|
+
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("-f, --force", "Skip confirmation to deploy").option("-e, --env <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$5)(ctx, opts));
|
|
1209
1377
|
};
|
|
1210
1378
|
const deployProject = {
|
|
1211
1379
|
name: "deploy-project",
|
|
1212
1380
|
description: "Deploy a Strapi Cloud project",
|
|
1213
|
-
action: action$
|
|
1214
|
-
command: command$
|
|
1381
|
+
action: action$5,
|
|
1382
|
+
command: command$7
|
|
1215
1383
|
};
|
|
1216
|
-
|
|
1217
|
-
async function getExistingConfig(ctx) {
|
|
1384
|
+
async function getLocalConfig(ctx) {
|
|
1218
1385
|
try {
|
|
1219
1386
|
return await retrieve();
|
|
1220
1387
|
} catch (e) {
|
|
@@ -1223,6 +1390,21 @@ async function getExistingConfig(ctx) {
|
|
|
1223
1390
|
return null;
|
|
1224
1391
|
}
|
|
1225
1392
|
}
|
|
1393
|
+
async function getLocalProject(ctx) {
|
|
1394
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1395
|
+
if (!localConfig || !localConfig.project) {
|
|
1396
|
+
ctx.logger.warn(
|
|
1397
|
+
`
|
|
1398
|
+
We couldn't find a valid local project config.
|
|
1399
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1400
|
+
"link"
|
|
1401
|
+
)} command.`
|
|
1402
|
+
);
|
|
1403
|
+
process.exit(1);
|
|
1404
|
+
}
|
|
1405
|
+
return localConfig.project;
|
|
1406
|
+
}
|
|
1407
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1226
1408
|
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1227
1409
|
if (existingConfig && existingConfig.project) {
|
|
1228
1410
|
const { shouldRelink } = await inquirer.prompt([
|
|
@@ -1252,7 +1434,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1252
1434
|
} = await cloudApiService.listLinkProjects();
|
|
1253
1435
|
spinner.succeed();
|
|
1254
1436
|
if (!Array.isArray(projectList)) {
|
|
1255
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1437
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1256
1438
|
return null;
|
|
1257
1439
|
}
|
|
1258
1440
|
const projects = projectList.filter(
|
|
@@ -1264,7 +1446,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1264
1446
|
};
|
|
1265
1447
|
});
|
|
1266
1448
|
if (projects.length === 0) {
|
|
1267
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1449
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1268
1450
|
return null;
|
|
1269
1451
|
}
|
|
1270
1452
|
return projects;
|
|
@@ -1282,7 +1464,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1282
1464
|
type: "list",
|
|
1283
1465
|
name: "linkProject",
|
|
1284
1466
|
message: "Which project do you want to link?",
|
|
1285
|
-
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1467
|
+
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1286
1468
|
}
|
|
1287
1469
|
]);
|
|
1288
1470
|
if (!answer.linkProject) {
|
|
@@ -1295,7 +1477,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1295
1477
|
return null;
|
|
1296
1478
|
}
|
|
1297
1479
|
}
|
|
1298
|
-
const action$
|
|
1480
|
+
const action$4 = async (ctx) => {
|
|
1299
1481
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1300
1482
|
const token = await getValidToken(ctx, promptLogin);
|
|
1301
1483
|
const { logger } = ctx;
|
|
@@ -1303,7 +1485,7 @@ const action$2 = async (ctx) => {
|
|
|
1303
1485
|
return;
|
|
1304
1486
|
}
|
|
1305
1487
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1306
|
-
const existingConfig = await
|
|
1488
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1307
1489
|
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1308
1490
|
if (!shouldRelink) {
|
|
1309
1491
|
return;
|
|
@@ -1338,7 +1520,9 @@ const action$2 = async (ctx) => {
|
|
|
1338
1520
|
return;
|
|
1339
1521
|
}
|
|
1340
1522
|
await save({ project: answer.linkProject });
|
|
1341
|
-
logger.log(
|
|
1523
|
+
logger.log(
|
|
1524
|
+
` You have successfully linked your project to ${chalk.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1525
|
+
);
|
|
1342
1526
|
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1343
1527
|
projectInternalName: answer.linkProject
|
|
1344
1528
|
});
|
|
@@ -1350,17 +1534,17 @@ const action$2 = async (ctx) => {
|
|
|
1350
1534
|
});
|
|
1351
1535
|
}
|
|
1352
1536
|
};
|
|
1353
|
-
const command$
|
|
1354
|
-
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$
|
|
1537
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1538
|
+
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$4)(ctx));
|
|
1355
1539
|
};
|
|
1356
1540
|
const link = {
|
|
1357
1541
|
name: "link-project",
|
|
1358
1542
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1359
|
-
action: action$
|
|
1360
|
-
command: command$
|
|
1543
|
+
action: action$4,
|
|
1544
|
+
command: command$6
|
|
1361
1545
|
};
|
|
1362
|
-
const command$
|
|
1363
|
-
|
|
1546
|
+
const command$5 = ({ ctx }) => {
|
|
1547
|
+
return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1364
1548
|
"after",
|
|
1365
1549
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1366
1550
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1369,10 +1553,10 @@ const login = {
|
|
|
1369
1553
|
name: "login",
|
|
1370
1554
|
description: "Strapi Cloud Login",
|
|
1371
1555
|
action: loginAction,
|
|
1372
|
-
command: command$
|
|
1556
|
+
command: command$5
|
|
1373
1557
|
};
|
|
1374
1558
|
const openModule = import("open");
|
|
1375
|
-
const action$
|
|
1559
|
+
const action$3 = async (ctx) => {
|
|
1376
1560
|
const { logger } = ctx;
|
|
1377
1561
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1378
1562
|
const token = await retrieveToken();
|
|
@@ -1404,25 +1588,25 @@ const action$1 = async (ctx) => {
|
|
|
1404
1588
|
}
|
|
1405
1589
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1406
1590
|
};
|
|
1407
|
-
const command$
|
|
1408
|
-
|
|
1591
|
+
const command$4 = ({ ctx }) => {
|
|
1592
|
+
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$3)(ctx));
|
|
1409
1593
|
};
|
|
1410
1594
|
const logout = {
|
|
1411
1595
|
name: "logout",
|
|
1412
1596
|
description: "Strapi Cloud Logout",
|
|
1413
|
-
action: action$
|
|
1414
|
-
command: command$
|
|
1597
|
+
action: action$3,
|
|
1598
|
+
command: command$4
|
|
1415
1599
|
};
|
|
1416
|
-
const command$
|
|
1417
|
-
|
|
1600
|
+
const command$3 = ({ ctx }) => {
|
|
1601
|
+
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$6)(ctx));
|
|
1418
1602
|
};
|
|
1419
1603
|
const createProject = {
|
|
1420
1604
|
name: "create-project",
|
|
1421
1605
|
description: "Create a new project",
|
|
1422
|
-
action: action$
|
|
1423
|
-
command: command$
|
|
1606
|
+
action: action$6,
|
|
1607
|
+
command: command$3
|
|
1424
1608
|
};
|
|
1425
|
-
const action = async (ctx) => {
|
|
1609
|
+
const action$2 = async (ctx) => {
|
|
1426
1610
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1427
1611
|
const token = await getValidToken(ctx, promptLogin);
|
|
1428
1612
|
const { logger } = ctx;
|
|
@@ -1442,12 +1626,194 @@ const action = async (ctx) => {
|
|
|
1442
1626
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1443
1627
|
}
|
|
1444
1628
|
};
|
|
1445
|
-
const command = ({ command: command2, ctx }) => {
|
|
1446
|
-
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));
|
|
1629
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1630
|
+
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$2)(ctx));
|
|
1447
1631
|
};
|
|
1448
1632
|
const listProjects = {
|
|
1449
1633
|
name: "list-projects",
|
|
1450
1634
|
description: "List Strapi Cloud projects",
|
|
1635
|
+
action: action$2,
|
|
1636
|
+
command: command$2
|
|
1637
|
+
};
|
|
1638
|
+
const action$1 = async (ctx) => {
|
|
1639
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1640
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1641
|
+
const { logger } = ctx;
|
|
1642
|
+
if (!token) {
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
const project = await getLocalProject(ctx);
|
|
1646
|
+
if (!project) {
|
|
1647
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1648
|
+
return;
|
|
1649
|
+
}
|
|
1650
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1651
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1652
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1653
|
+
projectInternalName: project.name
|
|
1654
|
+
});
|
|
1655
|
+
try {
|
|
1656
|
+
const {
|
|
1657
|
+
data: { data: environmentsList }
|
|
1658
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1659
|
+
spinner.succeed();
|
|
1660
|
+
logger.log(environmentsList);
|
|
1661
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1662
|
+
projectInternalName: project.name
|
|
1663
|
+
});
|
|
1664
|
+
} catch (e) {
|
|
1665
|
+
if (e.response && e.response.status === 404) {
|
|
1666
|
+
spinner.succeed();
|
|
1667
|
+
logger.warn(
|
|
1668
|
+
`
|
|
1669
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1670
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1671
|
+
"link"
|
|
1672
|
+
)} command`
|
|
1673
|
+
);
|
|
1674
|
+
} else {
|
|
1675
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1676
|
+
logger.debug("Failed to list environments", e);
|
|
1677
|
+
}
|
|
1678
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1679
|
+
projectInternalName: project.name
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1684
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1685
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1686
|
+
return cloud;
|
|
1687
|
+
}
|
|
1688
|
+
let environmentCmd = null;
|
|
1689
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1690
|
+
if (!environmentCmd) {
|
|
1691
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1692
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1693
|
+
}
|
|
1694
|
+
return environmentCmd;
|
|
1695
|
+
};
|
|
1696
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1697
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1698
|
+
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$1)(ctx));
|
|
1699
|
+
};
|
|
1700
|
+
const listEnvironments = {
|
|
1701
|
+
name: "list-environments",
|
|
1702
|
+
description: "List Strapi Cloud environments",
|
|
1703
|
+
action: action$1,
|
|
1704
|
+
command: command$1
|
|
1705
|
+
};
|
|
1706
|
+
const QUIT_OPTION = "Quit";
|
|
1707
|
+
const action = async (ctx) => {
|
|
1708
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1709
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1710
|
+
const { logger } = ctx;
|
|
1711
|
+
if (!token) {
|
|
1712
|
+
return;
|
|
1713
|
+
}
|
|
1714
|
+
const project = await getLocalProject(ctx);
|
|
1715
|
+
if (!project) {
|
|
1716
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1720
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1721
|
+
if (!environments) {
|
|
1722
|
+
logger.debug(`Fetching environments failed.`);
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
if (environments.length === 0) {
|
|
1726
|
+
logger.log(
|
|
1727
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1728
|
+
);
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1732
|
+
if (!answer) {
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1736
|
+
projectName: project.name,
|
|
1737
|
+
environmentName: answer.targetEnvironment
|
|
1738
|
+
});
|
|
1739
|
+
try {
|
|
1740
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1741
|
+
} catch (e) {
|
|
1742
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1743
|
+
projectName: project.name,
|
|
1744
|
+
environmentName: answer.targetEnvironment
|
|
1745
|
+
});
|
|
1746
|
+
logger.debug("Failed to link environment", e);
|
|
1747
|
+
logger.error(
|
|
1748
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1749
|
+
);
|
|
1750
|
+
process.exit(1);
|
|
1751
|
+
}
|
|
1752
|
+
logger.log(
|
|
1753
|
+
` You have successfully linked your project to ${chalk.cyan(answer.targetEnvironment)}, on ${chalk.cyan(project.displayName)}. You are now able to deploy your project.`
|
|
1754
|
+
);
|
|
1755
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1756
|
+
projectName: project.name,
|
|
1757
|
+
environmentName: answer.targetEnvironment
|
|
1758
|
+
});
|
|
1759
|
+
};
|
|
1760
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1761
|
+
const { logger } = ctx;
|
|
1762
|
+
try {
|
|
1763
|
+
const answer = await inquirer.prompt([
|
|
1764
|
+
{
|
|
1765
|
+
type: "list",
|
|
1766
|
+
name: "targetEnvironment",
|
|
1767
|
+
message: "Which environment do you want to link?",
|
|
1768
|
+
choices: [...environments, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1769
|
+
}
|
|
1770
|
+
]);
|
|
1771
|
+
if (!answer.targetEnvironment) {
|
|
1772
|
+
return null;
|
|
1773
|
+
}
|
|
1774
|
+
return answer;
|
|
1775
|
+
} catch (e) {
|
|
1776
|
+
logger.debug("Failed to get user input", e);
|
|
1777
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1778
|
+
return null;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1782
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1783
|
+
try {
|
|
1784
|
+
const {
|
|
1785
|
+
data: { data: environmentsList }
|
|
1786
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1787
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1788
|
+
throw new Error("Environments not found in server response");
|
|
1789
|
+
}
|
|
1790
|
+
spinner.succeed();
|
|
1791
|
+
return environmentsList.filter(
|
|
1792
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1793
|
+
);
|
|
1794
|
+
} catch (e) {
|
|
1795
|
+
if (e.response && e.response.status === 404) {
|
|
1796
|
+
spinner.succeed();
|
|
1797
|
+
ctx.logger.warn(
|
|
1798
|
+
`
|
|
1799
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1800
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1801
|
+
"link"
|
|
1802
|
+
)} command.`
|
|
1803
|
+
);
|
|
1804
|
+
} else {
|
|
1805
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1806
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
const command = ({ command: command2, ctx }) => {
|
|
1811
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1812
|
+
environmentCmd2.command("link").description("Link project to a specific Strapi Cloud project environment").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("link", action)(ctx));
|
|
1813
|
+
};
|
|
1814
|
+
const linkEnvironment = {
|
|
1815
|
+
name: "link-environment",
|
|
1816
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1451
1817
|
action,
|
|
1452
1818
|
command
|
|
1453
1819
|
};
|
|
@@ -1457,11 +1823,21 @@ const cli = {
|
|
|
1457
1823
|
login,
|
|
1458
1824
|
logout,
|
|
1459
1825
|
createProject,
|
|
1460
|
-
|
|
1826
|
+
linkEnvironment,
|
|
1827
|
+
listProjects,
|
|
1828
|
+
listEnvironments
|
|
1461
1829
|
};
|
|
1462
|
-
const cloudCommands = [
|
|
1830
|
+
const cloudCommands = [
|
|
1831
|
+
deployProject,
|
|
1832
|
+
link,
|
|
1833
|
+
login,
|
|
1834
|
+
logout,
|
|
1835
|
+
linkEnvironment,
|
|
1836
|
+
listProjects,
|
|
1837
|
+
listEnvironments
|
|
1838
|
+
];
|
|
1463
1839
|
async function initCloudCLIConfig() {
|
|
1464
|
-
const localConfig = await getLocalConfig();
|
|
1840
|
+
const localConfig = await getLocalConfig$1();
|
|
1465
1841
|
if (!localConfig.deviceId) {
|
|
1466
1842
|
localConfig.deviceId = crypto$1.randomUUID();
|
|
1467
1843
|
}
|
|
@@ -1475,7 +1851,10 @@ async function buildStrapiCloudCommands({
|
|
|
1475
1851
|
await initCloudCLIConfig();
|
|
1476
1852
|
for (const cloudCommand of cloudCommands) {
|
|
1477
1853
|
try {
|
|
1478
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1854
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1855
|
+
if (subCommand) {
|
|
1856
|
+
command2.addCommand(subCommand);
|
|
1857
|
+
}
|
|
1479
1858
|
} catch (e) {
|
|
1480
1859
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1481
1860
|
}
|