@strapi/cloud-cli 0.0.0-next.7466630056657c483fb286557dda890490597807 → 0.0.0-next.76a9dc5ca66301db734af3bc2111406c17ccb860
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 +2 -2
- package/dist/bin.js.map +1 -1
- package/dist/index.js +519 -114
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +516 -110
- 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 +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/services/token.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/helpers.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 +11 -11
- 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.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";
|
|
@@ -20,8 +22,8 @@ import ora from "ora";
|
|
|
20
22
|
import * as cliProgress from "cli-progress";
|
|
21
23
|
import pkgUp from "pkg-up";
|
|
22
24
|
import * as yup from "yup";
|
|
23
|
-
import _ from "lodash";
|
|
24
25
|
import EventSource from "eventsource";
|
|
26
|
+
import { createCommand } from "commander";
|
|
25
27
|
const apiConfig = {
|
|
26
28
|
apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
27
29
|
dashboardBaseUrl: env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -78,8 +80,7 @@ const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
|
78
80
|
const readGitignore = async (folderPath) => {
|
|
79
81
|
const gitignorePath = path.resolve(folderPath, ".gitignore");
|
|
80
82
|
const pathExist = await fse.pathExists(gitignorePath);
|
|
81
|
-
if (!pathExist)
|
|
82
|
-
return [];
|
|
83
|
+
if (!pathExist) return [];
|
|
83
84
|
const gitignoreContent = await fse.readFile(gitignorePath, "utf8");
|
|
84
85
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
85
86
|
};
|
|
@@ -118,7 +119,7 @@ async function getConfigPath() {
|
|
|
118
119
|
}
|
|
119
120
|
return configPath;
|
|
120
121
|
}
|
|
121
|
-
async function getLocalConfig() {
|
|
122
|
+
async function getLocalConfig$1() {
|
|
122
123
|
const configPath = await getConfigPath();
|
|
123
124
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
124
125
|
await fse__default.ensureFile(configFilePath);
|
|
@@ -134,7 +135,7 @@ async function saveLocalConfig(data) {
|
|
|
134
135
|
await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
135
136
|
}
|
|
136
137
|
const name = "@strapi/cloud-cli";
|
|
137
|
-
const version = "
|
|
138
|
+
const version = "5.8.0";
|
|
138
139
|
const description = "Commands to interact with the Strapi Cloud";
|
|
139
140
|
const keywords = [
|
|
140
141
|
"strapi",
|
|
@@ -179,14 +180,15 @@ const scripts = {
|
|
|
179
180
|
watch: "pack-up watch"
|
|
180
181
|
};
|
|
181
182
|
const dependencies = {
|
|
182
|
-
"@strapi/utils": "
|
|
183
|
-
axios: "1.
|
|
183
|
+
"@strapi/utils": "5.8.0",
|
|
184
|
+
axios: "1.7.4",
|
|
185
|
+
boxen: "5.1.2",
|
|
184
186
|
chalk: "4.1.2",
|
|
185
187
|
"cli-progress": "3.12.0",
|
|
186
188
|
commander: "8.3.0",
|
|
187
189
|
eventsource: "2.0.2",
|
|
188
190
|
"fast-safe-stringify": "2.1.1",
|
|
189
|
-
"fs-extra": "
|
|
191
|
+
"fs-extra": "11.2.0",
|
|
190
192
|
inquirer: "8.2.5",
|
|
191
193
|
jsonwebtoken: "9.0.0",
|
|
192
194
|
"jwks-rsa": "3.1.0",
|
|
@@ -195,20 +197,20 @@ const dependencies = {
|
|
|
195
197
|
open: "8.4.0",
|
|
196
198
|
ora: "5.4.1",
|
|
197
199
|
"pkg-up": "3.1.0",
|
|
198
|
-
tar: "6.1
|
|
200
|
+
tar: "6.2.1",
|
|
199
201
|
"xdg-app-paths": "8.3.0",
|
|
200
202
|
yup: "0.32.9"
|
|
201
203
|
};
|
|
202
204
|
const devDependencies = {
|
|
203
|
-
"@strapi/pack-up": "
|
|
205
|
+
"@strapi/pack-up": "5.0.2",
|
|
204
206
|
"@types/cli-progress": "3.11.5",
|
|
205
207
|
"@types/eventsource": "1.1.15",
|
|
206
208
|
"@types/lodash": "^4.14.191",
|
|
207
|
-
"eslint-config-custom": "
|
|
208
|
-
tsconfig: "
|
|
209
|
+
"eslint-config-custom": "5.8.0",
|
|
210
|
+
tsconfig: "5.8.0"
|
|
209
211
|
};
|
|
210
212
|
const engines = {
|
|
211
|
-
node: ">=18.0.0 <=
|
|
213
|
+
node: ">=18.0.0 <=22.x.x",
|
|
212
214
|
npm: ">=6.0.0"
|
|
213
215
|
};
|
|
214
216
|
const packageJson = {
|
|
@@ -235,7 +237,7 @@ const packageJson = {
|
|
|
235
237
|
};
|
|
236
238
|
const VERSION = "v1";
|
|
237
239
|
async function cloudApiFactory({ logger }, token) {
|
|
238
|
-
const localConfig = await getLocalConfig();
|
|
240
|
+
const localConfig = await getLocalConfig$1();
|
|
239
241
|
const customHeaders = {
|
|
240
242
|
"x-device-id": localConfig.deviceId,
|
|
241
243
|
"x-app-version": packageJson.version,
|
|
@@ -258,7 +260,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
258
260
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
259
261
|
return axiosCloudAPI.post(
|
|
260
262
|
`/deploy/${project.name}`,
|
|
261
|
-
{ file: fse__default.createReadStream(filePath) },
|
|
263
|
+
{ file: fse__default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
262
264
|
{
|
|
263
265
|
headers: {
|
|
264
266
|
"Content-Type": "multipart/form-data"
|
|
@@ -317,7 +319,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
317
319
|
},
|
|
318
320
|
async listLinkProjects() {
|
|
319
321
|
try {
|
|
320
|
-
const response = await axiosCloudAPI.get("/projects
|
|
322
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
321
323
|
if (response.status !== 200) {
|
|
322
324
|
throw new Error("Error fetching cloud projects from the server.");
|
|
323
325
|
}
|
|
@@ -329,6 +331,48 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
329
331
|
throw error;
|
|
330
332
|
}
|
|
331
333
|
},
|
|
334
|
+
async listEnvironments({ name: name2 }) {
|
|
335
|
+
try {
|
|
336
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
337
|
+
if (response.status !== 200) {
|
|
338
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
339
|
+
}
|
|
340
|
+
return response;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
logger.debug(
|
|
343
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
344
|
+
);
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
349
|
+
try {
|
|
350
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
351
|
+
if (response.status !== 200) {
|
|
352
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
353
|
+
}
|
|
354
|
+
return response;
|
|
355
|
+
} catch (error) {
|
|
356
|
+
logger.debug(
|
|
357
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
358
|
+
);
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
async getProject({ name: name2 }) {
|
|
363
|
+
try {
|
|
364
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
365
|
+
if (response.status !== 200) {
|
|
366
|
+
throw new Error("Error fetching project's details.");
|
|
367
|
+
}
|
|
368
|
+
return response;
|
|
369
|
+
} catch (error) {
|
|
370
|
+
logger.debug(
|
|
371
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
372
|
+
);
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
332
376
|
track(event, payload = {}) {
|
|
333
377
|
return axiosCloudAPI.post("/track", {
|
|
334
378
|
event,
|
|
@@ -338,26 +382,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
338
382
|
};
|
|
339
383
|
}
|
|
340
384
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
385
|
+
const getFilePath = (directoryPath) => path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
341
386
|
async function save(data, { directoryPath } = {}) {
|
|
342
|
-
const
|
|
343
|
-
const storedData = { ...alreadyInFileData, ...data };
|
|
344
|
-
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
387
|
+
const pathToFile = getFilePath(directoryPath);
|
|
345
388
|
await fse__default.ensureDir(path__default.dirname(pathToFile));
|
|
346
|
-
await fse__default.writeJson(pathToFile,
|
|
389
|
+
await fse__default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
347
390
|
}
|
|
348
391
|
async function retrieve({
|
|
349
392
|
directoryPath
|
|
350
393
|
} = {}) {
|
|
351
|
-
const pathToFile =
|
|
394
|
+
const pathToFile = getFilePath(directoryPath);
|
|
352
395
|
const pathExists = await fse__default.pathExists(pathToFile);
|
|
353
396
|
if (!pathExists) {
|
|
354
397
|
return {};
|
|
355
398
|
}
|
|
356
399
|
return fse__default.readJSON(pathToFile, { encoding: "utf8" });
|
|
357
400
|
}
|
|
401
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
402
|
+
const pathToFile = getFilePath(directoryPath);
|
|
403
|
+
const existingData = await retrieve({ directoryPath });
|
|
404
|
+
if (!existingData) {
|
|
405
|
+
throw new Error("No configuration data found to patch.");
|
|
406
|
+
}
|
|
407
|
+
const newData = merge(existingData, patchData);
|
|
408
|
+
await fse__default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
409
|
+
}
|
|
410
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
411
|
+
const pathToFile = getFilePath(directoryPath);
|
|
412
|
+
const pathExists = await fse__default.pathExists(pathToFile);
|
|
413
|
+
if (pathExists) {
|
|
414
|
+
await fse__default.remove(pathToFile);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
358
417
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
359
418
|
__proto__: null,
|
|
360
419
|
LOCAL_SAVE_FILENAME,
|
|
420
|
+
deleteConfig,
|
|
421
|
+
patch,
|
|
361
422
|
retrieve,
|
|
362
423
|
save
|
|
363
424
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -365,7 +426,7 @@ let cliConfig;
|
|
|
365
426
|
async function tokenServiceFactory({ logger }) {
|
|
366
427
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
367
428
|
async function saveToken(str) {
|
|
368
|
-
const appConfig = await getLocalConfig();
|
|
429
|
+
const appConfig = await getLocalConfig$1();
|
|
369
430
|
if (!appConfig) {
|
|
370
431
|
logger.error("There was a problem saving your token. Please try again.");
|
|
371
432
|
return;
|
|
@@ -379,7 +440,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
379
440
|
}
|
|
380
441
|
}
|
|
381
442
|
async function retrieveToken() {
|
|
382
|
-
const appConfig = await getLocalConfig();
|
|
443
|
+
const appConfig = await getLocalConfig$1();
|
|
383
444
|
if (appConfig.token) {
|
|
384
445
|
if (await isTokenValid(appConfig.token)) {
|
|
385
446
|
return appConfig.token;
|
|
@@ -441,7 +502,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
441
502
|
}
|
|
442
503
|
}
|
|
443
504
|
async function eraseToken() {
|
|
444
|
-
const appConfig = await getLocalConfig();
|
|
505
|
+
const appConfig = await getLocalConfig$1();
|
|
445
506
|
if (!appConfig) {
|
|
446
507
|
return;
|
|
447
508
|
}
|
|
@@ -462,8 +523,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
462
523
|
logger.log(
|
|
463
524
|
token ? "Oops! Your token seems expired or invalid. Please login again." : "We couldn't find a valid token. You need to be logged in to use this feature."
|
|
464
525
|
);
|
|
465
|
-
if (!await loginAction2(ctx))
|
|
466
|
-
return null;
|
|
526
|
+
if (!await loginAction2(ctx)) return null;
|
|
467
527
|
token = await retrieveToken();
|
|
468
528
|
}
|
|
469
529
|
return token;
|
|
@@ -602,21 +662,24 @@ yup.object({
|
|
|
602
662
|
name: yup.string().required(),
|
|
603
663
|
exports: yup.lazy(
|
|
604
664
|
(value) => yup.object(
|
|
605
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
665
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
666
|
+
(acc, [key, value2]) => {
|
|
667
|
+
if (typeof value2 === "object") {
|
|
668
|
+
acc[key] = yup.object({
|
|
669
|
+
types: yup.string().optional(),
|
|
670
|
+
source: yup.string().required(),
|
|
671
|
+
module: yup.string().optional(),
|
|
672
|
+
import: yup.string().required(),
|
|
673
|
+
require: yup.string().required(),
|
|
674
|
+
default: yup.string().required()
|
|
675
|
+
}).noUnknown(true);
|
|
676
|
+
} else {
|
|
677
|
+
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
678
|
+
}
|
|
679
|
+
return acc;
|
|
680
|
+
},
|
|
681
|
+
{}
|
|
682
|
+
) : void 0
|
|
620
683
|
).optional()
|
|
621
684
|
)
|
|
622
685
|
});
|
|
@@ -638,18 +701,6 @@ async function getProjectNameFromPackageJson(ctx) {
|
|
|
638
701
|
return "my-strapi-project";
|
|
639
702
|
}
|
|
640
703
|
}
|
|
641
|
-
function applyDefaultName(newDefaultName, questions, defaultValues) {
|
|
642
|
-
const newDefaultValues = _.cloneDeep(defaultValues);
|
|
643
|
-
newDefaultValues.name = newDefaultName;
|
|
644
|
-
const newQuestions = questions.map((question) => {
|
|
645
|
-
const questionCopy = _.cloneDeep(question);
|
|
646
|
-
if (questionCopy.name === "name") {
|
|
647
|
-
questionCopy.default = newDefaultName;
|
|
648
|
-
}
|
|
649
|
-
return questionCopy;
|
|
650
|
-
});
|
|
651
|
-
return { newQuestions, newDefaultValues };
|
|
652
|
-
}
|
|
653
704
|
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
654
705
|
try {
|
|
655
706
|
await cloudApiService.track(eventName, eventData);
|
|
@@ -813,6 +864,45 @@ async function loginAction(ctx) {
|
|
|
813
864
|
await authenticate();
|
|
814
865
|
return isAuthenticated;
|
|
815
866
|
}
|
|
867
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
868
|
+
return (questions) => {
|
|
869
|
+
return questions.map((question) => {
|
|
870
|
+
const questionName = question.name;
|
|
871
|
+
if (questionName in questionsMap) {
|
|
872
|
+
const questionDefault = questionsMap[questionName];
|
|
873
|
+
if (typeof questionDefault === "function") {
|
|
874
|
+
return {
|
|
875
|
+
...question,
|
|
876
|
+
default: questionDefault(question)
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
return {
|
|
880
|
+
...question,
|
|
881
|
+
default: questionDefault
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
return question;
|
|
885
|
+
});
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
function getDefaultsFromQuestions(questions) {
|
|
889
|
+
return questions.reduce((acc, question) => {
|
|
890
|
+
if (question.default && question.name) {
|
|
891
|
+
return { ...acc, [question.name]: question.default };
|
|
892
|
+
}
|
|
893
|
+
return acc;
|
|
894
|
+
}, {});
|
|
895
|
+
}
|
|
896
|
+
function getProjectNodeVersionDefault(question) {
|
|
897
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
898
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
899
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
900
|
+
if (choice) {
|
|
901
|
+
return choice.value;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
return question.default;
|
|
905
|
+
}
|
|
816
906
|
async function handleError(ctx, error) {
|
|
817
907
|
const { logger } = ctx;
|
|
818
908
|
logger.debug(error);
|
|
@@ -857,7 +947,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
857
947
|
throw e;
|
|
858
948
|
}
|
|
859
949
|
}
|
|
860
|
-
const action$
|
|
950
|
+
const action$6 = async (ctx) => {
|
|
861
951
|
const { logger } = ctx;
|
|
862
952
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
863
953
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -866,11 +956,16 @@ const action$4 = async (ctx) => {
|
|
|
866
956
|
}
|
|
867
957
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
868
958
|
const { data: config } = await cloudApi.config();
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
);
|
|
959
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
960
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
961
|
+
name: projectName,
|
|
962
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
963
|
+
});
|
|
964
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
965
|
+
const defaultValues = {
|
|
966
|
+
...config.projectCreation.defaults,
|
|
967
|
+
...getDefaultsFromQuestions(questions)
|
|
968
|
+
};
|
|
874
969
|
const projectAnswersDefaulted = defaults(defaultValues);
|
|
875
970
|
const projectAnswers = await inquirer.prompt(questions);
|
|
876
971
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -981,6 +1076,29 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
981
1076
|
});
|
|
982
1077
|
};
|
|
983
1078
|
};
|
|
1079
|
+
const boxenOptions = {
|
|
1080
|
+
padding: 1,
|
|
1081
|
+
margin: 1,
|
|
1082
|
+
align: "center",
|
|
1083
|
+
borderColor: "yellow",
|
|
1084
|
+
borderStyle: "round"
|
|
1085
|
+
};
|
|
1086
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1087
|
+
async function promptForEnvironment(environments) {
|
|
1088
|
+
const choices = environments.map((env2) => ({ name: env2, value: env2 }));
|
|
1089
|
+
const { selectedEnvironment } = await inquirer.prompt([
|
|
1090
|
+
{
|
|
1091
|
+
type: "list",
|
|
1092
|
+
name: "selectedEnvironment",
|
|
1093
|
+
message: "Select the environment to deploy:",
|
|
1094
|
+
choices: [...choices, { name: chalk.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1095
|
+
}
|
|
1096
|
+
]);
|
|
1097
|
+
if (selectedEnvironment === null) {
|
|
1098
|
+
process.exit(1);
|
|
1099
|
+
}
|
|
1100
|
+
return selectedEnvironment;
|
|
1101
|
+
}
|
|
984
1102
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
985
1103
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
986
1104
|
try {
|
|
@@ -1047,17 +1165,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1047
1165
|
return data.build_id;
|
|
1048
1166
|
} catch (e) {
|
|
1049
1167
|
progressBar.stop();
|
|
1050
|
-
|
|
1051
|
-
if (e.response.status === 404) {
|
|
1052
|
-
ctx.logger.warn(
|
|
1053
|
-
`The project does not exist. Please link your local project to a Strapi Cloud project using the link command.`
|
|
1054
|
-
);
|
|
1055
|
-
} else {
|
|
1056
|
-
ctx.logger.error(e.response.data);
|
|
1057
|
-
}
|
|
1058
|
-
} else {
|
|
1059
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1060
|
-
}
|
|
1168
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1061
1169
|
ctx.logger.debug(e);
|
|
1062
1170
|
} finally {
|
|
1063
1171
|
await fse__default.remove(tarFilePath);
|
|
@@ -1073,7 +1181,7 @@ async function getProject(ctx) {
|
|
|
1073
1181
|
const { project } = await retrieve();
|
|
1074
1182
|
if (!project) {
|
|
1075
1183
|
try {
|
|
1076
|
-
return await action$
|
|
1184
|
+
return await action$6(ctx);
|
|
1077
1185
|
} catch (e) {
|
|
1078
1186
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1079
1187
|
ctx.logger.debug(e);
|
|
@@ -1094,7 +1202,33 @@ async function getConfig({
|
|
|
1094
1202
|
return null;
|
|
1095
1203
|
}
|
|
1096
1204
|
}
|
|
1097
|
-
|
|
1205
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1206
|
+
if (!environments.includes(environment)) {
|
|
1207
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1208
|
+
process.exit(1);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1212
|
+
if (opts.env) {
|
|
1213
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1214
|
+
return opts.env;
|
|
1215
|
+
}
|
|
1216
|
+
if (project.targetEnvironment) {
|
|
1217
|
+
return project.targetEnvironment;
|
|
1218
|
+
}
|
|
1219
|
+
if (environments.length > 1) {
|
|
1220
|
+
return promptForEnvironment(environments);
|
|
1221
|
+
}
|
|
1222
|
+
return environments[0];
|
|
1223
|
+
}
|
|
1224
|
+
function hasPendingOrLiveDeployment(environments, targetEnvironment) {
|
|
1225
|
+
const environment = environments.find((env2) => env2.name === targetEnvironment);
|
|
1226
|
+
if (!environment) {
|
|
1227
|
+
throw new Error(`Environment details ${targetEnvironment} not found.`);
|
|
1228
|
+
}
|
|
1229
|
+
return environment.hasPendingDeployment || environment.hasLiveDeployment || false;
|
|
1230
|
+
}
|
|
1231
|
+
const action$5 = async (ctx, opts) => {
|
|
1098
1232
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1099
1233
|
const token = await getValidToken(ctx, promptLogin);
|
|
1100
1234
|
if (!token) {
|
|
@@ -1104,7 +1238,45 @@ const action$3 = async (ctx) => {
|
|
|
1104
1238
|
if (!project) {
|
|
1105
1239
|
return;
|
|
1106
1240
|
}
|
|
1107
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1241
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1242
|
+
let projectData;
|
|
1243
|
+
let environments;
|
|
1244
|
+
let environmentsDetails;
|
|
1245
|
+
try {
|
|
1246
|
+
const {
|
|
1247
|
+
data: { data, metadata }
|
|
1248
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1249
|
+
projectData = data;
|
|
1250
|
+
environments = projectData.environments;
|
|
1251
|
+
environmentsDetails = projectData.environmentsDetails;
|
|
1252
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
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.underline(`${metadata.dashboardUrls.project}`));
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
} catch (e) {
|
|
1261
|
+
if (e instanceof 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.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
|
+
}
|
|
1108
1280
|
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1109
1281
|
projectInternalName: project.name
|
|
1110
1282
|
});
|
|
@@ -1113,7 +1285,7 @@ const action$3 = async (ctx) => {
|
|
|
1113
1285
|
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1114
1286
|
if (!cliConfig2) {
|
|
1115
1287
|
ctx.logger.error(
|
|
1116
|
-
"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."
|
|
1117
1289
|
);
|
|
1118
1290
|
return;
|
|
1119
1291
|
}
|
|
@@ -1124,11 +1296,34 @@ const action$3 = async (ctx) => {
|
|
|
1124
1296
|
);
|
|
1125
1297
|
maxSize = 1e8;
|
|
1126
1298
|
}
|
|
1299
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1300
|
+
if (!opts.force) {
|
|
1301
|
+
const shouldDisplayWarning = hasPendingOrLiveDeployment(
|
|
1302
|
+
environmentsDetails,
|
|
1303
|
+
project.targetEnvironment
|
|
1304
|
+
);
|
|
1305
|
+
if (shouldDisplayWarning) {
|
|
1306
|
+
ctx.logger.log(boxen(cliConfig2.projectDeployment.confirmationText, boxenOptions));
|
|
1307
|
+
const { confirm } = await inquirer.prompt([
|
|
1308
|
+
{
|
|
1309
|
+
type: "confirm",
|
|
1310
|
+
name: "confirm",
|
|
1311
|
+
message: `Do you want to proceed with deployment to ${chalk.cyan(projectData.displayName)} on ${chalk.cyan(project.targetEnvironment)} environment?`
|
|
1312
|
+
}
|
|
1313
|
+
]);
|
|
1314
|
+
if (!confirm) {
|
|
1315
|
+
process.exit(1);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1127
1319
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1128
1320
|
if (!buildId) {
|
|
1129
1321
|
return;
|
|
1130
1322
|
}
|
|
1131
1323
|
try {
|
|
1324
|
+
ctx.logger.log(
|
|
1325
|
+
`🚀 Deploying project to ${chalk.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1326
|
+
);
|
|
1132
1327
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1133
1328
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1134
1329
|
ctx.logger.log(
|
|
@@ -1173,17 +1368,16 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1173
1368
|
process.exit(1);
|
|
1174
1369
|
});
|
|
1175
1370
|
};
|
|
1176
|
-
const command$
|
|
1177
|
-
|
|
1371
|
+
const command$7 = ({ ctx }) => {
|
|
1372
|
+
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));
|
|
1178
1373
|
};
|
|
1179
1374
|
const deployProject = {
|
|
1180
1375
|
name: "deploy-project",
|
|
1181
1376
|
description: "Deploy a Strapi Cloud project",
|
|
1182
|
-
action: action$
|
|
1183
|
-
command: command$
|
|
1377
|
+
action: action$5,
|
|
1378
|
+
command: command$7
|
|
1184
1379
|
};
|
|
1185
|
-
|
|
1186
|
-
async function getExistingConfig(ctx) {
|
|
1380
|
+
async function getLocalConfig(ctx) {
|
|
1187
1381
|
try {
|
|
1188
1382
|
return await retrieve();
|
|
1189
1383
|
} catch (e) {
|
|
@@ -1192,6 +1386,21 @@ async function getExistingConfig(ctx) {
|
|
|
1192
1386
|
return null;
|
|
1193
1387
|
}
|
|
1194
1388
|
}
|
|
1389
|
+
async function getLocalProject(ctx) {
|
|
1390
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1391
|
+
if (!localConfig || !localConfig.project) {
|
|
1392
|
+
ctx.logger.warn(
|
|
1393
|
+
`
|
|
1394
|
+
We couldn't find a valid local project config.
|
|
1395
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1396
|
+
"link"
|
|
1397
|
+
)} command.`
|
|
1398
|
+
);
|
|
1399
|
+
process.exit(1);
|
|
1400
|
+
}
|
|
1401
|
+
return localConfig.project;
|
|
1402
|
+
}
|
|
1403
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1195
1404
|
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1196
1405
|
if (existingConfig && existingConfig.project) {
|
|
1197
1406
|
const { shouldRelink } = await inquirer.prompt([
|
|
@@ -1221,7 +1430,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1221
1430
|
} = await cloudApiService.listLinkProjects();
|
|
1222
1431
|
spinner.succeed();
|
|
1223
1432
|
if (!Array.isArray(projectList)) {
|
|
1224
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1433
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1225
1434
|
return null;
|
|
1226
1435
|
}
|
|
1227
1436
|
const projects = projectList.filter(
|
|
@@ -1233,7 +1442,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1233
1442
|
};
|
|
1234
1443
|
});
|
|
1235
1444
|
if (projects.length === 0) {
|
|
1236
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1445
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1237
1446
|
return null;
|
|
1238
1447
|
}
|
|
1239
1448
|
return projects;
|
|
@@ -1251,7 +1460,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1251
1460
|
type: "list",
|
|
1252
1461
|
name: "linkProject",
|
|
1253
1462
|
message: "Which project do you want to link?",
|
|
1254
|
-
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1463
|
+
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1255
1464
|
}
|
|
1256
1465
|
]);
|
|
1257
1466
|
if (!answer.linkProject) {
|
|
@@ -1264,7 +1473,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1264
1473
|
return null;
|
|
1265
1474
|
}
|
|
1266
1475
|
}
|
|
1267
|
-
const action$
|
|
1476
|
+
const action$4 = async (ctx) => {
|
|
1268
1477
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1269
1478
|
const token = await getValidToken(ctx, promptLogin);
|
|
1270
1479
|
const { logger } = ctx;
|
|
@@ -1272,7 +1481,7 @@ const action$2 = async (ctx) => {
|
|
|
1272
1481
|
return;
|
|
1273
1482
|
}
|
|
1274
1483
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1275
|
-
const existingConfig = await
|
|
1484
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1276
1485
|
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1277
1486
|
if (!shouldRelink) {
|
|
1278
1487
|
return;
|
|
@@ -1307,7 +1516,9 @@ const action$2 = async (ctx) => {
|
|
|
1307
1516
|
return;
|
|
1308
1517
|
}
|
|
1309
1518
|
await save({ project: answer.linkProject });
|
|
1310
|
-
logger.log(
|
|
1519
|
+
logger.log(
|
|
1520
|
+
` You have successfully linked your project to ${chalk.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1521
|
+
);
|
|
1311
1522
|
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1312
1523
|
projectInternalName: answer.linkProject
|
|
1313
1524
|
});
|
|
@@ -1319,17 +1530,17 @@ const action$2 = async (ctx) => {
|
|
|
1319
1530
|
});
|
|
1320
1531
|
}
|
|
1321
1532
|
};
|
|
1322
|
-
const command$
|
|
1323
|
-
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$
|
|
1533
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1534
|
+
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));
|
|
1324
1535
|
};
|
|
1325
1536
|
const link = {
|
|
1326
1537
|
name: "link-project",
|
|
1327
1538
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1328
|
-
action: action$
|
|
1329
|
-
command: command$
|
|
1539
|
+
action: action$4,
|
|
1540
|
+
command: command$6
|
|
1330
1541
|
};
|
|
1331
|
-
const command$
|
|
1332
|
-
|
|
1542
|
+
const command$5 = ({ ctx }) => {
|
|
1543
|
+
return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1333
1544
|
"after",
|
|
1334
1545
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1335
1546
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1338,10 +1549,10 @@ const login = {
|
|
|
1338
1549
|
name: "login",
|
|
1339
1550
|
description: "Strapi Cloud Login",
|
|
1340
1551
|
action: loginAction,
|
|
1341
|
-
command: command$
|
|
1552
|
+
command: command$5
|
|
1342
1553
|
};
|
|
1343
1554
|
const openModule = import("open");
|
|
1344
|
-
const action$
|
|
1555
|
+
const action$3 = async (ctx) => {
|
|
1345
1556
|
const { logger } = ctx;
|
|
1346
1557
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1347
1558
|
const token = await retrieveToken();
|
|
@@ -1373,25 +1584,25 @@ const action$1 = async (ctx) => {
|
|
|
1373
1584
|
}
|
|
1374
1585
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1375
1586
|
};
|
|
1376
|
-
const command$
|
|
1377
|
-
|
|
1587
|
+
const command$4 = ({ ctx }) => {
|
|
1588
|
+
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));
|
|
1378
1589
|
};
|
|
1379
1590
|
const logout = {
|
|
1380
1591
|
name: "logout",
|
|
1381
1592
|
description: "Strapi Cloud Logout",
|
|
1382
|
-
action: action$
|
|
1383
|
-
command: command$
|
|
1593
|
+
action: action$3,
|
|
1594
|
+
command: command$4
|
|
1384
1595
|
};
|
|
1385
|
-
const command$
|
|
1386
|
-
|
|
1596
|
+
const command$3 = ({ ctx }) => {
|
|
1597
|
+
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));
|
|
1387
1598
|
};
|
|
1388
1599
|
const createProject = {
|
|
1389
1600
|
name: "create-project",
|
|
1390
1601
|
description: "Create a new project",
|
|
1391
|
-
action: action$
|
|
1392
|
-
command: command$
|
|
1602
|
+
action: action$6,
|
|
1603
|
+
command: command$3
|
|
1393
1604
|
};
|
|
1394
|
-
const action = async (ctx) => {
|
|
1605
|
+
const action$2 = async (ctx) => {
|
|
1395
1606
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1396
1607
|
const token = await getValidToken(ctx, promptLogin);
|
|
1397
1608
|
const { logger } = ctx;
|
|
@@ -1411,12 +1622,194 @@ const action = async (ctx) => {
|
|
|
1411
1622
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1412
1623
|
}
|
|
1413
1624
|
};
|
|
1414
|
-
const command = ({ command: command2, ctx }) => {
|
|
1415
|
-
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));
|
|
1625
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1626
|
+
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));
|
|
1416
1627
|
};
|
|
1417
1628
|
const listProjects = {
|
|
1418
1629
|
name: "list-projects",
|
|
1419
1630
|
description: "List Strapi Cloud projects",
|
|
1631
|
+
action: action$2,
|
|
1632
|
+
command: command$2
|
|
1633
|
+
};
|
|
1634
|
+
const action$1 = async (ctx) => {
|
|
1635
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1636
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1637
|
+
const { logger } = ctx;
|
|
1638
|
+
if (!token) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
const project = await getLocalProject(ctx);
|
|
1642
|
+
if (!project) {
|
|
1643
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1647
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1648
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1649
|
+
projectInternalName: project.name
|
|
1650
|
+
});
|
|
1651
|
+
try {
|
|
1652
|
+
const {
|
|
1653
|
+
data: { data: environmentsList }
|
|
1654
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1655
|
+
spinner.succeed();
|
|
1656
|
+
logger.log(environmentsList);
|
|
1657
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1658
|
+
projectInternalName: project.name
|
|
1659
|
+
});
|
|
1660
|
+
} catch (e) {
|
|
1661
|
+
if (e.response && e.response.status === 404) {
|
|
1662
|
+
spinner.succeed();
|
|
1663
|
+
logger.warn(
|
|
1664
|
+
`
|
|
1665
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1666
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1667
|
+
"link"
|
|
1668
|
+
)} command`
|
|
1669
|
+
);
|
|
1670
|
+
} else {
|
|
1671
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1672
|
+
logger.debug("Failed to list environments", e);
|
|
1673
|
+
}
|
|
1674
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1675
|
+
projectInternalName: project.name
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1680
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1681
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1682
|
+
return cloud;
|
|
1683
|
+
}
|
|
1684
|
+
let environmentCmd = null;
|
|
1685
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1686
|
+
if (!environmentCmd) {
|
|
1687
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1688
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1689
|
+
}
|
|
1690
|
+
return environmentCmd;
|
|
1691
|
+
};
|
|
1692
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1693
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1694
|
+
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));
|
|
1695
|
+
};
|
|
1696
|
+
const listEnvironments = {
|
|
1697
|
+
name: "list-environments",
|
|
1698
|
+
description: "List Strapi Cloud environments",
|
|
1699
|
+
action: action$1,
|
|
1700
|
+
command: command$1
|
|
1701
|
+
};
|
|
1702
|
+
const QUIT_OPTION = "Quit";
|
|
1703
|
+
const action = async (ctx) => {
|
|
1704
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1705
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1706
|
+
const { logger } = ctx;
|
|
1707
|
+
if (!token) {
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
const project = await getLocalProject(ctx);
|
|
1711
|
+
if (!project) {
|
|
1712
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1716
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1717
|
+
if (!environments) {
|
|
1718
|
+
logger.debug(`Fetching environments failed.`);
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1721
|
+
if (environments.length === 0) {
|
|
1722
|
+
logger.log(
|
|
1723
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1724
|
+
);
|
|
1725
|
+
return;
|
|
1726
|
+
}
|
|
1727
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1728
|
+
if (!answer) {
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1732
|
+
projectName: project.name,
|
|
1733
|
+
environmentName: answer.targetEnvironment
|
|
1734
|
+
});
|
|
1735
|
+
try {
|
|
1736
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1737
|
+
} catch (e) {
|
|
1738
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1739
|
+
projectName: project.name,
|
|
1740
|
+
environmentName: answer.targetEnvironment
|
|
1741
|
+
});
|
|
1742
|
+
logger.debug("Failed to link environment", e);
|
|
1743
|
+
logger.error(
|
|
1744
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1745
|
+
);
|
|
1746
|
+
process.exit(1);
|
|
1747
|
+
}
|
|
1748
|
+
logger.log(
|
|
1749
|
+
` You have successfully linked your project to ${chalk.cyan(answer.targetEnvironment)}, on ${chalk.cyan(project.displayName)}. You are now able to deploy your project.`
|
|
1750
|
+
);
|
|
1751
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1752
|
+
projectName: project.name,
|
|
1753
|
+
environmentName: answer.targetEnvironment
|
|
1754
|
+
});
|
|
1755
|
+
};
|
|
1756
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1757
|
+
const { logger } = ctx;
|
|
1758
|
+
try {
|
|
1759
|
+
const answer = await inquirer.prompt([
|
|
1760
|
+
{
|
|
1761
|
+
type: "list",
|
|
1762
|
+
name: "targetEnvironment",
|
|
1763
|
+
message: "Which environment do you want to link?",
|
|
1764
|
+
choices: [...environments, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1765
|
+
}
|
|
1766
|
+
]);
|
|
1767
|
+
if (!answer.targetEnvironment) {
|
|
1768
|
+
return null;
|
|
1769
|
+
}
|
|
1770
|
+
return answer;
|
|
1771
|
+
} catch (e) {
|
|
1772
|
+
logger.debug("Failed to get user input", e);
|
|
1773
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1774
|
+
return null;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1778
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1779
|
+
try {
|
|
1780
|
+
const {
|
|
1781
|
+
data: { data: environmentsList }
|
|
1782
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1783
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1784
|
+
throw new Error("Environments not found in server response");
|
|
1785
|
+
}
|
|
1786
|
+
spinner.succeed();
|
|
1787
|
+
return environmentsList.filter(
|
|
1788
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1789
|
+
);
|
|
1790
|
+
} catch (e) {
|
|
1791
|
+
if (e.response && e.response.status === 404) {
|
|
1792
|
+
spinner.succeed();
|
|
1793
|
+
ctx.logger.warn(
|
|
1794
|
+
`
|
|
1795
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1796
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1797
|
+
"link"
|
|
1798
|
+
)} command.`
|
|
1799
|
+
);
|
|
1800
|
+
} else {
|
|
1801
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1802
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
const command = ({ command: command2, ctx }) => {
|
|
1807
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1808
|
+
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));
|
|
1809
|
+
};
|
|
1810
|
+
const linkEnvironment = {
|
|
1811
|
+
name: "link-environment",
|
|
1812
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1420
1813
|
action,
|
|
1421
1814
|
command
|
|
1422
1815
|
};
|
|
@@ -1426,11 +1819,21 @@ const cli = {
|
|
|
1426
1819
|
login,
|
|
1427
1820
|
logout,
|
|
1428
1821
|
createProject,
|
|
1429
|
-
|
|
1822
|
+
linkEnvironment,
|
|
1823
|
+
listProjects,
|
|
1824
|
+
listEnvironments
|
|
1430
1825
|
};
|
|
1431
|
-
const cloudCommands = [
|
|
1826
|
+
const cloudCommands = [
|
|
1827
|
+
deployProject,
|
|
1828
|
+
link,
|
|
1829
|
+
login,
|
|
1830
|
+
logout,
|
|
1831
|
+
linkEnvironment,
|
|
1832
|
+
listProjects,
|
|
1833
|
+
listEnvironments
|
|
1834
|
+
];
|
|
1432
1835
|
async function initCloudCLIConfig() {
|
|
1433
|
-
const localConfig = await getLocalConfig();
|
|
1836
|
+
const localConfig = await getLocalConfig$1();
|
|
1434
1837
|
if (!localConfig.deviceId) {
|
|
1435
1838
|
localConfig.deviceId = crypto$1.randomUUID();
|
|
1436
1839
|
}
|
|
@@ -1444,7 +1847,10 @@ async function buildStrapiCloudCommands({
|
|
|
1444
1847
|
await initCloudCLIConfig();
|
|
1445
1848
|
for (const cloudCommand of cloudCommands) {
|
|
1446
1849
|
try {
|
|
1447
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1850
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1851
|
+
if (subCommand) {
|
|
1852
|
+
command2.addCommand(subCommand);
|
|
1853
|
+
}
|
|
1448
1854
|
} catch (e) {
|
|
1449
1855
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1450
1856
|
}
|