@strapi/cloud-cli 0.0.0-next.c27880c9af0e2c29e6d6512b0d5fbaa6b506acdc → 0.0.0-next.c3eb27c3a05a30387b6b44e15d3661201d54787d
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/LICENSE +18 -3
- package/dist/index.js +805 -311
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +804 -307
- 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 +1 -1
- 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/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 +4 -1
- package/dist/src/deploy-project/action.d.ts.map +1 -1
- package/dist/src/deploy-project/command.d.ts.map +1 -1
- package/dist/src/environment/command.d.ts +3 -0
- package/dist/src/environment/command.d.ts.map +1 -0
- package/dist/src/environment/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/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 +2 -2
- 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 +50 -8
- 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/services/token.d.ts +1 -1
- package/dist/src/services/token.d.ts.map +1 -1
- package/dist/src/types.d.ts +5 -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/compress-files.d.ts.map +1 -1
- package/dist/src/utils/pkg.d.ts.map +1 -1
- package/package.json +10 -9
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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";
|
|
4
|
+
import inquirer from "inquirer";
|
|
3
5
|
import * as path from "path";
|
|
4
6
|
import path__default from "path";
|
|
5
7
|
import chalk from "chalk";
|
|
6
8
|
import axios, { AxiosError } from "axios";
|
|
7
9
|
import * as crypto from "node:crypto";
|
|
8
10
|
import { env } from "@strapi/utils";
|
|
9
|
-
import * as fs from "fs";
|
|
10
11
|
import * as tar from "tar";
|
|
11
12
|
import { minimatch } from "minimatch";
|
|
12
|
-
import inquirer from "inquirer";
|
|
13
13
|
import { defaults, has } from "lodash/fp";
|
|
14
14
|
import os from "os";
|
|
15
15
|
import XDGAppPaths from "xdg-app-paths";
|
|
@@ -18,10 +18,10 @@ 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";
|
|
24
|
+
import { createCommand } from "commander";
|
|
25
25
|
const apiConfig = {
|
|
26
26
|
apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
27
27
|
dashboardBaseUrl: env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -40,23 +40,6 @@ const IGNORED_PATTERNS = [
|
|
|
40
40
|
"**/.idea/**",
|
|
41
41
|
"**/.vscode/**"
|
|
42
42
|
];
|
|
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
43
|
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
61
44
|
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
62
45
|
const relativeFilePath = path.join(folderPath, file);
|
|
@@ -74,16 +57,35 @@ const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
|
74
57
|
}
|
|
75
58
|
return isIgnored;
|
|
76
59
|
};
|
|
77
|
-
const
|
|
60
|
+
const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
61
|
+
const arrayOfFiles = [];
|
|
62
|
+
const entries = await fse.readdir(path.join(dirPath, subfolder));
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
const entryPathFromRoot = path.join(subfolder, entry);
|
|
65
|
+
const entryPath = path.relative(dirPath, entryPathFromRoot);
|
|
66
|
+
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
67
|
+
if (!isIgnored) {
|
|
68
|
+
if (fse.statSync(entryPath).isDirectory()) {
|
|
69
|
+
const subFiles = await getFiles(dirPath, ignorePatterns, entryPathFromRoot);
|
|
70
|
+
arrayOfFiles.push(...subFiles);
|
|
71
|
+
} else {
|
|
72
|
+
arrayOfFiles.push(entryPath);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return arrayOfFiles;
|
|
77
|
+
};
|
|
78
|
+
const readGitignore = async (folderPath) => {
|
|
78
79
|
const gitignorePath = path.resolve(folderPath, ".gitignore");
|
|
79
|
-
|
|
80
|
+
const pathExist = await fse.pathExists(gitignorePath);
|
|
81
|
+
if (!pathExist)
|
|
80
82
|
return [];
|
|
81
|
-
const gitignoreContent =
|
|
83
|
+
const gitignoreContent = await fse.readFile(gitignorePath, "utf8");
|
|
82
84
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
83
85
|
};
|
|
84
86
|
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
85
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
86
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
87
|
+
const ignorePatterns = await readGitignore(folderToCompress);
|
|
88
|
+
const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
|
|
87
89
|
return tar.c(
|
|
88
90
|
{
|
|
89
91
|
gzip: true,
|
|
@@ -96,7 +98,7 @@ const APP_FOLDER_NAME = "com.strapi.cli";
|
|
|
96
98
|
const CONFIG_FILENAME = "config.json";
|
|
97
99
|
async function checkDirectoryExists(directoryPath) {
|
|
98
100
|
try {
|
|
99
|
-
const fsStat = await
|
|
101
|
+
const fsStat = await fse__default.lstat(directoryPath);
|
|
100
102
|
return fsStat.isDirectory();
|
|
101
103
|
} catch (e) {
|
|
102
104
|
return false;
|
|
@@ -104,14 +106,14 @@ async function checkDirectoryExists(directoryPath) {
|
|
|
104
106
|
}
|
|
105
107
|
async function getTmpStoragePath() {
|
|
106
108
|
const storagePath = path__default.join(os.tmpdir(), APP_FOLDER_NAME);
|
|
107
|
-
await
|
|
109
|
+
await fse__default.ensureDir(storagePath);
|
|
108
110
|
return storagePath;
|
|
109
111
|
}
|
|
110
112
|
async function getConfigPath() {
|
|
111
113
|
const configDirs = XDGAppPaths(APP_FOLDER_NAME).configDirs();
|
|
112
114
|
const configPath = configDirs.find(checkDirectoryExists);
|
|
113
115
|
if (!configPath) {
|
|
114
|
-
await
|
|
116
|
+
await fse__default.ensureDir(configDirs[0]);
|
|
115
117
|
return configDirs[0];
|
|
116
118
|
}
|
|
117
119
|
return configPath;
|
|
@@ -119,9 +121,9 @@ async function getConfigPath() {
|
|
|
119
121
|
async function getLocalConfig() {
|
|
120
122
|
const configPath = await getConfigPath();
|
|
121
123
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
122
|
-
await
|
|
124
|
+
await fse__default.ensureFile(configFilePath);
|
|
123
125
|
try {
|
|
124
|
-
return await
|
|
126
|
+
return await fse__default.readJSON(configFilePath, { encoding: "utf8", throws: true });
|
|
125
127
|
} catch (e) {
|
|
126
128
|
return {};
|
|
127
129
|
}
|
|
@@ -129,10 +131,10 @@ async function getLocalConfig() {
|
|
|
129
131
|
async function saveLocalConfig(data) {
|
|
130
132
|
const configPath = await getConfigPath();
|
|
131
133
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
132
|
-
await
|
|
134
|
+
await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
133
135
|
}
|
|
134
136
|
const name = "@strapi/cloud-cli";
|
|
135
|
-
const version = "
|
|
137
|
+
const version = "5.2.0";
|
|
136
138
|
const description = "Commands to interact with the Strapi Cloud";
|
|
137
139
|
const keywords = [
|
|
138
140
|
"strapi",
|
|
@@ -173,17 +175,18 @@ const scripts = {
|
|
|
173
175
|
build: "pack-up build",
|
|
174
176
|
clean: "run -T rimraf ./dist",
|
|
175
177
|
lint: "run -T eslint .",
|
|
178
|
+
"test:unit": "run -T jest",
|
|
176
179
|
watch: "pack-up watch"
|
|
177
180
|
};
|
|
178
181
|
const dependencies = {
|
|
179
|
-
"@strapi/utils": "
|
|
180
|
-
axios: "1.
|
|
182
|
+
"@strapi/utils": "workspace:*",
|
|
183
|
+
axios: "1.7.4",
|
|
181
184
|
chalk: "4.1.2",
|
|
182
185
|
"cli-progress": "3.12.0",
|
|
183
186
|
commander: "8.3.0",
|
|
184
187
|
eventsource: "2.0.2",
|
|
185
188
|
"fast-safe-stringify": "2.1.1",
|
|
186
|
-
"fs-extra": "
|
|
189
|
+
"fs-extra": "11.2.0",
|
|
187
190
|
inquirer: "8.2.5",
|
|
188
191
|
jsonwebtoken: "9.0.0",
|
|
189
192
|
"jwks-rsa": "3.1.0",
|
|
@@ -192,7 +195,7 @@ const dependencies = {
|
|
|
192
195
|
open: "8.4.0",
|
|
193
196
|
ora: "5.4.1",
|
|
194
197
|
"pkg-up": "3.1.0",
|
|
195
|
-
tar: "6.1
|
|
198
|
+
tar: "6.2.1",
|
|
196
199
|
"xdg-app-paths": "8.3.0",
|
|
197
200
|
yup: "0.32.9"
|
|
198
201
|
};
|
|
@@ -201,11 +204,11 @@ const devDependencies = {
|
|
|
201
204
|
"@types/cli-progress": "3.11.5",
|
|
202
205
|
"@types/eventsource": "1.1.15",
|
|
203
206
|
"@types/lodash": "^4.14.191",
|
|
204
|
-
"eslint-config-custom": "
|
|
205
|
-
tsconfig: "
|
|
207
|
+
"eslint-config-custom": "workspace:*",
|
|
208
|
+
tsconfig: "workspace:*"
|
|
206
209
|
};
|
|
207
210
|
const engines = {
|
|
208
|
-
node: ">=18.0.0 <=
|
|
211
|
+
node: ">=18.0.0 <=22.x.x",
|
|
209
212
|
npm: ">=6.0.0"
|
|
210
213
|
};
|
|
211
214
|
const packageJson = {
|
|
@@ -231,7 +234,7 @@ const packageJson = {
|
|
|
231
234
|
engines
|
|
232
235
|
};
|
|
233
236
|
const VERSION = "v1";
|
|
234
|
-
async function cloudApiFactory(token) {
|
|
237
|
+
async function cloudApiFactory({ logger }, token) {
|
|
235
238
|
const localConfig = await getLocalConfig();
|
|
236
239
|
const customHeaders = {
|
|
237
240
|
"x-device-id": localConfig.deviceId,
|
|
@@ -255,7 +258,7 @@ async function cloudApiFactory(token) {
|
|
|
255
258
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
256
259
|
return axiosCloudAPI.post(
|
|
257
260
|
`/deploy/${project.name}`,
|
|
258
|
-
{ file:
|
|
261
|
+
{ file: fse__default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
259
262
|
{
|
|
260
263
|
headers: {
|
|
261
264
|
"Content-Type": "multipart/form-data"
|
|
@@ -284,11 +287,75 @@ async function cloudApiFactory(token) {
|
|
|
284
287
|
getUserInfo() {
|
|
285
288
|
return axiosCloudAPI.get("/user");
|
|
286
289
|
},
|
|
287
|
-
config() {
|
|
288
|
-
|
|
290
|
+
async config() {
|
|
291
|
+
try {
|
|
292
|
+
const response = await axiosCloudAPI.get("/config");
|
|
293
|
+
if (response.status !== 200) {
|
|
294
|
+
throw new Error("Error fetching cloud CLI config from the server.");
|
|
295
|
+
}
|
|
296
|
+
return response;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
logger.debug(
|
|
299
|
+
"🥲 Oops! Couldn't retrieve the cloud CLI config from the server. Please try again."
|
|
300
|
+
);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
async listProjects() {
|
|
305
|
+
try {
|
|
306
|
+
const response = await axiosCloudAPI.get("/projects");
|
|
307
|
+
if (response.status !== 200) {
|
|
308
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
309
|
+
}
|
|
310
|
+
return response;
|
|
311
|
+
} catch (error) {
|
|
312
|
+
logger.debug(
|
|
313
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
314
|
+
);
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
async listLinkProjects() {
|
|
319
|
+
try {
|
|
320
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
321
|
+
if (response.status !== 200) {
|
|
322
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
323
|
+
}
|
|
324
|
+
return response;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
logger.debug(
|
|
327
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
328
|
+
);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
async listEnvironments({ name: name2 }) {
|
|
333
|
+
try {
|
|
334
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
335
|
+
if (response.status !== 200) {
|
|
336
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
337
|
+
}
|
|
338
|
+
return response;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
logger.debug(
|
|
341
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
342
|
+
);
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
289
345
|
},
|
|
290
|
-
|
|
291
|
-
|
|
346
|
+
async getProject({ name: name2 }) {
|
|
347
|
+
try {
|
|
348
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
349
|
+
if (response.status !== 200) {
|
|
350
|
+
throw new Error("Error fetching project's details.");
|
|
351
|
+
}
|
|
352
|
+
return response;
|
|
353
|
+
} catch (error) {
|
|
354
|
+
logger.debug(
|
|
355
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
356
|
+
);
|
|
357
|
+
throw error;
|
|
358
|
+
}
|
|
292
359
|
},
|
|
293
360
|
track(event, payload = {}) {
|
|
294
361
|
return axiosCloudAPI.post("/track", {
|
|
@@ -303,18 +370,18 @@ async function save(data, { directoryPath } = {}) {
|
|
|
303
370
|
const alreadyInFileData = await retrieve({ directoryPath });
|
|
304
371
|
const storedData = { ...alreadyInFileData, ...data };
|
|
305
372
|
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
306
|
-
await
|
|
307
|
-
await
|
|
373
|
+
await fse__default.ensureDir(path__default.dirname(pathToFile));
|
|
374
|
+
await fse__default.writeJson(pathToFile, storedData, { encoding: "utf8" });
|
|
308
375
|
}
|
|
309
376
|
async function retrieve({
|
|
310
377
|
directoryPath
|
|
311
378
|
} = {}) {
|
|
312
379
|
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
313
|
-
const pathExists = await
|
|
380
|
+
const pathExists = await fse__default.pathExists(pathToFile);
|
|
314
381
|
if (!pathExists) {
|
|
315
382
|
return {};
|
|
316
383
|
}
|
|
317
|
-
return
|
|
384
|
+
return fse__default.readJSON(pathToFile, { encoding: "utf8" });
|
|
318
385
|
}
|
|
319
386
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
320
387
|
__proto__: null,
|
|
@@ -324,7 +391,7 @@ const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defi
|
|
|
324
391
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
325
392
|
let cliConfig;
|
|
326
393
|
async function tokenServiceFactory({ logger }) {
|
|
327
|
-
const cloudApiService = await cloudApiFactory();
|
|
394
|
+
const cloudApiService = await cloudApiFactory({ logger });
|
|
328
395
|
async function saveToken(str) {
|
|
329
396
|
const appConfig = await getLocalConfig();
|
|
330
397
|
if (!appConfig) {
|
|
@@ -373,14 +440,17 @@ async function tokenServiceFactory({ logger }) {
|
|
|
373
440
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
374
441
|
);
|
|
375
442
|
}
|
|
443
|
+
return Promise.reject(new Error("Invalid token"));
|
|
376
444
|
}
|
|
377
445
|
return new Promise((resolve, reject) => {
|
|
378
446
|
jwt.verify(idToken, getKey, (err) => {
|
|
379
447
|
if (err) {
|
|
380
448
|
reject(err);
|
|
381
|
-
} else {
|
|
382
|
-
resolve();
|
|
383
449
|
}
|
|
450
|
+
if (decodedToken.payload.exp < Math.floor(Date.now() / 1e3)) {
|
|
451
|
+
reject(new Error("Token is expired"));
|
|
452
|
+
}
|
|
453
|
+
resolve();
|
|
384
454
|
});
|
|
385
455
|
});
|
|
386
456
|
}
|
|
@@ -414,15 +484,15 @@ async function tokenServiceFactory({ logger }) {
|
|
|
414
484
|
throw e;
|
|
415
485
|
}
|
|
416
486
|
}
|
|
417
|
-
async function getValidToken() {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
logger.log(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
487
|
+
async function getValidToken(ctx, loginAction2) {
|
|
488
|
+
let token = await retrieveToken();
|
|
489
|
+
while (!token || !await isTokenValid(token)) {
|
|
490
|
+
logger.log(
|
|
491
|
+
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."
|
|
492
|
+
);
|
|
493
|
+
if (!await loginAction2(ctx))
|
|
494
|
+
return null;
|
|
495
|
+
token = await retrieveToken();
|
|
426
496
|
}
|
|
427
497
|
return token;
|
|
428
498
|
}
|
|
@@ -556,17 +626,257 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
556
626
|
local: strapiInfoSave,
|
|
557
627
|
tokenServiceFactory
|
|
558
628
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
559
|
-
|
|
629
|
+
yup.object({
|
|
630
|
+
name: yup.string().required(),
|
|
631
|
+
exports: yup.lazy(
|
|
632
|
+
(value) => yup.object(
|
|
633
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
634
|
+
(acc, [key, value2]) => {
|
|
635
|
+
if (typeof value2 === "object") {
|
|
636
|
+
acc[key] = yup.object({
|
|
637
|
+
types: yup.string().optional(),
|
|
638
|
+
source: yup.string().required(),
|
|
639
|
+
module: yup.string().optional(),
|
|
640
|
+
import: yup.string().required(),
|
|
641
|
+
require: yup.string().required(),
|
|
642
|
+
default: yup.string().required()
|
|
643
|
+
}).noUnknown(true);
|
|
644
|
+
} else {
|
|
645
|
+
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
646
|
+
}
|
|
647
|
+
return acc;
|
|
648
|
+
},
|
|
649
|
+
{}
|
|
650
|
+
) : void 0
|
|
651
|
+
).optional()
|
|
652
|
+
)
|
|
653
|
+
});
|
|
654
|
+
const loadPkg = async ({ cwd, logger }) => {
|
|
655
|
+
const pkgPath = await pkgUp({ cwd });
|
|
656
|
+
if (!pkgPath) {
|
|
657
|
+
throw new Error("Could not find a package.json in the current directory");
|
|
658
|
+
}
|
|
659
|
+
const buffer = await fse.readFile(pkgPath);
|
|
660
|
+
const pkg = JSON.parse(buffer.toString());
|
|
661
|
+
logger.debug("Loaded package.json:", os.EOL, pkg);
|
|
662
|
+
return pkg;
|
|
663
|
+
};
|
|
664
|
+
async function getProjectNameFromPackageJson(ctx) {
|
|
665
|
+
try {
|
|
666
|
+
const packageJson2 = await loadPkg(ctx);
|
|
667
|
+
return packageJson2.name || "my-strapi-project";
|
|
668
|
+
} catch (e) {
|
|
669
|
+
return "my-strapi-project";
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
673
|
+
try {
|
|
674
|
+
await cloudApiService.track(eventName, eventData);
|
|
675
|
+
} catch (e) {
|
|
676
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
const openModule$1 = import("open");
|
|
680
|
+
async function promptLogin(ctx) {
|
|
681
|
+
const response = await inquirer.prompt([
|
|
682
|
+
{
|
|
683
|
+
type: "confirm",
|
|
684
|
+
name: "login",
|
|
685
|
+
message: "Would you like to login?"
|
|
686
|
+
}
|
|
687
|
+
]);
|
|
688
|
+
if (response.login) {
|
|
689
|
+
const loginSuccessful = await loginAction(ctx);
|
|
690
|
+
return loginSuccessful;
|
|
691
|
+
}
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
async function loginAction(ctx) {
|
|
695
|
+
const { logger } = ctx;
|
|
560
696
|
const tokenService = await tokenServiceFactory(ctx);
|
|
697
|
+
const existingToken = await tokenService.retrieveToken();
|
|
698
|
+
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
699
|
+
if (existingToken) {
|
|
700
|
+
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
701
|
+
if (isTokenValid) {
|
|
702
|
+
try {
|
|
703
|
+
const userInfo = await cloudApiService.getUserInfo();
|
|
704
|
+
const { email } = userInfo.data.data;
|
|
705
|
+
if (email) {
|
|
706
|
+
logger.log(`You are already logged into your account (${email}).`);
|
|
707
|
+
} else {
|
|
708
|
+
logger.log("You are already logged in.");
|
|
709
|
+
}
|
|
710
|
+
logger.log(
|
|
711
|
+
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
712
|
+
);
|
|
713
|
+
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
714
|
+
return true;
|
|
715
|
+
} catch (e) {
|
|
716
|
+
logger.debug("Failed to fetch user info", e);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
let cliConfig2;
|
|
721
|
+
try {
|
|
722
|
+
logger.info("🔌 Connecting to the Strapi Cloud API...");
|
|
723
|
+
const config = await cloudApiService.config();
|
|
724
|
+
cliConfig2 = config.data;
|
|
725
|
+
} catch (e) {
|
|
726
|
+
logger.error("🥲 Oops! Something went wrong while logging you in. Please try again.");
|
|
727
|
+
logger.debug(e);
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
731
|
+
logger.debug("🔐 Creating device authentication request...", {
|
|
732
|
+
client_id: cliConfig2.clientId,
|
|
733
|
+
scope: cliConfig2.scope,
|
|
734
|
+
audience: cliConfig2.audience
|
|
735
|
+
});
|
|
736
|
+
const deviceAuthResponse = await axios.post(cliConfig2.deviceCodeAuthUrl, {
|
|
737
|
+
client_id: cliConfig2.clientId,
|
|
738
|
+
scope: cliConfig2.scope,
|
|
739
|
+
audience: cliConfig2.audience
|
|
740
|
+
}).catch((e) => {
|
|
741
|
+
logger.error("There was an issue with the authentication process. Please try again.");
|
|
742
|
+
if (e.message) {
|
|
743
|
+
logger.debug(e.message, e);
|
|
744
|
+
} else {
|
|
745
|
+
logger.debug(e);
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
openModule$1.then((open) => {
|
|
749
|
+
open.default(deviceAuthResponse.data.verification_uri_complete).catch((e) => {
|
|
750
|
+
logger.error("We encountered an issue opening the browser. Please try again later.");
|
|
751
|
+
logger.debug(e.message, e);
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
logger.log("If a browser tab does not open automatically, please follow the next steps:");
|
|
755
|
+
logger.log(
|
|
756
|
+
`1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
|
|
757
|
+
);
|
|
758
|
+
logger.log(
|
|
759
|
+
`2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
|
|
760
|
+
`
|
|
761
|
+
);
|
|
762
|
+
const tokenPayload = {
|
|
763
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
764
|
+
device_code: deviceAuthResponse.data.device_code,
|
|
765
|
+
client_id: cliConfig2.clientId
|
|
766
|
+
};
|
|
767
|
+
let isAuthenticated = false;
|
|
768
|
+
const authenticate = async () => {
|
|
769
|
+
const spinner = logger.spinner("Waiting for authentication");
|
|
770
|
+
spinner.start();
|
|
771
|
+
const spinnerFail = () => spinner.fail("Authentication failed!");
|
|
772
|
+
while (!isAuthenticated) {
|
|
773
|
+
try {
|
|
774
|
+
const tokenResponse = await axios.post(cliConfig2.tokenUrl, tokenPayload);
|
|
775
|
+
const authTokenData = tokenResponse.data;
|
|
776
|
+
if (tokenResponse.status === 200) {
|
|
777
|
+
try {
|
|
778
|
+
logger.debug("🔐 Validating token...");
|
|
779
|
+
await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
|
|
780
|
+
logger.debug("🔐 Token validation successful!");
|
|
781
|
+
} catch (e) {
|
|
782
|
+
logger.debug(e);
|
|
783
|
+
spinnerFail();
|
|
784
|
+
throw new Error("Unable to proceed: Token validation failed");
|
|
785
|
+
}
|
|
786
|
+
logger.debug("🔍 Fetching user information...");
|
|
787
|
+
const cloudApiServiceWithToken = await cloudApiFactory(ctx, authTokenData.access_token);
|
|
788
|
+
await cloudApiServiceWithToken.getUserInfo();
|
|
789
|
+
logger.debug("🔍 User information fetched successfully!");
|
|
790
|
+
try {
|
|
791
|
+
logger.debug("📝 Saving login information...");
|
|
792
|
+
await tokenService.saveToken(authTokenData.access_token);
|
|
793
|
+
logger.debug("📝 Login information saved successfully!");
|
|
794
|
+
isAuthenticated = true;
|
|
795
|
+
} catch (e) {
|
|
796
|
+
logger.error(
|
|
797
|
+
"There was a problem saving your login information. Please try logging in again."
|
|
798
|
+
);
|
|
799
|
+
logger.debug(e);
|
|
800
|
+
spinnerFail();
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
} catch (e) {
|
|
805
|
+
if (e.message === "Unable to proceed: Token validation failed") {
|
|
806
|
+
logger.error(
|
|
807
|
+
"There seems to be a problem with your login information. Please try logging in again."
|
|
808
|
+
);
|
|
809
|
+
spinnerFail();
|
|
810
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
814
|
+
logger.debug(e);
|
|
815
|
+
spinnerFail();
|
|
816
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
817
|
+
return false;
|
|
818
|
+
}
|
|
819
|
+
await new Promise((resolve) => {
|
|
820
|
+
setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
spinner.succeed("Authentication successful!");
|
|
825
|
+
logger.log("You are now logged into Strapi Cloud.");
|
|
826
|
+
logger.log(
|
|
827
|
+
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
828
|
+
);
|
|
829
|
+
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
830
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
831
|
+
};
|
|
832
|
+
await authenticate();
|
|
833
|
+
return isAuthenticated;
|
|
834
|
+
}
|
|
835
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
836
|
+
return (questions) => {
|
|
837
|
+
return questions.map((question) => {
|
|
838
|
+
const questionName = question.name;
|
|
839
|
+
if (questionName in questionsMap) {
|
|
840
|
+
const questionDefault = questionsMap[questionName];
|
|
841
|
+
if (typeof questionDefault === "function") {
|
|
842
|
+
return {
|
|
843
|
+
...question,
|
|
844
|
+
default: questionDefault(question)
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
return {
|
|
848
|
+
...question,
|
|
849
|
+
default: questionDefault
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
return question;
|
|
853
|
+
});
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
function getDefaultsFromQuestions(questions) {
|
|
857
|
+
return questions.reduce((acc, question) => {
|
|
858
|
+
if (question.default && question.name) {
|
|
859
|
+
return { ...acc, [question.name]: question.default };
|
|
860
|
+
}
|
|
861
|
+
return acc;
|
|
862
|
+
}, {});
|
|
863
|
+
}
|
|
864
|
+
function getProjectNodeVersionDefault(question) {
|
|
865
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
866
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
867
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
868
|
+
if (choice) {
|
|
869
|
+
return choice.value;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return question.default;
|
|
873
|
+
}
|
|
874
|
+
async function handleError(ctx, error) {
|
|
561
875
|
const { logger } = ctx;
|
|
562
876
|
logger.debug(error);
|
|
563
877
|
if (error instanceof AxiosError) {
|
|
564
878
|
const errorMessage = typeof error.response?.data === "string" ? error.response.data : null;
|
|
565
879
|
switch (error.response?.status) {
|
|
566
|
-
case 401:
|
|
567
|
-
logger.error("Your session has expired. Please log in again.");
|
|
568
|
-
await tokenService.eraseToken();
|
|
569
|
-
return;
|
|
570
880
|
case 403:
|
|
571
881
|
logger.error(
|
|
572
882
|
errorMessage || "You do not have permission to create a project. Please contact support for assistance."
|
|
@@ -592,28 +902,53 @@ async function handleError(ctx, error) {
|
|
|
592
902
|
"We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance."
|
|
593
903
|
);
|
|
594
904
|
}
|
|
595
|
-
|
|
905
|
+
async function createProject$1(ctx, cloudApi, projectInput) {
|
|
596
906
|
const { logger } = ctx;
|
|
597
|
-
const
|
|
598
|
-
|
|
907
|
+
const spinner = logger.spinner("Setting up your project...").start();
|
|
908
|
+
try {
|
|
909
|
+
const { data } = await cloudApi.createProject(projectInput);
|
|
910
|
+
await save({ project: data });
|
|
911
|
+
spinner.succeed("Project created successfully!");
|
|
912
|
+
return data;
|
|
913
|
+
} catch (e) {
|
|
914
|
+
spinner.fail("An error occurred while creating the project on Strapi Cloud.");
|
|
915
|
+
throw e;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
const action$5 = async (ctx) => {
|
|
919
|
+
const { logger } = ctx;
|
|
920
|
+
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
921
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
599
922
|
if (!token) {
|
|
600
923
|
return;
|
|
601
924
|
}
|
|
602
|
-
const cloudApi = await cloudApiFactory(token);
|
|
925
|
+
const cloudApi = await cloudApiFactory(ctx, token);
|
|
603
926
|
const { data: config } = await cloudApi.config();
|
|
604
|
-
const
|
|
927
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
928
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
929
|
+
name: projectName,
|
|
930
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
931
|
+
});
|
|
932
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
933
|
+
const defaultValues = {
|
|
934
|
+
...config.projectCreation.defaults,
|
|
935
|
+
...getDefaultsFromQuestions(questions)
|
|
936
|
+
};
|
|
605
937
|
const projectAnswersDefaulted = defaults(defaultValues);
|
|
606
938
|
const projectAnswers = await inquirer.prompt(questions);
|
|
607
939
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
608
|
-
const spinner = logger.spinner("Setting up your project...").start();
|
|
609
940
|
try {
|
|
610
|
-
|
|
611
|
-
await save({ project: data });
|
|
612
|
-
spinner.succeed("Project created successfully!");
|
|
613
|
-
return data;
|
|
941
|
+
return await createProject$1(ctx, cloudApi, projectInput);
|
|
614
942
|
} catch (e) {
|
|
615
|
-
|
|
616
|
-
|
|
943
|
+
if (e instanceof AxiosError && e.response?.status === 401) {
|
|
944
|
+
logger.warn("Oops! Your session has expired. Please log in again to retry.");
|
|
945
|
+
await eraseToken();
|
|
946
|
+
if (await promptLogin(ctx)) {
|
|
947
|
+
return await createProject$1(ctx, cloudApi, projectInput);
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
await handleError(ctx, e);
|
|
951
|
+
}
|
|
617
952
|
}
|
|
618
953
|
};
|
|
619
954
|
function notificationServiceFactory({ logger }) {
|
|
@@ -647,38 +982,6 @@ function notificationServiceFactory({ logger }) {
|
|
|
647
982
|
};
|
|
648
983
|
};
|
|
649
984
|
}
|
|
650
|
-
yup.object({
|
|
651
|
-
name: yup.string().required(),
|
|
652
|
-
exports: yup.lazy(
|
|
653
|
-
(value) => yup.object(
|
|
654
|
-
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
655
|
-
if (typeof value2 === "object") {
|
|
656
|
-
acc[key] = yup.object({
|
|
657
|
-
types: yup.string().optional(),
|
|
658
|
-
source: yup.string().required(),
|
|
659
|
-
module: yup.string().optional(),
|
|
660
|
-
import: yup.string().required(),
|
|
661
|
-
require: yup.string().required(),
|
|
662
|
-
default: yup.string().required()
|
|
663
|
-
}).noUnknown(true);
|
|
664
|
-
} else {
|
|
665
|
-
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
666
|
-
}
|
|
667
|
-
return acc;
|
|
668
|
-
}, {}) : void 0
|
|
669
|
-
).optional()
|
|
670
|
-
)
|
|
671
|
-
});
|
|
672
|
-
const loadPkg = async ({ cwd, logger }) => {
|
|
673
|
-
const pkgPath = await pkgUp({ cwd });
|
|
674
|
-
if (!pkgPath) {
|
|
675
|
-
throw new Error("Could not find a package.json in the current directory");
|
|
676
|
-
}
|
|
677
|
-
const buffer = await fs$1.readFile(pkgPath);
|
|
678
|
-
const pkg = JSON.parse(buffer.toString());
|
|
679
|
-
logger.debug("Loaded package.json:", os.EOL, pkg);
|
|
680
|
-
return pkg;
|
|
681
|
-
};
|
|
682
985
|
const buildLogsServiceFactory = ({ logger }) => {
|
|
683
986
|
return async (url, token, cliConfig2) => {
|
|
684
987
|
const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
|
|
@@ -732,6 +1035,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
732
1035
|
if (retries > MAX_RETRIES) {
|
|
733
1036
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
734
1037
|
es.close();
|
|
1038
|
+
clearExistingTimeout();
|
|
735
1039
|
reject(new Error("Max retries reached"));
|
|
736
1040
|
}
|
|
737
1041
|
};
|
|
@@ -740,8 +1044,34 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
740
1044
|
});
|
|
741
1045
|
};
|
|
742
1046
|
};
|
|
1047
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1048
|
+
async function promptForEnvironment(environments) {
|
|
1049
|
+
const choices = environments.map((env2) => ({ name: env2, value: env2 }));
|
|
1050
|
+
const { selectedEnvironment } = await inquirer.prompt([
|
|
1051
|
+
{
|
|
1052
|
+
type: "list",
|
|
1053
|
+
name: "selectedEnvironment",
|
|
1054
|
+
message: "Select the environment to deploy:",
|
|
1055
|
+
choices: [...choices, { name: chalk.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1056
|
+
}
|
|
1057
|
+
]);
|
|
1058
|
+
if (selectedEnvironment === null) {
|
|
1059
|
+
process.exit(1);
|
|
1060
|
+
}
|
|
1061
|
+
const { confirm } = await inquirer.prompt([
|
|
1062
|
+
{
|
|
1063
|
+
type: "confirm",
|
|
1064
|
+
name: "confirm",
|
|
1065
|
+
message: `Do you want to proceed with deployment to ${chalk.cyan(selectedEnvironment)}?`
|
|
1066
|
+
}
|
|
1067
|
+
]);
|
|
1068
|
+
if (!confirm) {
|
|
1069
|
+
process.exit(1);
|
|
1070
|
+
}
|
|
1071
|
+
return selectedEnvironment;
|
|
1072
|
+
}
|
|
743
1073
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
744
|
-
const cloudApi = await cloudApiFactory(token);
|
|
1074
|
+
const cloudApi = await cloudApiFactory(ctx, token);
|
|
745
1075
|
try {
|
|
746
1076
|
const storagePath = await getTmpStoragePath();
|
|
747
1077
|
const projectFolder = path__default.resolve(process.cwd());
|
|
@@ -774,13 +1104,13 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
774
1104
|
process.exit(1);
|
|
775
1105
|
}
|
|
776
1106
|
const tarFilePath = path__default.resolve(storagePath, compressedFilename);
|
|
777
|
-
const fileStats = await
|
|
1107
|
+
const fileStats = await fse__default.stat(tarFilePath);
|
|
778
1108
|
if (fileStats.size > maxProjectFileSize) {
|
|
779
1109
|
ctx.logger.log(
|
|
780
1110
|
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
781
1111
|
);
|
|
782
1112
|
try {
|
|
783
|
-
await
|
|
1113
|
+
await fse__default.remove(tarFilePath);
|
|
784
1114
|
} catch (e) {
|
|
785
1115
|
ctx.logger.log("Unable to remove file: ", tarFilePath);
|
|
786
1116
|
ctx.logger.debug(e);
|
|
@@ -806,20 +1136,10 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
806
1136
|
return data.build_id;
|
|
807
1137
|
} catch (e) {
|
|
808
1138
|
progressBar.stop();
|
|
809
|
-
|
|
810
|
-
if (e.response.status === 404) {
|
|
811
|
-
ctx.logger.error(
|
|
812
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
813
|
-
);
|
|
814
|
-
} else {
|
|
815
|
-
ctx.logger.error(e.response.data);
|
|
816
|
-
}
|
|
817
|
-
} else {
|
|
818
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
819
|
-
}
|
|
1139
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
820
1140
|
ctx.logger.debug(e);
|
|
821
1141
|
} finally {
|
|
822
|
-
await
|
|
1142
|
+
await fse__default.remove(tarFilePath);
|
|
823
1143
|
}
|
|
824
1144
|
process.exit(0);
|
|
825
1145
|
} catch (e) {
|
|
@@ -828,11 +1148,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
828
1148
|
process.exit(1);
|
|
829
1149
|
}
|
|
830
1150
|
}
|
|
831
|
-
async function getProject(ctx) {
|
|
1151
|
+
async function getProject$1(ctx) {
|
|
832
1152
|
const { project } = await retrieve();
|
|
833
1153
|
if (!project) {
|
|
834
1154
|
try {
|
|
835
|
-
return await action$
|
|
1155
|
+
return await action$5(ctx);
|
|
836
1156
|
} catch (e) {
|
|
837
1157
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
838
1158
|
ctx.logger.debug(e);
|
|
@@ -841,25 +1161,75 @@ async function getProject(ctx) {
|
|
|
841
1161
|
}
|
|
842
1162
|
return project;
|
|
843
1163
|
}
|
|
844
|
-
|
|
1164
|
+
async function getConfig({
|
|
1165
|
+
ctx,
|
|
1166
|
+
cloudApiService
|
|
1167
|
+
}) {
|
|
1168
|
+
try {
|
|
1169
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1170
|
+
return cliConfig2;
|
|
1171
|
+
} catch (e) {
|
|
1172
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1173
|
+
return null;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
const action$4 = async (ctx, opts) => {
|
|
845
1177
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
846
|
-
const
|
|
847
|
-
const token = await getValidToken();
|
|
1178
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
848
1179
|
if (!token) {
|
|
849
1180
|
return;
|
|
850
1181
|
}
|
|
851
|
-
const project = await getProject(ctx);
|
|
1182
|
+
const project = await getProject$1(ctx);
|
|
852
1183
|
if (!project) {
|
|
853
1184
|
return;
|
|
854
1185
|
}
|
|
1186
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1187
|
+
let environments;
|
|
855
1188
|
try {
|
|
856
|
-
|
|
1189
|
+
const {
|
|
1190
|
+
data: { data: projectData, metadata }
|
|
1191
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1192
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1193
|
+
environments = projectData.environments;
|
|
1194
|
+
if (isProjectSuspended) {
|
|
1195
|
+
ctx.logger.log(
|
|
1196
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1197
|
+
);
|
|
1198
|
+
ctx.logger.log(chalk.underline(`${metadata.dashboardUrls.project}`));
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
857
1201
|
} catch (e) {
|
|
858
|
-
|
|
1202
|
+
if (e instanceof AxiosError && e.response?.data) {
|
|
1203
|
+
if (e.response.status === 404) {
|
|
1204
|
+
ctx.logger.warn(
|
|
1205
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1206
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1207
|
+
"link"
|
|
1208
|
+
)} command before deploying.`
|
|
1209
|
+
);
|
|
1210
|
+
} else {
|
|
1211
|
+
ctx.logger.error(e.response.data);
|
|
1212
|
+
}
|
|
1213
|
+
} else {
|
|
1214
|
+
ctx.logger.error(
|
|
1215
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1216
|
+
);
|
|
1217
|
+
}
|
|
1218
|
+
ctx.logger.debug(e);
|
|
1219
|
+
return;
|
|
859
1220
|
}
|
|
1221
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1222
|
+
projectInternalName: project.name
|
|
1223
|
+
});
|
|
860
1224
|
const notificationService = notificationServiceFactory(ctx);
|
|
861
1225
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
862
|
-
const
|
|
1226
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1227
|
+
if (!cliConfig2) {
|
|
1228
|
+
ctx.logger.error(
|
|
1229
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1230
|
+
);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
863
1233
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
864
1234
|
if (Number.isNaN(maxSize)) {
|
|
865
1235
|
ctx.logger.debug(
|
|
@@ -867,6 +1237,17 @@ const action$2 = async (ctx) => {
|
|
|
867
1237
|
);
|
|
868
1238
|
maxSize = 1e8;
|
|
869
1239
|
}
|
|
1240
|
+
let targetEnvironment;
|
|
1241
|
+
if (opts.environment) {
|
|
1242
|
+
if (!environments.includes(opts.environment)) {
|
|
1243
|
+
ctx.logger.error(`Environment ${opts.environment} does not exist.`);
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
targetEnvironment = opts.environment;
|
|
1247
|
+
} else {
|
|
1248
|
+
targetEnvironment = environments.length > 1 ? await promptForEnvironment(environments) : environments[0];
|
|
1249
|
+
}
|
|
1250
|
+
project.targetEnvironment = targetEnvironment;
|
|
870
1251
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
871
1252
|
if (!buildId) {
|
|
872
1253
|
return;
|
|
@@ -881,10 +1262,11 @@ const action$2 = async (ctx) => {
|
|
|
881
1262
|
chalk.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
882
1263
|
);
|
|
883
1264
|
} catch (e) {
|
|
1265
|
+
ctx.logger.debug(e);
|
|
884
1266
|
if (e instanceof Error) {
|
|
885
1267
|
ctx.logger.error(e.message);
|
|
886
1268
|
} else {
|
|
887
|
-
|
|
1269
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
888
1270
|
}
|
|
889
1271
|
}
|
|
890
1272
|
};
|
|
@@ -915,185 +1297,175 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
915
1297
|
process.exit(1);
|
|
916
1298
|
});
|
|
917
1299
|
};
|
|
918
|
-
const command$
|
|
919
|
-
|
|
1300
|
+
const command$6 = ({ ctx }) => {
|
|
1301
|
+
return createCommand("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").option("-e, --environment <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$4)(ctx, opts));
|
|
920
1302
|
};
|
|
921
1303
|
const deployProject = {
|
|
922
1304
|
name: "deploy-project",
|
|
923
1305
|
description: "Deploy a Strapi Cloud project",
|
|
924
|
-
action: action$
|
|
925
|
-
command: command$
|
|
1306
|
+
action: action$4,
|
|
1307
|
+
command: command$6
|
|
926
1308
|
};
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
logger.log(`You are already logged into your account (${email}).`);
|
|
948
|
-
} else {
|
|
949
|
-
logger.log("You are already logged in.");
|
|
950
|
-
}
|
|
951
|
-
logger.log(
|
|
952
|
-
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
953
|
-
);
|
|
954
|
-
logger.log(chalk.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
955
|
-
return true;
|
|
956
|
-
} catch (e) {
|
|
957
|
-
logger.debug("Failed to fetch user info", e);
|
|
1309
|
+
const QUIT_OPTION = "Quit";
|
|
1310
|
+
async function getExistingConfig(ctx) {
|
|
1311
|
+
try {
|
|
1312
|
+
return await retrieve();
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1315
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1316
|
+
return null;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1320
|
+
if (existingConfig && existingConfig.project) {
|
|
1321
|
+
const { shouldRelink } = await inquirer.prompt([
|
|
1322
|
+
{
|
|
1323
|
+
type: "confirm",
|
|
1324
|
+
name: "shouldRelink",
|
|
1325
|
+
message: `A project named ${chalk.cyan(
|
|
1326
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1327
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1328
|
+
default: false
|
|
958
1329
|
}
|
|
1330
|
+
]);
|
|
1331
|
+
if (!shouldRelink) {
|
|
1332
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1333
|
+
currentProjectName: existingConfig.project?.name
|
|
1334
|
+
});
|
|
1335
|
+
return false;
|
|
959
1336
|
}
|
|
960
1337
|
}
|
|
961
|
-
|
|
1338
|
+
return true;
|
|
1339
|
+
}
|
|
1340
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1341
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
962
1342
|
try {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1343
|
+
const {
|
|
1344
|
+
data: { data: projectList }
|
|
1345
|
+
} = await cloudApiService.listLinkProjects();
|
|
1346
|
+
spinner.succeed();
|
|
1347
|
+
if (!Array.isArray(projectList)) {
|
|
1348
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1349
|
+
return null;
|
|
1350
|
+
}
|
|
1351
|
+
const projects = projectList.filter(
|
|
1352
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1353
|
+
).map((project) => {
|
|
1354
|
+
return {
|
|
1355
|
+
name: project.displayName,
|
|
1356
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1357
|
+
};
|
|
1358
|
+
});
|
|
1359
|
+
if (projects.length === 0) {
|
|
1360
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1361
|
+
return null;
|
|
1362
|
+
}
|
|
1363
|
+
return projects;
|
|
966
1364
|
} catch (e) {
|
|
967
|
-
|
|
968
|
-
logger.debug(e);
|
|
969
|
-
return
|
|
1365
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1366
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1367
|
+
return null;
|
|
970
1368
|
}
|
|
1369
|
+
}
|
|
1370
|
+
async function getUserSelection(ctx, projects) {
|
|
1371
|
+
const { logger } = ctx;
|
|
971
1372
|
try {
|
|
972
|
-
await
|
|
1373
|
+
const answer = await inquirer.prompt([
|
|
1374
|
+
{
|
|
1375
|
+
type: "list",
|
|
1376
|
+
name: "linkProject",
|
|
1377
|
+
message: "Which project do you want to link?",
|
|
1378
|
+
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1379
|
+
}
|
|
1380
|
+
]);
|
|
1381
|
+
if (!answer.linkProject) {
|
|
1382
|
+
return null;
|
|
1383
|
+
}
|
|
1384
|
+
return answer;
|
|
973
1385
|
} catch (e) {
|
|
974
|
-
logger.debug("Failed to
|
|
1386
|
+
logger.debug("Failed to get user input", e);
|
|
1387
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1388
|
+
return null;
|
|
975
1389
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
logger.error("We encountered an issue opening the browser. Please try again later.");
|
|
996
|
-
logger.debug(e.message, e);
|
|
997
|
-
});
|
|
998
|
-
});
|
|
999
|
-
logger.log("If a browser tab does not open automatically, please follow the next steps:");
|
|
1000
|
-
logger.log(
|
|
1001
|
-
`1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
|
|
1002
|
-
);
|
|
1003
|
-
logger.log(
|
|
1004
|
-
`2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
|
|
1005
|
-
`
|
|
1390
|
+
}
|
|
1391
|
+
const action$3 = async (ctx) => {
|
|
1392
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1393
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1394
|
+
const { logger } = ctx;
|
|
1395
|
+
if (!token) {
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1399
|
+
const existingConfig = await getExistingConfig(ctx);
|
|
1400
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1401
|
+
if (!shouldRelink) {
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1405
|
+
const projects = await getProjectsList(
|
|
1406
|
+
ctx,
|
|
1407
|
+
cloudApiService,
|
|
1408
|
+
existingConfig
|
|
1006
1409
|
);
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
if (tokenResponse.status === 200) {
|
|
1022
|
-
try {
|
|
1023
|
-
logger.debug("🔐 Validating token...");
|
|
1024
|
-
await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
|
|
1025
|
-
logger.debug("🔐 Token validation successful!");
|
|
1026
|
-
} catch (e) {
|
|
1027
|
-
logger.debug(e);
|
|
1028
|
-
spinnerFail();
|
|
1029
|
-
throw new Error("Unable to proceed: Token validation failed");
|
|
1030
|
-
}
|
|
1031
|
-
logger.debug("🔍 Fetching user information...");
|
|
1032
|
-
const cloudApiServiceWithToken = await cloudApiFactory(authTokenData.access_token);
|
|
1033
|
-
await cloudApiServiceWithToken.getUserInfo();
|
|
1034
|
-
logger.debug("🔍 User information fetched successfully!");
|
|
1035
|
-
try {
|
|
1036
|
-
logger.debug("📝 Saving login information...");
|
|
1037
|
-
await tokenService.saveToken(authTokenData.access_token);
|
|
1038
|
-
logger.debug("📝 Login information saved successfully!");
|
|
1039
|
-
isAuthenticated = true;
|
|
1040
|
-
} catch (e) {
|
|
1041
|
-
logger.error(
|
|
1042
|
-
"There was a problem saving your login information. Please try logging in again."
|
|
1043
|
-
);
|
|
1044
|
-
logger.debug(e);
|
|
1045
|
-
spinnerFail();
|
|
1046
|
-
return false;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
} catch (e) {
|
|
1050
|
-
if (e.message === "Unable to proceed: Token validation failed") {
|
|
1051
|
-
logger.error(
|
|
1052
|
-
"There seems to be a problem with your login information. Please try logging in again."
|
|
1053
|
-
);
|
|
1054
|
-
spinnerFail();
|
|
1055
|
-
await trackFailedLogin();
|
|
1056
|
-
return false;
|
|
1057
|
-
}
|
|
1058
|
-
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
1059
|
-
logger.debug(e);
|
|
1060
|
-
spinnerFail();
|
|
1061
|
-
await trackFailedLogin();
|
|
1062
|
-
return false;
|
|
1063
|
-
}
|
|
1064
|
-
await new Promise((resolve) => {
|
|
1065
|
-
setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
|
|
1066
|
-
});
|
|
1410
|
+
if (!projects) {
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1414
|
+
if (!answer) {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
try {
|
|
1418
|
+
const { confirmAction } = await inquirer.prompt([
|
|
1419
|
+
{
|
|
1420
|
+
type: "confirm",
|
|
1421
|
+
name: "confirmAction",
|
|
1422
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1423
|
+
default: false
|
|
1067
1424
|
}
|
|
1425
|
+
]);
|
|
1426
|
+
if (!confirmAction) {
|
|
1427
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1428
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1429
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1430
|
+
});
|
|
1431
|
+
return;
|
|
1068
1432
|
}
|
|
1069
|
-
|
|
1070
|
-
logger.log(
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
);
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1433
|
+
await save({ project: answer.linkProject });
|
|
1434
|
+
logger.log(`Project ${chalk.cyan(answer.linkProject.displayName)} linked successfully.`);
|
|
1435
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1436
|
+
projectInternalName: answer.linkProject
|
|
1437
|
+
});
|
|
1438
|
+
} catch (e) {
|
|
1439
|
+
logger.debug("Failed to link project", e);
|
|
1440
|
+
logger.error("An error occurred while linking the project.");
|
|
1441
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1442
|
+
projectInternalName: answer.linkProject
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
const command$5 = ({ command: command2, ctx }) => {
|
|
1447
|
+
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$3)(ctx));
|
|
1083
1448
|
};
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1449
|
+
const link = {
|
|
1450
|
+
name: "link-project",
|
|
1451
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1452
|
+
action: action$3,
|
|
1453
|
+
command: command$5
|
|
1454
|
+
};
|
|
1455
|
+
const command$4 = ({ ctx }) => {
|
|
1456
|
+
return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1086
1457
|
"after",
|
|
1087
1458
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1088
|
-
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login",
|
|
1459
|
+
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
1089
1460
|
};
|
|
1090
1461
|
const login = {
|
|
1091
1462
|
name: "login",
|
|
1092
1463
|
description: "Strapi Cloud Login",
|
|
1093
|
-
action:
|
|
1094
|
-
command: command$
|
|
1464
|
+
action: loginAction,
|
|
1465
|
+
command: command$4
|
|
1095
1466
|
};
|
|
1096
|
-
const
|
|
1467
|
+
const openModule = import("open");
|
|
1468
|
+
const action$2 = async (ctx) => {
|
|
1097
1469
|
const { logger } = ctx;
|
|
1098
1470
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1099
1471
|
const token = await retrieveToken();
|
|
@@ -1101,9 +1473,21 @@ const action = async (ctx) => {
|
|
|
1101
1473
|
logger.log("You're already logged out.");
|
|
1102
1474
|
return;
|
|
1103
1475
|
}
|
|
1104
|
-
const cloudApiService = await cloudApiFactory(token);
|
|
1476
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1477
|
+
const config = await cloudApiService.config();
|
|
1478
|
+
const cliConfig2 = config.data;
|
|
1105
1479
|
try {
|
|
1106
1480
|
await eraseToken();
|
|
1481
|
+
openModule.then((open) => {
|
|
1482
|
+
open.default(
|
|
1483
|
+
`${cliConfig2.baseUrl}/oidc/logout?client_id=${encodeURIComponent(
|
|
1484
|
+
cliConfig2.clientId
|
|
1485
|
+
)}&logout_hint=${encodeURIComponent(token)}
|
|
1486
|
+
`
|
|
1487
|
+
).catch((e) => {
|
|
1488
|
+
logger.debug(e.message, e);
|
|
1489
|
+
});
|
|
1490
|
+
});
|
|
1107
1491
|
logger.log(
|
|
1108
1492
|
"🔌 You have been logged out from the CLI. If you are on a shared computer, please make sure to log out from the Strapi Cloud Dashboard as well."
|
|
1109
1493
|
);
|
|
@@ -1111,37 +1495,147 @@ const action = async (ctx) => {
|
|
|
1111
1495
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1112
1496
|
logger.debug(e);
|
|
1113
1497
|
}
|
|
1114
|
-
|
|
1115
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1116
|
-
} catch (e) {
|
|
1117
|
-
logger.debug("Failed to track logout event", e);
|
|
1118
|
-
}
|
|
1498
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1119
1499
|
};
|
|
1120
|
-
const command$
|
|
1121
|
-
|
|
1500
|
+
const command$3 = ({ ctx }) => {
|
|
1501
|
+
return createCommand("cloud:logout").alias("logout").description("Strapi Cloud Logout").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("logout", action$2)(ctx));
|
|
1122
1502
|
};
|
|
1123
1503
|
const logout = {
|
|
1124
1504
|
name: "logout",
|
|
1125
1505
|
description: "Strapi Cloud Logout",
|
|
1126
|
-
action,
|
|
1127
|
-
command: command$
|
|
1506
|
+
action: action$2,
|
|
1507
|
+
command: command$3
|
|
1128
1508
|
};
|
|
1129
|
-
const command = ({
|
|
1130
|
-
|
|
1509
|
+
const command$2 = ({ ctx }) => {
|
|
1510
|
+
return createCommand("cloud:create-project").description("Create a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("cloud:create-project", action$5)(ctx));
|
|
1131
1511
|
};
|
|
1132
1512
|
const createProject = {
|
|
1133
1513
|
name: "create-project",
|
|
1134
1514
|
description: "Create a new project",
|
|
1135
|
-
action: action$
|
|
1515
|
+
action: action$5,
|
|
1516
|
+
command: command$2
|
|
1517
|
+
};
|
|
1518
|
+
const action$1 = async (ctx) => {
|
|
1519
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1520
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1521
|
+
const { logger } = ctx;
|
|
1522
|
+
if (!token) {
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1526
|
+
const spinner = logger.spinner("Fetching your projects...").start();
|
|
1527
|
+
try {
|
|
1528
|
+
const {
|
|
1529
|
+
data: { data: projectList }
|
|
1530
|
+
} = await cloudApiService.listProjects();
|
|
1531
|
+
spinner.succeed();
|
|
1532
|
+
logger.log(projectList);
|
|
1533
|
+
} catch (e) {
|
|
1534
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1535
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1539
|
+
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$1)(ctx));
|
|
1540
|
+
};
|
|
1541
|
+
const listProjects = {
|
|
1542
|
+
name: "list-projects",
|
|
1543
|
+
description: "List Strapi Cloud projects",
|
|
1544
|
+
action: action$1,
|
|
1545
|
+
command: command$1
|
|
1546
|
+
};
|
|
1547
|
+
async function getProject(ctx) {
|
|
1548
|
+
const { project } = await retrieve();
|
|
1549
|
+
if (!project) {
|
|
1550
|
+
ctx.logger.warn(
|
|
1551
|
+
`
|
|
1552
|
+
We couldn't find a valid local project config.
|
|
1553
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1554
|
+
"link"
|
|
1555
|
+
)} command`
|
|
1556
|
+
);
|
|
1557
|
+
process.exit(1);
|
|
1558
|
+
}
|
|
1559
|
+
return project;
|
|
1560
|
+
}
|
|
1561
|
+
const action = async (ctx) => {
|
|
1562
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1563
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1564
|
+
const { logger } = ctx;
|
|
1565
|
+
if (!token) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
const project = await getProject(ctx);
|
|
1569
|
+
if (!project) {
|
|
1570
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1574
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1575
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1576
|
+
projectInternalName: project.name
|
|
1577
|
+
});
|
|
1578
|
+
try {
|
|
1579
|
+
const {
|
|
1580
|
+
data: { data: environmentsList }
|
|
1581
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1582
|
+
spinner.succeed();
|
|
1583
|
+
logger.log(environmentsList);
|
|
1584
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1585
|
+
projectInternalName: project.name
|
|
1586
|
+
});
|
|
1587
|
+
} catch (e) {
|
|
1588
|
+
if (e.response && e.response.status === 404) {
|
|
1589
|
+
spinner.succeed();
|
|
1590
|
+
logger.warn(
|
|
1591
|
+
`
|
|
1592
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1593
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1594
|
+
"link"
|
|
1595
|
+
)} command`
|
|
1596
|
+
);
|
|
1597
|
+
} else {
|
|
1598
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1599
|
+
logger.debug("Failed to list environments", e);
|
|
1600
|
+
}
|
|
1601
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1602
|
+
projectInternalName: project.name
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1607
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1608
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
|
|
1609
|
+
return cloud;
|
|
1610
|
+
}
|
|
1611
|
+
let environmentCmd = null;
|
|
1612
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1613
|
+
if (!environmentCmd) {
|
|
1614
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1615
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1616
|
+
}
|
|
1617
|
+
return environmentCmd;
|
|
1618
|
+
};
|
|
1619
|
+
const command = ({ command: command2, ctx }) => {
|
|
1620
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1621
|
+
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)(ctx));
|
|
1622
|
+
};
|
|
1623
|
+
const listEnvironments = {
|
|
1624
|
+
name: "list-environments",
|
|
1625
|
+
description: "List Strapi Cloud environments",
|
|
1626
|
+
action,
|
|
1136
1627
|
command
|
|
1137
1628
|
};
|
|
1138
1629
|
const cli = {
|
|
1139
1630
|
deployProject,
|
|
1631
|
+
link,
|
|
1140
1632
|
login,
|
|
1141
1633
|
logout,
|
|
1142
|
-
createProject
|
|
1634
|
+
createProject,
|
|
1635
|
+
listProjects,
|
|
1636
|
+
listEnvironments
|
|
1143
1637
|
};
|
|
1144
|
-
const cloudCommands = [deployProject, login, logout];
|
|
1638
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
|
|
1145
1639
|
async function initCloudCLIConfig() {
|
|
1146
1640
|
const localConfig = await getLocalConfig();
|
|
1147
1641
|
if (!localConfig.deviceId) {
|
|
@@ -1157,7 +1651,10 @@ async function buildStrapiCloudCommands({
|
|
|
1157
1651
|
await initCloudCLIConfig();
|
|
1158
1652
|
for (const cloudCommand of cloudCommands) {
|
|
1159
1653
|
try {
|
|
1160
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1654
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1655
|
+
if (subCommand) {
|
|
1656
|
+
command2.addCommand(subCommand);
|
|
1657
|
+
}
|
|
1161
1658
|
} catch (e) {
|
|
1162
1659
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1163
1660
|
}
|