@strapi/cloud-cli 0.0.0-next.506c866896b405bfee0715be82ad4b0f8da1d26b → 0.0.0-next.51dcef446efe662f00da6d85d6bea2218c4c538e
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 +488 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +487 -106
- 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/action.d.ts.map +1 -1
- package/dist/src/create-project/command.d.ts.map +1 -1
- package/dist/src/create-project/utils/project-questions.utils.d.ts +20 -0
- package/dist/src/create-project/utils/project-questions.utils.d.ts.map +1 -0
- 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/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 +39 -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 +4 -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 +9 -9
- package/dist/src/create-project/utils/apply-default-name.d.ts +0 -7
- package/dist/src/create-project/utils/apply-default-name.d.ts.map +0 -1
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,10 +32,10 @@ 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");
|
|
38
|
+
const lodash = require("lodash");
|
|
38
39
|
const jwksClient = require("jwks-rsa");
|
|
39
40
|
const jwt = require("jsonwebtoken");
|
|
40
41
|
const stringify = require("fast-safe-stringify");
|
|
@@ -42,8 +43,8 @@ const ora = require("ora");
|
|
|
42
43
|
const cliProgress = require("cli-progress");
|
|
43
44
|
const pkgUp = require("pkg-up");
|
|
44
45
|
const yup = require("yup");
|
|
45
|
-
const _ = require("lodash");
|
|
46
46
|
const EventSource = require("eventsource");
|
|
47
|
+
const commander = require("commander");
|
|
47
48
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
48
49
|
function _interopNamespace(e) {
|
|
49
50
|
if (e && e.__esModule)
|
|
@@ -65,12 +66,12 @@ function _interopNamespace(e) {
|
|
|
65
66
|
}
|
|
66
67
|
const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
|
|
67
68
|
const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
|
|
69
|
+
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
68
70
|
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
69
71
|
const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
70
72
|
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
71
73
|
const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
|
|
72
74
|
const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
|
|
73
|
-
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
74
75
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
75
76
|
const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
|
|
76
77
|
const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
|
|
@@ -80,7 +81,6 @@ const ora__default = /* @__PURE__ */ _interopDefault(ora);
|
|
|
80
81
|
const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
|
|
81
82
|
const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
|
|
82
83
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
83
|
-
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
84
84
|
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
85
85
|
const apiConfig = {
|
|
86
86
|
apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
@@ -178,7 +178,7 @@ async function getConfigPath() {
|
|
|
178
178
|
}
|
|
179
179
|
return configPath;
|
|
180
180
|
}
|
|
181
|
-
async function getLocalConfig() {
|
|
181
|
+
async function getLocalConfig$1() {
|
|
182
182
|
const configPath = await getConfigPath();
|
|
183
183
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
184
184
|
await fse__namespace.default.ensureFile(configFilePath);
|
|
@@ -194,7 +194,7 @@ async function saveLocalConfig(data) {
|
|
|
194
194
|
await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
195
195
|
}
|
|
196
196
|
const name = "@strapi/cloud-cli";
|
|
197
|
-
const version = "4.
|
|
197
|
+
const version = "5.4.0";
|
|
198
198
|
const description = "Commands to interact with the Strapi Cloud";
|
|
199
199
|
const keywords = [
|
|
200
200
|
"strapi",
|
|
@@ -239,14 +239,14 @@ const scripts = {
|
|
|
239
239
|
watch: "pack-up watch"
|
|
240
240
|
};
|
|
241
241
|
const dependencies = {
|
|
242
|
-
"@strapi/utils": "4.
|
|
243
|
-
axios: "1.
|
|
242
|
+
"@strapi/utils": "5.4.0",
|
|
243
|
+
axios: "1.7.4",
|
|
244
244
|
chalk: "4.1.2",
|
|
245
245
|
"cli-progress": "3.12.0",
|
|
246
246
|
commander: "8.3.0",
|
|
247
247
|
eventsource: "2.0.2",
|
|
248
248
|
"fast-safe-stringify": "2.1.1",
|
|
249
|
-
"fs-extra": "
|
|
249
|
+
"fs-extra": "11.2.0",
|
|
250
250
|
inquirer: "8.2.5",
|
|
251
251
|
jsonwebtoken: "9.0.0",
|
|
252
252
|
"jwks-rsa": "3.1.0",
|
|
@@ -255,7 +255,7 @@ const dependencies = {
|
|
|
255
255
|
open: "8.4.0",
|
|
256
256
|
ora: "5.4.1",
|
|
257
257
|
"pkg-up": "3.1.0",
|
|
258
|
-
tar: "6.1
|
|
258
|
+
tar: "6.2.1",
|
|
259
259
|
"xdg-app-paths": "8.3.0",
|
|
260
260
|
yup: "0.32.9"
|
|
261
261
|
};
|
|
@@ -264,13 +264,14 @@ const devDependencies = {
|
|
|
264
264
|
"@types/cli-progress": "3.11.5",
|
|
265
265
|
"@types/eventsource": "1.1.15",
|
|
266
266
|
"@types/lodash": "^4.14.191",
|
|
267
|
-
"eslint-config-custom": "4.
|
|
268
|
-
tsconfig: "4.
|
|
267
|
+
"eslint-config-custom": "5.4.0",
|
|
268
|
+
tsconfig: "5.4.0"
|
|
269
269
|
};
|
|
270
270
|
const engines = {
|
|
271
|
-
node: ">=18.0.0 <=
|
|
271
|
+
node: ">=18.0.0 <=22.x.x",
|
|
272
272
|
npm: ">=6.0.0"
|
|
273
273
|
};
|
|
274
|
+
const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
|
|
274
275
|
const packageJson = {
|
|
275
276
|
name,
|
|
276
277
|
version,
|
|
@@ -291,11 +292,12 @@ const packageJson = {
|
|
|
291
292
|
scripts,
|
|
292
293
|
dependencies,
|
|
293
294
|
devDependencies,
|
|
294
|
-
engines
|
|
295
|
+
engines,
|
|
296
|
+
gitHead
|
|
295
297
|
};
|
|
296
298
|
const VERSION = "v1";
|
|
297
299
|
async function cloudApiFactory({ logger }, token) {
|
|
298
|
-
const localConfig = await getLocalConfig();
|
|
300
|
+
const localConfig = await getLocalConfig$1();
|
|
299
301
|
const customHeaders = {
|
|
300
302
|
"x-device-id": localConfig.deviceId,
|
|
301
303
|
"x-app-version": packageJson.version,
|
|
@@ -318,7 +320,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
318
320
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
319
321
|
return axiosCloudAPI.post(
|
|
320
322
|
`/deploy/${project.name}`,
|
|
321
|
-
{ file: fse__namespace.default.createReadStream(filePath) },
|
|
323
|
+
{ file: fse__namespace.default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
322
324
|
{
|
|
323
325
|
headers: {
|
|
324
326
|
"Content-Type": "multipart/form-data"
|
|
@@ -377,7 +379,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
377
379
|
},
|
|
378
380
|
async listLinkProjects() {
|
|
379
381
|
try {
|
|
380
|
-
const response = await axiosCloudAPI.get("/projects
|
|
382
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
381
383
|
if (response.status !== 200) {
|
|
382
384
|
throw new Error("Error fetching cloud projects from the server.");
|
|
383
385
|
}
|
|
@@ -389,6 +391,48 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
389
391
|
throw error;
|
|
390
392
|
}
|
|
391
393
|
},
|
|
394
|
+
async listEnvironments({ name: name2 }) {
|
|
395
|
+
try {
|
|
396
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
397
|
+
if (response.status !== 200) {
|
|
398
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
399
|
+
}
|
|
400
|
+
return response;
|
|
401
|
+
} catch (error) {
|
|
402
|
+
logger.debug(
|
|
403
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
404
|
+
);
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
409
|
+
try {
|
|
410
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
411
|
+
if (response.status !== 200) {
|
|
412
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
413
|
+
}
|
|
414
|
+
return response;
|
|
415
|
+
} catch (error) {
|
|
416
|
+
logger.debug(
|
|
417
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
418
|
+
);
|
|
419
|
+
throw error;
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
async getProject({ name: name2 }) {
|
|
423
|
+
try {
|
|
424
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
425
|
+
if (response.status !== 200) {
|
|
426
|
+
throw new Error("Error fetching project's details.");
|
|
427
|
+
}
|
|
428
|
+
return response;
|
|
429
|
+
} catch (error) {
|
|
430
|
+
logger.debug(
|
|
431
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
432
|
+
);
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
},
|
|
392
436
|
track(event, payload = {}) {
|
|
393
437
|
return axiosCloudAPI.post("/track", {
|
|
394
438
|
event,
|
|
@@ -398,26 +442,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
398
442
|
};
|
|
399
443
|
}
|
|
400
444
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
445
|
+
const getFilePath = (directoryPath) => path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
401
446
|
async function save(data, { directoryPath } = {}) {
|
|
402
|
-
const
|
|
403
|
-
const storedData = { ...alreadyInFileData, ...data };
|
|
404
|
-
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
447
|
+
const pathToFile = getFilePath(directoryPath);
|
|
405
448
|
await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
406
|
-
await fse__namespace.default.writeJson(pathToFile,
|
|
449
|
+
await fse__namespace.default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
407
450
|
}
|
|
408
451
|
async function retrieve({
|
|
409
452
|
directoryPath
|
|
410
453
|
} = {}) {
|
|
411
|
-
const pathToFile =
|
|
454
|
+
const pathToFile = getFilePath(directoryPath);
|
|
412
455
|
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
413
456
|
if (!pathExists) {
|
|
414
457
|
return {};
|
|
415
458
|
}
|
|
416
459
|
return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
|
|
417
460
|
}
|
|
461
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
462
|
+
const pathToFile = getFilePath(directoryPath);
|
|
463
|
+
const existingData = await retrieve({ directoryPath });
|
|
464
|
+
if (!existingData) {
|
|
465
|
+
throw new Error("No configuration data found to patch.");
|
|
466
|
+
}
|
|
467
|
+
const newData = lodash.merge(existingData, patchData);
|
|
468
|
+
await fse__namespace.default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
469
|
+
}
|
|
470
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
471
|
+
const pathToFile = getFilePath(directoryPath);
|
|
472
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
473
|
+
if (pathExists) {
|
|
474
|
+
await fse__namespace.default.remove(pathToFile);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
418
477
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
419
478
|
__proto__: null,
|
|
420
479
|
LOCAL_SAVE_FILENAME,
|
|
480
|
+
deleteConfig,
|
|
481
|
+
patch,
|
|
421
482
|
retrieve,
|
|
422
483
|
save
|
|
423
484
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -425,7 +486,7 @@ let cliConfig;
|
|
|
425
486
|
async function tokenServiceFactory({ logger }) {
|
|
426
487
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
427
488
|
async function saveToken(str) {
|
|
428
|
-
const appConfig = await getLocalConfig();
|
|
489
|
+
const appConfig = await getLocalConfig$1();
|
|
429
490
|
if (!appConfig) {
|
|
430
491
|
logger.error("There was a problem saving your token. Please try again.");
|
|
431
492
|
return;
|
|
@@ -439,7 +500,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
439
500
|
}
|
|
440
501
|
}
|
|
441
502
|
async function retrieveToken() {
|
|
442
|
-
const appConfig = await getLocalConfig();
|
|
503
|
+
const appConfig = await getLocalConfig$1();
|
|
443
504
|
if (appConfig.token) {
|
|
444
505
|
if (await isTokenValid(appConfig.token)) {
|
|
445
506
|
return appConfig.token;
|
|
@@ -501,7 +562,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
501
562
|
}
|
|
502
563
|
}
|
|
503
564
|
async function eraseToken() {
|
|
504
|
-
const appConfig = await getLocalConfig();
|
|
565
|
+
const appConfig = await getLocalConfig$1();
|
|
505
566
|
if (!appConfig) {
|
|
506
567
|
return;
|
|
507
568
|
}
|
|
@@ -662,21 +723,24 @@ yup__namespace.object({
|
|
|
662
723
|
name: yup__namespace.string().required(),
|
|
663
724
|
exports: yup__namespace.lazy(
|
|
664
725
|
(value) => yup__namespace.object(
|
|
665
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
726
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
727
|
+
(acc, [key, value2]) => {
|
|
728
|
+
if (typeof value2 === "object") {
|
|
729
|
+
acc[key] = yup__namespace.object({
|
|
730
|
+
types: yup__namespace.string().optional(),
|
|
731
|
+
source: yup__namespace.string().required(),
|
|
732
|
+
module: yup__namespace.string().optional(),
|
|
733
|
+
import: yup__namespace.string().required(),
|
|
734
|
+
require: yup__namespace.string().required(),
|
|
735
|
+
default: yup__namespace.string().required()
|
|
736
|
+
}).noUnknown(true);
|
|
737
|
+
} else {
|
|
738
|
+
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
739
|
+
}
|
|
740
|
+
return acc;
|
|
741
|
+
},
|
|
742
|
+
{}
|
|
743
|
+
) : void 0
|
|
680
744
|
).optional()
|
|
681
745
|
)
|
|
682
746
|
});
|
|
@@ -698,18 +762,6 @@ async function getProjectNameFromPackageJson(ctx) {
|
|
|
698
762
|
return "my-strapi-project";
|
|
699
763
|
}
|
|
700
764
|
}
|
|
701
|
-
function applyDefaultName(newDefaultName, questions, defaultValues) {
|
|
702
|
-
const newDefaultValues = ___default.default.cloneDeep(defaultValues);
|
|
703
|
-
newDefaultValues.name = newDefaultName;
|
|
704
|
-
const newQuestions = questions.map((question) => {
|
|
705
|
-
const questionCopy = ___default.default.cloneDeep(question);
|
|
706
|
-
if (questionCopy.name === "name") {
|
|
707
|
-
questionCopy.default = newDefaultName;
|
|
708
|
-
}
|
|
709
|
-
return questionCopy;
|
|
710
|
-
});
|
|
711
|
-
return { newQuestions, newDefaultValues };
|
|
712
|
-
}
|
|
713
765
|
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
714
766
|
try {
|
|
715
767
|
await cloudApiService.track(eventName, eventData);
|
|
@@ -873,6 +925,45 @@ async function loginAction(ctx) {
|
|
|
873
925
|
await authenticate();
|
|
874
926
|
return isAuthenticated;
|
|
875
927
|
}
|
|
928
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
929
|
+
return (questions) => {
|
|
930
|
+
return questions.map((question) => {
|
|
931
|
+
const questionName = question.name;
|
|
932
|
+
if (questionName in questionsMap) {
|
|
933
|
+
const questionDefault = questionsMap[questionName];
|
|
934
|
+
if (typeof questionDefault === "function") {
|
|
935
|
+
return {
|
|
936
|
+
...question,
|
|
937
|
+
default: questionDefault(question)
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
return {
|
|
941
|
+
...question,
|
|
942
|
+
default: questionDefault
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
return question;
|
|
946
|
+
});
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function getDefaultsFromQuestions(questions) {
|
|
950
|
+
return questions.reduce((acc, question) => {
|
|
951
|
+
if (question.default && question.name) {
|
|
952
|
+
return { ...acc, [question.name]: question.default };
|
|
953
|
+
}
|
|
954
|
+
return acc;
|
|
955
|
+
}, {});
|
|
956
|
+
}
|
|
957
|
+
function getProjectNodeVersionDefault(question) {
|
|
958
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
959
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
960
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
961
|
+
if (choice) {
|
|
962
|
+
return choice.value;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return question.default;
|
|
966
|
+
}
|
|
876
967
|
async function handleError(ctx, error) {
|
|
877
968
|
const { logger } = ctx;
|
|
878
969
|
logger.debug(error);
|
|
@@ -917,7 +1008,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
917
1008
|
throw e;
|
|
918
1009
|
}
|
|
919
1010
|
}
|
|
920
|
-
const action$
|
|
1011
|
+
const action$6 = async (ctx) => {
|
|
921
1012
|
const { logger } = ctx;
|
|
922
1013
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
923
1014
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -926,11 +1017,16 @@ const action$4 = async (ctx) => {
|
|
|
926
1017
|
}
|
|
927
1018
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
928
1019
|
const { data: config } = await cloudApi.config();
|
|
929
|
-
const
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
);
|
|
1020
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
1021
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
1022
|
+
name: projectName,
|
|
1023
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
1024
|
+
});
|
|
1025
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
1026
|
+
const defaultValues = {
|
|
1027
|
+
...config.projectCreation.defaults,
|
|
1028
|
+
...getDefaultsFromQuestions(questions)
|
|
1029
|
+
};
|
|
934
1030
|
const projectAnswersDefaulted = fp.defaults(defaultValues);
|
|
935
1031
|
const projectAnswers = await inquirer__default.default.prompt(questions);
|
|
936
1032
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -1041,6 +1137,32 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1041
1137
|
});
|
|
1042
1138
|
};
|
|
1043
1139
|
};
|
|
1140
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1141
|
+
async function promptForEnvironment(environments) {
|
|
1142
|
+
const choices = environments.map((env) => ({ name: env, value: env }));
|
|
1143
|
+
const { selectedEnvironment } = await inquirer__default.default.prompt([
|
|
1144
|
+
{
|
|
1145
|
+
type: "list",
|
|
1146
|
+
name: "selectedEnvironment",
|
|
1147
|
+
message: "Select the environment to deploy:",
|
|
1148
|
+
choices: [...choices, { name: chalk__default.default.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1149
|
+
}
|
|
1150
|
+
]);
|
|
1151
|
+
if (selectedEnvironment === null) {
|
|
1152
|
+
process.exit(1);
|
|
1153
|
+
}
|
|
1154
|
+
const { confirm } = await inquirer__default.default.prompt([
|
|
1155
|
+
{
|
|
1156
|
+
type: "confirm",
|
|
1157
|
+
name: "confirm",
|
|
1158
|
+
message: `Do you want to proceed with deployment to ${chalk__default.default.cyan(selectedEnvironment)}?`
|
|
1159
|
+
}
|
|
1160
|
+
]);
|
|
1161
|
+
if (!confirm) {
|
|
1162
|
+
process.exit(1);
|
|
1163
|
+
}
|
|
1164
|
+
return selectedEnvironment;
|
|
1165
|
+
}
|
|
1044
1166
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1045
1167
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1046
1168
|
try {
|
|
@@ -1107,17 +1229,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1107
1229
|
return data.build_id;
|
|
1108
1230
|
} catch (e) {
|
|
1109
1231
|
progressBar.stop();
|
|
1110
|
-
|
|
1111
|
-
if (e.response.status === 404) {
|
|
1112
|
-
ctx.logger.error(
|
|
1113
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
1114
|
-
);
|
|
1115
|
-
} else {
|
|
1116
|
-
ctx.logger.error(e.response.data);
|
|
1117
|
-
}
|
|
1118
|
-
} else {
|
|
1119
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1120
|
-
}
|
|
1232
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1121
1233
|
ctx.logger.debug(e);
|
|
1122
1234
|
} finally {
|
|
1123
1235
|
await fse__namespace.default.remove(tarFilePath);
|
|
@@ -1133,7 +1245,7 @@ async function getProject(ctx) {
|
|
|
1133
1245
|
const { project } = await retrieve();
|
|
1134
1246
|
if (!project) {
|
|
1135
1247
|
try {
|
|
1136
|
-
return await action$
|
|
1248
|
+
return await action$6(ctx);
|
|
1137
1249
|
} catch (e) {
|
|
1138
1250
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1139
1251
|
ctx.logger.debug(e);
|
|
@@ -1154,7 +1266,26 @@ async function getConfig({
|
|
|
1154
1266
|
return null;
|
|
1155
1267
|
}
|
|
1156
1268
|
}
|
|
1157
|
-
|
|
1269
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1270
|
+
if (!environments.includes(environment)) {
|
|
1271
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1272
|
+
process.exit(1);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1276
|
+
if (opts.env) {
|
|
1277
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1278
|
+
return opts.env;
|
|
1279
|
+
}
|
|
1280
|
+
if (project.targetEnvironment) {
|
|
1281
|
+
return project.targetEnvironment;
|
|
1282
|
+
}
|
|
1283
|
+
if (environments.length > 1) {
|
|
1284
|
+
return promptForEnvironment(environments);
|
|
1285
|
+
}
|
|
1286
|
+
return environments[0];
|
|
1287
|
+
}
|
|
1288
|
+
const action$5 = async (ctx, opts) => {
|
|
1158
1289
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1159
1290
|
const token = await getValidToken(ctx, promptLogin);
|
|
1160
1291
|
if (!token) {
|
|
@@ -1164,7 +1295,41 @@ const action$3 = async (ctx) => {
|
|
|
1164
1295
|
if (!project) {
|
|
1165
1296
|
return;
|
|
1166
1297
|
}
|
|
1167
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1298
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1299
|
+
let environments;
|
|
1300
|
+
try {
|
|
1301
|
+
const {
|
|
1302
|
+
data: { data: projectData, metadata }
|
|
1303
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1304
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1305
|
+
environments = projectData.environments;
|
|
1306
|
+
if (isProjectSuspended) {
|
|
1307
|
+
ctx.logger.log(
|
|
1308
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1309
|
+
);
|
|
1310
|
+
ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
if (e instanceof axios.AxiosError && e.response?.data) {
|
|
1315
|
+
if (e.response.status === 404) {
|
|
1316
|
+
ctx.logger.warn(
|
|
1317
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1318
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1319
|
+
"link"
|
|
1320
|
+
)} command before deploying.`
|
|
1321
|
+
);
|
|
1322
|
+
} else {
|
|
1323
|
+
ctx.logger.error(e.response.data);
|
|
1324
|
+
}
|
|
1325
|
+
} else {
|
|
1326
|
+
ctx.logger.error(
|
|
1327
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
ctx.logger.debug(e);
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1168
1333
|
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1169
1334
|
projectInternalName: project.name
|
|
1170
1335
|
});
|
|
@@ -1173,7 +1338,7 @@ const action$3 = async (ctx) => {
|
|
|
1173
1338
|
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1174
1339
|
if (!cliConfig2) {
|
|
1175
1340
|
ctx.logger.error(
|
|
1176
|
-
"An error occurred while retrieving data from Strapi Cloud. Please
|
|
1341
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1177
1342
|
);
|
|
1178
1343
|
return;
|
|
1179
1344
|
}
|
|
@@ -1184,11 +1349,15 @@ const action$3 = async (ctx) => {
|
|
|
1184
1349
|
);
|
|
1185
1350
|
maxSize = 1e8;
|
|
1186
1351
|
}
|
|
1352
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1187
1353
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1188
1354
|
if (!buildId) {
|
|
1189
1355
|
return;
|
|
1190
1356
|
}
|
|
1191
1357
|
try {
|
|
1358
|
+
ctx.logger.log(
|
|
1359
|
+
`🚀 Deploying project to ${chalk__default.default.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1360
|
+
);
|
|
1192
1361
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1193
1362
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1194
1363
|
ctx.logger.log(
|
|
@@ -1233,17 +1402,16 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1233
1402
|
process.exit(1);
|
|
1234
1403
|
});
|
|
1235
1404
|
};
|
|
1236
|
-
const command$
|
|
1237
|
-
|
|
1405
|
+
const command$7 = ({ ctx }) => {
|
|
1406
|
+
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, --env <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$5)(ctx, opts));
|
|
1238
1407
|
};
|
|
1239
1408
|
const deployProject = {
|
|
1240
1409
|
name: "deploy-project",
|
|
1241
1410
|
description: "Deploy a Strapi Cloud project",
|
|
1242
|
-
action: action$
|
|
1243
|
-
command: command$
|
|
1411
|
+
action: action$5,
|
|
1412
|
+
command: command$7
|
|
1244
1413
|
};
|
|
1245
|
-
|
|
1246
|
-
async function getExistingConfig(ctx) {
|
|
1414
|
+
async function getLocalConfig(ctx) {
|
|
1247
1415
|
try {
|
|
1248
1416
|
return await retrieve();
|
|
1249
1417
|
} catch (e) {
|
|
@@ -1252,6 +1420,21 @@ async function getExistingConfig(ctx) {
|
|
|
1252
1420
|
return null;
|
|
1253
1421
|
}
|
|
1254
1422
|
}
|
|
1423
|
+
async function getLocalProject(ctx) {
|
|
1424
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1425
|
+
if (!localConfig || !localConfig.project) {
|
|
1426
|
+
ctx.logger.warn(
|
|
1427
|
+
`
|
|
1428
|
+
We couldn't find a valid local project config.
|
|
1429
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1430
|
+
"link"
|
|
1431
|
+
)} command.`
|
|
1432
|
+
);
|
|
1433
|
+
process.exit(1);
|
|
1434
|
+
}
|
|
1435
|
+
return localConfig.project;
|
|
1436
|
+
}
|
|
1437
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1255
1438
|
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1256
1439
|
if (existingConfig && existingConfig.project) {
|
|
1257
1440
|
const { shouldRelink } = await inquirer__default.default.prompt([
|
|
@@ -1281,7 +1464,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1281
1464
|
} = await cloudApiService.listLinkProjects();
|
|
1282
1465
|
spinner.succeed();
|
|
1283
1466
|
if (!Array.isArray(projectList)) {
|
|
1284
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1467
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1285
1468
|
return null;
|
|
1286
1469
|
}
|
|
1287
1470
|
const projects = projectList.filter(
|
|
@@ -1293,7 +1476,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1293
1476
|
};
|
|
1294
1477
|
});
|
|
1295
1478
|
if (projects.length === 0) {
|
|
1296
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1479
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1297
1480
|
return null;
|
|
1298
1481
|
}
|
|
1299
1482
|
return projects;
|
|
@@ -1311,7 +1494,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1311
1494
|
type: "list",
|
|
1312
1495
|
name: "linkProject",
|
|
1313
1496
|
message: "Which project do you want to link?",
|
|
1314
|
-
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1497
|
+
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1315
1498
|
}
|
|
1316
1499
|
]);
|
|
1317
1500
|
if (!answer.linkProject) {
|
|
@@ -1324,7 +1507,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1324
1507
|
return null;
|
|
1325
1508
|
}
|
|
1326
1509
|
}
|
|
1327
|
-
const action$
|
|
1510
|
+
const action$4 = async (ctx) => {
|
|
1328
1511
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1329
1512
|
const token = await getValidToken(ctx, promptLogin);
|
|
1330
1513
|
const { logger } = ctx;
|
|
@@ -1332,7 +1515,7 @@ const action$2 = async (ctx) => {
|
|
|
1332
1515
|
return;
|
|
1333
1516
|
}
|
|
1334
1517
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1335
|
-
const existingConfig = await
|
|
1518
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1336
1519
|
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1337
1520
|
if (!shouldRelink) {
|
|
1338
1521
|
return;
|
|
@@ -1367,7 +1550,9 @@ const action$2 = async (ctx) => {
|
|
|
1367
1550
|
return;
|
|
1368
1551
|
}
|
|
1369
1552
|
await save({ project: answer.linkProject });
|
|
1370
|
-
logger.log(
|
|
1553
|
+
logger.log(
|
|
1554
|
+
` You have successfully linked your project to ${chalk__default.default.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1555
|
+
);
|
|
1371
1556
|
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1372
1557
|
projectInternalName: answer.linkProject
|
|
1373
1558
|
});
|
|
@@ -1379,17 +1564,17 @@ const action$2 = async (ctx) => {
|
|
|
1379
1564
|
});
|
|
1380
1565
|
}
|
|
1381
1566
|
};
|
|
1382
|
-
const command$
|
|
1383
|
-
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$
|
|
1567
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1568
|
+
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));
|
|
1384
1569
|
};
|
|
1385
1570
|
const link = {
|
|
1386
1571
|
name: "link-project",
|
|
1387
1572
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1388
|
-
action: action$
|
|
1389
|
-
command: command$
|
|
1573
|
+
action: action$4,
|
|
1574
|
+
command: command$6
|
|
1390
1575
|
};
|
|
1391
|
-
const command$
|
|
1392
|
-
|
|
1576
|
+
const command$5 = ({ ctx }) => {
|
|
1577
|
+
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1393
1578
|
"after",
|
|
1394
1579
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1395
1580
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1398,10 +1583,10 @@ const login = {
|
|
|
1398
1583
|
name: "login",
|
|
1399
1584
|
description: "Strapi Cloud Login",
|
|
1400
1585
|
action: loginAction,
|
|
1401
|
-
command: command$
|
|
1586
|
+
command: command$5
|
|
1402
1587
|
};
|
|
1403
1588
|
const openModule = import("open");
|
|
1404
|
-
const action$
|
|
1589
|
+
const action$3 = async (ctx) => {
|
|
1405
1590
|
const { logger } = ctx;
|
|
1406
1591
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1407
1592
|
const token = await retrieveToken();
|
|
@@ -1433,25 +1618,25 @@ const action$1 = async (ctx) => {
|
|
|
1433
1618
|
}
|
|
1434
1619
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1435
1620
|
};
|
|
1436
|
-
const command$
|
|
1437
|
-
|
|
1621
|
+
const command$4 = ({ ctx }) => {
|
|
1622
|
+
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$3)(ctx));
|
|
1438
1623
|
};
|
|
1439
1624
|
const logout = {
|
|
1440
1625
|
name: "logout",
|
|
1441
1626
|
description: "Strapi Cloud Logout",
|
|
1442
|
-
action: action$
|
|
1443
|
-
command: command$
|
|
1627
|
+
action: action$3,
|
|
1628
|
+
command: command$4
|
|
1444
1629
|
};
|
|
1445
|
-
const command$
|
|
1446
|
-
|
|
1630
|
+
const command$3 = ({ ctx }) => {
|
|
1631
|
+
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$6)(ctx));
|
|
1447
1632
|
};
|
|
1448
1633
|
const createProject = {
|
|
1449
1634
|
name: "create-project",
|
|
1450
1635
|
description: "Create a new project",
|
|
1451
|
-
action: action$
|
|
1452
|
-
command: command$
|
|
1636
|
+
action: action$6,
|
|
1637
|
+
command: command$3
|
|
1453
1638
|
};
|
|
1454
|
-
const action = async (ctx) => {
|
|
1639
|
+
const action$2 = async (ctx) => {
|
|
1455
1640
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1456
1641
|
const token = await getValidToken(ctx, promptLogin);
|
|
1457
1642
|
const { logger } = ctx;
|
|
@@ -1471,12 +1656,194 @@ const action = async (ctx) => {
|
|
|
1471
1656
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1472
1657
|
}
|
|
1473
1658
|
};
|
|
1474
|
-
const command = ({ command: command2, ctx }) => {
|
|
1475
|
-
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));
|
|
1659
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1660
|
+
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));
|
|
1476
1661
|
};
|
|
1477
1662
|
const listProjects = {
|
|
1478
1663
|
name: "list-projects",
|
|
1479
1664
|
description: "List Strapi Cloud projects",
|
|
1665
|
+
action: action$2,
|
|
1666
|
+
command: command$2
|
|
1667
|
+
};
|
|
1668
|
+
const action$1 = async (ctx) => {
|
|
1669
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1670
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1671
|
+
const { logger } = ctx;
|
|
1672
|
+
if (!token) {
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
const project = await getLocalProject(ctx);
|
|
1676
|
+
if (!project) {
|
|
1677
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1681
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1682
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1683
|
+
projectInternalName: project.name
|
|
1684
|
+
});
|
|
1685
|
+
try {
|
|
1686
|
+
const {
|
|
1687
|
+
data: { data: environmentsList }
|
|
1688
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1689
|
+
spinner.succeed();
|
|
1690
|
+
logger.log(environmentsList);
|
|
1691
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1692
|
+
projectInternalName: project.name
|
|
1693
|
+
});
|
|
1694
|
+
} catch (e) {
|
|
1695
|
+
if (e.response && e.response.status === 404) {
|
|
1696
|
+
spinner.succeed();
|
|
1697
|
+
logger.warn(
|
|
1698
|
+
`
|
|
1699
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1700
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1701
|
+
"link"
|
|
1702
|
+
)} command`
|
|
1703
|
+
);
|
|
1704
|
+
} else {
|
|
1705
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1706
|
+
logger.debug("Failed to list environments", e);
|
|
1707
|
+
}
|
|
1708
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1709
|
+
projectInternalName: project.name
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1714
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1715
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1716
|
+
return cloud;
|
|
1717
|
+
}
|
|
1718
|
+
let environmentCmd = null;
|
|
1719
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1720
|
+
if (!environmentCmd) {
|
|
1721
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1722
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1723
|
+
}
|
|
1724
|
+
return environmentCmd;
|
|
1725
|
+
};
|
|
1726
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1727
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1728
|
+
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));
|
|
1729
|
+
};
|
|
1730
|
+
const listEnvironments = {
|
|
1731
|
+
name: "list-environments",
|
|
1732
|
+
description: "List Strapi Cloud environments",
|
|
1733
|
+
action: action$1,
|
|
1734
|
+
command: command$1
|
|
1735
|
+
};
|
|
1736
|
+
const QUIT_OPTION = "Quit";
|
|
1737
|
+
const action = async (ctx) => {
|
|
1738
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1739
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1740
|
+
const { logger } = ctx;
|
|
1741
|
+
if (!token) {
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1744
|
+
const project = await getLocalProject(ctx);
|
|
1745
|
+
if (!project) {
|
|
1746
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1749
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1750
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1751
|
+
if (!environments) {
|
|
1752
|
+
logger.debug(`Fetching environments failed.`);
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1755
|
+
if (environments.length === 0) {
|
|
1756
|
+
logger.log(
|
|
1757
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1758
|
+
);
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1762
|
+
if (!answer) {
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1766
|
+
projectName: project.name,
|
|
1767
|
+
environmentName: answer.targetEnvironment
|
|
1768
|
+
});
|
|
1769
|
+
try {
|
|
1770
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1771
|
+
} catch (e) {
|
|
1772
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1773
|
+
projectName: project.name,
|
|
1774
|
+
environmentName: answer.targetEnvironment
|
|
1775
|
+
});
|
|
1776
|
+
logger.debug("Failed to link environment", e);
|
|
1777
|
+
logger.error(
|
|
1778
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1779
|
+
);
|
|
1780
|
+
process.exit(1);
|
|
1781
|
+
}
|
|
1782
|
+
logger.log(
|
|
1783
|
+
` You have successfully linked your project to ${chalk__default.default.cyan(answer.targetEnvironment)}, on ${chalk__default.default.cyan(project.displayName)}. You are now able to deploy your project.`
|
|
1784
|
+
);
|
|
1785
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1786
|
+
projectName: project.name,
|
|
1787
|
+
environmentName: answer.targetEnvironment
|
|
1788
|
+
});
|
|
1789
|
+
};
|
|
1790
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1791
|
+
const { logger } = ctx;
|
|
1792
|
+
try {
|
|
1793
|
+
const answer = await inquirer__default.default.prompt([
|
|
1794
|
+
{
|
|
1795
|
+
type: "list",
|
|
1796
|
+
name: "targetEnvironment",
|
|
1797
|
+
message: "Which environment do you want to link?",
|
|
1798
|
+
choices: [...environments, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1799
|
+
}
|
|
1800
|
+
]);
|
|
1801
|
+
if (!answer.targetEnvironment) {
|
|
1802
|
+
return null;
|
|
1803
|
+
}
|
|
1804
|
+
return answer;
|
|
1805
|
+
} catch (e) {
|
|
1806
|
+
logger.debug("Failed to get user input", e);
|
|
1807
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1808
|
+
return null;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1812
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1813
|
+
try {
|
|
1814
|
+
const {
|
|
1815
|
+
data: { data: environmentsList }
|
|
1816
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1817
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1818
|
+
throw new Error("Environments not found in server response");
|
|
1819
|
+
}
|
|
1820
|
+
spinner.succeed();
|
|
1821
|
+
return environmentsList.filter(
|
|
1822
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1823
|
+
);
|
|
1824
|
+
} catch (e) {
|
|
1825
|
+
if (e.response && e.response.status === 404) {
|
|
1826
|
+
spinner.succeed();
|
|
1827
|
+
ctx.logger.warn(
|
|
1828
|
+
`
|
|
1829
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1830
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1831
|
+
"link"
|
|
1832
|
+
)} command.`
|
|
1833
|
+
);
|
|
1834
|
+
} else {
|
|
1835
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1836
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
const command = ({ command: command2, ctx }) => {
|
|
1841
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1842
|
+
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));
|
|
1843
|
+
};
|
|
1844
|
+
const linkEnvironment = {
|
|
1845
|
+
name: "link-environment",
|
|
1846
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1480
1847
|
action,
|
|
1481
1848
|
command
|
|
1482
1849
|
};
|
|
@@ -1486,11 +1853,21 @@ const cli = {
|
|
|
1486
1853
|
login,
|
|
1487
1854
|
logout,
|
|
1488
1855
|
createProject,
|
|
1489
|
-
|
|
1856
|
+
linkEnvironment,
|
|
1857
|
+
listProjects,
|
|
1858
|
+
listEnvironments
|
|
1490
1859
|
};
|
|
1491
|
-
const cloudCommands = [
|
|
1860
|
+
const cloudCommands = [
|
|
1861
|
+
deployProject,
|
|
1862
|
+
link,
|
|
1863
|
+
login,
|
|
1864
|
+
logout,
|
|
1865
|
+
linkEnvironment,
|
|
1866
|
+
listProjects,
|
|
1867
|
+
listEnvironments
|
|
1868
|
+
];
|
|
1492
1869
|
async function initCloudCLIConfig() {
|
|
1493
|
-
const localConfig = await getLocalConfig();
|
|
1870
|
+
const localConfig = await getLocalConfig$1();
|
|
1494
1871
|
if (!localConfig.deviceId) {
|
|
1495
1872
|
localConfig.deviceId = crypto__default.default.randomUUID();
|
|
1496
1873
|
}
|
|
@@ -1504,7 +1881,10 @@ async function buildStrapiCloudCommands({
|
|
|
1504
1881
|
await initCloudCLIConfig();
|
|
1505
1882
|
for (const cloudCommand of cloudCommands) {
|
|
1506
1883
|
try {
|
|
1507
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1884
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1885
|
+
if (subCommand) {
|
|
1886
|
+
command2.addCommand(subCommand);
|
|
1887
|
+
}
|
|
1508
1888
|
} catch (e) {
|
|
1509
1889
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1510
1890
|
}
|