@strapi/cloud-cli 0.0.0-next.80375f19ecbd1a8f298515d011c3ddb5ed05f924 → 0.0.0-next.840550dc97a3782302ddf918d3a0d07e59dd11eb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +543 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +543 -145
- package/dist/index.mjs.map +1 -1
- package/dist/src/cloud/command.d.ts +3 -0
- package/dist/src/cloud/command.d.ts.map +1 -0
- package/dist/src/create-project/action.d.ts.map +1 -1
- package/dist/src/create-project/command.d.ts.map +1 -1
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts +3 -0
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts.map +1 -0
- package/dist/src/create-project/utils/project-questions.utils.d.ts +20 -0
- package/dist/src/create-project/utils/project-questions.utils.d.ts.map +1 -0
- package/dist/src/deploy-project/action.d.ts.map +1 -1
- package/dist/src/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.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 +44 -7
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/services/strapi-info-save.d.ts +1 -1
- package/dist/src/services/strapi-info-save.d.ts.map +1 -1
- package/dist/src/types.d.ts +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 +9 -8
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 EventSource = require("eventsource");
|
|
46
|
+
const commander = require("commander");
|
|
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,9 @@ 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 EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
87
84
|
const apiConfig = {
|
|
88
85
|
apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
89
86
|
dashboardBaseUrl: utils.env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -102,23 +99,6 @@ const IGNORED_PATTERNS = [
|
|
|
102
99
|
"**/.idea/**",
|
|
103
100
|
"**/.vscode/**"
|
|
104
101
|
];
|
|
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
102
|
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
123
103
|
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
124
104
|
const relativeFilePath = path__namespace.join(folderPath, file);
|
|
@@ -136,16 +116,35 @@ const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
|
136
116
|
}
|
|
137
117
|
return isIgnored;
|
|
138
118
|
};
|
|
139
|
-
const
|
|
119
|
+
const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
120
|
+
const arrayOfFiles = [];
|
|
121
|
+
const entries = await fse__namespace.readdir(path__namespace.join(dirPath, subfolder));
|
|
122
|
+
for (const entry of entries) {
|
|
123
|
+
const entryPathFromRoot = path__namespace.join(subfolder, entry);
|
|
124
|
+
const entryPath = path__namespace.relative(dirPath, entryPathFromRoot);
|
|
125
|
+
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
126
|
+
if (!isIgnored) {
|
|
127
|
+
if (fse__namespace.statSync(entryPath).isDirectory()) {
|
|
128
|
+
const subFiles = await getFiles(dirPath, ignorePatterns, entryPathFromRoot);
|
|
129
|
+
arrayOfFiles.push(...subFiles);
|
|
130
|
+
} else {
|
|
131
|
+
arrayOfFiles.push(entryPath);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return arrayOfFiles;
|
|
136
|
+
};
|
|
137
|
+
const readGitignore = async (folderPath) => {
|
|
140
138
|
const gitignorePath = path__namespace.resolve(folderPath, ".gitignore");
|
|
141
|
-
|
|
139
|
+
const pathExist = await fse__namespace.pathExists(gitignorePath);
|
|
140
|
+
if (!pathExist)
|
|
142
141
|
return [];
|
|
143
|
-
const gitignoreContent =
|
|
142
|
+
const gitignoreContent = await fse__namespace.readFile(gitignorePath, "utf8");
|
|
144
143
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
145
144
|
};
|
|
146
145
|
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
147
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
148
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
146
|
+
const ignorePatterns = await readGitignore(folderToCompress);
|
|
147
|
+
const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
|
|
149
148
|
return tar__namespace.c(
|
|
150
149
|
{
|
|
151
150
|
gzip: true,
|
|
@@ -158,7 +157,7 @@ const APP_FOLDER_NAME = "com.strapi.cli";
|
|
|
158
157
|
const CONFIG_FILENAME = "config.json";
|
|
159
158
|
async function checkDirectoryExists(directoryPath) {
|
|
160
159
|
try {
|
|
161
|
-
const fsStat = await
|
|
160
|
+
const fsStat = await fse__namespace.default.lstat(directoryPath);
|
|
162
161
|
return fsStat.isDirectory();
|
|
163
162
|
} catch (e) {
|
|
164
163
|
return false;
|
|
@@ -166,14 +165,14 @@ async function checkDirectoryExists(directoryPath) {
|
|
|
166
165
|
}
|
|
167
166
|
async function getTmpStoragePath() {
|
|
168
167
|
const storagePath = path__namespace.default.join(os__default.default.tmpdir(), APP_FOLDER_NAME);
|
|
169
|
-
await
|
|
168
|
+
await fse__namespace.default.ensureDir(storagePath);
|
|
170
169
|
return storagePath;
|
|
171
170
|
}
|
|
172
171
|
async function getConfigPath() {
|
|
173
172
|
const configDirs = XDGAppPaths__default.default(APP_FOLDER_NAME).configDirs();
|
|
174
173
|
const configPath = configDirs.find(checkDirectoryExists);
|
|
175
174
|
if (!configPath) {
|
|
176
|
-
await
|
|
175
|
+
await fse__namespace.default.ensureDir(configDirs[0]);
|
|
177
176
|
return configDirs[0];
|
|
178
177
|
}
|
|
179
178
|
return configPath;
|
|
@@ -181,9 +180,9 @@ async function getConfigPath() {
|
|
|
181
180
|
async function getLocalConfig() {
|
|
182
181
|
const configPath = await getConfigPath();
|
|
183
182
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
184
|
-
await
|
|
183
|
+
await fse__namespace.default.ensureFile(configFilePath);
|
|
185
184
|
try {
|
|
186
|
-
return await
|
|
185
|
+
return await fse__namespace.default.readJSON(configFilePath, { encoding: "utf8", throws: true });
|
|
187
186
|
} catch (e) {
|
|
188
187
|
return {};
|
|
189
188
|
}
|
|
@@ -191,10 +190,10 @@ async function getLocalConfig() {
|
|
|
191
190
|
async function saveLocalConfig(data) {
|
|
192
191
|
const configPath = await getConfigPath();
|
|
193
192
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
194
|
-
await
|
|
193
|
+
await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
195
194
|
}
|
|
196
195
|
const name = "@strapi/cloud-cli";
|
|
197
|
-
const version = "
|
|
196
|
+
const version = "5.0.2";
|
|
198
197
|
const description = "Commands to interact with the Strapi Cloud";
|
|
199
198
|
const keywords = [
|
|
200
199
|
"strapi",
|
|
@@ -235,17 +234,18 @@ const scripts = {
|
|
|
235
234
|
build: "pack-up build",
|
|
236
235
|
clean: "run -T rimraf ./dist",
|
|
237
236
|
lint: "run -T eslint .",
|
|
237
|
+
"test:unit": "run -T jest",
|
|
238
238
|
watch: "pack-up watch"
|
|
239
239
|
};
|
|
240
240
|
const dependencies = {
|
|
241
|
-
"@strapi/utils": "
|
|
242
|
-
axios: "1.
|
|
241
|
+
"@strapi/utils": "workspace:*",
|
|
242
|
+
axios: "1.7.4",
|
|
243
243
|
chalk: "4.1.2",
|
|
244
244
|
"cli-progress": "3.12.0",
|
|
245
245
|
commander: "8.3.0",
|
|
246
246
|
eventsource: "2.0.2",
|
|
247
247
|
"fast-safe-stringify": "2.1.1",
|
|
248
|
-
"fs-extra": "
|
|
248
|
+
"fs-extra": "11.2.0",
|
|
249
249
|
inquirer: "8.2.5",
|
|
250
250
|
jsonwebtoken: "9.0.0",
|
|
251
251
|
"jwks-rsa": "3.1.0",
|
|
@@ -254,7 +254,7 @@ const dependencies = {
|
|
|
254
254
|
open: "8.4.0",
|
|
255
255
|
ora: "5.4.1",
|
|
256
256
|
"pkg-up": "3.1.0",
|
|
257
|
-
tar: "6.1
|
|
257
|
+
tar: "6.2.1",
|
|
258
258
|
"xdg-app-paths": "8.3.0",
|
|
259
259
|
yup: "0.32.9"
|
|
260
260
|
};
|
|
@@ -263,8 +263,8 @@ const devDependencies = {
|
|
|
263
263
|
"@types/cli-progress": "3.11.5",
|
|
264
264
|
"@types/eventsource": "1.1.15",
|
|
265
265
|
"@types/lodash": "^4.14.191",
|
|
266
|
-
"eslint-config-custom": "
|
|
267
|
-
tsconfig: "
|
|
266
|
+
"eslint-config-custom": "workspace:*",
|
|
267
|
+
tsconfig: "workspace:*"
|
|
268
268
|
};
|
|
269
269
|
const engines = {
|
|
270
270
|
node: ">=18.0.0 <=20.x.x",
|
|
@@ -317,7 +317,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
317
317
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
318
318
|
return axiosCloudAPI.post(
|
|
319
319
|
`/deploy/${project.name}`,
|
|
320
|
-
{ file:
|
|
320
|
+
{ file: fse__namespace.default.createReadStream(filePath) },
|
|
321
321
|
{
|
|
322
322
|
headers: {
|
|
323
323
|
"Content-Type": "multipart/form-data"
|
|
@@ -360,8 +360,61 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
360
360
|
throw error;
|
|
361
361
|
}
|
|
362
362
|
},
|
|
363
|
-
listProjects() {
|
|
364
|
-
|
|
363
|
+
async listProjects() {
|
|
364
|
+
try {
|
|
365
|
+
const response = await axiosCloudAPI.get("/projects");
|
|
366
|
+
if (response.status !== 200) {
|
|
367
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
368
|
+
}
|
|
369
|
+
return response;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
logger.debug(
|
|
372
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
373
|
+
);
|
|
374
|
+
throw error;
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
async listLinkProjects() {
|
|
378
|
+
try {
|
|
379
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
380
|
+
if (response.status !== 200) {
|
|
381
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
382
|
+
}
|
|
383
|
+
return response;
|
|
384
|
+
} catch (error) {
|
|
385
|
+
logger.debug(
|
|
386
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
387
|
+
);
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
async listEnvironments({ name: name2 }) {
|
|
392
|
+
try {
|
|
393
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
394
|
+
if (response.status !== 200) {
|
|
395
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
396
|
+
}
|
|
397
|
+
return response;
|
|
398
|
+
} catch (error) {
|
|
399
|
+
logger.debug(
|
|
400
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
401
|
+
);
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
async getProject({ name: name2 }) {
|
|
406
|
+
try {
|
|
407
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
408
|
+
if (response.status !== 200) {
|
|
409
|
+
throw new Error("Error fetching project's details.");
|
|
410
|
+
}
|
|
411
|
+
return response;
|
|
412
|
+
} catch (error) {
|
|
413
|
+
logger.debug(
|
|
414
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
415
|
+
);
|
|
416
|
+
throw error;
|
|
417
|
+
}
|
|
365
418
|
},
|
|
366
419
|
track(event, payload = {}) {
|
|
367
420
|
return axiosCloudAPI.post("/track", {
|
|
@@ -376,18 +429,18 @@ async function save(data, { directoryPath } = {}) {
|
|
|
376
429
|
const alreadyInFileData = await retrieve({ directoryPath });
|
|
377
430
|
const storedData = { ...alreadyInFileData, ...data };
|
|
378
431
|
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
379
|
-
await
|
|
380
|
-
await
|
|
432
|
+
await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
433
|
+
await fse__namespace.default.writeJson(pathToFile, storedData, { encoding: "utf8" });
|
|
381
434
|
}
|
|
382
435
|
async function retrieve({
|
|
383
436
|
directoryPath
|
|
384
437
|
} = {}) {
|
|
385
438
|
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
386
|
-
const pathExists = await
|
|
439
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
387
440
|
if (!pathExists) {
|
|
388
441
|
return {};
|
|
389
442
|
}
|
|
390
|
-
return
|
|
443
|
+
return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
|
|
391
444
|
}
|
|
392
445
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
393
446
|
__proto__: null,
|
|
@@ -632,6 +685,56 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
632
685
|
local: strapiInfoSave,
|
|
633
686
|
tokenServiceFactory
|
|
634
687
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
688
|
+
yup__namespace.object({
|
|
689
|
+
name: yup__namespace.string().required(),
|
|
690
|
+
exports: yup__namespace.lazy(
|
|
691
|
+
(value) => yup__namespace.object(
|
|
692
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
693
|
+
(acc, [key, value2]) => {
|
|
694
|
+
if (typeof value2 === "object") {
|
|
695
|
+
acc[key] = yup__namespace.object({
|
|
696
|
+
types: yup__namespace.string().optional(),
|
|
697
|
+
source: yup__namespace.string().required(),
|
|
698
|
+
module: yup__namespace.string().optional(),
|
|
699
|
+
import: yup__namespace.string().required(),
|
|
700
|
+
require: yup__namespace.string().required(),
|
|
701
|
+
default: yup__namespace.string().required()
|
|
702
|
+
}).noUnknown(true);
|
|
703
|
+
} else {
|
|
704
|
+
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
705
|
+
}
|
|
706
|
+
return acc;
|
|
707
|
+
},
|
|
708
|
+
{}
|
|
709
|
+
) : void 0
|
|
710
|
+
).optional()
|
|
711
|
+
)
|
|
712
|
+
});
|
|
713
|
+
const loadPkg = async ({ cwd, logger }) => {
|
|
714
|
+
const pkgPath = await pkgUp__default.default({ cwd });
|
|
715
|
+
if (!pkgPath) {
|
|
716
|
+
throw new Error("Could not find a package.json in the current directory");
|
|
717
|
+
}
|
|
718
|
+
const buffer = await fse__namespace.readFile(pkgPath);
|
|
719
|
+
const pkg = JSON.parse(buffer.toString());
|
|
720
|
+
logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
|
|
721
|
+
return pkg;
|
|
722
|
+
};
|
|
723
|
+
async function getProjectNameFromPackageJson(ctx) {
|
|
724
|
+
try {
|
|
725
|
+
const packageJson2 = await loadPkg(ctx);
|
|
726
|
+
return packageJson2.name || "my-strapi-project";
|
|
727
|
+
} catch (e) {
|
|
728
|
+
return "my-strapi-project";
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
732
|
+
try {
|
|
733
|
+
await cloudApiService.track(eventName, eventData);
|
|
734
|
+
} catch (e) {
|
|
735
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
736
|
+
}
|
|
737
|
+
};
|
|
635
738
|
const openModule$1 = import("open");
|
|
636
739
|
async function promptLogin(ctx) {
|
|
637
740
|
const response = await inquirer__default.default.prompt([
|
|
@@ -652,13 +755,6 @@ async function loginAction(ctx) {
|
|
|
652
755
|
const tokenService = await tokenServiceFactory(ctx);
|
|
653
756
|
const existingToken = await tokenService.retrieveToken();
|
|
654
757
|
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
655
|
-
const trackFailedLogin = async () => {
|
|
656
|
-
try {
|
|
657
|
-
await cloudApiService.track("didNotLogin", { loginMethod: "cli" });
|
|
658
|
-
} catch (e) {
|
|
659
|
-
logger.debug("Failed to track failed login", e);
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
758
|
if (existingToken) {
|
|
663
759
|
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
664
760
|
if (isTokenValid) {
|
|
@@ -690,11 +786,7 @@ async function loginAction(ctx) {
|
|
|
690
786
|
logger.debug(e);
|
|
691
787
|
return false;
|
|
692
788
|
}
|
|
693
|
-
|
|
694
|
-
await cloudApiService.track("willLoginAttempt", {});
|
|
695
|
-
} catch (e) {
|
|
696
|
-
logger.debug("Failed to track login attempt", e);
|
|
697
|
-
}
|
|
789
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
698
790
|
logger.debug("🔐 Creating device authentication request...", {
|
|
699
791
|
client_id: cliConfig2.clientId,
|
|
700
792
|
scope: cliConfig2.scope,
|
|
@@ -774,13 +866,13 @@ async function loginAction(ctx) {
|
|
|
774
866
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
775
867
|
);
|
|
776
868
|
spinnerFail();
|
|
777
|
-
await
|
|
869
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
778
870
|
return false;
|
|
779
871
|
}
|
|
780
872
|
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
781
873
|
logger.debug(e);
|
|
782
874
|
spinnerFail();
|
|
783
|
-
await
|
|
875
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
784
876
|
return false;
|
|
785
877
|
}
|
|
786
878
|
await new Promise((resolve) => {
|
|
@@ -794,15 +886,50 @@ async function loginAction(ctx) {
|
|
|
794
886
|
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
795
887
|
);
|
|
796
888
|
logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
797
|
-
|
|
798
|
-
await cloudApiService.track("didLogin", { loginMethod: "cli" });
|
|
799
|
-
} catch (e) {
|
|
800
|
-
logger.debug("Failed to track login", e);
|
|
801
|
-
}
|
|
889
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
802
890
|
};
|
|
803
891
|
await authenticate();
|
|
804
892
|
return isAuthenticated;
|
|
805
893
|
}
|
|
894
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
895
|
+
return (questions) => {
|
|
896
|
+
return questions.map((question) => {
|
|
897
|
+
const questionName = question.name;
|
|
898
|
+
if (questionName in questionsMap) {
|
|
899
|
+
const questionDefault = questionsMap[questionName];
|
|
900
|
+
if (typeof questionDefault === "function") {
|
|
901
|
+
return {
|
|
902
|
+
...question,
|
|
903
|
+
default: questionDefault(question)
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
return {
|
|
907
|
+
...question,
|
|
908
|
+
default: questionDefault
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
return question;
|
|
912
|
+
});
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
function getDefaultsFromQuestions(questions) {
|
|
916
|
+
return questions.reduce((acc, question) => {
|
|
917
|
+
if (question.default && question.name) {
|
|
918
|
+
return { ...acc, [question.name]: question.default };
|
|
919
|
+
}
|
|
920
|
+
return acc;
|
|
921
|
+
}, {});
|
|
922
|
+
}
|
|
923
|
+
function getProjectNodeVersionDefault(question) {
|
|
924
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
925
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
926
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
927
|
+
if (choice) {
|
|
928
|
+
return choice.value;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
return question.default;
|
|
932
|
+
}
|
|
806
933
|
async function handleError(ctx, error) {
|
|
807
934
|
const { logger } = ctx;
|
|
808
935
|
logger.debug(error);
|
|
@@ -847,7 +974,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
847
974
|
throw e;
|
|
848
975
|
}
|
|
849
976
|
}
|
|
850
|
-
const action$
|
|
977
|
+
const action$5 = async (ctx) => {
|
|
851
978
|
const { logger } = ctx;
|
|
852
979
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
853
980
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -856,7 +983,16 @@ const action$2 = async (ctx) => {
|
|
|
856
983
|
}
|
|
857
984
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
858
985
|
const { data: config } = await cloudApi.config();
|
|
859
|
-
const
|
|
986
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
987
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
988
|
+
name: projectName,
|
|
989
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
990
|
+
});
|
|
991
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
992
|
+
const defaultValues = {
|
|
993
|
+
...config.projectCreation.defaults,
|
|
994
|
+
...getDefaultsFromQuestions(questions)
|
|
995
|
+
};
|
|
860
996
|
const projectAnswersDefaulted = fp.defaults(defaultValues);
|
|
861
997
|
const projectAnswers = await inquirer__default.default.prompt(questions);
|
|
862
998
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -905,38 +1041,6 @@ function notificationServiceFactory({ logger }) {
|
|
|
905
1041
|
};
|
|
906
1042
|
};
|
|
907
1043
|
}
|
|
908
|
-
yup__namespace.object({
|
|
909
|
-
name: yup__namespace.string().required(),
|
|
910
|
-
exports: yup__namespace.lazy(
|
|
911
|
-
(value) => yup__namespace.object(
|
|
912
|
-
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
913
|
-
if (typeof value2 === "object") {
|
|
914
|
-
acc[key] = yup__namespace.object({
|
|
915
|
-
types: yup__namespace.string().optional(),
|
|
916
|
-
source: yup__namespace.string().required(),
|
|
917
|
-
module: yup__namespace.string().optional(),
|
|
918
|
-
import: yup__namespace.string().required(),
|
|
919
|
-
require: yup__namespace.string().required(),
|
|
920
|
-
default: yup__namespace.string().required()
|
|
921
|
-
}).noUnknown(true);
|
|
922
|
-
} else {
|
|
923
|
-
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
924
|
-
}
|
|
925
|
-
return acc;
|
|
926
|
-
}, {}) : void 0
|
|
927
|
-
).optional()
|
|
928
|
-
)
|
|
929
|
-
});
|
|
930
|
-
const loadPkg = async ({ cwd, logger }) => {
|
|
931
|
-
const pkgPath = await pkgUp__default.default({ cwd });
|
|
932
|
-
if (!pkgPath) {
|
|
933
|
-
throw new Error("Could not find a package.json in the current directory");
|
|
934
|
-
}
|
|
935
|
-
const buffer = await fs__default.default.readFile(pkgPath);
|
|
936
|
-
const pkg = JSON.parse(buffer.toString());
|
|
937
|
-
logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
|
|
938
|
-
return pkg;
|
|
939
|
-
};
|
|
940
1044
|
const buildLogsServiceFactory = ({ logger }) => {
|
|
941
1045
|
return async (url, token, cliConfig2) => {
|
|
942
1046
|
const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
|
|
@@ -990,6 +1094,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
990
1094
|
if (retries > MAX_RETRIES) {
|
|
991
1095
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
992
1096
|
es.close();
|
|
1097
|
+
clearExistingTimeout();
|
|
993
1098
|
reject(new Error("Max retries reached"));
|
|
994
1099
|
}
|
|
995
1100
|
};
|
|
@@ -1032,13 +1137,13 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1032
1137
|
process.exit(1);
|
|
1033
1138
|
}
|
|
1034
1139
|
const tarFilePath = path__namespace.default.resolve(storagePath, compressedFilename);
|
|
1035
|
-
const fileStats = await
|
|
1140
|
+
const fileStats = await fse__namespace.default.stat(tarFilePath);
|
|
1036
1141
|
if (fileStats.size > maxProjectFileSize) {
|
|
1037
1142
|
ctx.logger.log(
|
|
1038
1143
|
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
1039
1144
|
);
|
|
1040
1145
|
try {
|
|
1041
|
-
await
|
|
1146
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
1042
1147
|
} catch (e) {
|
|
1043
1148
|
ctx.logger.log("Unable to remove file: ", tarFilePath);
|
|
1044
1149
|
ctx.logger.debug(e);
|
|
@@ -1064,20 +1169,10 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1064
1169
|
return data.build_id;
|
|
1065
1170
|
} catch (e) {
|
|
1066
1171
|
progressBar.stop();
|
|
1067
|
-
|
|
1068
|
-
if (e.response.status === 404) {
|
|
1069
|
-
ctx.logger.error(
|
|
1070
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
1071
|
-
);
|
|
1072
|
-
} else {
|
|
1073
|
-
ctx.logger.error(e.response.data);
|
|
1074
|
-
}
|
|
1075
|
-
} else {
|
|
1076
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1077
|
-
}
|
|
1172
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1078
1173
|
ctx.logger.debug(e);
|
|
1079
1174
|
} finally {
|
|
1080
|
-
await
|
|
1175
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
1081
1176
|
}
|
|
1082
1177
|
process.exit(0);
|
|
1083
1178
|
} catch (e) {
|
|
@@ -1086,11 +1181,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1086
1181
|
process.exit(1);
|
|
1087
1182
|
}
|
|
1088
1183
|
}
|
|
1089
|
-
async function getProject(ctx) {
|
|
1184
|
+
async function getProject$1(ctx) {
|
|
1090
1185
|
const { project } = await retrieve();
|
|
1091
1186
|
if (!project) {
|
|
1092
1187
|
try {
|
|
1093
|
-
return await action$
|
|
1188
|
+
return await action$5(ctx);
|
|
1094
1189
|
} catch (e) {
|
|
1095
1190
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1096
1191
|
ctx.logger.debug(e);
|
|
@@ -1099,25 +1194,73 @@ async function getProject(ctx) {
|
|
|
1099
1194
|
}
|
|
1100
1195
|
return project;
|
|
1101
1196
|
}
|
|
1102
|
-
|
|
1197
|
+
async function getConfig({
|
|
1198
|
+
ctx,
|
|
1199
|
+
cloudApiService
|
|
1200
|
+
}) {
|
|
1201
|
+
try {
|
|
1202
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1203
|
+
return cliConfig2;
|
|
1204
|
+
} catch (e) {
|
|
1205
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1206
|
+
return null;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
const action$4 = async (ctx) => {
|
|
1103
1210
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1104
1211
|
const token = await getValidToken(ctx, promptLogin);
|
|
1105
1212
|
if (!token) {
|
|
1106
1213
|
return;
|
|
1107
1214
|
}
|
|
1108
|
-
const project = await getProject(ctx);
|
|
1215
|
+
const project = await getProject$1(ctx);
|
|
1109
1216
|
if (!project) {
|
|
1110
1217
|
return;
|
|
1111
1218
|
}
|
|
1112
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1219
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1113
1220
|
try {
|
|
1114
|
-
|
|
1221
|
+
const {
|
|
1222
|
+
data: { data: projectData, metadata }
|
|
1223
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1224
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1225
|
+
if (isProjectSuspended) {
|
|
1226
|
+
ctx.logger.log(
|
|
1227
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1228
|
+
);
|
|
1229
|
+
ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1115
1232
|
} catch (e) {
|
|
1116
|
-
|
|
1233
|
+
if (e instanceof axios.AxiosError && e.response?.data) {
|
|
1234
|
+
if (e.response.status === 404) {
|
|
1235
|
+
ctx.logger.warn(
|
|
1236
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1237
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1238
|
+
"link"
|
|
1239
|
+
)} command before deploying.`
|
|
1240
|
+
);
|
|
1241
|
+
} else {
|
|
1242
|
+
ctx.logger.error(e.response.data);
|
|
1243
|
+
}
|
|
1244
|
+
} else {
|
|
1245
|
+
ctx.logger.error(
|
|
1246
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
ctx.logger.debug(e);
|
|
1250
|
+
return;
|
|
1117
1251
|
}
|
|
1252
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1253
|
+
projectInternalName: project.name
|
|
1254
|
+
});
|
|
1118
1255
|
const notificationService = notificationServiceFactory(ctx);
|
|
1119
1256
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
1120
|
-
const
|
|
1257
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1258
|
+
if (!cliConfig2) {
|
|
1259
|
+
ctx.logger.error(
|
|
1260
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1261
|
+
);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1121
1264
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
1122
1265
|
if (Number.isNaN(maxSize)) {
|
|
1123
1266
|
ctx.logger.debug(
|
|
@@ -1139,10 +1282,11 @@ const action$1 = async (ctx) => {
|
|
|
1139
1282
|
chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
1140
1283
|
);
|
|
1141
1284
|
} catch (e) {
|
|
1285
|
+
ctx.logger.debug(e);
|
|
1142
1286
|
if (e instanceof Error) {
|
|
1143
1287
|
ctx.logger.error(e.message);
|
|
1144
1288
|
} else {
|
|
1145
|
-
|
|
1289
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1146
1290
|
}
|
|
1147
1291
|
}
|
|
1148
1292
|
};
|
|
@@ -1173,17 +1317,163 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1173
1317
|
process.exit(1);
|
|
1174
1318
|
});
|
|
1175
1319
|
};
|
|
1176
|
-
const command$
|
|
1177
|
-
|
|
1320
|
+
const command$6 = ({ ctx }) => {
|
|
1321
|
+
return commander.createCommand("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("deploy", action$4)(ctx));
|
|
1178
1322
|
};
|
|
1179
1323
|
const deployProject = {
|
|
1180
1324
|
name: "deploy-project",
|
|
1181
1325
|
description: "Deploy a Strapi Cloud project",
|
|
1182
|
-
action: action$
|
|
1183
|
-
command: command$
|
|
1326
|
+
action: action$4,
|
|
1327
|
+
command: command$6
|
|
1328
|
+
};
|
|
1329
|
+
const QUIT_OPTION = "Quit";
|
|
1330
|
+
async function getExistingConfig(ctx) {
|
|
1331
|
+
try {
|
|
1332
|
+
return await retrieve();
|
|
1333
|
+
} catch (e) {
|
|
1334
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1335
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1336
|
+
return null;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1340
|
+
if (existingConfig && existingConfig.project) {
|
|
1341
|
+
const { shouldRelink } = await inquirer__default.default.prompt([
|
|
1342
|
+
{
|
|
1343
|
+
type: "confirm",
|
|
1344
|
+
name: "shouldRelink",
|
|
1345
|
+
message: `A project named ${chalk__default.default.cyan(
|
|
1346
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1347
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1348
|
+
default: false
|
|
1349
|
+
}
|
|
1350
|
+
]);
|
|
1351
|
+
if (!shouldRelink) {
|
|
1352
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1353
|
+
currentProjectName: existingConfig.project?.name
|
|
1354
|
+
});
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
return true;
|
|
1359
|
+
}
|
|
1360
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1361
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
1362
|
+
try {
|
|
1363
|
+
const {
|
|
1364
|
+
data: { data: projectList }
|
|
1365
|
+
} = await cloudApiService.listLinkProjects();
|
|
1366
|
+
spinner.succeed();
|
|
1367
|
+
if (!Array.isArray(projectList)) {
|
|
1368
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1369
|
+
return null;
|
|
1370
|
+
}
|
|
1371
|
+
const projects = projectList.filter(
|
|
1372
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1373
|
+
).map((project) => {
|
|
1374
|
+
return {
|
|
1375
|
+
name: project.displayName,
|
|
1376
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1377
|
+
};
|
|
1378
|
+
});
|
|
1379
|
+
if (projects.length === 0) {
|
|
1380
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1381
|
+
return null;
|
|
1382
|
+
}
|
|
1383
|
+
return projects;
|
|
1384
|
+
} catch (e) {
|
|
1385
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1386
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
async function getUserSelection(ctx, projects) {
|
|
1391
|
+
const { logger } = ctx;
|
|
1392
|
+
try {
|
|
1393
|
+
const answer = await inquirer__default.default.prompt([
|
|
1394
|
+
{
|
|
1395
|
+
type: "list",
|
|
1396
|
+
name: "linkProject",
|
|
1397
|
+
message: "Which project do you want to link?",
|
|
1398
|
+
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1399
|
+
}
|
|
1400
|
+
]);
|
|
1401
|
+
if (!answer.linkProject) {
|
|
1402
|
+
return null;
|
|
1403
|
+
}
|
|
1404
|
+
return answer;
|
|
1405
|
+
} catch (e) {
|
|
1406
|
+
logger.debug("Failed to get user input", e);
|
|
1407
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1408
|
+
return null;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
const action$3 = async (ctx) => {
|
|
1412
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1413
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1414
|
+
const { logger } = ctx;
|
|
1415
|
+
if (!token) {
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1419
|
+
const existingConfig = await getExistingConfig(ctx);
|
|
1420
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1421
|
+
if (!shouldRelink) {
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1425
|
+
const projects = await getProjectsList(
|
|
1426
|
+
ctx,
|
|
1427
|
+
cloudApiService,
|
|
1428
|
+
existingConfig
|
|
1429
|
+
);
|
|
1430
|
+
if (!projects) {
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1434
|
+
if (!answer) {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
try {
|
|
1438
|
+
const { confirmAction } = await inquirer__default.default.prompt([
|
|
1439
|
+
{
|
|
1440
|
+
type: "confirm",
|
|
1441
|
+
name: "confirmAction",
|
|
1442
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1443
|
+
default: false
|
|
1444
|
+
}
|
|
1445
|
+
]);
|
|
1446
|
+
if (!confirmAction) {
|
|
1447
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1448
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1449
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1450
|
+
});
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
await save({ project: answer.linkProject });
|
|
1454
|
+
logger.log(`Project ${chalk__default.default.cyan(answer.linkProject.displayName)} linked successfully.`);
|
|
1455
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1456
|
+
projectInternalName: answer.linkProject
|
|
1457
|
+
});
|
|
1458
|
+
} catch (e) {
|
|
1459
|
+
logger.debug("Failed to link project", e);
|
|
1460
|
+
logger.error("An error occurred while linking the project.");
|
|
1461
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1462
|
+
projectInternalName: answer.linkProject
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
1466
|
+
const command$5 = ({ command: command2, ctx }) => {
|
|
1467
|
+
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));
|
|
1468
|
+
};
|
|
1469
|
+
const link = {
|
|
1470
|
+
name: "link-project",
|
|
1471
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1472
|
+
action: action$3,
|
|
1473
|
+
command: command$5
|
|
1184
1474
|
};
|
|
1185
|
-
const command$
|
|
1186
|
-
|
|
1475
|
+
const command$4 = ({ ctx }) => {
|
|
1476
|
+
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1187
1477
|
"after",
|
|
1188
1478
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1189
1479
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1192,10 +1482,10 @@ const login = {
|
|
|
1192
1482
|
name: "login",
|
|
1193
1483
|
description: "Strapi Cloud Login",
|
|
1194
1484
|
action: loginAction,
|
|
1195
|
-
command: command$
|
|
1485
|
+
command: command$4
|
|
1196
1486
|
};
|
|
1197
1487
|
const openModule = import("open");
|
|
1198
|
-
const action = async (ctx) => {
|
|
1488
|
+
const action$2 = async (ctx) => {
|
|
1199
1489
|
const { logger } = ctx;
|
|
1200
1490
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1201
1491
|
const token = await retrieveToken();
|
|
@@ -1225,37 +1515,139 @@ const action = async (ctx) => {
|
|
|
1225
1515
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1226
1516
|
logger.debug(e);
|
|
1227
1517
|
}
|
|
1228
|
-
|
|
1229
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1230
|
-
} catch (e) {
|
|
1231
|
-
logger.debug("Failed to track logout event", e);
|
|
1232
|
-
}
|
|
1518
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1233
1519
|
};
|
|
1234
|
-
const command$
|
|
1235
|
-
|
|
1520
|
+
const command$3 = ({ ctx }) => {
|
|
1521
|
+
return commander.createCommand("cloud:logout").alias("logout").description("Strapi Cloud Logout").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("logout", action$2)(ctx));
|
|
1236
1522
|
};
|
|
1237
1523
|
const logout = {
|
|
1238
1524
|
name: "logout",
|
|
1239
1525
|
description: "Strapi Cloud Logout",
|
|
1240
|
-
action,
|
|
1241
|
-
command: command$
|
|
1526
|
+
action: action$2,
|
|
1527
|
+
command: command$3
|
|
1242
1528
|
};
|
|
1243
|
-
const command = ({
|
|
1244
|
-
|
|
1529
|
+
const command$2 = ({ ctx }) => {
|
|
1530
|
+
return commander.createCommand("cloud:create-project").description("Create a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("cloud:create-project", action$5)(ctx));
|
|
1245
1531
|
};
|
|
1246
1532
|
const createProject = {
|
|
1247
1533
|
name: "create-project",
|
|
1248
1534
|
description: "Create a new project",
|
|
1249
|
-
action: action$
|
|
1535
|
+
action: action$5,
|
|
1536
|
+
command: command$2
|
|
1537
|
+
};
|
|
1538
|
+
const action$1 = async (ctx) => {
|
|
1539
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1540
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1541
|
+
const { logger } = ctx;
|
|
1542
|
+
if (!token) {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1546
|
+
const spinner = logger.spinner("Fetching your projects...").start();
|
|
1547
|
+
try {
|
|
1548
|
+
const {
|
|
1549
|
+
data: { data: projectList }
|
|
1550
|
+
} = await cloudApiService.listProjects();
|
|
1551
|
+
spinner.succeed();
|
|
1552
|
+
logger.log(projectList);
|
|
1553
|
+
} catch (e) {
|
|
1554
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1555
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1559
|
+
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));
|
|
1560
|
+
};
|
|
1561
|
+
const listProjects = {
|
|
1562
|
+
name: "list-projects",
|
|
1563
|
+
description: "List Strapi Cloud projects",
|
|
1564
|
+
action: action$1,
|
|
1565
|
+
command: command$1
|
|
1566
|
+
};
|
|
1567
|
+
async function getProject(ctx) {
|
|
1568
|
+
const { project } = await retrieve();
|
|
1569
|
+
if (!project) {
|
|
1570
|
+
ctx.logger.warn(
|
|
1571
|
+
`
|
|
1572
|
+
We couldn't find a valid local project config.
|
|
1573
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1574
|
+
"link"
|
|
1575
|
+
)} command`
|
|
1576
|
+
);
|
|
1577
|
+
process.exit(1);
|
|
1578
|
+
}
|
|
1579
|
+
return project;
|
|
1580
|
+
}
|
|
1581
|
+
const action = async (ctx) => {
|
|
1582
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1583
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1584
|
+
const { logger } = ctx;
|
|
1585
|
+
if (!token) {
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
const project = await getProject(ctx);
|
|
1589
|
+
if (!project) {
|
|
1590
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1594
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1595
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1596
|
+
projectInternalName: project.name
|
|
1597
|
+
});
|
|
1598
|
+
try {
|
|
1599
|
+
const {
|
|
1600
|
+
data: { data: environmentsList }
|
|
1601
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1602
|
+
spinner.succeed();
|
|
1603
|
+
logger.log(environmentsList);
|
|
1604
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1605
|
+
projectInternalName: project.name
|
|
1606
|
+
});
|
|
1607
|
+
} catch (e) {
|
|
1608
|
+
if (e.response && e.response.status === 404) {
|
|
1609
|
+
spinner.succeed();
|
|
1610
|
+
logger.warn(
|
|
1611
|
+
`
|
|
1612
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1613
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1614
|
+
"link"
|
|
1615
|
+
)} command`
|
|
1616
|
+
);
|
|
1617
|
+
} else {
|
|
1618
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1619
|
+
logger.debug("Failed to list environments", e);
|
|
1620
|
+
}
|
|
1621
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1622
|
+
projectInternalName: project.name
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
function defineCloudNamespace(command2) {
|
|
1627
|
+
return command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1628
|
+
}
|
|
1629
|
+
const command = ({ command: command2, ctx }) => {
|
|
1630
|
+
const cloud = defineCloudNamespace(command2);
|
|
1631
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
|
|
1632
|
+
const environment = cloud.command("environment").description("Manage environments for a Strapi Cloud project");
|
|
1633
|
+
environment.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));
|
|
1634
|
+
};
|
|
1635
|
+
const listEnvironments = {
|
|
1636
|
+
name: "list-environments",
|
|
1637
|
+
description: "List Strapi Cloud environments",
|
|
1638
|
+
action,
|
|
1250
1639
|
command
|
|
1251
1640
|
};
|
|
1252
1641
|
const cli = {
|
|
1253
1642
|
deployProject,
|
|
1643
|
+
link,
|
|
1254
1644
|
login,
|
|
1255
1645
|
logout,
|
|
1256
|
-
createProject
|
|
1646
|
+
createProject,
|
|
1647
|
+
listProjects,
|
|
1648
|
+
listEnvironments
|
|
1257
1649
|
};
|
|
1258
|
-
const cloudCommands = [deployProject, login, logout];
|
|
1650
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
|
|
1259
1651
|
async function initCloudCLIConfig() {
|
|
1260
1652
|
const localConfig = await getLocalConfig();
|
|
1261
1653
|
if (!localConfig.deviceId) {
|
|
@@ -1271,7 +1663,10 @@ async function buildStrapiCloudCommands({
|
|
|
1271
1663
|
await initCloudCLIConfig();
|
|
1272
1664
|
for (const cloudCommand of cloudCommands) {
|
|
1273
1665
|
try {
|
|
1274
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1666
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1667
|
+
if (subCommand) {
|
|
1668
|
+
command2.addCommand(subCommand);
|
|
1669
|
+
}
|
|
1275
1670
|
} catch (e) {
|
|
1276
1671
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1277
1672
|
}
|