@strapi/cloud-cli 0.0.0-next.ae38a9dcdeddea4b4c0978686fb024413e5c54f5 → 0.0.0-next.af5da17207f828ea159182ea6e2d9a07ae6d34bf
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 +703 -129
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +700 -125
- 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 +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/link/action.d.ts +4 -0
- package/dist/src/link/action.d.ts.map +1 -0
- package/dist/src/link/command.d.ts +7 -0
- package/dist/src/link/command.d.ts.map +1 -0
- package/dist/src/link/index.d.ts +7 -0
- package/dist/src/link/index.d.ts.map +1 -0
- package/dist/src/login/action.d.ts.map +1 -1
- package/dist/src/login/command.d.ts.map +1 -1
- package/dist/src/logout/action.d.ts.map +1 -1
- package/dist/src/logout/command.d.ts.map +1 -1
- package/dist/src/services/build-logs.d.ts.map +1 -1
- package/dist/src/services/cli-api.d.ts +58 -8
- 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 +8 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/analytics.d.ts +4 -0
- package/dist/src/utils/analytics.d.ts.map +1 -0
- 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 -10
- 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,8 @@ 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");
|
|
28
|
+
const boxen = require("boxen");
|
|
27
29
|
const path = require("path");
|
|
28
30
|
const chalk = require("chalk");
|
|
29
31
|
const axios = require("axios");
|
|
@@ -31,10 +33,10 @@ const crypto = require("node:crypto");
|
|
|
31
33
|
const utils = require("@strapi/utils");
|
|
32
34
|
const tar = require("tar");
|
|
33
35
|
const minimatch = require("minimatch");
|
|
34
|
-
const inquirer = require("inquirer");
|
|
35
36
|
const fp = require("lodash/fp");
|
|
36
37
|
const os = require("os");
|
|
37
38
|
const XDGAppPaths = require("xdg-app-paths");
|
|
39
|
+
const lodash = require("lodash");
|
|
38
40
|
const jwksClient = require("jwks-rsa");
|
|
39
41
|
const jwt = require("jsonwebtoken");
|
|
40
42
|
const stringify = require("fast-safe-stringify");
|
|
@@ -42,12 +44,11 @@ const ora = require("ora");
|
|
|
42
44
|
const cliProgress = require("cli-progress");
|
|
43
45
|
const pkgUp = require("pkg-up");
|
|
44
46
|
const yup = require("yup");
|
|
45
|
-
const _ = require("lodash");
|
|
46
47
|
const EventSource = require("eventsource");
|
|
48
|
+
const commander = require("commander");
|
|
47
49
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
48
50
|
function _interopNamespace(e) {
|
|
49
|
-
if (e && e.__esModule)
|
|
50
|
-
return e;
|
|
51
|
+
if (e && e.__esModule) return e;
|
|
51
52
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
52
53
|
if (e) {
|
|
53
54
|
for (const k in e) {
|
|
@@ -65,12 +66,13 @@ 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);
|
|
70
|
+
const boxen__default = /* @__PURE__ */ _interopDefault(boxen);
|
|
68
71
|
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
69
72
|
const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
70
73
|
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
71
74
|
const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
|
|
72
75
|
const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
|
|
73
|
-
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
74
76
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
75
77
|
const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
|
|
76
78
|
const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
|
|
@@ -80,7 +82,6 @@ const ora__default = /* @__PURE__ */ _interopDefault(ora);
|
|
|
80
82
|
const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
|
|
81
83
|
const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
|
|
82
84
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
83
|
-
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
84
85
|
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
85
86
|
const apiConfig = {
|
|
86
87
|
apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
@@ -138,8 +139,7 @@ const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
|
138
139
|
const readGitignore = async (folderPath) => {
|
|
139
140
|
const gitignorePath = path__namespace.resolve(folderPath, ".gitignore");
|
|
140
141
|
const pathExist = await fse__namespace.pathExists(gitignorePath);
|
|
141
|
-
if (!pathExist)
|
|
142
|
-
return [];
|
|
142
|
+
if (!pathExist) return [];
|
|
143
143
|
const gitignoreContent = await fse__namespace.readFile(gitignorePath, "utf8");
|
|
144
144
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
145
145
|
};
|
|
@@ -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 = "
|
|
197
|
+
const version = "5.5.0";
|
|
198
198
|
const description = "Commands to interact with the Strapi Cloud";
|
|
199
199
|
const keywords = [
|
|
200
200
|
"strapi",
|
|
@@ -239,14 +239,15 @@ const scripts = {
|
|
|
239
239
|
watch: "pack-up watch"
|
|
240
240
|
};
|
|
241
241
|
const dependencies = {
|
|
242
|
-
"@strapi/utils": "
|
|
243
|
-
axios: "1.
|
|
242
|
+
"@strapi/utils": "workspace:*",
|
|
243
|
+
axios: "1.7.4",
|
|
244
|
+
boxen: "5.1.2",
|
|
244
245
|
chalk: "4.1.2",
|
|
245
246
|
"cli-progress": "3.12.0",
|
|
246
247
|
commander: "8.3.0",
|
|
247
248
|
eventsource: "2.0.2",
|
|
248
249
|
"fast-safe-stringify": "2.1.1",
|
|
249
|
-
"fs-extra": "
|
|
250
|
+
"fs-extra": "11.2.0",
|
|
250
251
|
inquirer: "8.2.5",
|
|
251
252
|
jsonwebtoken: "9.0.0",
|
|
252
253
|
"jwks-rsa": "3.1.0",
|
|
@@ -255,22 +256,23 @@ const dependencies = {
|
|
|
255
256
|
open: "8.4.0",
|
|
256
257
|
ora: "5.4.1",
|
|
257
258
|
"pkg-up": "3.1.0",
|
|
258
|
-
tar: "6.1
|
|
259
|
+
tar: "6.2.1",
|
|
259
260
|
"xdg-app-paths": "8.3.0",
|
|
260
261
|
yup: "0.32.9"
|
|
261
262
|
};
|
|
262
263
|
const devDependencies = {
|
|
263
|
-
"@strapi/pack-up": "
|
|
264
|
+
"@strapi/pack-up": "5.0.2",
|
|
264
265
|
"@types/cli-progress": "3.11.5",
|
|
265
266
|
"@types/eventsource": "1.1.15",
|
|
266
267
|
"@types/lodash": "^4.14.191",
|
|
267
|
-
"eslint-config-custom": "
|
|
268
|
-
tsconfig: "
|
|
268
|
+
"eslint-config-custom": "workspace:*",
|
|
269
|
+
tsconfig: "workspace:*"
|
|
269
270
|
};
|
|
270
271
|
const engines = {
|
|
271
|
-
node: ">=18.0.0 <=
|
|
272
|
+
node: ">=18.0.0 <=22.x.x",
|
|
272
273
|
npm: ">=6.0.0"
|
|
273
274
|
};
|
|
275
|
+
const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
|
|
274
276
|
const packageJson = {
|
|
275
277
|
name,
|
|
276
278
|
version,
|
|
@@ -291,11 +293,12 @@ const packageJson = {
|
|
|
291
293
|
scripts,
|
|
292
294
|
dependencies,
|
|
293
295
|
devDependencies,
|
|
294
|
-
engines
|
|
296
|
+
engines,
|
|
297
|
+
gitHead
|
|
295
298
|
};
|
|
296
299
|
const VERSION = "v1";
|
|
297
300
|
async function cloudApiFactory({ logger }, token) {
|
|
298
|
-
const localConfig = await getLocalConfig();
|
|
301
|
+
const localConfig = await getLocalConfig$1();
|
|
299
302
|
const customHeaders = {
|
|
300
303
|
"x-device-id": localConfig.deviceId,
|
|
301
304
|
"x-app-version": packageJson.version,
|
|
@@ -318,7 +321,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
318
321
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
319
322
|
return axiosCloudAPI.post(
|
|
320
323
|
`/deploy/${project.name}`,
|
|
321
|
-
{ file: fse__namespace.default.createReadStream(filePath) },
|
|
324
|
+
{ file: fse__namespace.default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
322
325
|
{
|
|
323
326
|
headers: {
|
|
324
327
|
"Content-Type": "multipart/form-data"
|
|
@@ -375,6 +378,62 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
375
378
|
throw error;
|
|
376
379
|
}
|
|
377
380
|
},
|
|
381
|
+
async listLinkProjects() {
|
|
382
|
+
try {
|
|
383
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
384
|
+
if (response.status !== 200) {
|
|
385
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
386
|
+
}
|
|
387
|
+
return response;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
logger.debug(
|
|
390
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
391
|
+
);
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
async listEnvironments({ name: name2 }) {
|
|
396
|
+
try {
|
|
397
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
398
|
+
if (response.status !== 200) {
|
|
399
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
400
|
+
}
|
|
401
|
+
return response;
|
|
402
|
+
} catch (error) {
|
|
403
|
+
logger.debug(
|
|
404
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
405
|
+
);
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
410
|
+
try {
|
|
411
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
412
|
+
if (response.status !== 200) {
|
|
413
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
414
|
+
}
|
|
415
|
+
return response;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
logger.debug(
|
|
418
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
419
|
+
);
|
|
420
|
+
throw error;
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
async getProject({ name: name2 }) {
|
|
424
|
+
try {
|
|
425
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
426
|
+
if (response.status !== 200) {
|
|
427
|
+
throw new Error("Error fetching project's details.");
|
|
428
|
+
}
|
|
429
|
+
return response;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
logger.debug(
|
|
432
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
433
|
+
);
|
|
434
|
+
throw error;
|
|
435
|
+
}
|
|
436
|
+
},
|
|
378
437
|
track(event, payload = {}) {
|
|
379
438
|
return axiosCloudAPI.post("/track", {
|
|
380
439
|
event,
|
|
@@ -384,26 +443,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
384
443
|
};
|
|
385
444
|
}
|
|
386
445
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
446
|
+
const getFilePath = (directoryPath) => path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
387
447
|
async function save(data, { directoryPath } = {}) {
|
|
388
|
-
const
|
|
389
|
-
const storedData = { ...alreadyInFileData, ...data };
|
|
390
|
-
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
448
|
+
const pathToFile = getFilePath(directoryPath);
|
|
391
449
|
await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
392
|
-
await fse__namespace.default.writeJson(pathToFile,
|
|
450
|
+
await fse__namespace.default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
393
451
|
}
|
|
394
452
|
async function retrieve({
|
|
395
453
|
directoryPath
|
|
396
454
|
} = {}) {
|
|
397
|
-
const pathToFile =
|
|
455
|
+
const pathToFile = getFilePath(directoryPath);
|
|
398
456
|
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
399
457
|
if (!pathExists) {
|
|
400
458
|
return {};
|
|
401
459
|
}
|
|
402
460
|
return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
|
|
403
461
|
}
|
|
462
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
463
|
+
const pathToFile = getFilePath(directoryPath);
|
|
464
|
+
const existingData = await retrieve({ directoryPath });
|
|
465
|
+
if (!existingData) {
|
|
466
|
+
throw new Error("No configuration data found to patch.");
|
|
467
|
+
}
|
|
468
|
+
const newData = lodash.merge(existingData, patchData);
|
|
469
|
+
await fse__namespace.default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
470
|
+
}
|
|
471
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
472
|
+
const pathToFile = getFilePath(directoryPath);
|
|
473
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
474
|
+
if (pathExists) {
|
|
475
|
+
await fse__namespace.default.remove(pathToFile);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
404
478
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
405
479
|
__proto__: null,
|
|
406
480
|
LOCAL_SAVE_FILENAME,
|
|
481
|
+
deleteConfig,
|
|
482
|
+
patch,
|
|
407
483
|
retrieve,
|
|
408
484
|
save
|
|
409
485
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -411,7 +487,7 @@ let cliConfig;
|
|
|
411
487
|
async function tokenServiceFactory({ logger }) {
|
|
412
488
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
413
489
|
async function saveToken(str) {
|
|
414
|
-
const appConfig = await getLocalConfig();
|
|
490
|
+
const appConfig = await getLocalConfig$1();
|
|
415
491
|
if (!appConfig) {
|
|
416
492
|
logger.error("There was a problem saving your token. Please try again.");
|
|
417
493
|
return;
|
|
@@ -425,7 +501,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
425
501
|
}
|
|
426
502
|
}
|
|
427
503
|
async function retrieveToken() {
|
|
428
|
-
const appConfig = await getLocalConfig();
|
|
504
|
+
const appConfig = await getLocalConfig$1();
|
|
429
505
|
if (appConfig.token) {
|
|
430
506
|
if (await isTokenValid(appConfig.token)) {
|
|
431
507
|
return appConfig.token;
|
|
@@ -487,7 +563,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
487
563
|
}
|
|
488
564
|
}
|
|
489
565
|
async function eraseToken() {
|
|
490
|
-
const appConfig = await getLocalConfig();
|
|
566
|
+
const appConfig = await getLocalConfig$1();
|
|
491
567
|
if (!appConfig) {
|
|
492
568
|
return;
|
|
493
569
|
}
|
|
@@ -508,8 +584,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
508
584
|
logger.log(
|
|
509
585
|
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."
|
|
510
586
|
);
|
|
511
|
-
if (!await loginAction2(ctx))
|
|
512
|
-
return null;
|
|
587
|
+
if (!await loginAction2(ctx)) return null;
|
|
513
588
|
token = await retrieveToken();
|
|
514
589
|
}
|
|
515
590
|
return token;
|
|
@@ -648,21 +723,24 @@ yup__namespace.object({
|
|
|
648
723
|
name: yup__namespace.string().required(),
|
|
649
724
|
exports: yup__namespace.lazy(
|
|
650
725
|
(value) => yup__namespace.object(
|
|
651
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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
|
|
666
744
|
).optional()
|
|
667
745
|
)
|
|
668
746
|
});
|
|
@@ -684,18 +762,13 @@ async function getProjectNameFromPackageJson(ctx) {
|
|
|
684
762
|
return "my-strapi-project";
|
|
685
763
|
}
|
|
686
764
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
return questionCopy;
|
|
696
|
-
});
|
|
697
|
-
return { newQuestions, newDefaultValues };
|
|
698
|
-
}
|
|
765
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
766
|
+
try {
|
|
767
|
+
await cloudApiService.track(eventName, eventData);
|
|
768
|
+
} catch (e) {
|
|
769
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
699
772
|
const openModule$1 = import("open");
|
|
700
773
|
async function promptLogin(ctx) {
|
|
701
774
|
const response = await inquirer__default.default.prompt([
|
|
@@ -716,13 +789,6 @@ async function loginAction(ctx) {
|
|
|
716
789
|
const tokenService = await tokenServiceFactory(ctx);
|
|
717
790
|
const existingToken = await tokenService.retrieveToken();
|
|
718
791
|
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
719
|
-
const trackFailedLogin = async () => {
|
|
720
|
-
try {
|
|
721
|
-
await cloudApiService.track("didNotLogin", { loginMethod: "cli" });
|
|
722
|
-
} catch (e) {
|
|
723
|
-
logger.debug("Failed to track failed login", e);
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
792
|
if (existingToken) {
|
|
727
793
|
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
728
794
|
if (isTokenValid) {
|
|
@@ -754,11 +820,7 @@ async function loginAction(ctx) {
|
|
|
754
820
|
logger.debug(e);
|
|
755
821
|
return false;
|
|
756
822
|
}
|
|
757
|
-
|
|
758
|
-
await cloudApiService.track("willLoginAttempt", {});
|
|
759
|
-
} catch (e) {
|
|
760
|
-
logger.debug("Failed to track login attempt", e);
|
|
761
|
-
}
|
|
823
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
762
824
|
logger.debug("🔐 Creating device authentication request...", {
|
|
763
825
|
client_id: cliConfig2.clientId,
|
|
764
826
|
scope: cliConfig2.scope,
|
|
@@ -838,13 +900,13 @@ async function loginAction(ctx) {
|
|
|
838
900
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
839
901
|
);
|
|
840
902
|
spinnerFail();
|
|
841
|
-
await
|
|
903
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
842
904
|
return false;
|
|
843
905
|
}
|
|
844
906
|
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
845
907
|
logger.debug(e);
|
|
846
908
|
spinnerFail();
|
|
847
|
-
await
|
|
909
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
848
910
|
return false;
|
|
849
911
|
}
|
|
850
912
|
await new Promise((resolve) => {
|
|
@@ -858,15 +920,50 @@ async function loginAction(ctx) {
|
|
|
858
920
|
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
859
921
|
);
|
|
860
922
|
logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
861
|
-
|
|
862
|
-
await cloudApiService.track("didLogin", { loginMethod: "cli" });
|
|
863
|
-
} catch (e) {
|
|
864
|
-
logger.debug("Failed to track login", e);
|
|
865
|
-
}
|
|
923
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
866
924
|
};
|
|
867
925
|
await authenticate();
|
|
868
926
|
return isAuthenticated;
|
|
869
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
|
+
}
|
|
870
967
|
async function handleError(ctx, error) {
|
|
871
968
|
const { logger } = ctx;
|
|
872
969
|
logger.debug(error);
|
|
@@ -911,7 +1008,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
911
1008
|
throw e;
|
|
912
1009
|
}
|
|
913
1010
|
}
|
|
914
|
-
const action$
|
|
1011
|
+
const action$6 = async (ctx) => {
|
|
915
1012
|
const { logger } = ctx;
|
|
916
1013
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
917
1014
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -920,11 +1017,16 @@ const action$3 = async (ctx) => {
|
|
|
920
1017
|
}
|
|
921
1018
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
922
1019
|
const { data: config } = await cloudApi.config();
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
);
|
|
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
|
+
};
|
|
928
1030
|
const projectAnswersDefaulted = fp.defaults(defaultValues);
|
|
929
1031
|
const projectAnswers = await inquirer__default.default.prompt(questions);
|
|
930
1032
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -1026,6 +1128,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1026
1128
|
if (retries > MAX_RETRIES) {
|
|
1027
1129
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
1028
1130
|
es.close();
|
|
1131
|
+
clearExistingTimeout();
|
|
1029
1132
|
reject(new Error("Max retries reached"));
|
|
1030
1133
|
}
|
|
1031
1134
|
};
|
|
@@ -1034,6 +1137,29 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1034
1137
|
});
|
|
1035
1138
|
};
|
|
1036
1139
|
};
|
|
1140
|
+
const boxenOptions = {
|
|
1141
|
+
padding: 1,
|
|
1142
|
+
margin: 1,
|
|
1143
|
+
align: "center",
|
|
1144
|
+
borderColor: "yellow",
|
|
1145
|
+
borderStyle: "round"
|
|
1146
|
+
};
|
|
1147
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1148
|
+
async function promptForEnvironment(environments) {
|
|
1149
|
+
const choices = environments.map((env) => ({ name: env, value: env }));
|
|
1150
|
+
const { selectedEnvironment } = await inquirer__default.default.prompt([
|
|
1151
|
+
{
|
|
1152
|
+
type: "list",
|
|
1153
|
+
name: "selectedEnvironment",
|
|
1154
|
+
message: "Select the environment to deploy:",
|
|
1155
|
+
choices: [...choices, { name: chalk__default.default.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1156
|
+
}
|
|
1157
|
+
]);
|
|
1158
|
+
if (selectedEnvironment === null) {
|
|
1159
|
+
process.exit(1);
|
|
1160
|
+
}
|
|
1161
|
+
return selectedEnvironment;
|
|
1162
|
+
}
|
|
1037
1163
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1038
1164
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1039
1165
|
try {
|
|
@@ -1100,17 +1226,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1100
1226
|
return data.build_id;
|
|
1101
1227
|
} catch (e) {
|
|
1102
1228
|
progressBar.stop();
|
|
1103
|
-
|
|
1104
|
-
if (e.response.status === 404) {
|
|
1105
|
-
ctx.logger.error(
|
|
1106
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
1107
|
-
);
|
|
1108
|
-
} else {
|
|
1109
|
-
ctx.logger.error(e.response.data);
|
|
1110
|
-
}
|
|
1111
|
-
} else {
|
|
1112
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1113
|
-
}
|
|
1229
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1114
1230
|
ctx.logger.debug(e);
|
|
1115
1231
|
} finally {
|
|
1116
1232
|
await fse__namespace.default.remove(tarFilePath);
|
|
@@ -1126,7 +1242,7 @@ async function getProject(ctx) {
|
|
|
1126
1242
|
const { project } = await retrieve();
|
|
1127
1243
|
if (!project) {
|
|
1128
1244
|
try {
|
|
1129
|
-
return await action$
|
|
1245
|
+
return await action$6(ctx);
|
|
1130
1246
|
} catch (e) {
|
|
1131
1247
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1132
1248
|
ctx.logger.debug(e);
|
|
@@ -1135,7 +1251,45 @@ async function getProject(ctx) {
|
|
|
1135
1251
|
}
|
|
1136
1252
|
return project;
|
|
1137
1253
|
}
|
|
1138
|
-
|
|
1254
|
+
async function getConfig({
|
|
1255
|
+
ctx,
|
|
1256
|
+
cloudApiService
|
|
1257
|
+
}) {
|
|
1258
|
+
try {
|
|
1259
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1260
|
+
return cliConfig2;
|
|
1261
|
+
} catch (e) {
|
|
1262
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1267
|
+
if (!environments.includes(environment)) {
|
|
1268
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1269
|
+
process.exit(1);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1273
|
+
if (opts.env) {
|
|
1274
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1275
|
+
return opts.env;
|
|
1276
|
+
}
|
|
1277
|
+
if (project.targetEnvironment) {
|
|
1278
|
+
return project.targetEnvironment;
|
|
1279
|
+
}
|
|
1280
|
+
if (environments.length > 1) {
|
|
1281
|
+
return promptForEnvironment(environments);
|
|
1282
|
+
}
|
|
1283
|
+
return environments[0];
|
|
1284
|
+
}
|
|
1285
|
+
function hasPendingOrLiveDeployment(environments, targetEnvironment) {
|
|
1286
|
+
const environment = environments.find((env) => env.name === targetEnvironment);
|
|
1287
|
+
if (!environment) {
|
|
1288
|
+
throw new Error(`Environment details ${targetEnvironment} not found.`);
|
|
1289
|
+
}
|
|
1290
|
+
return environment.hasPendingDeployment || environment.hasLiveDeployment || false;
|
|
1291
|
+
}
|
|
1292
|
+
const action$5 = async (ctx, opts) => {
|
|
1139
1293
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1140
1294
|
const token = await getValidToken(ctx, promptLogin);
|
|
1141
1295
|
if (!token) {
|
|
@@ -1145,15 +1299,57 @@ const action$2 = async (ctx) => {
|
|
|
1145
1299
|
if (!project) {
|
|
1146
1300
|
return;
|
|
1147
1301
|
}
|
|
1148
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1302
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1303
|
+
let projectData;
|
|
1304
|
+
let environments;
|
|
1305
|
+
let environmentsDetails;
|
|
1149
1306
|
try {
|
|
1150
|
-
|
|
1307
|
+
const {
|
|
1308
|
+
data: { data, metadata }
|
|
1309
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1310
|
+
projectData = data;
|
|
1311
|
+
environments = projectData.environments;
|
|
1312
|
+
environmentsDetails = projectData.environmentsDetails;
|
|
1313
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1314
|
+
if (isProjectSuspended) {
|
|
1315
|
+
ctx.logger.log(
|
|
1316
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1317
|
+
);
|
|
1318
|
+
ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1151
1321
|
} catch (e) {
|
|
1152
|
-
|
|
1322
|
+
if (e instanceof axios.AxiosError && e.response?.data) {
|
|
1323
|
+
if (e.response.status === 404) {
|
|
1324
|
+
ctx.logger.warn(
|
|
1325
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1326
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1327
|
+
"link"
|
|
1328
|
+
)} command before deploying.`
|
|
1329
|
+
);
|
|
1330
|
+
} else {
|
|
1331
|
+
ctx.logger.error(e.response.data);
|
|
1332
|
+
}
|
|
1333
|
+
} else {
|
|
1334
|
+
ctx.logger.error(
|
|
1335
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
ctx.logger.debug(e);
|
|
1339
|
+
return;
|
|
1153
1340
|
}
|
|
1341
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1342
|
+
projectInternalName: project.name
|
|
1343
|
+
});
|
|
1154
1344
|
const notificationService = notificationServiceFactory(ctx);
|
|
1155
1345
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
1156
|
-
const
|
|
1346
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1347
|
+
if (!cliConfig2) {
|
|
1348
|
+
ctx.logger.error(
|
|
1349
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1350
|
+
);
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1157
1353
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
1158
1354
|
if (Number.isNaN(maxSize)) {
|
|
1159
1355
|
ctx.logger.debug(
|
|
@@ -1161,11 +1357,34 @@ const action$2 = async (ctx) => {
|
|
|
1161
1357
|
);
|
|
1162
1358
|
maxSize = 1e8;
|
|
1163
1359
|
}
|
|
1360
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1361
|
+
if (!opts.force) {
|
|
1362
|
+
const shouldDisplayWarning = hasPendingOrLiveDeployment(
|
|
1363
|
+
environmentsDetails,
|
|
1364
|
+
project.targetEnvironment
|
|
1365
|
+
);
|
|
1366
|
+
if (shouldDisplayWarning) {
|
|
1367
|
+
ctx.logger.log(boxen__default.default(cliConfig2.projectDeployment.confirmationText, boxenOptions));
|
|
1368
|
+
const { confirm } = await inquirer__default.default.prompt([
|
|
1369
|
+
{
|
|
1370
|
+
type: "confirm",
|
|
1371
|
+
name: "confirm",
|
|
1372
|
+
message: `Do you want to proceed with deployment to ${chalk__default.default.cyan(projectData.displayName)} on ${chalk__default.default.cyan(project.targetEnvironment)} environment?`
|
|
1373
|
+
}
|
|
1374
|
+
]);
|
|
1375
|
+
if (!confirm) {
|
|
1376
|
+
process.exit(1);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1164
1380
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1165
1381
|
if (!buildId) {
|
|
1166
1382
|
return;
|
|
1167
1383
|
}
|
|
1168
1384
|
try {
|
|
1385
|
+
ctx.logger.log(
|
|
1386
|
+
`🚀 Deploying project to ${chalk__default.default.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1387
|
+
);
|
|
1169
1388
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1170
1389
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1171
1390
|
ctx.logger.log(
|
|
@@ -1175,10 +1394,11 @@ const action$2 = async (ctx) => {
|
|
|
1175
1394
|
chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
1176
1395
|
);
|
|
1177
1396
|
} catch (e) {
|
|
1397
|
+
ctx.logger.debug(e);
|
|
1178
1398
|
if (e instanceof Error) {
|
|
1179
1399
|
ctx.logger.error(e.message);
|
|
1180
1400
|
} else {
|
|
1181
|
-
|
|
1401
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1182
1402
|
}
|
|
1183
1403
|
}
|
|
1184
1404
|
};
|
|
@@ -1209,17 +1429,179 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1209
1429
|
process.exit(1);
|
|
1210
1430
|
});
|
|
1211
1431
|
};
|
|
1212
|
-
const command$
|
|
1213
|
-
|
|
1432
|
+
const command$7 = ({ ctx }) => {
|
|
1433
|
+
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("-f, --force", "Skip confirmation to deploy").option("-e, --env <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$5)(ctx, opts));
|
|
1214
1434
|
};
|
|
1215
1435
|
const deployProject = {
|
|
1216
1436
|
name: "deploy-project",
|
|
1217
1437
|
description: "Deploy a Strapi Cloud project",
|
|
1218
|
-
action: action$
|
|
1219
|
-
command: command$
|
|
1438
|
+
action: action$5,
|
|
1439
|
+
command: command$7
|
|
1440
|
+
};
|
|
1441
|
+
async function getLocalConfig(ctx) {
|
|
1442
|
+
try {
|
|
1443
|
+
return await retrieve();
|
|
1444
|
+
} catch (e) {
|
|
1445
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1446
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
async function getLocalProject(ctx) {
|
|
1451
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1452
|
+
if (!localConfig || !localConfig.project) {
|
|
1453
|
+
ctx.logger.warn(
|
|
1454
|
+
`
|
|
1455
|
+
We couldn't find a valid local project config.
|
|
1456
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1457
|
+
"link"
|
|
1458
|
+
)} command.`
|
|
1459
|
+
);
|
|
1460
|
+
process.exit(1);
|
|
1461
|
+
}
|
|
1462
|
+
return localConfig.project;
|
|
1463
|
+
}
|
|
1464
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1465
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1466
|
+
if (existingConfig && existingConfig.project) {
|
|
1467
|
+
const { shouldRelink } = await inquirer__default.default.prompt([
|
|
1468
|
+
{
|
|
1469
|
+
type: "confirm",
|
|
1470
|
+
name: "shouldRelink",
|
|
1471
|
+
message: `A project named ${chalk__default.default.cyan(
|
|
1472
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1473
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1474
|
+
default: false
|
|
1475
|
+
}
|
|
1476
|
+
]);
|
|
1477
|
+
if (!shouldRelink) {
|
|
1478
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1479
|
+
currentProjectName: existingConfig.project?.name
|
|
1480
|
+
});
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return true;
|
|
1485
|
+
}
|
|
1486
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1487
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
1488
|
+
try {
|
|
1489
|
+
const {
|
|
1490
|
+
data: { data: projectList }
|
|
1491
|
+
} = await cloudApiService.listLinkProjects();
|
|
1492
|
+
spinner.succeed();
|
|
1493
|
+
if (!Array.isArray(projectList)) {
|
|
1494
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
const projects = projectList.filter(
|
|
1498
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1499
|
+
).map((project) => {
|
|
1500
|
+
return {
|
|
1501
|
+
name: project.displayName,
|
|
1502
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1503
|
+
};
|
|
1504
|
+
});
|
|
1505
|
+
if (projects.length === 0) {
|
|
1506
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1507
|
+
return null;
|
|
1508
|
+
}
|
|
1509
|
+
return projects;
|
|
1510
|
+
} catch (e) {
|
|
1511
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1512
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1513
|
+
return null;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
async function getUserSelection(ctx, projects) {
|
|
1517
|
+
const { logger } = ctx;
|
|
1518
|
+
try {
|
|
1519
|
+
const answer = await inquirer__default.default.prompt([
|
|
1520
|
+
{
|
|
1521
|
+
type: "list",
|
|
1522
|
+
name: "linkProject",
|
|
1523
|
+
message: "Which project do you want to link?",
|
|
1524
|
+
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1525
|
+
}
|
|
1526
|
+
]);
|
|
1527
|
+
if (!answer.linkProject) {
|
|
1528
|
+
return null;
|
|
1529
|
+
}
|
|
1530
|
+
return answer;
|
|
1531
|
+
} catch (e) {
|
|
1532
|
+
logger.debug("Failed to get user input", e);
|
|
1533
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
const action$4 = async (ctx) => {
|
|
1538
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1539
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1540
|
+
const { logger } = ctx;
|
|
1541
|
+
if (!token) {
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1545
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1546
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1547
|
+
if (!shouldRelink) {
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1551
|
+
const projects = await getProjectsList(
|
|
1552
|
+
ctx,
|
|
1553
|
+
cloudApiService,
|
|
1554
|
+
existingConfig
|
|
1555
|
+
);
|
|
1556
|
+
if (!projects) {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1560
|
+
if (!answer) {
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
try {
|
|
1564
|
+
const { confirmAction } = await inquirer__default.default.prompt([
|
|
1565
|
+
{
|
|
1566
|
+
type: "confirm",
|
|
1567
|
+
name: "confirmAction",
|
|
1568
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1569
|
+
default: false
|
|
1570
|
+
}
|
|
1571
|
+
]);
|
|
1572
|
+
if (!confirmAction) {
|
|
1573
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1574
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1575
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1576
|
+
});
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
await save({ project: answer.linkProject });
|
|
1580
|
+
logger.log(
|
|
1581
|
+
` You have successfully linked your project to ${chalk__default.default.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1582
|
+
);
|
|
1583
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1584
|
+
projectInternalName: answer.linkProject
|
|
1585
|
+
});
|
|
1586
|
+
} catch (e) {
|
|
1587
|
+
logger.debug("Failed to link project", e);
|
|
1588
|
+
logger.error("An error occurred while linking the project.");
|
|
1589
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1590
|
+
projectInternalName: answer.linkProject
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1220
1593
|
};
|
|
1221
|
-
const command$
|
|
1222
|
-
command2.command("cloud:
|
|
1594
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1595
|
+
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));
|
|
1596
|
+
};
|
|
1597
|
+
const link = {
|
|
1598
|
+
name: "link-project",
|
|
1599
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1600
|
+
action: action$4,
|
|
1601
|
+
command: command$6
|
|
1602
|
+
};
|
|
1603
|
+
const command$5 = ({ ctx }) => {
|
|
1604
|
+
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1223
1605
|
"after",
|
|
1224
1606
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1225
1607
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1228,10 +1610,10 @@ const login = {
|
|
|
1228
1610
|
name: "login",
|
|
1229
1611
|
description: "Strapi Cloud Login",
|
|
1230
1612
|
action: loginAction,
|
|
1231
|
-
command: command$
|
|
1613
|
+
command: command$5
|
|
1232
1614
|
};
|
|
1233
1615
|
const openModule = import("open");
|
|
1234
|
-
const action$
|
|
1616
|
+
const action$3 = async (ctx) => {
|
|
1235
1617
|
const { logger } = ctx;
|
|
1236
1618
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1237
1619
|
const token = await retrieveToken();
|
|
@@ -1261,31 +1643,27 @@ const action$1 = async (ctx) => {
|
|
|
1261
1643
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1262
1644
|
logger.debug(e);
|
|
1263
1645
|
}
|
|
1264
|
-
|
|
1265
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1266
|
-
} catch (e) {
|
|
1267
|
-
logger.debug("Failed to track logout event", e);
|
|
1268
|
-
}
|
|
1646
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1269
1647
|
};
|
|
1270
|
-
const command$
|
|
1271
|
-
|
|
1648
|
+
const command$4 = ({ ctx }) => {
|
|
1649
|
+
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));
|
|
1272
1650
|
};
|
|
1273
1651
|
const logout = {
|
|
1274
1652
|
name: "logout",
|
|
1275
1653
|
description: "Strapi Cloud Logout",
|
|
1276
|
-
action: action$
|
|
1277
|
-
command: command$
|
|
1654
|
+
action: action$3,
|
|
1655
|
+
command: command$4
|
|
1278
1656
|
};
|
|
1279
|
-
const command$
|
|
1280
|
-
|
|
1657
|
+
const command$3 = ({ ctx }) => {
|
|
1658
|
+
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));
|
|
1281
1659
|
};
|
|
1282
1660
|
const createProject = {
|
|
1283
1661
|
name: "create-project",
|
|
1284
1662
|
description: "Create a new project",
|
|
1285
|
-
action: action$
|
|
1286
|
-
command: command$
|
|
1663
|
+
action: action$6,
|
|
1664
|
+
command: command$3
|
|
1287
1665
|
};
|
|
1288
|
-
const action = async (ctx) => {
|
|
1666
|
+
const action$2 = async (ctx) => {
|
|
1289
1667
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1290
1668
|
const token = await getValidToken(ctx, promptLogin);
|
|
1291
1669
|
const { logger } = ctx;
|
|
@@ -1305,25 +1683,218 @@ const action = async (ctx) => {
|
|
|
1305
1683
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1306
1684
|
}
|
|
1307
1685
|
};
|
|
1308
|
-
const command = ({ command: command2, ctx }) => {
|
|
1309
|
-
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("
|
|
1686
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1687
|
+
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));
|
|
1310
1688
|
};
|
|
1311
1689
|
const listProjects = {
|
|
1312
1690
|
name: "list-projects",
|
|
1313
1691
|
description: "List Strapi Cloud projects",
|
|
1692
|
+
action: action$2,
|
|
1693
|
+
command: command$2
|
|
1694
|
+
};
|
|
1695
|
+
const action$1 = async (ctx) => {
|
|
1696
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1697
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1698
|
+
const { logger } = ctx;
|
|
1699
|
+
if (!token) {
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
const project = await getLocalProject(ctx);
|
|
1703
|
+
if (!project) {
|
|
1704
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1708
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1709
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1710
|
+
projectInternalName: project.name
|
|
1711
|
+
});
|
|
1712
|
+
try {
|
|
1713
|
+
const {
|
|
1714
|
+
data: { data: environmentsList }
|
|
1715
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1716
|
+
spinner.succeed();
|
|
1717
|
+
logger.log(environmentsList);
|
|
1718
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1719
|
+
projectInternalName: project.name
|
|
1720
|
+
});
|
|
1721
|
+
} catch (e) {
|
|
1722
|
+
if (e.response && e.response.status === 404) {
|
|
1723
|
+
spinner.succeed();
|
|
1724
|
+
logger.warn(
|
|
1725
|
+
`
|
|
1726
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1727
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1728
|
+
"link"
|
|
1729
|
+
)} command`
|
|
1730
|
+
);
|
|
1731
|
+
} else {
|
|
1732
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1733
|
+
logger.debug("Failed to list environments", e);
|
|
1734
|
+
}
|
|
1735
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1736
|
+
projectInternalName: project.name
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1741
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1742
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1743
|
+
return cloud;
|
|
1744
|
+
}
|
|
1745
|
+
let environmentCmd = null;
|
|
1746
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1747
|
+
if (!environmentCmd) {
|
|
1748
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1749
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1750
|
+
}
|
|
1751
|
+
return environmentCmd;
|
|
1752
|
+
};
|
|
1753
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1754
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1755
|
+
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));
|
|
1756
|
+
};
|
|
1757
|
+
const listEnvironments = {
|
|
1758
|
+
name: "list-environments",
|
|
1759
|
+
description: "List Strapi Cloud environments",
|
|
1760
|
+
action: action$1,
|
|
1761
|
+
command: command$1
|
|
1762
|
+
};
|
|
1763
|
+
const QUIT_OPTION = "Quit";
|
|
1764
|
+
const action = async (ctx) => {
|
|
1765
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1766
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1767
|
+
const { logger } = ctx;
|
|
1768
|
+
if (!token) {
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
const project = await getLocalProject(ctx);
|
|
1772
|
+
if (!project) {
|
|
1773
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1777
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1778
|
+
if (!environments) {
|
|
1779
|
+
logger.debug(`Fetching environments failed.`);
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
if (environments.length === 0) {
|
|
1783
|
+
logger.log(
|
|
1784
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1785
|
+
);
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1789
|
+
if (!answer) {
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1793
|
+
projectName: project.name,
|
|
1794
|
+
environmentName: answer.targetEnvironment
|
|
1795
|
+
});
|
|
1796
|
+
try {
|
|
1797
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1798
|
+
} catch (e) {
|
|
1799
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1800
|
+
projectName: project.name,
|
|
1801
|
+
environmentName: answer.targetEnvironment
|
|
1802
|
+
});
|
|
1803
|
+
logger.debug("Failed to link environment", e);
|
|
1804
|
+
logger.error(
|
|
1805
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1806
|
+
);
|
|
1807
|
+
process.exit(1);
|
|
1808
|
+
}
|
|
1809
|
+
logger.log(
|
|
1810
|
+
` 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.`
|
|
1811
|
+
);
|
|
1812
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1813
|
+
projectName: project.name,
|
|
1814
|
+
environmentName: answer.targetEnvironment
|
|
1815
|
+
});
|
|
1816
|
+
};
|
|
1817
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1818
|
+
const { logger } = ctx;
|
|
1819
|
+
try {
|
|
1820
|
+
const answer = await inquirer__default.default.prompt([
|
|
1821
|
+
{
|
|
1822
|
+
type: "list",
|
|
1823
|
+
name: "targetEnvironment",
|
|
1824
|
+
message: "Which environment do you want to link?",
|
|
1825
|
+
choices: [...environments, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1826
|
+
}
|
|
1827
|
+
]);
|
|
1828
|
+
if (!answer.targetEnvironment) {
|
|
1829
|
+
return null;
|
|
1830
|
+
}
|
|
1831
|
+
return answer;
|
|
1832
|
+
} catch (e) {
|
|
1833
|
+
logger.debug("Failed to get user input", e);
|
|
1834
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1835
|
+
return null;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1839
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1840
|
+
try {
|
|
1841
|
+
const {
|
|
1842
|
+
data: { data: environmentsList }
|
|
1843
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1844
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1845
|
+
throw new Error("Environments not found in server response");
|
|
1846
|
+
}
|
|
1847
|
+
spinner.succeed();
|
|
1848
|
+
return environmentsList.filter(
|
|
1849
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1850
|
+
);
|
|
1851
|
+
} catch (e) {
|
|
1852
|
+
if (e.response && e.response.status === 404) {
|
|
1853
|
+
spinner.succeed();
|
|
1854
|
+
ctx.logger.warn(
|
|
1855
|
+
`
|
|
1856
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1857
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1858
|
+
"link"
|
|
1859
|
+
)} command.`
|
|
1860
|
+
);
|
|
1861
|
+
} else {
|
|
1862
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1863
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
const command = ({ command: command2, ctx }) => {
|
|
1868
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1869
|
+
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));
|
|
1870
|
+
};
|
|
1871
|
+
const linkEnvironment = {
|
|
1872
|
+
name: "link-environment",
|
|
1873
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1314
1874
|
action,
|
|
1315
1875
|
command
|
|
1316
1876
|
};
|
|
1317
1877
|
const cli = {
|
|
1318
1878
|
deployProject,
|
|
1879
|
+
link,
|
|
1319
1880
|
login,
|
|
1320
1881
|
logout,
|
|
1321
1882
|
createProject,
|
|
1322
|
-
|
|
1883
|
+
linkEnvironment,
|
|
1884
|
+
listProjects,
|
|
1885
|
+
listEnvironments
|
|
1323
1886
|
};
|
|
1324
|
-
const cloudCommands = [
|
|
1887
|
+
const cloudCommands = [
|
|
1888
|
+
deployProject,
|
|
1889
|
+
link,
|
|
1890
|
+
login,
|
|
1891
|
+
logout,
|
|
1892
|
+
linkEnvironment,
|
|
1893
|
+
listProjects,
|
|
1894
|
+
listEnvironments
|
|
1895
|
+
];
|
|
1325
1896
|
async function initCloudCLIConfig() {
|
|
1326
|
-
const localConfig = await getLocalConfig();
|
|
1897
|
+
const localConfig = await getLocalConfig$1();
|
|
1327
1898
|
if (!localConfig.deviceId) {
|
|
1328
1899
|
localConfig.deviceId = crypto__default.default.randomUUID();
|
|
1329
1900
|
}
|
|
@@ -1337,7 +1908,10 @@ async function buildStrapiCloudCommands({
|
|
|
1337
1908
|
await initCloudCLIConfig();
|
|
1338
1909
|
for (const cloudCommand of cloudCommands) {
|
|
1339
1910
|
try {
|
|
1340
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1911
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1912
|
+
if (subCommand) {
|
|
1913
|
+
command2.addCommand(subCommand);
|
|
1914
|
+
}
|
|
1341
1915
|
} catch (e) {
|
|
1342
1916
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1343
1917
|
}
|