@strapi/cloud-cli 0.0.0-next.84f5cfd43cfdb85f000d388b196a36d874382dab → 0.0.0-next.852f43d1ddd36786b695b80b6dbef65a785954e4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +441 -142
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +441 -139
- package/dist/index.mjs.map +1 -1
- package/dist/src/create-project/action.d.ts.map +1 -1
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts +3 -0
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts.map +1 -0
- 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.map +1 -1
- package/dist/src/index.d.ts +2 -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/list-projects/action.d.ts +4 -0
- package/dist/src/list-projects/action.d.ts.map +1 -0
- package/dist/src/list-projects/command.d.ts +7 -0
- package/dist/src/list-projects/command.d.ts.map +1 -0
- package/dist/src/list-projects/index.d.ts +7 -0
- package/dist/src/list-projects/index.d.ts.map +1 -0
- package/dist/src/login/action.d.ts.map +1 -1
- package/dist/src/logout/action.d.ts.map +1 -1
- package/dist/src/services/build-logs.d.ts.map +1 -1
- package/dist/src/services/cli-api.d.ts +35 -7
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/services/strapi-info-save.d.ts +1 -1
- package/dist/src/services/strapi-info-save.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -0
- 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/compress-files.d.ts.map +1 -1
- package/dist/src/utils/pkg.d.ts.map +1 -1
- package/package.json +7 -6
- package/dist/src/utils/tests/compress-files.test.d.ts +0 -2
- package/dist/src/utils/tests/compress-files.test.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import crypto$1 from "crypto";
|
|
2
|
-
import fse from "fs-extra";
|
|
2
|
+
import * as fse from "fs-extra";
|
|
3
|
+
import fse__default from "fs-extra";
|
|
3
4
|
import * as path from "path";
|
|
4
5
|
import path__default from "path";
|
|
5
6
|
import chalk from "chalk";
|
|
6
7
|
import axios, { AxiosError } from "axios";
|
|
7
8
|
import * as crypto from "node:crypto";
|
|
8
9
|
import { env } from "@strapi/utils";
|
|
9
|
-
import * as fs from "fs";
|
|
10
10
|
import * as tar from "tar";
|
|
11
11
|
import { minimatch } from "minimatch";
|
|
12
12
|
import inquirer from "inquirer";
|
|
@@ -18,10 +18,9 @@ import jwt from "jsonwebtoken";
|
|
|
18
18
|
import stringify from "fast-safe-stringify";
|
|
19
19
|
import ora from "ora";
|
|
20
20
|
import * as cliProgress from "cli-progress";
|
|
21
|
-
import EventSource from "eventsource";
|
|
22
|
-
import fs$1 from "fs/promises";
|
|
23
21
|
import pkgUp from "pkg-up";
|
|
24
22
|
import * as yup from "yup";
|
|
23
|
+
import EventSource from "eventsource";
|
|
25
24
|
const apiConfig = {
|
|
26
25
|
apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
27
26
|
dashboardBaseUrl: env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -40,23 +39,6 @@ const IGNORED_PATTERNS = [
|
|
|
40
39
|
"**/.idea/**",
|
|
41
40
|
"**/.vscode/**"
|
|
42
41
|
];
|
|
43
|
-
const getFiles = (dirPath, ignorePatterns = [], arrayOfFiles = [], subfolder = "") => {
|
|
44
|
-
const entries = fs.readdirSync(path.join(dirPath, subfolder));
|
|
45
|
-
entries.forEach((entry) => {
|
|
46
|
-
const entryPathFromRoot = path.join(subfolder, entry);
|
|
47
|
-
const entryPath = path.relative(dirPath, entryPathFromRoot);
|
|
48
|
-
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
49
|
-
if (isIgnored) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (fs.statSync(entryPath).isDirectory()) {
|
|
53
|
-
getFiles(dirPath, ignorePatterns, arrayOfFiles, entryPathFromRoot);
|
|
54
|
-
} else {
|
|
55
|
-
arrayOfFiles.push(entryPath);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return arrayOfFiles;
|
|
59
|
-
};
|
|
60
42
|
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
61
43
|
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
62
44
|
const relativeFilePath = path.join(folderPath, file);
|
|
@@ -74,16 +56,35 @@ const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
|
74
56
|
}
|
|
75
57
|
return isIgnored;
|
|
76
58
|
};
|
|
77
|
-
const
|
|
59
|
+
const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
60
|
+
const arrayOfFiles = [];
|
|
61
|
+
const entries = await fse.readdir(path.join(dirPath, subfolder));
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
const entryPathFromRoot = path.join(subfolder, entry);
|
|
64
|
+
const entryPath = path.relative(dirPath, entryPathFromRoot);
|
|
65
|
+
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
66
|
+
if (!isIgnored) {
|
|
67
|
+
if (fse.statSync(entryPath).isDirectory()) {
|
|
68
|
+
const subFiles = await getFiles(dirPath, ignorePatterns, entryPathFromRoot);
|
|
69
|
+
arrayOfFiles.push(...subFiles);
|
|
70
|
+
} else {
|
|
71
|
+
arrayOfFiles.push(entryPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return arrayOfFiles;
|
|
76
|
+
};
|
|
77
|
+
const readGitignore = async (folderPath) => {
|
|
78
78
|
const gitignorePath = path.resolve(folderPath, ".gitignore");
|
|
79
|
-
|
|
79
|
+
const pathExist = await fse.pathExists(gitignorePath);
|
|
80
|
+
if (!pathExist)
|
|
80
81
|
return [];
|
|
81
|
-
const gitignoreContent =
|
|
82
|
+
const gitignoreContent = await fse.readFile(gitignorePath, "utf8");
|
|
82
83
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
83
84
|
};
|
|
84
85
|
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
85
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
86
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
86
|
+
const ignorePatterns = await readGitignore(folderToCompress);
|
|
87
|
+
const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
|
|
87
88
|
return tar.c(
|
|
88
89
|
{
|
|
89
90
|
gzip: true,
|
|
@@ -96,7 +97,7 @@ const APP_FOLDER_NAME = "com.strapi.cli";
|
|
|
96
97
|
const CONFIG_FILENAME = "config.json";
|
|
97
98
|
async function checkDirectoryExists(directoryPath) {
|
|
98
99
|
try {
|
|
99
|
-
const fsStat = await
|
|
100
|
+
const fsStat = await fse__default.lstat(directoryPath);
|
|
100
101
|
return fsStat.isDirectory();
|
|
101
102
|
} catch (e) {
|
|
102
103
|
return false;
|
|
@@ -104,14 +105,14 @@ async function checkDirectoryExists(directoryPath) {
|
|
|
104
105
|
}
|
|
105
106
|
async function getTmpStoragePath() {
|
|
106
107
|
const storagePath = path__default.join(os.tmpdir(), APP_FOLDER_NAME);
|
|
107
|
-
await
|
|
108
|
+
await fse__default.ensureDir(storagePath);
|
|
108
109
|
return storagePath;
|
|
109
110
|
}
|
|
110
111
|
async function getConfigPath() {
|
|
111
112
|
const configDirs = XDGAppPaths(APP_FOLDER_NAME).configDirs();
|
|
112
113
|
const configPath = configDirs.find(checkDirectoryExists);
|
|
113
114
|
if (!configPath) {
|
|
114
|
-
await
|
|
115
|
+
await fse__default.ensureDir(configDirs[0]);
|
|
115
116
|
return configDirs[0];
|
|
116
117
|
}
|
|
117
118
|
return configPath;
|
|
@@ -119,9 +120,9 @@ async function getConfigPath() {
|
|
|
119
120
|
async function getLocalConfig() {
|
|
120
121
|
const configPath = await getConfigPath();
|
|
121
122
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
122
|
-
await
|
|
123
|
+
await fse__default.ensureFile(configFilePath);
|
|
123
124
|
try {
|
|
124
|
-
return await
|
|
125
|
+
return await fse__default.readJSON(configFilePath, { encoding: "utf8", throws: true });
|
|
125
126
|
} catch (e) {
|
|
126
127
|
return {};
|
|
127
128
|
}
|
|
@@ -129,10 +130,10 @@ async function getLocalConfig() {
|
|
|
129
130
|
async function saveLocalConfig(data) {
|
|
130
131
|
const configPath = await getConfigPath();
|
|
131
132
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
132
|
-
await
|
|
133
|
+
await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
133
134
|
}
|
|
134
135
|
const name = "@strapi/cloud-cli";
|
|
135
|
-
const version = "4.25.
|
|
136
|
+
const version = "4.25.10";
|
|
136
137
|
const description = "Commands to interact with the Strapi Cloud";
|
|
137
138
|
const keywords = [
|
|
138
139
|
"strapi",
|
|
@@ -173,11 +174,12 @@ const scripts = {
|
|
|
173
174
|
build: "pack-up build",
|
|
174
175
|
clean: "run -T rimraf ./dist",
|
|
175
176
|
lint: "run -T eslint .",
|
|
177
|
+
"test:unit": "run -T jest",
|
|
176
178
|
watch: "pack-up watch"
|
|
177
179
|
};
|
|
178
180
|
const dependencies = {
|
|
179
|
-
"@strapi/utils": "4.25.
|
|
180
|
-
axios: "1.
|
|
181
|
+
"@strapi/utils": "4.25.10",
|
|
182
|
+
axios: "1.7.4",
|
|
181
183
|
chalk: "4.1.2",
|
|
182
184
|
"cli-progress": "3.12.0",
|
|
183
185
|
commander: "8.3.0",
|
|
@@ -201,8 +203,8 @@ const devDependencies = {
|
|
|
201
203
|
"@types/cli-progress": "3.11.5",
|
|
202
204
|
"@types/eventsource": "1.1.15",
|
|
203
205
|
"@types/lodash": "^4.14.191",
|
|
204
|
-
"eslint-config-custom": "4.25.
|
|
205
|
-
tsconfig: "4.25.
|
|
206
|
+
"eslint-config-custom": "4.25.10",
|
|
207
|
+
tsconfig: "4.25.10"
|
|
206
208
|
};
|
|
207
209
|
const engines = {
|
|
208
210
|
node: ">=18.0.0 <=20.x.x",
|
|
@@ -255,7 +257,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
255
257
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
256
258
|
return axiosCloudAPI.post(
|
|
257
259
|
`/deploy/${project.name}`,
|
|
258
|
-
{ file:
|
|
260
|
+
{ file: fse__default.createReadStream(filePath) },
|
|
259
261
|
{
|
|
260
262
|
headers: {
|
|
261
263
|
"Content-Type": "multipart/form-data"
|
|
@@ -298,8 +300,47 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
298
300
|
throw error;
|
|
299
301
|
}
|
|
300
302
|
},
|
|
301
|
-
listProjects() {
|
|
302
|
-
|
|
303
|
+
async listProjects() {
|
|
304
|
+
try {
|
|
305
|
+
const response = await axiosCloudAPI.get("/projects");
|
|
306
|
+
if (response.status !== 200) {
|
|
307
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
308
|
+
}
|
|
309
|
+
return response;
|
|
310
|
+
} catch (error) {
|
|
311
|
+
logger.debug(
|
|
312
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
313
|
+
);
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
async listLinkProjects() {
|
|
318
|
+
try {
|
|
319
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
320
|
+
if (response.status !== 200) {
|
|
321
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
322
|
+
}
|
|
323
|
+
return response;
|
|
324
|
+
} catch (error) {
|
|
325
|
+
logger.debug(
|
|
326
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
327
|
+
);
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
async getProject({ name: name2 }) {
|
|
332
|
+
try {
|
|
333
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
334
|
+
if (response.status !== 200) {
|
|
335
|
+
throw new Error("Error fetching project's details.");
|
|
336
|
+
}
|
|
337
|
+
return response;
|
|
338
|
+
} catch (error) {
|
|
339
|
+
logger.debug(
|
|
340
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
341
|
+
);
|
|
342
|
+
throw error;
|
|
343
|
+
}
|
|
303
344
|
},
|
|
304
345
|
track(event, payload = {}) {
|
|
305
346
|
return axiosCloudAPI.post("/track", {
|
|
@@ -314,18 +355,18 @@ async function save(data, { directoryPath } = {}) {
|
|
|
314
355
|
const alreadyInFileData = await retrieve({ directoryPath });
|
|
315
356
|
const storedData = { ...alreadyInFileData, ...data };
|
|
316
357
|
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
317
|
-
await
|
|
318
|
-
await
|
|
358
|
+
await fse__default.ensureDir(path__default.dirname(pathToFile));
|
|
359
|
+
await fse__default.writeJson(pathToFile, storedData, { encoding: "utf8" });
|
|
319
360
|
}
|
|
320
361
|
async function retrieve({
|
|
321
362
|
directoryPath
|
|
322
363
|
} = {}) {
|
|
323
364
|
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
324
|
-
const pathExists = await
|
|
365
|
+
const pathExists = await fse__default.pathExists(pathToFile);
|
|
325
366
|
if (!pathExists) {
|
|
326
367
|
return {};
|
|
327
368
|
}
|
|
328
|
-
return
|
|
369
|
+
return fse__default.readJSON(pathToFile, { encoding: "utf8" });
|
|
329
370
|
}
|
|
330
371
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
331
372
|
__proto__: null,
|
|
@@ -570,6 +611,53 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
570
611
|
local: strapiInfoSave,
|
|
571
612
|
tokenServiceFactory
|
|
572
613
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
614
|
+
yup.object({
|
|
615
|
+
name: yup.string().required(),
|
|
616
|
+
exports: yup.lazy(
|
|
617
|
+
(value) => yup.object(
|
|
618
|
+
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
619
|
+
if (typeof value2 === "object") {
|
|
620
|
+
acc[key] = yup.object({
|
|
621
|
+
types: yup.string().optional(),
|
|
622
|
+
source: yup.string().required(),
|
|
623
|
+
module: yup.string().optional(),
|
|
624
|
+
import: yup.string().required(),
|
|
625
|
+
require: yup.string().required(),
|
|
626
|
+
default: yup.string().required()
|
|
627
|
+
}).noUnknown(true);
|
|
628
|
+
} else {
|
|
629
|
+
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
630
|
+
}
|
|
631
|
+
return acc;
|
|
632
|
+
}, {}) : void 0
|
|
633
|
+
).optional()
|
|
634
|
+
)
|
|
635
|
+
});
|
|
636
|
+
const loadPkg = async ({ cwd, logger }) => {
|
|
637
|
+
const pkgPath = await pkgUp({ cwd });
|
|
638
|
+
if (!pkgPath) {
|
|
639
|
+
throw new Error("Could not find a package.json in the current directory");
|
|
640
|
+
}
|
|
641
|
+
const buffer = await fse.readFile(pkgPath);
|
|
642
|
+
const pkg = JSON.parse(buffer.toString());
|
|
643
|
+
logger.debug("Loaded package.json:", os.EOL, pkg);
|
|
644
|
+
return pkg;
|
|
645
|
+
};
|
|
646
|
+
async function getProjectNameFromPackageJson(ctx) {
|
|
647
|
+
try {
|
|
648
|
+
const packageJson2 = await loadPkg(ctx);
|
|
649
|
+
return packageJson2.name || "my-strapi-project";
|
|
650
|
+
} catch (e) {
|
|
651
|
+
return "my-strapi-project";
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
655
|
+
try {
|
|
656
|
+
await cloudApiService.track(eventName, eventData);
|
|
657
|
+
} catch (e) {
|
|
658
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
659
|
+
}
|
|
660
|
+
};
|
|
573
661
|
const openModule$1 = import("open");
|
|
574
662
|
async function promptLogin(ctx) {
|
|
575
663
|
const response = await inquirer.prompt([
|
|
@@ -590,13 +678,6 @@ async function loginAction(ctx) {
|
|
|
590
678
|
const tokenService = await tokenServiceFactory(ctx);
|
|
591
679
|
const existingToken = await tokenService.retrieveToken();
|
|
592
680
|
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
593
|
-
const trackFailedLogin = async () => {
|
|
594
|
-
try {
|
|
595
|
-
await cloudApiService.track("didNotLogin", { loginMethod: "cli" });
|
|
596
|
-
} catch (e) {
|
|
597
|
-
logger.debug("Failed to track failed login", e);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
681
|
if (existingToken) {
|
|
601
682
|
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
602
683
|
if (isTokenValid) {
|
|
@@ -628,11 +709,7 @@ async function loginAction(ctx) {
|
|
|
628
709
|
logger.debug(e);
|
|
629
710
|
return false;
|
|
630
711
|
}
|
|
631
|
-
|
|
632
|
-
await cloudApiService.track("willLoginAttempt", {});
|
|
633
|
-
} catch (e) {
|
|
634
|
-
logger.debug("Failed to track login attempt", e);
|
|
635
|
-
}
|
|
712
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
636
713
|
logger.debug("🔐 Creating device authentication request...", {
|
|
637
714
|
client_id: cliConfig2.clientId,
|
|
638
715
|
scope: cliConfig2.scope,
|
|
@@ -712,13 +789,13 @@ async function loginAction(ctx) {
|
|
|
712
789
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
713
790
|
);
|
|
714
791
|
spinnerFail();
|
|
715
|
-
await
|
|
792
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
716
793
|
return false;
|
|
717
794
|
}
|
|
718
795
|
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
719
796
|
logger.debug(e);
|
|
720
797
|
spinnerFail();
|
|
721
|
-
await
|
|
798
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
722
799
|
return false;
|
|
723
800
|
}
|
|
724
801
|
await new Promise((resolve) => {
|
|
@@ -732,15 +809,50 @@ async function loginAction(ctx) {
|
|
|
732
809
|
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
733
810
|
);
|
|
734
811
|
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
735
|
-
|
|
736
|
-
await cloudApiService.track("didLogin", { loginMethod: "cli" });
|
|
737
|
-
} catch (e) {
|
|
738
|
-
logger.debug("Failed to track login", e);
|
|
739
|
-
}
|
|
812
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
740
813
|
};
|
|
741
814
|
await authenticate();
|
|
742
815
|
return isAuthenticated;
|
|
743
816
|
}
|
|
817
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
818
|
+
return (questions) => {
|
|
819
|
+
return questions.map((question) => {
|
|
820
|
+
const questionName = question.name;
|
|
821
|
+
if (questionName in questionsMap) {
|
|
822
|
+
const questionDefault = questionsMap[questionName];
|
|
823
|
+
if (typeof questionDefault === "function") {
|
|
824
|
+
return {
|
|
825
|
+
...question,
|
|
826
|
+
default: questionDefault(question)
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
return {
|
|
830
|
+
...question,
|
|
831
|
+
default: questionDefault
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
return question;
|
|
835
|
+
});
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
function getDefaultsFromQuestions(questions) {
|
|
839
|
+
return questions.reduce((acc, question) => {
|
|
840
|
+
if (question.default && question.name) {
|
|
841
|
+
return { ...acc, [question.name]: question.default };
|
|
842
|
+
}
|
|
843
|
+
return acc;
|
|
844
|
+
}, {});
|
|
845
|
+
}
|
|
846
|
+
function getProjectNodeVersionDefault(question) {
|
|
847
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
848
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
849
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
850
|
+
if (choice) {
|
|
851
|
+
return choice.value;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return question.default;
|
|
855
|
+
}
|
|
744
856
|
async function handleError(ctx, error) {
|
|
745
857
|
const { logger } = ctx;
|
|
746
858
|
logger.debug(error);
|
|
@@ -785,7 +897,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
785
897
|
throw e;
|
|
786
898
|
}
|
|
787
899
|
}
|
|
788
|
-
const action$
|
|
900
|
+
const action$4 = async (ctx) => {
|
|
789
901
|
const { logger } = ctx;
|
|
790
902
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
791
903
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -794,7 +906,16 @@ const action$2 = async (ctx) => {
|
|
|
794
906
|
}
|
|
795
907
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
796
908
|
const { data: config } = await cloudApi.config();
|
|
797
|
-
const
|
|
909
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
910
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
911
|
+
name: projectName,
|
|
912
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
913
|
+
});
|
|
914
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
915
|
+
const defaultValues = {
|
|
916
|
+
...config.projectCreation.defaults,
|
|
917
|
+
...getDefaultsFromQuestions(questions)
|
|
918
|
+
};
|
|
798
919
|
const projectAnswersDefaulted = defaults(defaultValues);
|
|
799
920
|
const projectAnswers = await inquirer.prompt(questions);
|
|
800
921
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -843,38 +964,6 @@ function notificationServiceFactory({ logger }) {
|
|
|
843
964
|
};
|
|
844
965
|
};
|
|
845
966
|
}
|
|
846
|
-
yup.object({
|
|
847
|
-
name: yup.string().required(),
|
|
848
|
-
exports: yup.lazy(
|
|
849
|
-
(value) => yup.object(
|
|
850
|
-
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
851
|
-
if (typeof value2 === "object") {
|
|
852
|
-
acc[key] = yup.object({
|
|
853
|
-
types: yup.string().optional(),
|
|
854
|
-
source: yup.string().required(),
|
|
855
|
-
module: yup.string().optional(),
|
|
856
|
-
import: yup.string().required(),
|
|
857
|
-
require: yup.string().required(),
|
|
858
|
-
default: yup.string().required()
|
|
859
|
-
}).noUnknown(true);
|
|
860
|
-
} else {
|
|
861
|
-
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
862
|
-
}
|
|
863
|
-
return acc;
|
|
864
|
-
}, {}) : void 0
|
|
865
|
-
).optional()
|
|
866
|
-
)
|
|
867
|
-
});
|
|
868
|
-
const loadPkg = async ({ cwd, logger }) => {
|
|
869
|
-
const pkgPath = await pkgUp({ cwd });
|
|
870
|
-
if (!pkgPath) {
|
|
871
|
-
throw new Error("Could not find a package.json in the current directory");
|
|
872
|
-
}
|
|
873
|
-
const buffer = await fs$1.readFile(pkgPath);
|
|
874
|
-
const pkg = JSON.parse(buffer.toString());
|
|
875
|
-
logger.debug("Loaded package.json:", os.EOL, pkg);
|
|
876
|
-
return pkg;
|
|
877
|
-
};
|
|
878
967
|
const buildLogsServiceFactory = ({ logger }) => {
|
|
879
968
|
return async (url, token, cliConfig2) => {
|
|
880
969
|
const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
|
|
@@ -928,6 +1017,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
928
1017
|
if (retries > MAX_RETRIES) {
|
|
929
1018
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
930
1019
|
es.close();
|
|
1020
|
+
clearExistingTimeout();
|
|
931
1021
|
reject(new Error("Max retries reached"));
|
|
932
1022
|
}
|
|
933
1023
|
};
|
|
@@ -970,13 +1060,13 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
970
1060
|
process.exit(1);
|
|
971
1061
|
}
|
|
972
1062
|
const tarFilePath = path__default.resolve(storagePath, compressedFilename);
|
|
973
|
-
const fileStats = await
|
|
1063
|
+
const fileStats = await fse__default.stat(tarFilePath);
|
|
974
1064
|
if (fileStats.size > maxProjectFileSize) {
|
|
975
1065
|
ctx.logger.log(
|
|
976
1066
|
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
977
1067
|
);
|
|
978
1068
|
try {
|
|
979
|
-
await
|
|
1069
|
+
await fse__default.remove(tarFilePath);
|
|
980
1070
|
} catch (e) {
|
|
981
1071
|
ctx.logger.log("Unable to remove file: ", tarFilePath);
|
|
982
1072
|
ctx.logger.debug(e);
|
|
@@ -1002,20 +1092,10 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1002
1092
|
return data.build_id;
|
|
1003
1093
|
} catch (e) {
|
|
1004
1094
|
progressBar.stop();
|
|
1005
|
-
|
|
1006
|
-
if (e.response.status === 404) {
|
|
1007
|
-
ctx.logger.error(
|
|
1008
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
1009
|
-
);
|
|
1010
|
-
} else {
|
|
1011
|
-
ctx.logger.error(e.response.data);
|
|
1012
|
-
}
|
|
1013
|
-
} else {
|
|
1014
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1015
|
-
}
|
|
1095
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1016
1096
|
ctx.logger.debug(e);
|
|
1017
1097
|
} finally {
|
|
1018
|
-
await
|
|
1098
|
+
await fse__default.remove(tarFilePath);
|
|
1019
1099
|
}
|
|
1020
1100
|
process.exit(0);
|
|
1021
1101
|
} catch (e) {
|
|
@@ -1028,7 +1108,7 @@ async function getProject(ctx) {
|
|
|
1028
1108
|
const { project } = await retrieve();
|
|
1029
1109
|
if (!project) {
|
|
1030
1110
|
try {
|
|
1031
|
-
return await action$
|
|
1111
|
+
return await action$4(ctx);
|
|
1032
1112
|
} catch (e) {
|
|
1033
1113
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1034
1114
|
ctx.logger.debug(e);
|
|
@@ -1037,7 +1117,19 @@ async function getProject(ctx) {
|
|
|
1037
1117
|
}
|
|
1038
1118
|
return project;
|
|
1039
1119
|
}
|
|
1040
|
-
|
|
1120
|
+
async function getConfig({
|
|
1121
|
+
ctx,
|
|
1122
|
+
cloudApiService
|
|
1123
|
+
}) {
|
|
1124
|
+
try {
|
|
1125
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1126
|
+
return cliConfig2;
|
|
1127
|
+
} catch (e) {
|
|
1128
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1129
|
+
return null;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
const action$3 = async (ctx) => {
|
|
1041
1133
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1042
1134
|
const token = await getValidToken(ctx, promptLogin);
|
|
1043
1135
|
if (!token) {
|
|
@@ -1047,15 +1139,51 @@ const action$1 = async (ctx) => {
|
|
|
1047
1139
|
if (!project) {
|
|
1048
1140
|
return;
|
|
1049
1141
|
}
|
|
1050
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1142
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1051
1143
|
try {
|
|
1052
|
-
|
|
1144
|
+
const {
|
|
1145
|
+
data: { data: projectData, metadata }
|
|
1146
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1147
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1148
|
+
if (isProjectSuspended) {
|
|
1149
|
+
ctx.logger.log(
|
|
1150
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1151
|
+
);
|
|
1152
|
+
ctx.logger.log(chalk.underline(`${metadata.dashboardUrls.project}`));
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1053
1155
|
} catch (e) {
|
|
1054
|
-
|
|
1156
|
+
if (e instanceof AxiosError && e.response?.data) {
|
|
1157
|
+
if (e.response.status === 404) {
|
|
1158
|
+
ctx.logger.warn(
|
|
1159
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1160
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1161
|
+
"link"
|
|
1162
|
+
)} command before deploying.`
|
|
1163
|
+
);
|
|
1164
|
+
} else {
|
|
1165
|
+
ctx.logger.error(e.response.data);
|
|
1166
|
+
}
|
|
1167
|
+
} else {
|
|
1168
|
+
ctx.logger.error(
|
|
1169
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
ctx.logger.debug(e);
|
|
1173
|
+
return;
|
|
1055
1174
|
}
|
|
1175
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1176
|
+
projectInternalName: project.name
|
|
1177
|
+
});
|
|
1056
1178
|
const notificationService = notificationServiceFactory(ctx);
|
|
1057
1179
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
1058
|
-
const
|
|
1180
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1181
|
+
if (!cliConfig2) {
|
|
1182
|
+
ctx.logger.error(
|
|
1183
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1184
|
+
);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1059
1187
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
1060
1188
|
if (Number.isNaN(maxSize)) {
|
|
1061
1189
|
ctx.logger.debug(
|
|
@@ -1077,10 +1205,11 @@ const action$1 = async (ctx) => {
|
|
|
1077
1205
|
chalk.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
1078
1206
|
);
|
|
1079
1207
|
} catch (e) {
|
|
1208
|
+
ctx.logger.debug(e);
|
|
1080
1209
|
if (e instanceof Error) {
|
|
1081
1210
|
ctx.logger.error(e.message);
|
|
1082
1211
|
} else {
|
|
1083
|
-
|
|
1212
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1084
1213
|
}
|
|
1085
1214
|
}
|
|
1086
1215
|
};
|
|
@@ -1111,16 +1240,162 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1111
1240
|
process.exit(1);
|
|
1112
1241
|
});
|
|
1113
1242
|
};
|
|
1114
|
-
const command$
|
|
1115
|
-
command2.command("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").action(() => runAction("deploy", action$
|
|
1243
|
+
const command$5 = ({ command: command2, ctx }) => {
|
|
1244
|
+
command2.command("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").action(() => runAction("deploy", action$3)(ctx));
|
|
1116
1245
|
};
|
|
1117
1246
|
const deployProject = {
|
|
1118
1247
|
name: "deploy-project",
|
|
1119
1248
|
description: "Deploy a Strapi Cloud project",
|
|
1120
|
-
action: action$
|
|
1121
|
-
command: command$
|
|
1249
|
+
action: action$3,
|
|
1250
|
+
command: command$5
|
|
1122
1251
|
};
|
|
1123
|
-
const
|
|
1252
|
+
const QUIT_OPTION = "Quit";
|
|
1253
|
+
async function getExistingConfig(ctx) {
|
|
1254
|
+
try {
|
|
1255
|
+
return await retrieve();
|
|
1256
|
+
} catch (e) {
|
|
1257
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1258
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1259
|
+
return null;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1263
|
+
if (existingConfig && existingConfig.project) {
|
|
1264
|
+
const { shouldRelink } = await inquirer.prompt([
|
|
1265
|
+
{
|
|
1266
|
+
type: "confirm",
|
|
1267
|
+
name: "shouldRelink",
|
|
1268
|
+
message: `A project named ${chalk.cyan(
|
|
1269
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1270
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1271
|
+
default: false
|
|
1272
|
+
}
|
|
1273
|
+
]);
|
|
1274
|
+
if (!shouldRelink) {
|
|
1275
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1276
|
+
currentProjectName: existingConfig.project?.name
|
|
1277
|
+
});
|
|
1278
|
+
return false;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1284
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
1285
|
+
try {
|
|
1286
|
+
const {
|
|
1287
|
+
data: { data: projectList }
|
|
1288
|
+
} = await cloudApiService.listLinkProjects();
|
|
1289
|
+
spinner.succeed();
|
|
1290
|
+
if (!Array.isArray(projectList)) {
|
|
1291
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1292
|
+
return null;
|
|
1293
|
+
}
|
|
1294
|
+
const projects = projectList.filter(
|
|
1295
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1296
|
+
).map((project) => {
|
|
1297
|
+
return {
|
|
1298
|
+
name: project.displayName,
|
|
1299
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1300
|
+
};
|
|
1301
|
+
});
|
|
1302
|
+
if (projects.length === 0) {
|
|
1303
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1304
|
+
return null;
|
|
1305
|
+
}
|
|
1306
|
+
return projects;
|
|
1307
|
+
} catch (e) {
|
|
1308
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1309
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1310
|
+
return null;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
async function getUserSelection(ctx, projects) {
|
|
1314
|
+
const { logger } = ctx;
|
|
1315
|
+
try {
|
|
1316
|
+
const answer = await inquirer.prompt([
|
|
1317
|
+
{
|
|
1318
|
+
type: "list",
|
|
1319
|
+
name: "linkProject",
|
|
1320
|
+
message: "Which project do you want to link?",
|
|
1321
|
+
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1322
|
+
}
|
|
1323
|
+
]);
|
|
1324
|
+
if (!answer.linkProject) {
|
|
1325
|
+
return null;
|
|
1326
|
+
}
|
|
1327
|
+
return answer;
|
|
1328
|
+
} catch (e) {
|
|
1329
|
+
logger.debug("Failed to get user input", e);
|
|
1330
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
const action$2 = async (ctx) => {
|
|
1335
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1336
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1337
|
+
const { logger } = ctx;
|
|
1338
|
+
if (!token) {
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1342
|
+
const existingConfig = await getExistingConfig(ctx);
|
|
1343
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1344
|
+
if (!shouldRelink) {
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1348
|
+
const projects = await getProjectsList(
|
|
1349
|
+
ctx,
|
|
1350
|
+
cloudApiService,
|
|
1351
|
+
existingConfig
|
|
1352
|
+
);
|
|
1353
|
+
if (!projects) {
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1357
|
+
if (!answer) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
try {
|
|
1361
|
+
const { confirmAction } = await inquirer.prompt([
|
|
1362
|
+
{
|
|
1363
|
+
type: "confirm",
|
|
1364
|
+
name: "confirmAction",
|
|
1365
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1366
|
+
default: false
|
|
1367
|
+
}
|
|
1368
|
+
]);
|
|
1369
|
+
if (!confirmAction) {
|
|
1370
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1371
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1372
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1373
|
+
});
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
await save({ project: answer.linkProject });
|
|
1377
|
+
logger.log(`Project ${chalk.cyan(answer.linkProject.displayName)} linked successfully.`);
|
|
1378
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1379
|
+
projectInternalName: answer.linkProject
|
|
1380
|
+
});
|
|
1381
|
+
} catch (e) {
|
|
1382
|
+
logger.debug("Failed to link project", e);
|
|
1383
|
+
logger.error("An error occurred while linking the project.");
|
|
1384
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1385
|
+
projectInternalName: answer.linkProject
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
const command$4 = ({ command: command2, ctx }) => {
|
|
1390
|
+
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$2)(ctx));
|
|
1391
|
+
};
|
|
1392
|
+
const link = {
|
|
1393
|
+
name: "link-project",
|
|
1394
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1395
|
+
action: action$2,
|
|
1396
|
+
command: command$4
|
|
1397
|
+
};
|
|
1398
|
+
const command$3 = ({ command: command2, ctx }) => {
|
|
1124
1399
|
command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1125
1400
|
"after",
|
|
1126
1401
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
@@ -1130,10 +1405,10 @@ const login = {
|
|
|
1130
1405
|
name: "login",
|
|
1131
1406
|
description: "Strapi Cloud Login",
|
|
1132
1407
|
action: loginAction,
|
|
1133
|
-
command: command$
|
|
1408
|
+
command: command$3
|
|
1134
1409
|
};
|
|
1135
1410
|
const openModule = import("open");
|
|
1136
|
-
const action = async (ctx) => {
|
|
1411
|
+
const action$1 = async (ctx) => {
|
|
1137
1412
|
const { logger } = ctx;
|
|
1138
1413
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1139
1414
|
const token = await retrieveToken();
|
|
@@ -1163,37 +1438,64 @@ const action = async (ctx) => {
|
|
|
1163
1438
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1164
1439
|
logger.debug(e);
|
|
1165
1440
|
}
|
|
1166
|
-
|
|
1167
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1168
|
-
} catch (e) {
|
|
1169
|
-
logger.debug("Failed to track logout event", e);
|
|
1170
|
-
}
|
|
1441
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1171
1442
|
};
|
|
1172
|
-
const command$
|
|
1173
|
-
command2.command("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)(ctx));
|
|
1443
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1444
|
+
command2.command("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$1)(ctx));
|
|
1174
1445
|
};
|
|
1175
1446
|
const logout = {
|
|
1176
1447
|
name: "logout",
|
|
1177
1448
|
description: "Strapi Cloud Logout",
|
|
1178
|
-
action,
|
|
1179
|
-
command: command$
|
|
1449
|
+
action: action$1,
|
|
1450
|
+
command: command$2
|
|
1180
1451
|
};
|
|
1181
|
-
const command = ({ command: command2, ctx }) => {
|
|
1182
|
-
command2.command("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$
|
|
1452
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1453
|
+
command2.command("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$4)(ctx));
|
|
1183
1454
|
};
|
|
1184
1455
|
const createProject = {
|
|
1185
1456
|
name: "create-project",
|
|
1186
1457
|
description: "Create a new project",
|
|
1187
|
-
action: action$
|
|
1458
|
+
action: action$4,
|
|
1459
|
+
command: command$1
|
|
1460
|
+
};
|
|
1461
|
+
const action = async (ctx) => {
|
|
1462
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1463
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1464
|
+
const { logger } = ctx;
|
|
1465
|
+
if (!token) {
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1469
|
+
const spinner = logger.spinner("Fetching your projects...").start();
|
|
1470
|
+
try {
|
|
1471
|
+
const {
|
|
1472
|
+
data: { data: projectList }
|
|
1473
|
+
} = await cloudApiService.listProjects();
|
|
1474
|
+
spinner.succeed();
|
|
1475
|
+
logger.log(projectList);
|
|
1476
|
+
} catch (e) {
|
|
1477
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1478
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
const command = ({ command: command2, ctx }) => {
|
|
1482
|
+
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));
|
|
1483
|
+
};
|
|
1484
|
+
const listProjects = {
|
|
1485
|
+
name: "list-projects",
|
|
1486
|
+
description: "List Strapi Cloud projects",
|
|
1487
|
+
action,
|
|
1188
1488
|
command
|
|
1189
1489
|
};
|
|
1190
1490
|
const cli = {
|
|
1191
1491
|
deployProject,
|
|
1492
|
+
link,
|
|
1192
1493
|
login,
|
|
1193
1494
|
logout,
|
|
1194
|
-
createProject
|
|
1495
|
+
createProject,
|
|
1496
|
+
listProjects
|
|
1195
1497
|
};
|
|
1196
|
-
const cloudCommands = [deployProject, login, logout];
|
|
1498
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects];
|
|
1197
1499
|
async function initCloudCLIConfig() {
|
|
1198
1500
|
const localConfig = await getLocalConfig();
|
|
1199
1501
|
if (!localConfig.deviceId) {
|