@strapi/cloud-cli 0.0.0-next.b11829e6c6aacb45bc1ec2f341609d04d88080d2 → 0.0.0-next.d54a672641d83234230d3d80d92aaf87f60f8c75
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 +578 -293
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +577 -290
- package/dist/index.mjs.map +1 -1
- 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/utils/apply-default-name.d.ts +7 -0
- package/dist/src/create-project/utils/apply-default-name.d.ts.map +1 -0
- 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/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 +2 -2
- 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 +22 -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 +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 +6 -5
- 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.js
CHANGED
|
@@ -29,7 +29,6 @@ const chalk = require("chalk");
|
|
|
29
29
|
const axios = require("axios");
|
|
30
30
|
const crypto = require("node:crypto");
|
|
31
31
|
const utils = require("@strapi/utils");
|
|
32
|
-
const fs = require("fs");
|
|
33
32
|
const tar = require("tar");
|
|
34
33
|
const minimatch = require("minimatch");
|
|
35
34
|
const inquirer = require("inquirer");
|
|
@@ -41,10 +40,10 @@ const jwt = require("jsonwebtoken");
|
|
|
41
40
|
const stringify = require("fast-safe-stringify");
|
|
42
41
|
const ora = require("ora");
|
|
43
42
|
const cliProgress = require("cli-progress");
|
|
44
|
-
const EventSource = require("eventsource");
|
|
45
|
-
const fs$1 = require("fs/promises");
|
|
46
43
|
const pkgUp = require("pkg-up");
|
|
47
44
|
const yup = require("yup");
|
|
45
|
+
const _ = require("lodash");
|
|
46
|
+
const EventSource = require("eventsource");
|
|
48
47
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
49
48
|
function _interopNamespace(e) {
|
|
50
49
|
if (e && e.__esModule)
|
|
@@ -65,12 +64,11 @@ function _interopNamespace(e) {
|
|
|
65
64
|
return Object.freeze(n);
|
|
66
65
|
}
|
|
67
66
|
const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
|
|
68
|
-
const
|
|
67
|
+
const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
|
|
69
68
|
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
70
69
|
const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
71
70
|
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
72
71
|
const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
|
|
73
|
-
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
74
72
|
const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
|
|
75
73
|
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
76
74
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
@@ -80,10 +78,10 @@ const jwt__default = /* @__PURE__ */ _interopDefault(jwt);
|
|
|
80
78
|
const stringify__default = /* @__PURE__ */ _interopDefault(stringify);
|
|
81
79
|
const ora__default = /* @__PURE__ */ _interopDefault(ora);
|
|
82
80
|
const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
|
|
83
|
-
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
84
|
-
const fs__default = /* @__PURE__ */ _interopDefault(fs$1);
|
|
85
81
|
const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
|
|
86
82
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
83
|
+
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
84
|
+
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
87
85
|
const apiConfig = {
|
|
88
86
|
apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
89
87
|
dashboardBaseUrl: utils.env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -102,23 +100,6 @@ const IGNORED_PATTERNS = [
|
|
|
102
100
|
"**/.idea/**",
|
|
103
101
|
"**/.vscode/**"
|
|
104
102
|
];
|
|
105
|
-
const getFiles = (dirPath, ignorePatterns = [], arrayOfFiles = [], subfolder = "") => {
|
|
106
|
-
const entries = fs__namespace.readdirSync(path__namespace.join(dirPath, subfolder));
|
|
107
|
-
entries.forEach((entry) => {
|
|
108
|
-
const entryPathFromRoot = path__namespace.join(subfolder, entry);
|
|
109
|
-
const entryPath = path__namespace.relative(dirPath, entryPathFromRoot);
|
|
110
|
-
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
111
|
-
if (isIgnored) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (fs__namespace.statSync(entryPath).isDirectory()) {
|
|
115
|
-
getFiles(dirPath, ignorePatterns, arrayOfFiles, entryPathFromRoot);
|
|
116
|
-
} else {
|
|
117
|
-
arrayOfFiles.push(entryPath);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
return arrayOfFiles;
|
|
121
|
-
};
|
|
122
103
|
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
123
104
|
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
124
105
|
const relativeFilePath = path__namespace.join(folderPath, file);
|
|
@@ -136,16 +117,35 @@ const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
|
136
117
|
}
|
|
137
118
|
return isIgnored;
|
|
138
119
|
};
|
|
139
|
-
const
|
|
120
|
+
const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
121
|
+
const arrayOfFiles = [];
|
|
122
|
+
const entries = await fse__namespace.readdir(path__namespace.join(dirPath, subfolder));
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
const entryPathFromRoot = path__namespace.join(subfolder, entry);
|
|
125
|
+
const entryPath = path__namespace.relative(dirPath, entryPathFromRoot);
|
|
126
|
+
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
127
|
+
if (!isIgnored) {
|
|
128
|
+
if (fse__namespace.statSync(entryPath).isDirectory()) {
|
|
129
|
+
const subFiles = await getFiles(dirPath, ignorePatterns, entryPathFromRoot);
|
|
130
|
+
arrayOfFiles.push(...subFiles);
|
|
131
|
+
} else {
|
|
132
|
+
arrayOfFiles.push(entryPath);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return arrayOfFiles;
|
|
137
|
+
};
|
|
138
|
+
const readGitignore = async (folderPath) => {
|
|
140
139
|
const gitignorePath = path__namespace.resolve(folderPath, ".gitignore");
|
|
141
|
-
|
|
140
|
+
const pathExist = await fse__namespace.pathExists(gitignorePath);
|
|
141
|
+
if (!pathExist)
|
|
142
142
|
return [];
|
|
143
|
-
const gitignoreContent =
|
|
143
|
+
const gitignoreContent = await fse__namespace.readFile(gitignorePath, "utf8");
|
|
144
144
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
145
145
|
};
|
|
146
146
|
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
147
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
148
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
147
|
+
const ignorePatterns = await readGitignore(folderToCompress);
|
|
148
|
+
const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
|
|
149
149
|
return tar__namespace.c(
|
|
150
150
|
{
|
|
151
151
|
gzip: true,
|
|
@@ -158,7 +158,7 @@ const APP_FOLDER_NAME = "com.strapi.cli";
|
|
|
158
158
|
const CONFIG_FILENAME = "config.json";
|
|
159
159
|
async function checkDirectoryExists(directoryPath) {
|
|
160
160
|
try {
|
|
161
|
-
const fsStat = await
|
|
161
|
+
const fsStat = await fse__namespace.default.lstat(directoryPath);
|
|
162
162
|
return fsStat.isDirectory();
|
|
163
163
|
} catch (e) {
|
|
164
164
|
return false;
|
|
@@ -166,14 +166,14 @@ async function checkDirectoryExists(directoryPath) {
|
|
|
166
166
|
}
|
|
167
167
|
async function getTmpStoragePath() {
|
|
168
168
|
const storagePath = path__namespace.default.join(os__default.default.tmpdir(), APP_FOLDER_NAME);
|
|
169
|
-
await
|
|
169
|
+
await fse__namespace.default.ensureDir(storagePath);
|
|
170
170
|
return storagePath;
|
|
171
171
|
}
|
|
172
172
|
async function getConfigPath() {
|
|
173
173
|
const configDirs = XDGAppPaths__default.default(APP_FOLDER_NAME).configDirs();
|
|
174
174
|
const configPath = configDirs.find(checkDirectoryExists);
|
|
175
175
|
if (!configPath) {
|
|
176
|
-
await
|
|
176
|
+
await fse__namespace.default.ensureDir(configDirs[0]);
|
|
177
177
|
return configDirs[0];
|
|
178
178
|
}
|
|
179
179
|
return configPath;
|
|
@@ -181,9 +181,9 @@ async function getConfigPath() {
|
|
|
181
181
|
async function getLocalConfig() {
|
|
182
182
|
const configPath = await getConfigPath();
|
|
183
183
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
184
|
-
await
|
|
184
|
+
await fse__namespace.default.ensureFile(configFilePath);
|
|
185
185
|
try {
|
|
186
|
-
return await
|
|
186
|
+
return await fse__namespace.default.readJSON(configFilePath, { encoding: "utf8", throws: true });
|
|
187
187
|
} catch (e) {
|
|
188
188
|
return {};
|
|
189
189
|
}
|
|
@@ -191,10 +191,10 @@ async function getLocalConfig() {
|
|
|
191
191
|
async function saveLocalConfig(data) {
|
|
192
192
|
const configPath = await getConfigPath();
|
|
193
193
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
194
|
-
await
|
|
194
|
+
await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
195
195
|
}
|
|
196
196
|
const name = "@strapi/cloud-cli";
|
|
197
|
-
const version = "4.25.
|
|
197
|
+
const version = "4.25.5";
|
|
198
198
|
const description = "Commands to interact with the Strapi Cloud";
|
|
199
199
|
const keywords = [
|
|
200
200
|
"strapi",
|
|
@@ -235,10 +235,11 @@ const scripts = {
|
|
|
235
235
|
build: "pack-up build",
|
|
236
236
|
clean: "run -T rimraf ./dist",
|
|
237
237
|
lint: "run -T eslint .",
|
|
238
|
+
"test:unit": "run -T jest",
|
|
238
239
|
watch: "pack-up watch"
|
|
239
240
|
};
|
|
240
241
|
const dependencies = {
|
|
241
|
-
"@strapi/utils": "4.25.
|
|
242
|
+
"@strapi/utils": "4.25.5",
|
|
242
243
|
axios: "1.6.0",
|
|
243
244
|
chalk: "4.1.2",
|
|
244
245
|
"cli-progress": "3.12.0",
|
|
@@ -263,8 +264,8 @@ const devDependencies = {
|
|
|
263
264
|
"@types/cli-progress": "3.11.5",
|
|
264
265
|
"@types/eventsource": "1.1.15",
|
|
265
266
|
"@types/lodash": "^4.14.191",
|
|
266
|
-
"eslint-config-custom": "4.25.
|
|
267
|
-
tsconfig: "4.25.
|
|
267
|
+
"eslint-config-custom": "4.25.5",
|
|
268
|
+
tsconfig: "4.25.5"
|
|
268
269
|
};
|
|
269
270
|
const engines = {
|
|
270
271
|
node: ">=18.0.0 <=20.x.x",
|
|
@@ -293,7 +294,7 @@ const packageJson = {
|
|
|
293
294
|
engines
|
|
294
295
|
};
|
|
295
296
|
const VERSION = "v1";
|
|
296
|
-
async function cloudApiFactory(token) {
|
|
297
|
+
async function cloudApiFactory({ logger }, token) {
|
|
297
298
|
const localConfig = await getLocalConfig();
|
|
298
299
|
const customHeaders = {
|
|
299
300
|
"x-device-id": localConfig.deviceId,
|
|
@@ -317,7 +318,7 @@ async function cloudApiFactory(token) {
|
|
|
317
318
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
318
319
|
return axiosCloudAPI.post(
|
|
319
320
|
`/deploy/${project.name}`,
|
|
320
|
-
{ file:
|
|
321
|
+
{ file: fse__namespace.default.createReadStream(filePath) },
|
|
321
322
|
{
|
|
322
323
|
headers: {
|
|
323
324
|
"Content-Type": "multipart/form-data"
|
|
@@ -346,11 +347,47 @@ async function cloudApiFactory(token) {
|
|
|
346
347
|
getUserInfo() {
|
|
347
348
|
return axiosCloudAPI.get("/user");
|
|
348
349
|
},
|
|
349
|
-
config() {
|
|
350
|
-
|
|
350
|
+
async config() {
|
|
351
|
+
try {
|
|
352
|
+
const response = await axiosCloudAPI.get("/config");
|
|
353
|
+
if (response.status !== 200) {
|
|
354
|
+
throw new Error("Error fetching cloud CLI config from the server.");
|
|
355
|
+
}
|
|
356
|
+
return response;
|
|
357
|
+
} catch (error) {
|
|
358
|
+
logger.debug(
|
|
359
|
+
"🥲 Oops! Couldn't retrieve the cloud CLI config from the server. Please try again."
|
|
360
|
+
);
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
async listProjects() {
|
|
365
|
+
try {
|
|
366
|
+
const response = await axiosCloudAPI.get("/projects");
|
|
367
|
+
if (response.status !== 200) {
|
|
368
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
369
|
+
}
|
|
370
|
+
return response;
|
|
371
|
+
} catch (error) {
|
|
372
|
+
logger.debug(
|
|
373
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
374
|
+
);
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
351
377
|
},
|
|
352
|
-
|
|
353
|
-
|
|
378
|
+
async listLinkProjects() {
|
|
379
|
+
try {
|
|
380
|
+
const response = await axiosCloudAPI.get("/projects/linkable");
|
|
381
|
+
if (response.status !== 200) {
|
|
382
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
383
|
+
}
|
|
384
|
+
return response;
|
|
385
|
+
} catch (error) {
|
|
386
|
+
logger.debug(
|
|
387
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
388
|
+
);
|
|
389
|
+
throw error;
|
|
390
|
+
}
|
|
354
391
|
},
|
|
355
392
|
track(event, payload = {}) {
|
|
356
393
|
return axiosCloudAPI.post("/track", {
|
|
@@ -365,18 +402,18 @@ async function save(data, { directoryPath } = {}) {
|
|
|
365
402
|
const alreadyInFileData = await retrieve({ directoryPath });
|
|
366
403
|
const storedData = { ...alreadyInFileData, ...data };
|
|
367
404
|
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
368
|
-
await
|
|
369
|
-
await
|
|
405
|
+
await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
406
|
+
await fse__namespace.default.writeJson(pathToFile, storedData, { encoding: "utf8" });
|
|
370
407
|
}
|
|
371
408
|
async function retrieve({
|
|
372
409
|
directoryPath
|
|
373
410
|
} = {}) {
|
|
374
411
|
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
375
|
-
const pathExists = await
|
|
412
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
376
413
|
if (!pathExists) {
|
|
377
414
|
return {};
|
|
378
415
|
}
|
|
379
|
-
return
|
|
416
|
+
return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
|
|
380
417
|
}
|
|
381
418
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
382
419
|
__proto__: null,
|
|
@@ -386,7 +423,7 @@ const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defi
|
|
|
386
423
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
387
424
|
let cliConfig;
|
|
388
425
|
async function tokenServiceFactory({ logger }) {
|
|
389
|
-
const cloudApiService = await cloudApiFactory();
|
|
426
|
+
const cloudApiService = await cloudApiFactory({ logger });
|
|
390
427
|
async function saveToken(str) {
|
|
391
428
|
const appConfig = await getLocalConfig();
|
|
392
429
|
if (!appConfig) {
|
|
@@ -435,14 +472,17 @@ async function tokenServiceFactory({ logger }) {
|
|
|
435
472
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
436
473
|
);
|
|
437
474
|
}
|
|
475
|
+
return Promise.reject(new Error("Invalid token"));
|
|
438
476
|
}
|
|
439
477
|
return new Promise((resolve, reject) => {
|
|
440
478
|
jwt__default.default.verify(idToken, getKey, (err) => {
|
|
441
479
|
if (err) {
|
|
442
480
|
reject(err);
|
|
443
|
-
} else {
|
|
444
|
-
resolve();
|
|
445
481
|
}
|
|
482
|
+
if (decodedToken.payload.exp < Math.floor(Date.now() / 1e3)) {
|
|
483
|
+
reject(new Error("Token is expired"));
|
|
484
|
+
}
|
|
485
|
+
resolve();
|
|
446
486
|
});
|
|
447
487
|
});
|
|
448
488
|
}
|
|
@@ -476,15 +516,15 @@ async function tokenServiceFactory({ logger }) {
|
|
|
476
516
|
throw e;
|
|
477
517
|
}
|
|
478
518
|
}
|
|
479
|
-
async function getValidToken() {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
logger.log(
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
519
|
+
async function getValidToken(ctx, loginAction2) {
|
|
520
|
+
let token = await retrieveToken();
|
|
521
|
+
while (!token || !await isTokenValid(token)) {
|
|
522
|
+
logger.log(
|
|
523
|
+
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."
|
|
524
|
+
);
|
|
525
|
+
if (!await loginAction2(ctx))
|
|
526
|
+
return null;
|
|
527
|
+
token = await retrieveToken();
|
|
488
528
|
}
|
|
489
529
|
return token;
|
|
490
530
|
}
|
|
@@ -618,17 +658,227 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
618
658
|
local: strapiInfoSave,
|
|
619
659
|
tokenServiceFactory
|
|
620
660
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
621
|
-
|
|
661
|
+
yup__namespace.object({
|
|
662
|
+
name: yup__namespace.string().required(),
|
|
663
|
+
exports: yup__namespace.lazy(
|
|
664
|
+
(value) => yup__namespace.object(
|
|
665
|
+
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
666
|
+
if (typeof value2 === "object") {
|
|
667
|
+
acc[key] = yup__namespace.object({
|
|
668
|
+
types: yup__namespace.string().optional(),
|
|
669
|
+
source: yup__namespace.string().required(),
|
|
670
|
+
module: yup__namespace.string().optional(),
|
|
671
|
+
import: yup__namespace.string().required(),
|
|
672
|
+
require: yup__namespace.string().required(),
|
|
673
|
+
default: yup__namespace.string().required()
|
|
674
|
+
}).noUnknown(true);
|
|
675
|
+
} else {
|
|
676
|
+
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
677
|
+
}
|
|
678
|
+
return acc;
|
|
679
|
+
}, {}) : void 0
|
|
680
|
+
).optional()
|
|
681
|
+
)
|
|
682
|
+
});
|
|
683
|
+
const loadPkg = async ({ cwd, logger }) => {
|
|
684
|
+
const pkgPath = await pkgUp__default.default({ cwd });
|
|
685
|
+
if (!pkgPath) {
|
|
686
|
+
throw new Error("Could not find a package.json in the current directory");
|
|
687
|
+
}
|
|
688
|
+
const buffer = await fse__namespace.readFile(pkgPath);
|
|
689
|
+
const pkg = JSON.parse(buffer.toString());
|
|
690
|
+
logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
|
|
691
|
+
return pkg;
|
|
692
|
+
};
|
|
693
|
+
async function getProjectNameFromPackageJson(ctx) {
|
|
694
|
+
try {
|
|
695
|
+
const packageJson2 = await loadPkg(ctx);
|
|
696
|
+
return packageJson2.name || "my-strapi-project";
|
|
697
|
+
} catch (e) {
|
|
698
|
+
return "my-strapi-project";
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
function applyDefaultName(newDefaultName, questions, defaultValues) {
|
|
702
|
+
const newDefaultValues = ___default.default.cloneDeep(defaultValues);
|
|
703
|
+
newDefaultValues.name = newDefaultName;
|
|
704
|
+
const newQuestions = questions.map((question) => {
|
|
705
|
+
const questionCopy = ___default.default.cloneDeep(question);
|
|
706
|
+
if (questionCopy.name === "name") {
|
|
707
|
+
questionCopy.default = newDefaultName;
|
|
708
|
+
}
|
|
709
|
+
return questionCopy;
|
|
710
|
+
});
|
|
711
|
+
return { newQuestions, newDefaultValues };
|
|
712
|
+
}
|
|
713
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
714
|
+
try {
|
|
715
|
+
await cloudApiService.track(eventName, eventData);
|
|
716
|
+
} catch (e) {
|
|
717
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
const openModule$1 = import("open");
|
|
721
|
+
async function promptLogin(ctx) {
|
|
722
|
+
const response = await inquirer__default.default.prompt([
|
|
723
|
+
{
|
|
724
|
+
type: "confirm",
|
|
725
|
+
name: "login",
|
|
726
|
+
message: "Would you like to login?"
|
|
727
|
+
}
|
|
728
|
+
]);
|
|
729
|
+
if (response.login) {
|
|
730
|
+
const loginSuccessful = await loginAction(ctx);
|
|
731
|
+
return loginSuccessful;
|
|
732
|
+
}
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
async function loginAction(ctx) {
|
|
736
|
+
const { logger } = ctx;
|
|
622
737
|
const tokenService = await tokenServiceFactory(ctx);
|
|
738
|
+
const existingToken = await tokenService.retrieveToken();
|
|
739
|
+
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
740
|
+
if (existingToken) {
|
|
741
|
+
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
742
|
+
if (isTokenValid) {
|
|
743
|
+
try {
|
|
744
|
+
const userInfo = await cloudApiService.getUserInfo();
|
|
745
|
+
const { email } = userInfo.data.data;
|
|
746
|
+
if (email) {
|
|
747
|
+
logger.log(`You are already logged into your account (${email}).`);
|
|
748
|
+
} else {
|
|
749
|
+
logger.log("You are already logged in.");
|
|
750
|
+
}
|
|
751
|
+
logger.log(
|
|
752
|
+
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
753
|
+
);
|
|
754
|
+
logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
755
|
+
return true;
|
|
756
|
+
} catch (e) {
|
|
757
|
+
logger.debug("Failed to fetch user info", e);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
let cliConfig2;
|
|
762
|
+
try {
|
|
763
|
+
logger.info("🔌 Connecting to the Strapi Cloud API...");
|
|
764
|
+
const config = await cloudApiService.config();
|
|
765
|
+
cliConfig2 = config.data;
|
|
766
|
+
} catch (e) {
|
|
767
|
+
logger.error("🥲 Oops! Something went wrong while logging you in. Please try again.");
|
|
768
|
+
logger.debug(e);
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
772
|
+
logger.debug("🔐 Creating device authentication request...", {
|
|
773
|
+
client_id: cliConfig2.clientId,
|
|
774
|
+
scope: cliConfig2.scope,
|
|
775
|
+
audience: cliConfig2.audience
|
|
776
|
+
});
|
|
777
|
+
const deviceAuthResponse = await axios__default.default.post(cliConfig2.deviceCodeAuthUrl, {
|
|
778
|
+
client_id: cliConfig2.clientId,
|
|
779
|
+
scope: cliConfig2.scope,
|
|
780
|
+
audience: cliConfig2.audience
|
|
781
|
+
}).catch((e) => {
|
|
782
|
+
logger.error("There was an issue with the authentication process. Please try again.");
|
|
783
|
+
if (e.message) {
|
|
784
|
+
logger.debug(e.message, e);
|
|
785
|
+
} else {
|
|
786
|
+
logger.debug(e);
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
openModule$1.then((open) => {
|
|
790
|
+
open.default(deviceAuthResponse.data.verification_uri_complete).catch((e) => {
|
|
791
|
+
logger.error("We encountered an issue opening the browser. Please try again later.");
|
|
792
|
+
logger.debug(e.message, e);
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
logger.log("If a browser tab does not open automatically, please follow the next steps:");
|
|
796
|
+
logger.log(
|
|
797
|
+
`1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
|
|
798
|
+
);
|
|
799
|
+
logger.log(
|
|
800
|
+
`2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
|
|
801
|
+
`
|
|
802
|
+
);
|
|
803
|
+
const tokenPayload = {
|
|
804
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
805
|
+
device_code: deviceAuthResponse.data.device_code,
|
|
806
|
+
client_id: cliConfig2.clientId
|
|
807
|
+
};
|
|
808
|
+
let isAuthenticated = false;
|
|
809
|
+
const authenticate = async () => {
|
|
810
|
+
const spinner = logger.spinner("Waiting for authentication");
|
|
811
|
+
spinner.start();
|
|
812
|
+
const spinnerFail = () => spinner.fail("Authentication failed!");
|
|
813
|
+
while (!isAuthenticated) {
|
|
814
|
+
try {
|
|
815
|
+
const tokenResponse = await axios__default.default.post(cliConfig2.tokenUrl, tokenPayload);
|
|
816
|
+
const authTokenData = tokenResponse.data;
|
|
817
|
+
if (tokenResponse.status === 200) {
|
|
818
|
+
try {
|
|
819
|
+
logger.debug("🔐 Validating token...");
|
|
820
|
+
await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
|
|
821
|
+
logger.debug("🔐 Token validation successful!");
|
|
822
|
+
} catch (e) {
|
|
823
|
+
logger.debug(e);
|
|
824
|
+
spinnerFail();
|
|
825
|
+
throw new Error("Unable to proceed: Token validation failed");
|
|
826
|
+
}
|
|
827
|
+
logger.debug("🔍 Fetching user information...");
|
|
828
|
+
const cloudApiServiceWithToken = await cloudApiFactory(ctx, authTokenData.access_token);
|
|
829
|
+
await cloudApiServiceWithToken.getUserInfo();
|
|
830
|
+
logger.debug("🔍 User information fetched successfully!");
|
|
831
|
+
try {
|
|
832
|
+
logger.debug("📝 Saving login information...");
|
|
833
|
+
await tokenService.saveToken(authTokenData.access_token);
|
|
834
|
+
logger.debug("📝 Login information saved successfully!");
|
|
835
|
+
isAuthenticated = true;
|
|
836
|
+
} catch (e) {
|
|
837
|
+
logger.error(
|
|
838
|
+
"There was a problem saving your login information. Please try logging in again."
|
|
839
|
+
);
|
|
840
|
+
logger.debug(e);
|
|
841
|
+
spinnerFail();
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
} catch (e) {
|
|
846
|
+
if (e.message === "Unable to proceed: Token validation failed") {
|
|
847
|
+
logger.error(
|
|
848
|
+
"There seems to be a problem with your login information. Please try logging in again."
|
|
849
|
+
);
|
|
850
|
+
spinnerFail();
|
|
851
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
855
|
+
logger.debug(e);
|
|
856
|
+
spinnerFail();
|
|
857
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
await new Promise((resolve) => {
|
|
861
|
+
setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
spinner.succeed("Authentication successful!");
|
|
866
|
+
logger.log("You are now logged into Strapi Cloud.");
|
|
867
|
+
logger.log(
|
|
868
|
+
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
869
|
+
);
|
|
870
|
+
logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
871
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
872
|
+
};
|
|
873
|
+
await authenticate();
|
|
874
|
+
return isAuthenticated;
|
|
875
|
+
}
|
|
876
|
+
async function handleError(ctx, error) {
|
|
623
877
|
const { logger } = ctx;
|
|
624
878
|
logger.debug(error);
|
|
625
879
|
if (error instanceof axios.AxiosError) {
|
|
626
880
|
const errorMessage = typeof error.response?.data === "string" ? error.response.data : null;
|
|
627
881
|
switch (error.response?.status) {
|
|
628
|
-
case 401:
|
|
629
|
-
logger.error("Your session has expired. Please log in again.");
|
|
630
|
-
await tokenService.eraseToken();
|
|
631
|
-
return;
|
|
632
882
|
case 403:
|
|
633
883
|
logger.error(
|
|
634
884
|
errorMessage || "You do not have permission to create a project. Please contact support for assistance."
|
|
@@ -654,28 +904,48 @@ async function handleError(ctx, error) {
|
|
|
654
904
|
"We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance."
|
|
655
905
|
);
|
|
656
906
|
}
|
|
657
|
-
|
|
907
|
+
async function createProject$1(ctx, cloudApi, projectInput) {
|
|
658
908
|
const { logger } = ctx;
|
|
659
|
-
const
|
|
660
|
-
|
|
909
|
+
const spinner = logger.spinner("Setting up your project...").start();
|
|
910
|
+
try {
|
|
911
|
+
const { data } = await cloudApi.createProject(projectInput);
|
|
912
|
+
await save({ project: data });
|
|
913
|
+
spinner.succeed("Project created successfully!");
|
|
914
|
+
return data;
|
|
915
|
+
} catch (e) {
|
|
916
|
+
spinner.fail("An error occurred while creating the project on Strapi Cloud.");
|
|
917
|
+
throw e;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
const action$4 = async (ctx) => {
|
|
921
|
+
const { logger } = ctx;
|
|
922
|
+
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
923
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
661
924
|
if (!token) {
|
|
662
925
|
return;
|
|
663
926
|
}
|
|
664
|
-
const cloudApi = await cloudApiFactory(token);
|
|
927
|
+
const cloudApi = await cloudApiFactory(ctx, token);
|
|
665
928
|
const { data: config } = await cloudApi.config();
|
|
666
|
-
const { questions,
|
|
929
|
+
const { newQuestions: questions, newDefaultValues: defaultValues } = applyDefaultName(
|
|
930
|
+
await getProjectNameFromPackageJson(ctx),
|
|
931
|
+
config.projectCreation.questions,
|
|
932
|
+
config.projectCreation.defaults
|
|
933
|
+
);
|
|
667
934
|
const projectAnswersDefaulted = fp.defaults(defaultValues);
|
|
668
935
|
const projectAnswers = await inquirer__default.default.prompt(questions);
|
|
669
936
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
670
|
-
const spinner = logger.spinner("Setting up your project...").start();
|
|
671
937
|
try {
|
|
672
|
-
|
|
673
|
-
await save({ project: data });
|
|
674
|
-
spinner.succeed("Project created successfully!");
|
|
675
|
-
return data;
|
|
938
|
+
return await createProject$1(ctx, cloudApi, projectInput);
|
|
676
939
|
} catch (e) {
|
|
677
|
-
|
|
678
|
-
|
|
940
|
+
if (e instanceof axios.AxiosError && e.response?.status === 401) {
|
|
941
|
+
logger.warn("Oops! Your session has expired. Please log in again to retry.");
|
|
942
|
+
await eraseToken();
|
|
943
|
+
if (await promptLogin(ctx)) {
|
|
944
|
+
return await createProject$1(ctx, cloudApi, projectInput);
|
|
945
|
+
}
|
|
946
|
+
} else {
|
|
947
|
+
await handleError(ctx, e);
|
|
948
|
+
}
|
|
679
949
|
}
|
|
680
950
|
};
|
|
681
951
|
function notificationServiceFactory({ logger }) {
|
|
@@ -709,38 +979,6 @@ function notificationServiceFactory({ logger }) {
|
|
|
709
979
|
};
|
|
710
980
|
};
|
|
711
981
|
}
|
|
712
|
-
yup__namespace.object({
|
|
713
|
-
name: yup__namespace.string().required(),
|
|
714
|
-
exports: yup__namespace.lazy(
|
|
715
|
-
(value) => yup__namespace.object(
|
|
716
|
-
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
717
|
-
if (typeof value2 === "object") {
|
|
718
|
-
acc[key] = yup__namespace.object({
|
|
719
|
-
types: yup__namespace.string().optional(),
|
|
720
|
-
source: yup__namespace.string().required(),
|
|
721
|
-
module: yup__namespace.string().optional(),
|
|
722
|
-
import: yup__namespace.string().required(),
|
|
723
|
-
require: yup__namespace.string().required(),
|
|
724
|
-
default: yup__namespace.string().required()
|
|
725
|
-
}).noUnknown(true);
|
|
726
|
-
} else {
|
|
727
|
-
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
728
|
-
}
|
|
729
|
-
return acc;
|
|
730
|
-
}, {}) : void 0
|
|
731
|
-
).optional()
|
|
732
|
-
)
|
|
733
|
-
});
|
|
734
|
-
const loadPkg = async ({ cwd, logger }) => {
|
|
735
|
-
const pkgPath = await pkgUp__default.default({ cwd });
|
|
736
|
-
if (!pkgPath) {
|
|
737
|
-
throw new Error("Could not find a package.json in the current directory");
|
|
738
|
-
}
|
|
739
|
-
const buffer = await fs__default.default.readFile(pkgPath);
|
|
740
|
-
const pkg = JSON.parse(buffer.toString());
|
|
741
|
-
logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
|
|
742
|
-
return pkg;
|
|
743
|
-
};
|
|
744
982
|
const buildLogsServiceFactory = ({ logger }) => {
|
|
745
983
|
return async (url, token, cliConfig2) => {
|
|
746
984
|
const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
|
|
@@ -794,6 +1032,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
794
1032
|
if (retries > MAX_RETRIES) {
|
|
795
1033
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
796
1034
|
es.close();
|
|
1035
|
+
clearExistingTimeout();
|
|
797
1036
|
reject(new Error("Max retries reached"));
|
|
798
1037
|
}
|
|
799
1038
|
};
|
|
@@ -803,7 +1042,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
803
1042
|
};
|
|
804
1043
|
};
|
|
805
1044
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
806
|
-
const cloudApi = await cloudApiFactory(token);
|
|
1045
|
+
const cloudApi = await cloudApiFactory(ctx, token);
|
|
807
1046
|
try {
|
|
808
1047
|
const storagePath = await getTmpStoragePath();
|
|
809
1048
|
const projectFolder = path__namespace.default.resolve(process.cwd());
|
|
@@ -836,13 +1075,13 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
836
1075
|
process.exit(1);
|
|
837
1076
|
}
|
|
838
1077
|
const tarFilePath = path__namespace.default.resolve(storagePath, compressedFilename);
|
|
839
|
-
const fileStats = await
|
|
1078
|
+
const fileStats = await fse__namespace.default.stat(tarFilePath);
|
|
840
1079
|
if (fileStats.size > maxProjectFileSize) {
|
|
841
1080
|
ctx.logger.log(
|
|
842
1081
|
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
843
1082
|
);
|
|
844
1083
|
try {
|
|
845
|
-
await
|
|
1084
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
846
1085
|
} catch (e) {
|
|
847
1086
|
ctx.logger.log("Unable to remove file: ", tarFilePath);
|
|
848
1087
|
ctx.logger.debug(e);
|
|
@@ -881,7 +1120,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
881
1120
|
}
|
|
882
1121
|
ctx.logger.debug(e);
|
|
883
1122
|
} finally {
|
|
884
|
-
await
|
|
1123
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
885
1124
|
}
|
|
886
1125
|
process.exit(0);
|
|
887
1126
|
} catch (e) {
|
|
@@ -894,7 +1133,7 @@ async function getProject(ctx) {
|
|
|
894
1133
|
const { project } = await retrieve();
|
|
895
1134
|
if (!project) {
|
|
896
1135
|
try {
|
|
897
|
-
return await action$
|
|
1136
|
+
return await action$4(ctx);
|
|
898
1137
|
} catch (e) {
|
|
899
1138
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
900
1139
|
ctx.logger.debug(e);
|
|
@@ -903,10 +1142,21 @@ async function getProject(ctx) {
|
|
|
903
1142
|
}
|
|
904
1143
|
return project;
|
|
905
1144
|
}
|
|
906
|
-
|
|
1145
|
+
async function getConfig({
|
|
1146
|
+
ctx,
|
|
1147
|
+
cloudApiService
|
|
1148
|
+
}) {
|
|
1149
|
+
try {
|
|
1150
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1151
|
+
return cliConfig2;
|
|
1152
|
+
} catch (e) {
|
|
1153
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1154
|
+
return null;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
const action$3 = async (ctx) => {
|
|
907
1158
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
908
|
-
const
|
|
909
|
-
const token = await getValidToken();
|
|
1159
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
910
1160
|
if (!token) {
|
|
911
1161
|
return;
|
|
912
1162
|
}
|
|
@@ -914,14 +1164,19 @@ const action$2 = async (ctx) => {
|
|
|
914
1164
|
if (!project) {
|
|
915
1165
|
return;
|
|
916
1166
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
}
|
|
1167
|
+
const cloudApiService = await cloudApiFactory(ctx);
|
|
1168
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1169
|
+
projectInternalName: project.name
|
|
1170
|
+
});
|
|
922
1171
|
const notificationService = notificationServiceFactory(ctx);
|
|
923
1172
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
924
|
-
const
|
|
1173
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1174
|
+
if (!cliConfig2) {
|
|
1175
|
+
ctx.logger.error(
|
|
1176
|
+
"An error occurred while retrieving data from Strapi Cloud. Please try check your network or again later."
|
|
1177
|
+
);
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
925
1180
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
926
1181
|
if (Number.isNaN(maxSize)) {
|
|
927
1182
|
ctx.logger.debug(
|
|
@@ -943,10 +1198,11 @@ const action$2 = async (ctx) => {
|
|
|
943
1198
|
chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
944
1199
|
);
|
|
945
1200
|
} catch (e) {
|
|
1201
|
+
ctx.logger.debug(e);
|
|
946
1202
|
if (e instanceof Error) {
|
|
947
1203
|
ctx.logger.error(e.message);
|
|
948
1204
|
} else {
|
|
949
|
-
|
|
1205
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
950
1206
|
}
|
|
951
1207
|
}
|
|
952
1208
|
};
|
|
@@ -977,185 +1233,175 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
977
1233
|
process.exit(1);
|
|
978
1234
|
});
|
|
979
1235
|
};
|
|
980
|
-
const command$
|
|
981
|
-
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$
|
|
1236
|
+
const command$5 = ({ command: command2, ctx }) => {
|
|
1237
|
+
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));
|
|
982
1238
|
};
|
|
983
1239
|
const deployProject = {
|
|
984
1240
|
name: "deploy-project",
|
|
985
1241
|
description: "Deploy a Strapi Cloud project",
|
|
986
|
-
action: action$
|
|
987
|
-
command: command$
|
|
1242
|
+
action: action$3,
|
|
1243
|
+
command: command$5
|
|
988
1244
|
};
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
logger.log(`You are already logged into your account (${email}).`);
|
|
1010
|
-
} else {
|
|
1011
|
-
logger.log("You are already logged in.");
|
|
1012
|
-
}
|
|
1013
|
-
logger.log(
|
|
1014
|
-
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
1015
|
-
);
|
|
1016
|
-
logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
1017
|
-
return true;
|
|
1018
|
-
} catch (e) {
|
|
1019
|
-
logger.debug("Failed to fetch user info", e);
|
|
1245
|
+
const QUIT_OPTION = "Quit";
|
|
1246
|
+
async function getExistingConfig(ctx) {
|
|
1247
|
+
try {
|
|
1248
|
+
return await retrieve();
|
|
1249
|
+
} catch (e) {
|
|
1250
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1251
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1252
|
+
return null;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1256
|
+
if (existingConfig && existingConfig.project) {
|
|
1257
|
+
const { shouldRelink } = await inquirer__default.default.prompt([
|
|
1258
|
+
{
|
|
1259
|
+
type: "confirm",
|
|
1260
|
+
name: "shouldRelink",
|
|
1261
|
+
message: `A project named ${chalk__default.default.cyan(
|
|
1262
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1263
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1264
|
+
default: false
|
|
1020
1265
|
}
|
|
1266
|
+
]);
|
|
1267
|
+
if (!shouldRelink) {
|
|
1268
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1269
|
+
currentProjectName: existingConfig.project?.name
|
|
1270
|
+
});
|
|
1271
|
+
return false;
|
|
1021
1272
|
}
|
|
1022
1273
|
}
|
|
1023
|
-
|
|
1274
|
+
return true;
|
|
1275
|
+
}
|
|
1276
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1277
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
1024
1278
|
try {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1279
|
+
const {
|
|
1280
|
+
data: { data: projectList }
|
|
1281
|
+
} = await cloudApiService.listLinkProjects();
|
|
1282
|
+
spinner.succeed();
|
|
1283
|
+
if (!Array.isArray(projectList)) {
|
|
1284
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
const projects = projectList.filter(
|
|
1288
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1289
|
+
).map((project) => {
|
|
1290
|
+
return {
|
|
1291
|
+
name: project.displayName,
|
|
1292
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1293
|
+
};
|
|
1294
|
+
});
|
|
1295
|
+
if (projects.length === 0) {
|
|
1296
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1297
|
+
return null;
|
|
1298
|
+
}
|
|
1299
|
+
return projects;
|
|
1028
1300
|
} catch (e) {
|
|
1029
|
-
|
|
1030
|
-
logger.debug(e);
|
|
1031
|
-
return
|
|
1301
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1302
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1303
|
+
return null;
|
|
1032
1304
|
}
|
|
1305
|
+
}
|
|
1306
|
+
async function getUserSelection(ctx, projects) {
|
|
1307
|
+
const { logger } = ctx;
|
|
1033
1308
|
try {
|
|
1034
|
-
await
|
|
1309
|
+
const answer = await inquirer__default.default.prompt([
|
|
1310
|
+
{
|
|
1311
|
+
type: "list",
|
|
1312
|
+
name: "linkProject",
|
|
1313
|
+
message: "Which project do you want to link?",
|
|
1314
|
+
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1315
|
+
}
|
|
1316
|
+
]);
|
|
1317
|
+
if (!answer.linkProject) {
|
|
1318
|
+
return null;
|
|
1319
|
+
}
|
|
1320
|
+
return answer;
|
|
1035
1321
|
} catch (e) {
|
|
1036
|
-
logger.debug("Failed to
|
|
1322
|
+
logger.debug("Failed to get user input", e);
|
|
1323
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1324
|
+
return null;
|
|
1037
1325
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
logger.error("We encountered an issue opening the browser. Please try again later.");
|
|
1058
|
-
logger.debug(e.message, e);
|
|
1059
|
-
});
|
|
1060
|
-
});
|
|
1061
|
-
logger.log("If a browser tab does not open automatically, please follow the next steps:");
|
|
1062
|
-
logger.log(
|
|
1063
|
-
`1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
|
|
1064
|
-
);
|
|
1065
|
-
logger.log(
|
|
1066
|
-
`2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
|
|
1067
|
-
`
|
|
1326
|
+
}
|
|
1327
|
+
const action$2 = async (ctx) => {
|
|
1328
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1329
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1330
|
+
const { logger } = ctx;
|
|
1331
|
+
if (!token) {
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1335
|
+
const existingConfig = await getExistingConfig(ctx);
|
|
1336
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1337
|
+
if (!shouldRelink) {
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1341
|
+
const projects = await getProjectsList(
|
|
1342
|
+
ctx,
|
|
1343
|
+
cloudApiService,
|
|
1344
|
+
existingConfig
|
|
1068
1345
|
);
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
if (tokenResponse.status === 200) {
|
|
1084
|
-
try {
|
|
1085
|
-
logger.debug("🔐 Validating token...");
|
|
1086
|
-
await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
|
|
1087
|
-
logger.debug("🔐 Token validation successful!");
|
|
1088
|
-
} catch (e) {
|
|
1089
|
-
logger.debug(e);
|
|
1090
|
-
spinnerFail();
|
|
1091
|
-
throw new Error("Unable to proceed: Token validation failed");
|
|
1092
|
-
}
|
|
1093
|
-
logger.debug("🔍 Fetching user information...");
|
|
1094
|
-
const cloudApiServiceWithToken = await cloudApiFactory(authTokenData.access_token);
|
|
1095
|
-
await cloudApiServiceWithToken.getUserInfo();
|
|
1096
|
-
logger.debug("🔍 User information fetched successfully!");
|
|
1097
|
-
try {
|
|
1098
|
-
logger.debug("📝 Saving login information...");
|
|
1099
|
-
await tokenService.saveToken(authTokenData.access_token);
|
|
1100
|
-
logger.debug("📝 Login information saved successfully!");
|
|
1101
|
-
isAuthenticated = true;
|
|
1102
|
-
} catch (e) {
|
|
1103
|
-
logger.error(
|
|
1104
|
-
"There was a problem saving your login information. Please try logging in again."
|
|
1105
|
-
);
|
|
1106
|
-
logger.debug(e);
|
|
1107
|
-
spinnerFail();
|
|
1108
|
-
return false;
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
} catch (e) {
|
|
1112
|
-
if (e.message === "Unable to proceed: Token validation failed") {
|
|
1113
|
-
logger.error(
|
|
1114
|
-
"There seems to be a problem with your login information. Please try logging in again."
|
|
1115
|
-
);
|
|
1116
|
-
spinnerFail();
|
|
1117
|
-
await trackFailedLogin();
|
|
1118
|
-
return false;
|
|
1119
|
-
}
|
|
1120
|
-
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
1121
|
-
logger.debug(e);
|
|
1122
|
-
spinnerFail();
|
|
1123
|
-
await trackFailedLogin();
|
|
1124
|
-
return false;
|
|
1125
|
-
}
|
|
1126
|
-
await new Promise((resolve) => {
|
|
1127
|
-
setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
|
|
1128
|
-
});
|
|
1346
|
+
if (!projects) {
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1350
|
+
if (!answer) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
try {
|
|
1354
|
+
const { confirmAction } = await inquirer__default.default.prompt([
|
|
1355
|
+
{
|
|
1356
|
+
type: "confirm",
|
|
1357
|
+
name: "confirmAction",
|
|
1358
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1359
|
+
default: false
|
|
1129
1360
|
}
|
|
1361
|
+
]);
|
|
1362
|
+
if (!confirmAction) {
|
|
1363
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1364
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1365
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1366
|
+
});
|
|
1367
|
+
return;
|
|
1130
1368
|
}
|
|
1131
|
-
|
|
1132
|
-
logger.log(
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
);
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
await authenticate();
|
|
1144
|
-
return isAuthenticated;
|
|
1369
|
+
await save({ project: answer.linkProject });
|
|
1370
|
+
logger.log(`Project ${chalk__default.default.cyan(answer.linkProject.displayName)} linked successfully.`);
|
|
1371
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1372
|
+
projectInternalName: answer.linkProject
|
|
1373
|
+
});
|
|
1374
|
+
} catch (e) {
|
|
1375
|
+
logger.debug("Failed to link project", e);
|
|
1376
|
+
logger.error("An error occurred while linking the project.");
|
|
1377
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1378
|
+
projectInternalName: answer.linkProject
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1145
1381
|
};
|
|
1146
|
-
const command$
|
|
1382
|
+
const command$4 = ({ command: command2, ctx }) => {
|
|
1383
|
+
command2.command("cloud:link").alias("link").description("Link a local directory to a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("link", action$2)(ctx));
|
|
1384
|
+
};
|
|
1385
|
+
const link = {
|
|
1386
|
+
name: "link-project",
|
|
1387
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1388
|
+
action: action$2,
|
|
1389
|
+
command: command$4
|
|
1390
|
+
};
|
|
1391
|
+
const command$3 = ({ command: command2, ctx }) => {
|
|
1147
1392
|
command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1148
1393
|
"after",
|
|
1149
1394
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1150
|
-
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login",
|
|
1395
|
+
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
1151
1396
|
};
|
|
1152
1397
|
const login = {
|
|
1153
1398
|
name: "login",
|
|
1154
1399
|
description: "Strapi Cloud Login",
|
|
1155
|
-
action:
|
|
1156
|
-
command: command$
|
|
1400
|
+
action: loginAction,
|
|
1401
|
+
command: command$3
|
|
1157
1402
|
};
|
|
1158
|
-
const
|
|
1403
|
+
const openModule = import("open");
|
|
1404
|
+
const action$1 = async (ctx) => {
|
|
1159
1405
|
const { logger } = ctx;
|
|
1160
1406
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1161
1407
|
const token = await retrieveToken();
|
|
@@ -1163,9 +1409,21 @@ const action = async (ctx) => {
|
|
|
1163
1409
|
logger.log("You're already logged out.");
|
|
1164
1410
|
return;
|
|
1165
1411
|
}
|
|
1166
|
-
const cloudApiService = await cloudApiFactory(token);
|
|
1412
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1413
|
+
const config = await cloudApiService.config();
|
|
1414
|
+
const cliConfig2 = config.data;
|
|
1167
1415
|
try {
|
|
1168
1416
|
await eraseToken();
|
|
1417
|
+
openModule.then((open) => {
|
|
1418
|
+
open.default(
|
|
1419
|
+
`${cliConfig2.baseUrl}/oidc/logout?client_id=${encodeURIComponent(
|
|
1420
|
+
cliConfig2.clientId
|
|
1421
|
+
)}&logout_hint=${encodeURIComponent(token)}
|
|
1422
|
+
`
|
|
1423
|
+
).catch((e) => {
|
|
1424
|
+
logger.debug(e.message, e);
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1169
1427
|
logger.log(
|
|
1170
1428
|
"🔌 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."
|
|
1171
1429
|
);
|
|
@@ -1173,37 +1431,64 @@ const action = async (ctx) => {
|
|
|
1173
1431
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1174
1432
|
logger.debug(e);
|
|
1175
1433
|
}
|
|
1176
|
-
|
|
1177
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1178
|
-
} catch (e) {
|
|
1179
|
-
logger.debug("Failed to track logout event", e);
|
|
1180
|
-
}
|
|
1434
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1181
1435
|
};
|
|
1182
|
-
const command$
|
|
1183
|
-
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));
|
|
1436
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1437
|
+
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));
|
|
1184
1438
|
};
|
|
1185
1439
|
const logout = {
|
|
1186
1440
|
name: "logout",
|
|
1187
1441
|
description: "Strapi Cloud Logout",
|
|
1188
|
-
action,
|
|
1189
|
-
command: command$
|
|
1442
|
+
action: action$1,
|
|
1443
|
+
command: command$2
|
|
1190
1444
|
};
|
|
1191
|
-
const command = ({ command: command2, ctx }) => {
|
|
1192
|
-
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$
|
|
1445
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1446
|
+
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));
|
|
1193
1447
|
};
|
|
1194
1448
|
const createProject = {
|
|
1195
1449
|
name: "create-project",
|
|
1196
1450
|
description: "Create a new project",
|
|
1197
|
-
action: action$
|
|
1451
|
+
action: action$4,
|
|
1452
|
+
command: command$1
|
|
1453
|
+
};
|
|
1454
|
+
const action = async (ctx) => {
|
|
1455
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1456
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1457
|
+
const { logger } = ctx;
|
|
1458
|
+
if (!token) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1462
|
+
const spinner = logger.spinner("Fetching your projects...").start();
|
|
1463
|
+
try {
|
|
1464
|
+
const {
|
|
1465
|
+
data: { data: projectList }
|
|
1466
|
+
} = await cloudApiService.listProjects();
|
|
1467
|
+
spinner.succeed();
|
|
1468
|
+
logger.log(projectList);
|
|
1469
|
+
} catch (e) {
|
|
1470
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1471
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
const command = ({ command: command2, ctx }) => {
|
|
1475
|
+
command2.command("cloud:projects").alias("projects").description("List Strapi Cloud projects").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("projects", action)(ctx));
|
|
1476
|
+
};
|
|
1477
|
+
const listProjects = {
|
|
1478
|
+
name: "list-projects",
|
|
1479
|
+
description: "List Strapi Cloud projects",
|
|
1480
|
+
action,
|
|
1198
1481
|
command
|
|
1199
1482
|
};
|
|
1200
1483
|
const cli = {
|
|
1201
1484
|
deployProject,
|
|
1485
|
+
link,
|
|
1202
1486
|
login,
|
|
1203
1487
|
logout,
|
|
1204
|
-
createProject
|
|
1488
|
+
createProject,
|
|
1489
|
+
listProjects
|
|
1205
1490
|
};
|
|
1206
|
-
const cloudCommands = [deployProject, login, logout];
|
|
1491
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects];
|
|
1207
1492
|
async function initCloudCLIConfig() {
|
|
1208
1493
|
const localConfig = await getLocalConfig();
|
|
1209
1494
|
if (!localConfig.deviceId) {
|