@strapi/cloud-cli 5.0.0-rc.9 → 5.0.1
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 +442 -143
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +442 -140
- package/dist/index.mjs.map +1 -1
- package/dist/src/create-project/action.d.ts.map +1 -1
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts +3 -0
- package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts.map +1 -0
- package/dist/src/create-project/utils/project-questions.utils.d.ts +20 -0
- package/dist/src/create-project/utils/project-questions.utils.d.ts.map +1 -0
- package/dist/src/deploy-project/action.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/link/action.d.ts +4 -0
- package/dist/src/link/action.d.ts.map +1 -0
- package/dist/src/link/command.d.ts +7 -0
- package/dist/src/link/command.d.ts.map +1 -0
- package/dist/src/link/index.d.ts +7 -0
- package/dist/src/link/index.d.ts.map +1 -0
- package/dist/src/list-projects/action.d.ts +4 -0
- package/dist/src/list-projects/action.d.ts.map +1 -0
- package/dist/src/list-projects/command.d.ts +7 -0
- package/dist/src/list-projects/command.d.ts.map +1 -0
- package/dist/src/list-projects/index.d.ts +7 -0
- package/dist/src/list-projects/index.d.ts.map +1 -0
- package/dist/src/login/action.d.ts.map +1 -1
- package/dist/src/logout/action.d.ts.map +1 -1
- package/dist/src/services/build-logs.d.ts.map +1 -1
- package/dist/src/services/cli-api.d.ts +35 -7
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/services/strapi-info-save.d.ts +1 -1
- package/dist/src/services/strapi-info-save.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/analytics.d.ts +4 -0
- package/dist/src/utils/analytics.d.ts.map +1 -0
- package/dist/src/utils/compress-files.d.ts.map +1 -1
- package/dist/src/utils/pkg.d.ts.map +1 -1
- package/package.json +8 -7
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,9 @@ 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");
|
|
48
46
|
const commander = require("commander");
|
|
49
47
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
50
48
|
function _interopNamespace(e) {
|
|
@@ -66,12 +64,11 @@ function _interopNamespace(e) {
|
|
|
66
64
|
return Object.freeze(n);
|
|
67
65
|
}
|
|
68
66
|
const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
|
|
69
|
-
const
|
|
67
|
+
const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
|
|
70
68
|
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
71
69
|
const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
72
70
|
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
73
71
|
const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
|
|
74
|
-
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
75
72
|
const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
|
|
76
73
|
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
77
74
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
@@ -81,10 +78,9 @@ const jwt__default = /* @__PURE__ */ _interopDefault(jwt);
|
|
|
81
78
|
const stringify__default = /* @__PURE__ */ _interopDefault(stringify);
|
|
82
79
|
const ora__default = /* @__PURE__ */ _interopDefault(ora);
|
|
83
80
|
const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
|
|
84
|
-
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
85
|
-
const fs__default = /* @__PURE__ */ _interopDefault(fs$1);
|
|
86
81
|
const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
|
|
87
82
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
83
|
+
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
88
84
|
const apiConfig = {
|
|
89
85
|
apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
90
86
|
dashboardBaseUrl: utils.env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -103,23 +99,6 @@ const IGNORED_PATTERNS = [
|
|
|
103
99
|
"**/.idea/**",
|
|
104
100
|
"**/.vscode/**"
|
|
105
101
|
];
|
|
106
|
-
const getFiles = (dirPath, ignorePatterns = [], arrayOfFiles = [], subfolder = "") => {
|
|
107
|
-
const entries = fs__namespace.readdirSync(path__namespace.join(dirPath, subfolder));
|
|
108
|
-
entries.forEach((entry) => {
|
|
109
|
-
const entryPathFromRoot = path__namespace.join(subfolder, entry);
|
|
110
|
-
const entryPath = path__namespace.relative(dirPath, entryPathFromRoot);
|
|
111
|
-
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
112
|
-
if (isIgnored) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (fs__namespace.statSync(entryPath).isDirectory()) {
|
|
116
|
-
getFiles(dirPath, ignorePatterns, arrayOfFiles, entryPathFromRoot);
|
|
117
|
-
} else {
|
|
118
|
-
arrayOfFiles.push(entryPath);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
return arrayOfFiles;
|
|
122
|
-
};
|
|
123
102
|
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
124
103
|
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
125
104
|
const relativeFilePath = path__namespace.join(folderPath, file);
|
|
@@ -137,16 +116,35 @@ const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
|
137
116
|
}
|
|
138
117
|
return isIgnored;
|
|
139
118
|
};
|
|
140
|
-
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) => {
|
|
141
138
|
const gitignorePath = path__namespace.resolve(folderPath, ".gitignore");
|
|
142
|
-
|
|
139
|
+
const pathExist = await fse__namespace.pathExists(gitignorePath);
|
|
140
|
+
if (!pathExist)
|
|
143
141
|
return [];
|
|
144
|
-
const gitignoreContent =
|
|
142
|
+
const gitignoreContent = await fse__namespace.readFile(gitignorePath, "utf8");
|
|
145
143
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
146
144
|
};
|
|
147
145
|
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
148
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
149
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
146
|
+
const ignorePatterns = await readGitignore(folderToCompress);
|
|
147
|
+
const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
|
|
150
148
|
return tar__namespace.c(
|
|
151
149
|
{
|
|
152
150
|
gzip: true,
|
|
@@ -159,7 +157,7 @@ const APP_FOLDER_NAME = "com.strapi.cli";
|
|
|
159
157
|
const CONFIG_FILENAME = "config.json";
|
|
160
158
|
async function checkDirectoryExists(directoryPath) {
|
|
161
159
|
try {
|
|
162
|
-
const fsStat = await
|
|
160
|
+
const fsStat = await fse__namespace.default.lstat(directoryPath);
|
|
163
161
|
return fsStat.isDirectory();
|
|
164
162
|
} catch (e) {
|
|
165
163
|
return false;
|
|
@@ -167,14 +165,14 @@ async function checkDirectoryExists(directoryPath) {
|
|
|
167
165
|
}
|
|
168
166
|
async function getTmpStoragePath() {
|
|
169
167
|
const storagePath = path__namespace.default.join(os__default.default.tmpdir(), APP_FOLDER_NAME);
|
|
170
|
-
await
|
|
168
|
+
await fse__namespace.default.ensureDir(storagePath);
|
|
171
169
|
return storagePath;
|
|
172
170
|
}
|
|
173
171
|
async function getConfigPath() {
|
|
174
172
|
const configDirs = XDGAppPaths__default.default(APP_FOLDER_NAME).configDirs();
|
|
175
173
|
const configPath = configDirs.find(checkDirectoryExists);
|
|
176
174
|
if (!configPath) {
|
|
177
|
-
await
|
|
175
|
+
await fse__namespace.default.ensureDir(configDirs[0]);
|
|
178
176
|
return configDirs[0];
|
|
179
177
|
}
|
|
180
178
|
return configPath;
|
|
@@ -182,9 +180,9 @@ async function getConfigPath() {
|
|
|
182
180
|
async function getLocalConfig() {
|
|
183
181
|
const configPath = await getConfigPath();
|
|
184
182
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
185
|
-
await
|
|
183
|
+
await fse__namespace.default.ensureFile(configFilePath);
|
|
186
184
|
try {
|
|
187
|
-
return await
|
|
185
|
+
return await fse__namespace.default.readJSON(configFilePath, { encoding: "utf8", throws: true });
|
|
188
186
|
} catch (e) {
|
|
189
187
|
return {};
|
|
190
188
|
}
|
|
@@ -192,10 +190,10 @@ async function getLocalConfig() {
|
|
|
192
190
|
async function saveLocalConfig(data) {
|
|
193
191
|
const configPath = await getConfigPath();
|
|
194
192
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
195
|
-
await
|
|
193
|
+
await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
196
194
|
}
|
|
197
195
|
const name = "@strapi/cloud-cli";
|
|
198
|
-
const version = "5.0.0
|
|
196
|
+
const version = "5.0.0";
|
|
199
197
|
const description = "Commands to interact with the Strapi Cloud";
|
|
200
198
|
const keywords = [
|
|
201
199
|
"strapi",
|
|
@@ -236,11 +234,12 @@ const scripts = {
|
|
|
236
234
|
build: "pack-up build",
|
|
237
235
|
clean: "run -T rimraf ./dist",
|
|
238
236
|
lint: "run -T eslint .",
|
|
237
|
+
"test:unit": "run -T jest",
|
|
239
238
|
watch: "pack-up watch"
|
|
240
239
|
};
|
|
241
240
|
const dependencies = {
|
|
242
241
|
"@strapi/utils": "workspace:*",
|
|
243
|
-
axios: "1.
|
|
242
|
+
axios: "1.7.4",
|
|
244
243
|
chalk: "4.1.2",
|
|
245
244
|
"cli-progress": "3.12.0",
|
|
246
245
|
commander: "8.3.0",
|
|
@@ -255,7 +254,7 @@ const dependencies = {
|
|
|
255
254
|
open: "8.4.0",
|
|
256
255
|
ora: "5.4.1",
|
|
257
256
|
"pkg-up": "3.1.0",
|
|
258
|
-
tar: "6.1
|
|
257
|
+
tar: "6.2.1",
|
|
259
258
|
"xdg-app-paths": "8.3.0",
|
|
260
259
|
yup: "0.32.9"
|
|
261
260
|
};
|
|
@@ -318,7 +317,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
318
317
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
319
318
|
return axiosCloudAPI.post(
|
|
320
319
|
`/deploy/${project.name}`,
|
|
321
|
-
{ file:
|
|
320
|
+
{ file: fse__namespace.default.createReadStream(filePath) },
|
|
322
321
|
{
|
|
323
322
|
headers: {
|
|
324
323
|
"Content-Type": "multipart/form-data"
|
|
@@ -361,8 +360,47 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
361
360
|
throw error;
|
|
362
361
|
}
|
|
363
362
|
},
|
|
364
|
-
listProjects() {
|
|
365
|
-
|
|
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 getProject({ name: name2 }) {
|
|
392
|
+
try {
|
|
393
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
394
|
+
if (response.status !== 200) {
|
|
395
|
+
throw new Error("Error fetching project's details.");
|
|
396
|
+
}
|
|
397
|
+
return response;
|
|
398
|
+
} catch (error) {
|
|
399
|
+
logger.debug(
|
|
400
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
401
|
+
);
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
366
404
|
},
|
|
367
405
|
track(event, payload = {}) {
|
|
368
406
|
return axiosCloudAPI.post("/track", {
|
|
@@ -377,18 +415,18 @@ async function save(data, { directoryPath } = {}) {
|
|
|
377
415
|
const alreadyInFileData = await retrieve({ directoryPath });
|
|
378
416
|
const storedData = { ...alreadyInFileData, ...data };
|
|
379
417
|
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
380
|
-
await
|
|
381
|
-
await
|
|
418
|
+
await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
419
|
+
await fse__namespace.default.writeJson(pathToFile, storedData, { encoding: "utf8" });
|
|
382
420
|
}
|
|
383
421
|
async function retrieve({
|
|
384
422
|
directoryPath
|
|
385
423
|
} = {}) {
|
|
386
424
|
const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
387
|
-
const pathExists = await
|
|
425
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
388
426
|
if (!pathExists) {
|
|
389
427
|
return {};
|
|
390
428
|
}
|
|
391
|
-
return
|
|
429
|
+
return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
|
|
392
430
|
}
|
|
393
431
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
432
|
__proto__: null,
|
|
@@ -633,6 +671,56 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
633
671
|
local: strapiInfoSave,
|
|
634
672
|
tokenServiceFactory
|
|
635
673
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
674
|
+
yup__namespace.object({
|
|
675
|
+
name: yup__namespace.string().required(),
|
|
676
|
+
exports: yup__namespace.lazy(
|
|
677
|
+
(value) => yup__namespace.object(
|
|
678
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
679
|
+
(acc, [key, value2]) => {
|
|
680
|
+
if (typeof value2 === "object") {
|
|
681
|
+
acc[key] = yup__namespace.object({
|
|
682
|
+
types: yup__namespace.string().optional(),
|
|
683
|
+
source: yup__namespace.string().required(),
|
|
684
|
+
module: yup__namespace.string().optional(),
|
|
685
|
+
import: yup__namespace.string().required(),
|
|
686
|
+
require: yup__namespace.string().required(),
|
|
687
|
+
default: yup__namespace.string().required()
|
|
688
|
+
}).noUnknown(true);
|
|
689
|
+
} else {
|
|
690
|
+
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
691
|
+
}
|
|
692
|
+
return acc;
|
|
693
|
+
},
|
|
694
|
+
{}
|
|
695
|
+
) : void 0
|
|
696
|
+
).optional()
|
|
697
|
+
)
|
|
698
|
+
});
|
|
699
|
+
const loadPkg = async ({ cwd, logger }) => {
|
|
700
|
+
const pkgPath = await pkgUp__default.default({ cwd });
|
|
701
|
+
if (!pkgPath) {
|
|
702
|
+
throw new Error("Could not find a package.json in the current directory");
|
|
703
|
+
}
|
|
704
|
+
const buffer = await fse__namespace.readFile(pkgPath);
|
|
705
|
+
const pkg = JSON.parse(buffer.toString());
|
|
706
|
+
logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
|
|
707
|
+
return pkg;
|
|
708
|
+
};
|
|
709
|
+
async function getProjectNameFromPackageJson(ctx) {
|
|
710
|
+
try {
|
|
711
|
+
const packageJson2 = await loadPkg(ctx);
|
|
712
|
+
return packageJson2.name || "my-strapi-project";
|
|
713
|
+
} catch (e) {
|
|
714
|
+
return "my-strapi-project";
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
718
|
+
try {
|
|
719
|
+
await cloudApiService.track(eventName, eventData);
|
|
720
|
+
} catch (e) {
|
|
721
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
636
724
|
const openModule$1 = import("open");
|
|
637
725
|
async function promptLogin(ctx) {
|
|
638
726
|
const response = await inquirer__default.default.prompt([
|
|
@@ -653,13 +741,6 @@ async function loginAction(ctx) {
|
|
|
653
741
|
const tokenService = await tokenServiceFactory(ctx);
|
|
654
742
|
const existingToken = await tokenService.retrieveToken();
|
|
655
743
|
const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
|
|
656
|
-
const trackFailedLogin = async () => {
|
|
657
|
-
try {
|
|
658
|
-
await cloudApiService.track("didNotLogin", { loginMethod: "cli" });
|
|
659
|
-
} catch (e) {
|
|
660
|
-
logger.debug("Failed to track failed login", e);
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
744
|
if (existingToken) {
|
|
664
745
|
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
665
746
|
if (isTokenValid) {
|
|
@@ -691,11 +772,7 @@ async function loginAction(ctx) {
|
|
|
691
772
|
logger.debug(e);
|
|
692
773
|
return false;
|
|
693
774
|
}
|
|
694
|
-
|
|
695
|
-
await cloudApiService.track("willLoginAttempt", {});
|
|
696
|
-
} catch (e) {
|
|
697
|
-
logger.debug("Failed to track login attempt", e);
|
|
698
|
-
}
|
|
775
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
699
776
|
logger.debug("🔐 Creating device authentication request...", {
|
|
700
777
|
client_id: cliConfig2.clientId,
|
|
701
778
|
scope: cliConfig2.scope,
|
|
@@ -775,13 +852,13 @@ async function loginAction(ctx) {
|
|
|
775
852
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
776
853
|
);
|
|
777
854
|
spinnerFail();
|
|
778
|
-
await
|
|
855
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
779
856
|
return false;
|
|
780
857
|
}
|
|
781
858
|
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
782
859
|
logger.debug(e);
|
|
783
860
|
spinnerFail();
|
|
784
|
-
await
|
|
861
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
785
862
|
return false;
|
|
786
863
|
}
|
|
787
864
|
await new Promise((resolve) => {
|
|
@@ -795,15 +872,50 @@ async function loginAction(ctx) {
|
|
|
795
872
|
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
796
873
|
);
|
|
797
874
|
logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
|
|
798
|
-
|
|
799
|
-
await cloudApiService.track("didLogin", { loginMethod: "cli" });
|
|
800
|
-
} catch (e) {
|
|
801
|
-
logger.debug("Failed to track login", e);
|
|
802
|
-
}
|
|
875
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
803
876
|
};
|
|
804
877
|
await authenticate();
|
|
805
878
|
return isAuthenticated;
|
|
806
879
|
}
|
|
880
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
881
|
+
return (questions) => {
|
|
882
|
+
return questions.map((question) => {
|
|
883
|
+
const questionName = question.name;
|
|
884
|
+
if (questionName in questionsMap) {
|
|
885
|
+
const questionDefault = questionsMap[questionName];
|
|
886
|
+
if (typeof questionDefault === "function") {
|
|
887
|
+
return {
|
|
888
|
+
...question,
|
|
889
|
+
default: questionDefault(question)
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
return {
|
|
893
|
+
...question,
|
|
894
|
+
default: questionDefault
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
return question;
|
|
898
|
+
});
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
function getDefaultsFromQuestions(questions) {
|
|
902
|
+
return questions.reduce((acc, question) => {
|
|
903
|
+
if (question.default && question.name) {
|
|
904
|
+
return { ...acc, [question.name]: question.default };
|
|
905
|
+
}
|
|
906
|
+
return acc;
|
|
907
|
+
}, {});
|
|
908
|
+
}
|
|
909
|
+
function getProjectNodeVersionDefault(question) {
|
|
910
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
911
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
912
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
913
|
+
if (choice) {
|
|
914
|
+
return choice.value;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return question.default;
|
|
918
|
+
}
|
|
807
919
|
async function handleError(ctx, error) {
|
|
808
920
|
const { logger } = ctx;
|
|
809
921
|
logger.debug(error);
|
|
@@ -848,7 +960,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
848
960
|
throw e;
|
|
849
961
|
}
|
|
850
962
|
}
|
|
851
|
-
const action$
|
|
963
|
+
const action$4 = async (ctx) => {
|
|
852
964
|
const { logger } = ctx;
|
|
853
965
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
854
966
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -857,7 +969,16 @@ const action$2 = async (ctx) => {
|
|
|
857
969
|
}
|
|
858
970
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
859
971
|
const { data: config } = await cloudApi.config();
|
|
860
|
-
const
|
|
972
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
973
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
974
|
+
name: projectName,
|
|
975
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
976
|
+
});
|
|
977
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
978
|
+
const defaultValues = {
|
|
979
|
+
...config.projectCreation.defaults,
|
|
980
|
+
...getDefaultsFromQuestions(questions)
|
|
981
|
+
};
|
|
861
982
|
const projectAnswersDefaulted = fp.defaults(defaultValues);
|
|
862
983
|
const projectAnswers = await inquirer__default.default.prompt(questions);
|
|
863
984
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -906,41 +1027,6 @@ function notificationServiceFactory({ logger }) {
|
|
|
906
1027
|
};
|
|
907
1028
|
};
|
|
908
1029
|
}
|
|
909
|
-
yup__namespace.object({
|
|
910
|
-
name: yup__namespace.string().required(),
|
|
911
|
-
exports: yup__namespace.lazy(
|
|
912
|
-
(value) => yup__namespace.object(
|
|
913
|
-
typeof value === "object" ? Object.entries(value).reduce(
|
|
914
|
-
(acc, [key, value2]) => {
|
|
915
|
-
if (typeof value2 === "object") {
|
|
916
|
-
acc[key] = yup__namespace.object({
|
|
917
|
-
types: yup__namespace.string().optional(),
|
|
918
|
-
source: yup__namespace.string().required(),
|
|
919
|
-
module: yup__namespace.string().optional(),
|
|
920
|
-
import: yup__namespace.string().required(),
|
|
921
|
-
require: yup__namespace.string().required(),
|
|
922
|
-
default: yup__namespace.string().required()
|
|
923
|
-
}).noUnknown(true);
|
|
924
|
-
} else {
|
|
925
|
-
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
926
|
-
}
|
|
927
|
-
return acc;
|
|
928
|
-
},
|
|
929
|
-
{}
|
|
930
|
-
) : void 0
|
|
931
|
-
).optional()
|
|
932
|
-
)
|
|
933
|
-
});
|
|
934
|
-
const loadPkg = async ({ cwd, logger }) => {
|
|
935
|
-
const pkgPath = await pkgUp__default.default({ cwd });
|
|
936
|
-
if (!pkgPath) {
|
|
937
|
-
throw new Error("Could not find a package.json in the current directory");
|
|
938
|
-
}
|
|
939
|
-
const buffer = await fs__default.default.readFile(pkgPath);
|
|
940
|
-
const pkg = JSON.parse(buffer.toString());
|
|
941
|
-
logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
|
|
942
|
-
return pkg;
|
|
943
|
-
};
|
|
944
1030
|
const buildLogsServiceFactory = ({ logger }) => {
|
|
945
1031
|
return async (url, token, cliConfig2) => {
|
|
946
1032
|
const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
|
|
@@ -994,6 +1080,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
994
1080
|
if (retries > MAX_RETRIES) {
|
|
995
1081
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
996
1082
|
es.close();
|
|
1083
|
+
clearExistingTimeout();
|
|
997
1084
|
reject(new Error("Max retries reached"));
|
|
998
1085
|
}
|
|
999
1086
|
};
|
|
@@ -1036,13 +1123,13 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1036
1123
|
process.exit(1);
|
|
1037
1124
|
}
|
|
1038
1125
|
const tarFilePath = path__namespace.default.resolve(storagePath, compressedFilename);
|
|
1039
|
-
const fileStats = await
|
|
1126
|
+
const fileStats = await fse__namespace.default.stat(tarFilePath);
|
|
1040
1127
|
if (fileStats.size > maxProjectFileSize) {
|
|
1041
1128
|
ctx.logger.log(
|
|
1042
1129
|
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
1043
1130
|
);
|
|
1044
1131
|
try {
|
|
1045
|
-
await
|
|
1132
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
1046
1133
|
} catch (e) {
|
|
1047
1134
|
ctx.logger.log("Unable to remove file: ", tarFilePath);
|
|
1048
1135
|
ctx.logger.debug(e);
|
|
@@ -1068,20 +1155,10 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1068
1155
|
return data.build_id;
|
|
1069
1156
|
} catch (e) {
|
|
1070
1157
|
progressBar.stop();
|
|
1071
|
-
|
|
1072
|
-
if (e.response.status === 404) {
|
|
1073
|
-
ctx.logger.error(
|
|
1074
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
1075
|
-
);
|
|
1076
|
-
} else {
|
|
1077
|
-
ctx.logger.error(e.response.data);
|
|
1078
|
-
}
|
|
1079
|
-
} else {
|
|
1080
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1081
|
-
}
|
|
1158
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1082
1159
|
ctx.logger.debug(e);
|
|
1083
1160
|
} finally {
|
|
1084
|
-
await
|
|
1161
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
1085
1162
|
}
|
|
1086
1163
|
process.exit(0);
|
|
1087
1164
|
} catch (e) {
|
|
@@ -1094,7 +1171,7 @@ async function getProject(ctx) {
|
|
|
1094
1171
|
const { project } = await retrieve();
|
|
1095
1172
|
if (!project) {
|
|
1096
1173
|
try {
|
|
1097
|
-
return await action$
|
|
1174
|
+
return await action$4(ctx);
|
|
1098
1175
|
} catch (e) {
|
|
1099
1176
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1100
1177
|
ctx.logger.debug(e);
|
|
@@ -1103,7 +1180,19 @@ async function getProject(ctx) {
|
|
|
1103
1180
|
}
|
|
1104
1181
|
return project;
|
|
1105
1182
|
}
|
|
1106
|
-
|
|
1183
|
+
async function getConfig({
|
|
1184
|
+
ctx,
|
|
1185
|
+
cloudApiService
|
|
1186
|
+
}) {
|
|
1187
|
+
try {
|
|
1188
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1189
|
+
return cliConfig2;
|
|
1190
|
+
} catch (e) {
|
|
1191
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1192
|
+
return null;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
const action$3 = async (ctx) => {
|
|
1107
1196
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1108
1197
|
const token = await getValidToken(ctx, promptLogin);
|
|
1109
1198
|
if (!token) {
|
|
@@ -1113,15 +1202,51 @@ const action$1 = async (ctx) => {
|
|
|
1113
1202
|
if (!project) {
|
|
1114
1203
|
return;
|
|
1115
1204
|
}
|
|
1116
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1205
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1117
1206
|
try {
|
|
1118
|
-
|
|
1207
|
+
const {
|
|
1208
|
+
data: { data: projectData, metadata }
|
|
1209
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1210
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1211
|
+
if (isProjectSuspended) {
|
|
1212
|
+
ctx.logger.log(
|
|
1213
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1214
|
+
);
|
|
1215
|
+
ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1119
1218
|
} catch (e) {
|
|
1120
|
-
|
|
1219
|
+
if (e instanceof axios.AxiosError && e.response?.data) {
|
|
1220
|
+
if (e.response.status === 404) {
|
|
1221
|
+
ctx.logger.warn(
|
|
1222
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1223
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1224
|
+
"link"
|
|
1225
|
+
)} command before deploying.`
|
|
1226
|
+
);
|
|
1227
|
+
} else {
|
|
1228
|
+
ctx.logger.error(e.response.data);
|
|
1229
|
+
}
|
|
1230
|
+
} else {
|
|
1231
|
+
ctx.logger.error(
|
|
1232
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
ctx.logger.debug(e);
|
|
1236
|
+
return;
|
|
1121
1237
|
}
|
|
1238
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1239
|
+
projectInternalName: project.name
|
|
1240
|
+
});
|
|
1122
1241
|
const notificationService = notificationServiceFactory(ctx);
|
|
1123
1242
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
1124
|
-
const
|
|
1243
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1244
|
+
if (!cliConfig2) {
|
|
1245
|
+
ctx.logger.error(
|
|
1246
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1247
|
+
);
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1125
1250
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
1126
1251
|
if (Number.isNaN(maxSize)) {
|
|
1127
1252
|
ctx.logger.debug(
|
|
@@ -1143,10 +1268,11 @@ const action$1 = async (ctx) => {
|
|
|
1143
1268
|
chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
1144
1269
|
);
|
|
1145
1270
|
} catch (e) {
|
|
1271
|
+
ctx.logger.debug(e);
|
|
1146
1272
|
if (e instanceof Error) {
|
|
1147
1273
|
ctx.logger.error(e.message);
|
|
1148
1274
|
} else {
|
|
1149
|
-
|
|
1275
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1150
1276
|
}
|
|
1151
1277
|
}
|
|
1152
1278
|
};
|
|
@@ -1177,16 +1303,162 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1177
1303
|
process.exit(1);
|
|
1178
1304
|
});
|
|
1179
1305
|
};
|
|
1180
|
-
const command$
|
|
1181
|
-
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$
|
|
1306
|
+
const command$5 = ({ ctx }) => {
|
|
1307
|
+
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$3)(ctx));
|
|
1182
1308
|
};
|
|
1183
1309
|
const deployProject = {
|
|
1184
1310
|
name: "deploy-project",
|
|
1185
1311
|
description: "Deploy a Strapi Cloud project",
|
|
1186
|
-
action: action$
|
|
1187
|
-
command: command$
|
|
1312
|
+
action: action$3,
|
|
1313
|
+
command: command$5
|
|
1188
1314
|
};
|
|
1189
|
-
const
|
|
1315
|
+
const QUIT_OPTION = "Quit";
|
|
1316
|
+
async function getExistingConfig(ctx) {
|
|
1317
|
+
try {
|
|
1318
|
+
return await retrieve();
|
|
1319
|
+
} catch (e) {
|
|
1320
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1321
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1322
|
+
return null;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1326
|
+
if (existingConfig && existingConfig.project) {
|
|
1327
|
+
const { shouldRelink } = await inquirer__default.default.prompt([
|
|
1328
|
+
{
|
|
1329
|
+
type: "confirm",
|
|
1330
|
+
name: "shouldRelink",
|
|
1331
|
+
message: `A project named ${chalk__default.default.cyan(
|
|
1332
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1333
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1334
|
+
default: false
|
|
1335
|
+
}
|
|
1336
|
+
]);
|
|
1337
|
+
if (!shouldRelink) {
|
|
1338
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1339
|
+
currentProjectName: existingConfig.project?.name
|
|
1340
|
+
});
|
|
1341
|
+
return false;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
return true;
|
|
1345
|
+
}
|
|
1346
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1347
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
1348
|
+
try {
|
|
1349
|
+
const {
|
|
1350
|
+
data: { data: projectList }
|
|
1351
|
+
} = await cloudApiService.listLinkProjects();
|
|
1352
|
+
spinner.succeed();
|
|
1353
|
+
if (!Array.isArray(projectList)) {
|
|
1354
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1355
|
+
return null;
|
|
1356
|
+
}
|
|
1357
|
+
const projects = projectList.filter(
|
|
1358
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1359
|
+
).map((project) => {
|
|
1360
|
+
return {
|
|
1361
|
+
name: project.displayName,
|
|
1362
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1363
|
+
};
|
|
1364
|
+
});
|
|
1365
|
+
if (projects.length === 0) {
|
|
1366
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1367
|
+
return null;
|
|
1368
|
+
}
|
|
1369
|
+
return projects;
|
|
1370
|
+
} catch (e) {
|
|
1371
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1372
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
async function getUserSelection(ctx, projects) {
|
|
1377
|
+
const { logger } = ctx;
|
|
1378
|
+
try {
|
|
1379
|
+
const answer = await inquirer__default.default.prompt([
|
|
1380
|
+
{
|
|
1381
|
+
type: "list",
|
|
1382
|
+
name: "linkProject",
|
|
1383
|
+
message: "Which project do you want to link?",
|
|
1384
|
+
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1385
|
+
}
|
|
1386
|
+
]);
|
|
1387
|
+
if (!answer.linkProject) {
|
|
1388
|
+
return null;
|
|
1389
|
+
}
|
|
1390
|
+
return answer;
|
|
1391
|
+
} catch (e) {
|
|
1392
|
+
logger.debug("Failed to get user input", e);
|
|
1393
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1394
|
+
return null;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
const action$2 = async (ctx) => {
|
|
1398
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1399
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1400
|
+
const { logger } = ctx;
|
|
1401
|
+
if (!token) {
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1405
|
+
const existingConfig = await getExistingConfig(ctx);
|
|
1406
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1407
|
+
if (!shouldRelink) {
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1411
|
+
const projects = await getProjectsList(
|
|
1412
|
+
ctx,
|
|
1413
|
+
cloudApiService,
|
|
1414
|
+
existingConfig
|
|
1415
|
+
);
|
|
1416
|
+
if (!projects) {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1420
|
+
if (!answer) {
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
try {
|
|
1424
|
+
const { confirmAction } = await inquirer__default.default.prompt([
|
|
1425
|
+
{
|
|
1426
|
+
type: "confirm",
|
|
1427
|
+
name: "confirmAction",
|
|
1428
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1429
|
+
default: false
|
|
1430
|
+
}
|
|
1431
|
+
]);
|
|
1432
|
+
if (!confirmAction) {
|
|
1433
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1434
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1435
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1436
|
+
});
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
await save({ project: answer.linkProject });
|
|
1440
|
+
logger.log(`Project ${chalk__default.default.cyan(answer.linkProject.displayName)} linked successfully.`);
|
|
1441
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1442
|
+
projectInternalName: answer.linkProject
|
|
1443
|
+
});
|
|
1444
|
+
} catch (e) {
|
|
1445
|
+
logger.debug("Failed to link project", e);
|
|
1446
|
+
logger.error("An error occurred while linking the project.");
|
|
1447
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1448
|
+
projectInternalName: answer.linkProject
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
const command$4 = ({ command: command2, ctx }) => {
|
|
1453
|
+
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));
|
|
1454
|
+
};
|
|
1455
|
+
const link = {
|
|
1456
|
+
name: "link-project",
|
|
1457
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1458
|
+
action: action$2,
|
|
1459
|
+
command: command$4
|
|
1460
|
+
};
|
|
1461
|
+
const command$3 = ({ ctx }) => {
|
|
1190
1462
|
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1191
1463
|
"after",
|
|
1192
1464
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
@@ -1196,10 +1468,10 @@ const login = {
|
|
|
1196
1468
|
name: "login",
|
|
1197
1469
|
description: "Strapi Cloud Login",
|
|
1198
1470
|
action: loginAction,
|
|
1199
|
-
command: command$
|
|
1471
|
+
command: command$3
|
|
1200
1472
|
};
|
|
1201
1473
|
const openModule = import("open");
|
|
1202
|
-
const action = async (ctx) => {
|
|
1474
|
+
const action$1 = async (ctx) => {
|
|
1203
1475
|
const { logger } = ctx;
|
|
1204
1476
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1205
1477
|
const token = await retrieveToken();
|
|
@@ -1229,37 +1501,64 @@ const action = async (ctx) => {
|
|
|
1229
1501
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1230
1502
|
logger.debug(e);
|
|
1231
1503
|
}
|
|
1232
|
-
|
|
1233
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1234
|
-
} catch (e) {
|
|
1235
|
-
logger.debug("Failed to track logout event", e);
|
|
1236
|
-
}
|
|
1504
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1237
1505
|
};
|
|
1238
|
-
const command$
|
|
1239
|
-
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)(ctx));
|
|
1506
|
+
const command$2 = ({ ctx }) => {
|
|
1507
|
+
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$1)(ctx));
|
|
1240
1508
|
};
|
|
1241
1509
|
const logout = {
|
|
1242
1510
|
name: "logout",
|
|
1243
1511
|
description: "Strapi Cloud Logout",
|
|
1244
|
-
action,
|
|
1245
|
-
command: command$
|
|
1512
|
+
action: action$1,
|
|
1513
|
+
command: command$2
|
|
1246
1514
|
};
|
|
1247
|
-
const command = ({ ctx }) => {
|
|
1248
|
-
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$
|
|
1515
|
+
const command$1 = ({ ctx }) => {
|
|
1516
|
+
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$4)(ctx));
|
|
1249
1517
|
};
|
|
1250
1518
|
const createProject = {
|
|
1251
1519
|
name: "create-project",
|
|
1252
1520
|
description: "Create a new project",
|
|
1253
|
-
action: action$
|
|
1521
|
+
action: action$4,
|
|
1522
|
+
command: command$1
|
|
1523
|
+
};
|
|
1524
|
+
const action = async (ctx) => {
|
|
1525
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1526
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1527
|
+
const { logger } = ctx;
|
|
1528
|
+
if (!token) {
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1531
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1532
|
+
const spinner = logger.spinner("Fetching your projects...").start();
|
|
1533
|
+
try {
|
|
1534
|
+
const {
|
|
1535
|
+
data: { data: projectList }
|
|
1536
|
+
} = await cloudApiService.listProjects();
|
|
1537
|
+
spinner.succeed();
|
|
1538
|
+
logger.log(projectList);
|
|
1539
|
+
} catch (e) {
|
|
1540
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1541
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
const command = ({ command: command2, ctx }) => {
|
|
1545
|
+
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));
|
|
1546
|
+
};
|
|
1547
|
+
const listProjects = {
|
|
1548
|
+
name: "list-projects",
|
|
1549
|
+
description: "List Strapi Cloud projects",
|
|
1550
|
+
action,
|
|
1254
1551
|
command
|
|
1255
1552
|
};
|
|
1256
1553
|
const cli = {
|
|
1257
1554
|
deployProject,
|
|
1555
|
+
link,
|
|
1258
1556
|
login,
|
|
1259
1557
|
logout,
|
|
1260
|
-
createProject
|
|
1558
|
+
createProject,
|
|
1559
|
+
listProjects
|
|
1261
1560
|
};
|
|
1262
|
-
const cloudCommands = [deployProject, login, logout];
|
|
1561
|
+
const cloudCommands = [deployProject, link, login, logout, listProjects];
|
|
1263
1562
|
async function initCloudCLIConfig() {
|
|
1264
1563
|
const localConfig = await getLocalConfig();
|
|
1265
1564
|
if (!localConfig.deviceId) {
|