@strapi/cloud-cli 0.0.0-next.80375f19ecbd1a8f298515d011c3ddb5ed05f924 → 0.0.0-next.820adfc37c687bbcc4a213ae6929c541358b71e8
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/bin.js +2 -2
- package/dist/bin.js.map +1 -1
- package/dist/index.js +805 -165
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +802 -159
- 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 +5 -1
- package/dist/src/deploy-project/action.d.ts.map +1 -1
- package/dist/src/deploy-project/command.d.ts.map +1 -1
- package/dist/src/environment/command.d.ts +3 -0
- package/dist/src/environment/command.d.ts.map +1 -0
- package/dist/src/environment/link/action.d.ts +4 -0
- package/dist/src/environment/link/action.d.ts.map +1 -0
- package/dist/src/environment/link/command.d.ts +4 -0
- package/dist/src/environment/link/command.d.ts.map +1 -0
- package/dist/src/environment/link/index.d.ts +7 -0
- package/dist/src/environment/link/index.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 +4 -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 +64 -9
- package/dist/src/services/cli-api.d.ts.map +1 -1
- package/dist/src/services/strapi-info-save.d.ts +15 -2
- package/dist/src/services/strapi-info-save.d.ts.map +1 -1
- package/dist/src/services/token.d.ts.map +1 -1
- package/dist/src/types.d.ts +8 -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/get-local-config.d.ts +6 -0
- package/dist/src/utils/get-local-config.d.ts.map +1 -0
- package/dist/src/utils/helpers.d.ts.map +1 -1
- package/dist/src/utils/pkg.d.ts.map +1 -1
- package/package.json +12 -10
package/dist/index.js
CHANGED
|
@@ -24,31 +24,31 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
25
|
const crypto$1 = require("crypto");
|
|
26
26
|
const fse = require("fs-extra");
|
|
27
|
+
const inquirer = require("inquirer");
|
|
28
|
+
const boxen = require("boxen");
|
|
27
29
|
const path = require("path");
|
|
28
30
|
const chalk = require("chalk");
|
|
29
31
|
const axios = require("axios");
|
|
30
32
|
const crypto = require("node:crypto");
|
|
31
33
|
const utils = require("@strapi/utils");
|
|
32
|
-
const fs = require("fs");
|
|
33
34
|
const tar = require("tar");
|
|
34
35
|
const minimatch = require("minimatch");
|
|
35
|
-
const inquirer = require("inquirer");
|
|
36
36
|
const fp = require("lodash/fp");
|
|
37
37
|
const os = require("os");
|
|
38
38
|
const XDGAppPaths = require("xdg-app-paths");
|
|
39
|
+
const lodash = require("lodash");
|
|
39
40
|
const jwksClient = require("jwks-rsa");
|
|
40
41
|
const jwt = require("jsonwebtoken");
|
|
41
42
|
const stringify = require("fast-safe-stringify");
|
|
42
43
|
const ora = require("ora");
|
|
43
44
|
const cliProgress = require("cli-progress");
|
|
44
|
-
const EventSource = require("eventsource");
|
|
45
|
-
const fs$1 = require("fs/promises");
|
|
46
45
|
const pkgUp = require("pkg-up");
|
|
47
46
|
const yup = require("yup");
|
|
47
|
+
const EventSource = require("eventsource");
|
|
48
|
+
const commander = require("commander");
|
|
48
49
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
49
50
|
function _interopNamespace(e) {
|
|
50
|
-
if (e && e.__esModule)
|
|
51
|
-
return e;
|
|
51
|
+
if (e && e.__esModule) return e;
|
|
52
52
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
53
53
|
if (e) {
|
|
54
54
|
for (const k in e) {
|
|
@@ -65,14 +65,14 @@ function _interopNamespace(e) {
|
|
|
65
65
|
return Object.freeze(n);
|
|
66
66
|
}
|
|
67
67
|
const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
|
|
68
|
-
const
|
|
68
|
+
const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
|
|
69
|
+
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
70
|
+
const boxen__default = /* @__PURE__ */ _interopDefault(boxen);
|
|
69
71
|
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
70
72
|
const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
71
73
|
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
72
74
|
const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
|
|
73
|
-
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
74
75
|
const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
|
|
75
|
-
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
|
|
76
76
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
77
77
|
const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
|
|
78
78
|
const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
|
|
@@ -80,10 +80,9 @@ const jwt__default = /* @__PURE__ */ _interopDefault(jwt);
|
|
|
80
80
|
const stringify__default = /* @__PURE__ */ _interopDefault(stringify);
|
|
81
81
|
const ora__default = /* @__PURE__ */ _interopDefault(ora);
|
|
82
82
|
const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
|
|
83
|
-
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
84
|
-
const fs__default = /* @__PURE__ */ _interopDefault(fs$1);
|
|
85
83
|
const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
|
|
86
84
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
85
|
+
const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
|
|
87
86
|
const apiConfig = {
|
|
88
87
|
apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
|
|
89
88
|
dashboardBaseUrl: utils.env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
|
|
@@ -102,23 +101,6 @@ const IGNORED_PATTERNS = [
|
|
|
102
101
|
"**/.idea/**",
|
|
103
102
|
"**/.vscode/**"
|
|
104
103
|
];
|
|
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
104
|
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
123
105
|
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
124
106
|
const relativeFilePath = path__namespace.join(folderPath, file);
|
|
@@ -136,16 +118,34 @@ const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
|
136
118
|
}
|
|
137
119
|
return isIgnored;
|
|
138
120
|
};
|
|
139
|
-
const
|
|
121
|
+
const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
122
|
+
const arrayOfFiles = [];
|
|
123
|
+
const entries = await fse__namespace.readdir(path__namespace.join(dirPath, subfolder));
|
|
124
|
+
for (const entry of entries) {
|
|
125
|
+
const entryPathFromRoot = path__namespace.join(subfolder, entry);
|
|
126
|
+
const entryPath = path__namespace.relative(dirPath, entryPathFromRoot);
|
|
127
|
+
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
128
|
+
if (!isIgnored) {
|
|
129
|
+
if (fse__namespace.statSync(entryPath).isDirectory()) {
|
|
130
|
+
const subFiles = await getFiles(dirPath, ignorePatterns, entryPathFromRoot);
|
|
131
|
+
arrayOfFiles.push(...subFiles);
|
|
132
|
+
} else {
|
|
133
|
+
arrayOfFiles.push(entryPath);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return arrayOfFiles;
|
|
138
|
+
};
|
|
139
|
+
const readGitignore = async (folderPath) => {
|
|
140
140
|
const gitignorePath = path__namespace.resolve(folderPath, ".gitignore");
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const gitignoreContent =
|
|
141
|
+
const pathExist = await fse__namespace.pathExists(gitignorePath);
|
|
142
|
+
if (!pathExist) return [];
|
|
143
|
+
const gitignoreContent = await fse__namespace.readFile(gitignorePath, "utf8");
|
|
144
144
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
145
145
|
};
|
|
146
146
|
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
147
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
148
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
147
|
+
const ignorePatterns = await readGitignore(folderToCompress);
|
|
148
|
+
const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
|
|
149
149
|
return tar__namespace.c(
|
|
150
150
|
{
|
|
151
151
|
gzip: true,
|
|
@@ -158,7 +158,7 @@ const APP_FOLDER_NAME = "com.strapi.cli";
|
|
|
158
158
|
const CONFIG_FILENAME = "config.json";
|
|
159
159
|
async function checkDirectoryExists(directoryPath) {
|
|
160
160
|
try {
|
|
161
|
-
const fsStat = await
|
|
161
|
+
const fsStat = await fse__namespace.default.lstat(directoryPath);
|
|
162
162
|
return fsStat.isDirectory();
|
|
163
163
|
} catch (e) {
|
|
164
164
|
return false;
|
|
@@ -166,24 +166,24 @@ async function checkDirectoryExists(directoryPath) {
|
|
|
166
166
|
}
|
|
167
167
|
async function getTmpStoragePath() {
|
|
168
168
|
const storagePath = path__namespace.default.join(os__default.default.tmpdir(), APP_FOLDER_NAME);
|
|
169
|
-
await
|
|
169
|
+
await fse__namespace.default.ensureDir(storagePath);
|
|
170
170
|
return storagePath;
|
|
171
171
|
}
|
|
172
172
|
async function getConfigPath() {
|
|
173
173
|
const configDirs = XDGAppPaths__default.default(APP_FOLDER_NAME).configDirs();
|
|
174
174
|
const configPath = configDirs.find(checkDirectoryExists);
|
|
175
175
|
if (!configPath) {
|
|
176
|
-
await
|
|
176
|
+
await fse__namespace.default.ensureDir(configDirs[0]);
|
|
177
177
|
return configDirs[0];
|
|
178
178
|
}
|
|
179
179
|
return configPath;
|
|
180
180
|
}
|
|
181
|
-
async function getLocalConfig() {
|
|
181
|
+
async function getLocalConfig$1() {
|
|
182
182
|
const configPath = await getConfigPath();
|
|
183
183
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
184
|
-
await
|
|
184
|
+
await fse__namespace.default.ensureFile(configFilePath);
|
|
185
185
|
try {
|
|
186
|
-
return await
|
|
186
|
+
return await fse__namespace.default.readJSON(configFilePath, { encoding: "utf8", throws: true });
|
|
187
187
|
} catch (e) {
|
|
188
188
|
return {};
|
|
189
189
|
}
|
|
@@ -191,10 +191,10 @@ async function getLocalConfig() {
|
|
|
191
191
|
async function saveLocalConfig(data) {
|
|
192
192
|
const configPath = await getConfigPath();
|
|
193
193
|
const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
|
|
194
|
-
await
|
|
194
|
+
await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
195
195
|
}
|
|
196
196
|
const name = "@strapi/cloud-cli";
|
|
197
|
-
const version = "
|
|
197
|
+
const version = "5.5.0";
|
|
198
198
|
const description = "Commands to interact with the Strapi Cloud";
|
|
199
199
|
const keywords = [
|
|
200
200
|
"strapi",
|
|
@@ -235,17 +235,19 @@ const scripts = {
|
|
|
235
235
|
build: "pack-up build",
|
|
236
236
|
clean: "run -T rimraf ./dist",
|
|
237
237
|
lint: "run -T eslint .",
|
|
238
|
+
"test:unit": "run -T jest",
|
|
238
239
|
watch: "pack-up watch"
|
|
239
240
|
};
|
|
240
241
|
const dependencies = {
|
|
241
|
-
"@strapi/utils": "
|
|
242
|
-
axios: "1.
|
|
242
|
+
"@strapi/utils": "workspace:*",
|
|
243
|
+
axios: "1.7.4",
|
|
244
|
+
boxen: "5.1.2",
|
|
243
245
|
chalk: "4.1.2",
|
|
244
246
|
"cli-progress": "3.12.0",
|
|
245
247
|
commander: "8.3.0",
|
|
246
248
|
eventsource: "2.0.2",
|
|
247
249
|
"fast-safe-stringify": "2.1.1",
|
|
248
|
-
"fs-extra": "
|
|
250
|
+
"fs-extra": "11.2.0",
|
|
249
251
|
inquirer: "8.2.5",
|
|
250
252
|
jsonwebtoken: "9.0.0",
|
|
251
253
|
"jwks-rsa": "3.1.0",
|
|
@@ -254,22 +256,23 @@ const dependencies = {
|
|
|
254
256
|
open: "8.4.0",
|
|
255
257
|
ora: "5.4.1",
|
|
256
258
|
"pkg-up": "3.1.0",
|
|
257
|
-
tar: "6.1
|
|
259
|
+
tar: "6.2.1",
|
|
258
260
|
"xdg-app-paths": "8.3.0",
|
|
259
261
|
yup: "0.32.9"
|
|
260
262
|
};
|
|
261
263
|
const devDependencies = {
|
|
262
|
-
"@strapi/pack-up": "
|
|
264
|
+
"@strapi/pack-up": "5.0.2",
|
|
263
265
|
"@types/cli-progress": "3.11.5",
|
|
264
266
|
"@types/eventsource": "1.1.15",
|
|
265
267
|
"@types/lodash": "^4.14.191",
|
|
266
|
-
"eslint-config-custom": "
|
|
267
|
-
tsconfig: "
|
|
268
|
+
"eslint-config-custom": "workspace:*",
|
|
269
|
+
tsconfig: "workspace:*"
|
|
268
270
|
};
|
|
269
271
|
const engines = {
|
|
270
|
-
node: ">=18.0.0 <=
|
|
272
|
+
node: ">=18.0.0 <=22.x.x",
|
|
271
273
|
npm: ">=6.0.0"
|
|
272
274
|
};
|
|
275
|
+
const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
|
|
273
276
|
const packageJson = {
|
|
274
277
|
name,
|
|
275
278
|
version,
|
|
@@ -290,11 +293,12 @@ const packageJson = {
|
|
|
290
293
|
scripts,
|
|
291
294
|
dependencies,
|
|
292
295
|
devDependencies,
|
|
293
|
-
engines
|
|
296
|
+
engines,
|
|
297
|
+
gitHead
|
|
294
298
|
};
|
|
295
299
|
const VERSION = "v1";
|
|
296
300
|
async function cloudApiFactory({ logger }, token) {
|
|
297
|
-
const localConfig = await getLocalConfig();
|
|
301
|
+
const localConfig = await getLocalConfig$1();
|
|
298
302
|
const customHeaders = {
|
|
299
303
|
"x-device-id": localConfig.deviceId,
|
|
300
304
|
"x-app-version": packageJson.version,
|
|
@@ -317,7 +321,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
317
321
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
318
322
|
return axiosCloudAPI.post(
|
|
319
323
|
`/deploy/${project.name}`,
|
|
320
|
-
{ file:
|
|
324
|
+
{ file: fse__namespace.default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
321
325
|
{
|
|
322
326
|
headers: {
|
|
323
327
|
"Content-Type": "multipart/form-data"
|
|
@@ -360,8 +364,75 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
360
364
|
throw error;
|
|
361
365
|
}
|
|
362
366
|
},
|
|
363
|
-
listProjects() {
|
|
364
|
-
|
|
367
|
+
async listProjects() {
|
|
368
|
+
try {
|
|
369
|
+
const response = await axiosCloudAPI.get("/projects");
|
|
370
|
+
if (response.status !== 200) {
|
|
371
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
372
|
+
}
|
|
373
|
+
return response;
|
|
374
|
+
} catch (error) {
|
|
375
|
+
logger.debug(
|
|
376
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
377
|
+
);
|
|
378
|
+
throw error;
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
async listLinkProjects() {
|
|
382
|
+
try {
|
|
383
|
+
const response = await axiosCloudAPI.get("/projects-linkable");
|
|
384
|
+
if (response.status !== 200) {
|
|
385
|
+
throw new Error("Error fetching cloud projects from the server.");
|
|
386
|
+
}
|
|
387
|
+
return response;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
logger.debug(
|
|
390
|
+
"🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
|
|
391
|
+
);
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
async listEnvironments({ name: name2 }) {
|
|
396
|
+
try {
|
|
397
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
398
|
+
if (response.status !== 200) {
|
|
399
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
400
|
+
}
|
|
401
|
+
return response;
|
|
402
|
+
} catch (error) {
|
|
403
|
+
logger.debug(
|
|
404
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
405
|
+
);
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
410
|
+
try {
|
|
411
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
412
|
+
if (response.status !== 200) {
|
|
413
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
414
|
+
}
|
|
415
|
+
return response;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
logger.debug(
|
|
418
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
419
|
+
);
|
|
420
|
+
throw error;
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
async getProject({ name: name2 }) {
|
|
424
|
+
try {
|
|
425
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
426
|
+
if (response.status !== 200) {
|
|
427
|
+
throw new Error("Error fetching project's details.");
|
|
428
|
+
}
|
|
429
|
+
return response;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
logger.debug(
|
|
432
|
+
"🥲 Oops! There was a problem retrieving your project's details. Please try again."
|
|
433
|
+
);
|
|
434
|
+
throw error;
|
|
435
|
+
}
|
|
365
436
|
},
|
|
366
437
|
track(event, payload = {}) {
|
|
367
438
|
return axiosCloudAPI.post("/track", {
|
|
@@ -372,26 +443,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
372
443
|
};
|
|
373
444
|
}
|
|
374
445
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
446
|
+
const getFilePath = (directoryPath) => path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
375
447
|
async function save(data, { directoryPath } = {}) {
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
await fse__default.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
380
|
-
await fse__default.default.writeJson(pathToFile, storedData, { encoding: "utf8" });
|
|
448
|
+
const pathToFile = getFilePath(directoryPath);
|
|
449
|
+
await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
|
|
450
|
+
await fse__namespace.default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
381
451
|
}
|
|
382
452
|
async function retrieve({
|
|
383
453
|
directoryPath
|
|
384
454
|
} = {}) {
|
|
385
|
-
const pathToFile =
|
|
386
|
-
const pathExists = await
|
|
455
|
+
const pathToFile = getFilePath(directoryPath);
|
|
456
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
387
457
|
if (!pathExists) {
|
|
388
458
|
return {};
|
|
389
459
|
}
|
|
390
|
-
return
|
|
460
|
+
return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
|
|
461
|
+
}
|
|
462
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
463
|
+
const pathToFile = getFilePath(directoryPath);
|
|
464
|
+
const existingData = await retrieve({ directoryPath });
|
|
465
|
+
if (!existingData) {
|
|
466
|
+
throw new Error("No configuration data found to patch.");
|
|
467
|
+
}
|
|
468
|
+
const newData = lodash.merge(existingData, patchData);
|
|
469
|
+
await fse__namespace.default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
470
|
+
}
|
|
471
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
472
|
+
const pathToFile = getFilePath(directoryPath);
|
|
473
|
+
const pathExists = await fse__namespace.default.pathExists(pathToFile);
|
|
474
|
+
if (pathExists) {
|
|
475
|
+
await fse__namespace.default.remove(pathToFile);
|
|
476
|
+
}
|
|
391
477
|
}
|
|
392
478
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
393
479
|
__proto__: null,
|
|
394
480
|
LOCAL_SAVE_FILENAME,
|
|
481
|
+
deleteConfig,
|
|
482
|
+
patch,
|
|
395
483
|
retrieve,
|
|
396
484
|
save
|
|
397
485
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -399,7 +487,7 @@ let cliConfig;
|
|
|
399
487
|
async function tokenServiceFactory({ logger }) {
|
|
400
488
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
401
489
|
async function saveToken(str) {
|
|
402
|
-
const appConfig = await getLocalConfig();
|
|
490
|
+
const appConfig = await getLocalConfig$1();
|
|
403
491
|
if (!appConfig) {
|
|
404
492
|
logger.error("There was a problem saving your token. Please try again.");
|
|
405
493
|
return;
|
|
@@ -413,7 +501,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
413
501
|
}
|
|
414
502
|
}
|
|
415
503
|
async function retrieveToken() {
|
|
416
|
-
const appConfig = await getLocalConfig();
|
|
504
|
+
const appConfig = await getLocalConfig$1();
|
|
417
505
|
if (appConfig.token) {
|
|
418
506
|
if (await isTokenValid(appConfig.token)) {
|
|
419
507
|
return appConfig.token;
|
|
@@ -475,7 +563,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
475
563
|
}
|
|
476
564
|
}
|
|
477
565
|
async function eraseToken() {
|
|
478
|
-
const appConfig = await getLocalConfig();
|
|
566
|
+
const appConfig = await getLocalConfig$1();
|
|
479
567
|
if (!appConfig) {
|
|
480
568
|
return;
|
|
481
569
|
}
|
|
@@ -496,8 +584,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
496
584
|
logger.log(
|
|
497
585
|
token ? "Oops! Your token seems expired or invalid. Please login again." : "We couldn't find a valid token. You need to be logged in to use this feature."
|
|
498
586
|
);
|
|
499
|
-
if (!await loginAction2(ctx))
|
|
500
|
-
return null;
|
|
587
|
+
if (!await loginAction2(ctx)) return null;
|
|
501
588
|
token = await retrieveToken();
|
|
502
589
|
}
|
|
503
590
|
return token;
|
|
@@ -632,6 +719,56 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
632
719
|
local: strapiInfoSave,
|
|
633
720
|
tokenServiceFactory
|
|
634
721
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
722
|
+
yup__namespace.object({
|
|
723
|
+
name: yup__namespace.string().required(),
|
|
724
|
+
exports: yup__namespace.lazy(
|
|
725
|
+
(value) => yup__namespace.object(
|
|
726
|
+
typeof value === "object" ? Object.entries(value).reduce(
|
|
727
|
+
(acc, [key, value2]) => {
|
|
728
|
+
if (typeof value2 === "object") {
|
|
729
|
+
acc[key] = yup__namespace.object({
|
|
730
|
+
types: yup__namespace.string().optional(),
|
|
731
|
+
source: yup__namespace.string().required(),
|
|
732
|
+
module: yup__namespace.string().optional(),
|
|
733
|
+
import: yup__namespace.string().required(),
|
|
734
|
+
require: yup__namespace.string().required(),
|
|
735
|
+
default: yup__namespace.string().required()
|
|
736
|
+
}).noUnknown(true);
|
|
737
|
+
} else {
|
|
738
|
+
acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
|
|
739
|
+
}
|
|
740
|
+
return acc;
|
|
741
|
+
},
|
|
742
|
+
{}
|
|
743
|
+
) : void 0
|
|
744
|
+
).optional()
|
|
745
|
+
)
|
|
746
|
+
});
|
|
747
|
+
const loadPkg = async ({ cwd, logger }) => {
|
|
748
|
+
const pkgPath = await pkgUp__default.default({ cwd });
|
|
749
|
+
if (!pkgPath) {
|
|
750
|
+
throw new Error("Could not find a package.json in the current directory");
|
|
751
|
+
}
|
|
752
|
+
const buffer = await fse__namespace.readFile(pkgPath);
|
|
753
|
+
const pkg = JSON.parse(buffer.toString());
|
|
754
|
+
logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
|
|
755
|
+
return pkg;
|
|
756
|
+
};
|
|
757
|
+
async function getProjectNameFromPackageJson(ctx) {
|
|
758
|
+
try {
|
|
759
|
+
const packageJson2 = await loadPkg(ctx);
|
|
760
|
+
return packageJson2.name || "my-strapi-project";
|
|
761
|
+
} catch (e) {
|
|
762
|
+
return "my-strapi-project";
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
|
|
766
|
+
try {
|
|
767
|
+
await cloudApiService.track(eventName, eventData);
|
|
768
|
+
} catch (e) {
|
|
769
|
+
ctx.logger.debug(`Failed to track ${eventName}`, e);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
635
772
|
const openModule$1 = import("open");
|
|
636
773
|
async function promptLogin(ctx) {
|
|
637
774
|
const response = await inquirer__default.default.prompt([
|
|
@@ -652,13 +789,6 @@ async function loginAction(ctx) {
|
|
|
652
789
|
const tokenService = await tokenServiceFactory(ctx);
|
|
653
790
|
const existingToken = await tokenService.retrieveToken();
|
|
654
791
|
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
792
|
if (existingToken) {
|
|
663
793
|
const isTokenValid = await tokenService.isTokenValid(existingToken);
|
|
664
794
|
if (isTokenValid) {
|
|
@@ -690,11 +820,7 @@ async function loginAction(ctx) {
|
|
|
690
820
|
logger.debug(e);
|
|
691
821
|
return false;
|
|
692
822
|
}
|
|
693
|
-
|
|
694
|
-
await cloudApiService.track("willLoginAttempt", {});
|
|
695
|
-
} catch (e) {
|
|
696
|
-
logger.debug("Failed to track login attempt", e);
|
|
697
|
-
}
|
|
823
|
+
await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
|
|
698
824
|
logger.debug("🔐 Creating device authentication request...", {
|
|
699
825
|
client_id: cliConfig2.clientId,
|
|
700
826
|
scope: cliConfig2.scope,
|
|
@@ -774,13 +900,13 @@ async function loginAction(ctx) {
|
|
|
774
900
|
"There seems to be a problem with your login information. Please try logging in again."
|
|
775
901
|
);
|
|
776
902
|
spinnerFail();
|
|
777
|
-
await
|
|
903
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
778
904
|
return false;
|
|
779
905
|
}
|
|
780
906
|
if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
|
|
781
907
|
logger.debug(e);
|
|
782
908
|
spinnerFail();
|
|
783
|
-
await
|
|
909
|
+
await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
|
|
784
910
|
return false;
|
|
785
911
|
}
|
|
786
912
|
await new Promise((resolve) => {
|
|
@@ -794,15 +920,50 @@ async function loginAction(ctx) {
|
|
|
794
920
|
"To access your dashboard, please copy and paste the following URL into your web browser:"
|
|
795
921
|
);
|
|
796
922
|
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
|
-
}
|
|
923
|
+
await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
|
|
802
924
|
};
|
|
803
925
|
await authenticate();
|
|
804
926
|
return isAuthenticated;
|
|
805
927
|
}
|
|
928
|
+
function questionDefaultValuesMapper(questionsMap) {
|
|
929
|
+
return (questions) => {
|
|
930
|
+
return questions.map((question) => {
|
|
931
|
+
const questionName = question.name;
|
|
932
|
+
if (questionName in questionsMap) {
|
|
933
|
+
const questionDefault = questionsMap[questionName];
|
|
934
|
+
if (typeof questionDefault === "function") {
|
|
935
|
+
return {
|
|
936
|
+
...question,
|
|
937
|
+
default: questionDefault(question)
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
return {
|
|
941
|
+
...question,
|
|
942
|
+
default: questionDefault
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
return question;
|
|
946
|
+
});
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function getDefaultsFromQuestions(questions) {
|
|
950
|
+
return questions.reduce((acc, question) => {
|
|
951
|
+
if (question.default && question.name) {
|
|
952
|
+
return { ...acc, [question.name]: question.default };
|
|
953
|
+
}
|
|
954
|
+
return acc;
|
|
955
|
+
}, {});
|
|
956
|
+
}
|
|
957
|
+
function getProjectNodeVersionDefault(question) {
|
|
958
|
+
const currentNodeVersion = process.versions.node.split(".")[0];
|
|
959
|
+
if (question.type === "list" && Array.isArray(question.choices)) {
|
|
960
|
+
const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
|
|
961
|
+
if (choice) {
|
|
962
|
+
return choice.value;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return question.default;
|
|
966
|
+
}
|
|
806
967
|
async function handleError(ctx, error) {
|
|
807
968
|
const { logger } = ctx;
|
|
808
969
|
logger.debug(error);
|
|
@@ -847,7 +1008,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
847
1008
|
throw e;
|
|
848
1009
|
}
|
|
849
1010
|
}
|
|
850
|
-
const action$
|
|
1011
|
+
const action$6 = async (ctx) => {
|
|
851
1012
|
const { logger } = ctx;
|
|
852
1013
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
853
1014
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -856,7 +1017,16 @@ const action$2 = async (ctx) => {
|
|
|
856
1017
|
}
|
|
857
1018
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
858
1019
|
const { data: config } = await cloudApi.config();
|
|
859
|
-
const
|
|
1020
|
+
const projectName = await getProjectNameFromPackageJson(ctx);
|
|
1021
|
+
const defaultAnswersMapper = questionDefaultValuesMapper({
|
|
1022
|
+
name: projectName,
|
|
1023
|
+
nodeVersion: getProjectNodeVersionDefault
|
|
1024
|
+
});
|
|
1025
|
+
const questions = defaultAnswersMapper(config.projectCreation.questions);
|
|
1026
|
+
const defaultValues = {
|
|
1027
|
+
...config.projectCreation.defaults,
|
|
1028
|
+
...getDefaultsFromQuestions(questions)
|
|
1029
|
+
};
|
|
860
1030
|
const projectAnswersDefaulted = fp.defaults(defaultValues);
|
|
861
1031
|
const projectAnswers = await inquirer__default.default.prompt(questions);
|
|
862
1032
|
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
@@ -905,38 +1075,6 @@ function notificationServiceFactory({ logger }) {
|
|
|
905
1075
|
};
|
|
906
1076
|
};
|
|
907
1077
|
}
|
|
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
1078
|
const buildLogsServiceFactory = ({ logger }) => {
|
|
941
1079
|
return async (url, token, cliConfig2) => {
|
|
942
1080
|
const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
|
|
@@ -990,6 +1128,7 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
990
1128
|
if (retries > MAX_RETRIES) {
|
|
991
1129
|
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
992
1130
|
es.close();
|
|
1131
|
+
clearExistingTimeout();
|
|
993
1132
|
reject(new Error("Max retries reached"));
|
|
994
1133
|
}
|
|
995
1134
|
};
|
|
@@ -998,6 +1137,29 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
998
1137
|
});
|
|
999
1138
|
};
|
|
1000
1139
|
};
|
|
1140
|
+
const boxenOptions = {
|
|
1141
|
+
padding: 1,
|
|
1142
|
+
margin: 1,
|
|
1143
|
+
align: "center",
|
|
1144
|
+
borderColor: "yellow",
|
|
1145
|
+
borderStyle: "round"
|
|
1146
|
+
};
|
|
1147
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1148
|
+
async function promptForEnvironment(environments) {
|
|
1149
|
+
const choices = environments.map((env) => ({ name: env, value: env }));
|
|
1150
|
+
const { selectedEnvironment } = await inquirer__default.default.prompt([
|
|
1151
|
+
{
|
|
1152
|
+
type: "list",
|
|
1153
|
+
name: "selectedEnvironment",
|
|
1154
|
+
message: "Select the environment to deploy:",
|
|
1155
|
+
choices: [...choices, { name: chalk__default.default.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1156
|
+
}
|
|
1157
|
+
]);
|
|
1158
|
+
if (selectedEnvironment === null) {
|
|
1159
|
+
process.exit(1);
|
|
1160
|
+
}
|
|
1161
|
+
return selectedEnvironment;
|
|
1162
|
+
}
|
|
1001
1163
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1002
1164
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1003
1165
|
try {
|
|
@@ -1032,13 +1194,13 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1032
1194
|
process.exit(1);
|
|
1033
1195
|
}
|
|
1034
1196
|
const tarFilePath = path__namespace.default.resolve(storagePath, compressedFilename);
|
|
1035
|
-
const fileStats = await
|
|
1197
|
+
const fileStats = await fse__namespace.default.stat(tarFilePath);
|
|
1036
1198
|
if (fileStats.size > maxProjectFileSize) {
|
|
1037
1199
|
ctx.logger.log(
|
|
1038
1200
|
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
1039
1201
|
);
|
|
1040
1202
|
try {
|
|
1041
|
-
await
|
|
1203
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
1042
1204
|
} catch (e) {
|
|
1043
1205
|
ctx.logger.log("Unable to remove file: ", tarFilePath);
|
|
1044
1206
|
ctx.logger.debug(e);
|
|
@@ -1064,20 +1226,10 @@ async function upload(ctx, project, token, maxProjectFileSize) {
|
|
|
1064
1226
|
return data.build_id;
|
|
1065
1227
|
} catch (e) {
|
|
1066
1228
|
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
|
-
}
|
|
1229
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1078
1230
|
ctx.logger.debug(e);
|
|
1079
1231
|
} finally {
|
|
1080
|
-
await
|
|
1232
|
+
await fse__namespace.default.remove(tarFilePath);
|
|
1081
1233
|
}
|
|
1082
1234
|
process.exit(0);
|
|
1083
1235
|
} catch (e) {
|
|
@@ -1090,7 +1242,7 @@ async function getProject(ctx) {
|
|
|
1090
1242
|
const { project } = await retrieve();
|
|
1091
1243
|
if (!project) {
|
|
1092
1244
|
try {
|
|
1093
|
-
return await action$
|
|
1245
|
+
return await action$6(ctx);
|
|
1094
1246
|
} catch (e) {
|
|
1095
1247
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1096
1248
|
ctx.logger.debug(e);
|
|
@@ -1099,7 +1251,45 @@ async function getProject(ctx) {
|
|
|
1099
1251
|
}
|
|
1100
1252
|
return project;
|
|
1101
1253
|
}
|
|
1102
|
-
|
|
1254
|
+
async function getConfig({
|
|
1255
|
+
ctx,
|
|
1256
|
+
cloudApiService
|
|
1257
|
+
}) {
|
|
1258
|
+
try {
|
|
1259
|
+
const { data: cliConfig2 } = await cloudApiService.config();
|
|
1260
|
+
return cliConfig2;
|
|
1261
|
+
} catch (e) {
|
|
1262
|
+
ctx.logger.debug("Failed to get cli config", e);
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1267
|
+
if (!environments.includes(environment)) {
|
|
1268
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1269
|
+
process.exit(1);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1273
|
+
if (opts.env) {
|
|
1274
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1275
|
+
return opts.env;
|
|
1276
|
+
}
|
|
1277
|
+
if (project.targetEnvironment) {
|
|
1278
|
+
return project.targetEnvironment;
|
|
1279
|
+
}
|
|
1280
|
+
if (environments.length > 1) {
|
|
1281
|
+
return promptForEnvironment(environments);
|
|
1282
|
+
}
|
|
1283
|
+
return environments[0];
|
|
1284
|
+
}
|
|
1285
|
+
function hasPendingOrLiveDeployment(environments, targetEnvironment) {
|
|
1286
|
+
const environment = environments.find((env) => env.name === targetEnvironment);
|
|
1287
|
+
if (!environment) {
|
|
1288
|
+
throw new Error(`Environment details ${targetEnvironment} not found.`);
|
|
1289
|
+
}
|
|
1290
|
+
return environment.hasPendingDeployment || environment.hasLiveDeployment || false;
|
|
1291
|
+
}
|
|
1292
|
+
const action$5 = async (ctx, opts) => {
|
|
1103
1293
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1104
1294
|
const token = await getValidToken(ctx, promptLogin);
|
|
1105
1295
|
if (!token) {
|
|
@@ -1109,15 +1299,57 @@ const action$1 = async (ctx) => {
|
|
|
1109
1299
|
if (!project) {
|
|
1110
1300
|
return;
|
|
1111
1301
|
}
|
|
1112
|
-
const cloudApiService = await cloudApiFactory(ctx);
|
|
1302
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1303
|
+
let projectData;
|
|
1304
|
+
let environments;
|
|
1305
|
+
let environmentsDetails;
|
|
1113
1306
|
try {
|
|
1114
|
-
|
|
1307
|
+
const {
|
|
1308
|
+
data: { data, metadata }
|
|
1309
|
+
} = await cloudApiService.getProject({ name: project.name });
|
|
1310
|
+
projectData = data;
|
|
1311
|
+
environments = projectData.environments;
|
|
1312
|
+
environmentsDetails = projectData.environmentsDetails;
|
|
1313
|
+
const isProjectSuspended = projectData.suspendedAt;
|
|
1314
|
+
if (isProjectSuspended) {
|
|
1315
|
+
ctx.logger.log(
|
|
1316
|
+
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
1317
|
+
);
|
|
1318
|
+
ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1115
1321
|
} catch (e) {
|
|
1116
|
-
|
|
1322
|
+
if (e instanceof axios.AxiosError && e.response?.data) {
|
|
1323
|
+
if (e.response.status === 404) {
|
|
1324
|
+
ctx.logger.warn(
|
|
1325
|
+
`The project associated with this folder does not exist in Strapi Cloud.
|
|
1326
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1327
|
+
"link"
|
|
1328
|
+
)} command before deploying.`
|
|
1329
|
+
);
|
|
1330
|
+
} else {
|
|
1331
|
+
ctx.logger.error(e.response.data);
|
|
1332
|
+
}
|
|
1333
|
+
} else {
|
|
1334
|
+
ctx.logger.error(
|
|
1335
|
+
"An error occurred while retrieving the project's information. Please try again later."
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
ctx.logger.debug(e);
|
|
1339
|
+
return;
|
|
1117
1340
|
}
|
|
1341
|
+
await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
|
|
1342
|
+
projectInternalName: project.name
|
|
1343
|
+
});
|
|
1118
1344
|
const notificationService = notificationServiceFactory(ctx);
|
|
1119
1345
|
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
1120
|
-
const
|
|
1346
|
+
const cliConfig2 = await getConfig({ ctx, cloudApiService });
|
|
1347
|
+
if (!cliConfig2) {
|
|
1348
|
+
ctx.logger.error(
|
|
1349
|
+
"An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
|
|
1350
|
+
);
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1121
1353
|
let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
|
|
1122
1354
|
if (Number.isNaN(maxSize)) {
|
|
1123
1355
|
ctx.logger.debug(
|
|
@@ -1125,11 +1357,34 @@ const action$1 = async (ctx) => {
|
|
|
1125
1357
|
);
|
|
1126
1358
|
maxSize = 1e8;
|
|
1127
1359
|
}
|
|
1360
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1361
|
+
if (!opts.force) {
|
|
1362
|
+
const shouldDisplayWarning = hasPendingOrLiveDeployment(
|
|
1363
|
+
environmentsDetails,
|
|
1364
|
+
project.targetEnvironment
|
|
1365
|
+
);
|
|
1366
|
+
if (shouldDisplayWarning) {
|
|
1367
|
+
ctx.logger.log(boxen__default.default(cliConfig2.projectDeployment.confirmationText, boxenOptions));
|
|
1368
|
+
const { confirm } = await inquirer__default.default.prompt([
|
|
1369
|
+
{
|
|
1370
|
+
type: "confirm",
|
|
1371
|
+
name: "confirm",
|
|
1372
|
+
message: `Do you want to proceed with deployment to ${chalk__default.default.cyan(projectData.displayName)} on ${chalk__default.default.cyan(project.targetEnvironment)} environment?`
|
|
1373
|
+
}
|
|
1374
|
+
]);
|
|
1375
|
+
if (!confirm) {
|
|
1376
|
+
process.exit(1);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1128
1380
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1129
1381
|
if (!buildId) {
|
|
1130
1382
|
return;
|
|
1131
1383
|
}
|
|
1132
1384
|
try {
|
|
1385
|
+
ctx.logger.log(
|
|
1386
|
+
`🚀 Deploying project to ${chalk__default.default.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1387
|
+
);
|
|
1133
1388
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1134
1389
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1135
1390
|
ctx.logger.log(
|
|
@@ -1139,10 +1394,11 @@ const action$1 = async (ctx) => {
|
|
|
1139
1394
|
chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
|
|
1140
1395
|
);
|
|
1141
1396
|
} catch (e) {
|
|
1397
|
+
ctx.logger.debug(e);
|
|
1142
1398
|
if (e instanceof Error) {
|
|
1143
1399
|
ctx.logger.error(e.message);
|
|
1144
1400
|
} else {
|
|
1145
|
-
|
|
1401
|
+
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1146
1402
|
}
|
|
1147
1403
|
}
|
|
1148
1404
|
};
|
|
@@ -1173,17 +1429,179 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1173
1429
|
process.exit(1);
|
|
1174
1430
|
});
|
|
1175
1431
|
};
|
|
1176
|
-
const command$
|
|
1177
|
-
|
|
1432
|
+
const command$7 = ({ ctx }) => {
|
|
1433
|
+
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").option("-f, --force", "Skip confirmation to deploy").option("-e, --env <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$5)(ctx, opts));
|
|
1178
1434
|
};
|
|
1179
1435
|
const deployProject = {
|
|
1180
1436
|
name: "deploy-project",
|
|
1181
1437
|
description: "Deploy a Strapi Cloud project",
|
|
1182
|
-
action: action$
|
|
1183
|
-
command: command$
|
|
1438
|
+
action: action$5,
|
|
1439
|
+
command: command$7
|
|
1184
1440
|
};
|
|
1185
|
-
|
|
1186
|
-
|
|
1441
|
+
async function getLocalConfig(ctx) {
|
|
1442
|
+
try {
|
|
1443
|
+
return await retrieve();
|
|
1444
|
+
} catch (e) {
|
|
1445
|
+
ctx.logger.debug("Failed to get project config", e);
|
|
1446
|
+
ctx.logger.error("An error occurred while retrieving config data from your local project.");
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
async function getLocalProject(ctx) {
|
|
1451
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1452
|
+
if (!localConfig || !localConfig.project) {
|
|
1453
|
+
ctx.logger.warn(
|
|
1454
|
+
`
|
|
1455
|
+
We couldn't find a valid local project config.
|
|
1456
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1457
|
+
"link"
|
|
1458
|
+
)} command.`
|
|
1459
|
+
);
|
|
1460
|
+
process.exit(1);
|
|
1461
|
+
}
|
|
1462
|
+
return localConfig.project;
|
|
1463
|
+
}
|
|
1464
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1465
|
+
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1466
|
+
if (existingConfig && existingConfig.project) {
|
|
1467
|
+
const { shouldRelink } = await inquirer__default.default.prompt([
|
|
1468
|
+
{
|
|
1469
|
+
type: "confirm",
|
|
1470
|
+
name: "shouldRelink",
|
|
1471
|
+
message: `A project named ${chalk__default.default.cyan(
|
|
1472
|
+
existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
|
|
1473
|
+
)} is already linked to this local folder. Do you want to update the link?`,
|
|
1474
|
+
default: false
|
|
1475
|
+
}
|
|
1476
|
+
]);
|
|
1477
|
+
if (!shouldRelink) {
|
|
1478
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1479
|
+
currentProjectName: existingConfig.project?.name
|
|
1480
|
+
});
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return true;
|
|
1485
|
+
}
|
|
1486
|
+
async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
1487
|
+
const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
|
|
1488
|
+
try {
|
|
1489
|
+
const {
|
|
1490
|
+
data: { data: projectList }
|
|
1491
|
+
} = await cloudApiService.listLinkProjects();
|
|
1492
|
+
spinner.succeed();
|
|
1493
|
+
if (!Array.isArray(projectList)) {
|
|
1494
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
const projects = projectList.filter(
|
|
1498
|
+
(project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
|
|
1499
|
+
).map((project) => {
|
|
1500
|
+
return {
|
|
1501
|
+
name: project.displayName,
|
|
1502
|
+
value: { name: project.name, displayName: project.displayName }
|
|
1503
|
+
};
|
|
1504
|
+
});
|
|
1505
|
+
if (projects.length === 0) {
|
|
1506
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1507
|
+
return null;
|
|
1508
|
+
}
|
|
1509
|
+
return projects;
|
|
1510
|
+
} catch (e) {
|
|
1511
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1512
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1513
|
+
return null;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
async function getUserSelection(ctx, projects) {
|
|
1517
|
+
const { logger } = ctx;
|
|
1518
|
+
try {
|
|
1519
|
+
const answer = await inquirer__default.default.prompt([
|
|
1520
|
+
{
|
|
1521
|
+
type: "list",
|
|
1522
|
+
name: "linkProject",
|
|
1523
|
+
message: "Which project do you want to link?",
|
|
1524
|
+
choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1525
|
+
}
|
|
1526
|
+
]);
|
|
1527
|
+
if (!answer.linkProject) {
|
|
1528
|
+
return null;
|
|
1529
|
+
}
|
|
1530
|
+
return answer;
|
|
1531
|
+
} catch (e) {
|
|
1532
|
+
logger.debug("Failed to get user input", e);
|
|
1533
|
+
logger.error("An error occurred while trying to get your input.");
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
const action$4 = async (ctx) => {
|
|
1538
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1539
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1540
|
+
const { logger } = ctx;
|
|
1541
|
+
if (!token) {
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1545
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1546
|
+
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1547
|
+
if (!shouldRelink) {
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
await trackEvent(ctx, cloudApiService, "willLinkProject", {});
|
|
1551
|
+
const projects = await getProjectsList(
|
|
1552
|
+
ctx,
|
|
1553
|
+
cloudApiService,
|
|
1554
|
+
existingConfig
|
|
1555
|
+
);
|
|
1556
|
+
if (!projects) {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const answer = await getUserSelection(ctx, projects);
|
|
1560
|
+
if (!answer) {
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
try {
|
|
1564
|
+
const { confirmAction } = await inquirer__default.default.prompt([
|
|
1565
|
+
{
|
|
1566
|
+
type: "confirm",
|
|
1567
|
+
name: "confirmAction",
|
|
1568
|
+
message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
|
|
1569
|
+
default: false
|
|
1570
|
+
}
|
|
1571
|
+
]);
|
|
1572
|
+
if (!confirmAction) {
|
|
1573
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1574
|
+
cancelledProjectName: answer.linkProject.name,
|
|
1575
|
+
currentProjectName: existingConfig ? existingConfig.project?.name : null
|
|
1576
|
+
});
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
await save({ project: answer.linkProject });
|
|
1580
|
+
logger.log(
|
|
1581
|
+
` You have successfully linked your project to ${chalk__default.default.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1582
|
+
);
|
|
1583
|
+
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1584
|
+
projectInternalName: answer.linkProject
|
|
1585
|
+
});
|
|
1586
|
+
} catch (e) {
|
|
1587
|
+
logger.debug("Failed to link project", e);
|
|
1588
|
+
logger.error("An error occurred while linking the project.");
|
|
1589
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
|
|
1590
|
+
projectInternalName: answer.linkProject
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1595
|
+
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$4)(ctx));
|
|
1596
|
+
};
|
|
1597
|
+
const link = {
|
|
1598
|
+
name: "link-project",
|
|
1599
|
+
description: "Link a local directory to a Strapi Cloud project",
|
|
1600
|
+
action: action$4,
|
|
1601
|
+
command: command$6
|
|
1602
|
+
};
|
|
1603
|
+
const command$5 = ({ ctx }) => {
|
|
1604
|
+
return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1187
1605
|
"after",
|
|
1188
1606
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
1189
1607
|
).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
|
|
@@ -1192,10 +1610,10 @@ const login = {
|
|
|
1192
1610
|
name: "login",
|
|
1193
1611
|
description: "Strapi Cloud Login",
|
|
1194
1612
|
action: loginAction,
|
|
1195
|
-
command: command$
|
|
1613
|
+
command: command$5
|
|
1196
1614
|
};
|
|
1197
1615
|
const openModule = import("open");
|
|
1198
|
-
const action = async (ctx) => {
|
|
1616
|
+
const action$3 = async (ctx) => {
|
|
1199
1617
|
const { logger } = ctx;
|
|
1200
1618
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1201
1619
|
const token = await retrieveToken();
|
|
@@ -1225,39 +1643,258 @@ const action = async (ctx) => {
|
|
|
1225
1643
|
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
1226
1644
|
logger.debug(e);
|
|
1227
1645
|
}
|
|
1228
|
-
|
|
1229
|
-
await cloudApiService.track("didLogout", { loginMethod: "cli" });
|
|
1230
|
-
} catch (e) {
|
|
1231
|
-
logger.debug("Failed to track logout event", e);
|
|
1232
|
-
}
|
|
1646
|
+
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1233
1647
|
};
|
|
1234
|
-
const command$
|
|
1235
|
-
|
|
1648
|
+
const command$4 = ({ ctx }) => {
|
|
1649
|
+
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$3)(ctx));
|
|
1236
1650
|
};
|
|
1237
1651
|
const logout = {
|
|
1238
1652
|
name: "logout",
|
|
1239
1653
|
description: "Strapi Cloud Logout",
|
|
1240
|
-
action,
|
|
1241
|
-
command: command$
|
|
1654
|
+
action: action$3,
|
|
1655
|
+
command: command$4
|
|
1242
1656
|
};
|
|
1243
|
-
const command = ({
|
|
1244
|
-
|
|
1657
|
+
const command$3 = ({ ctx }) => {
|
|
1658
|
+
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$6)(ctx));
|
|
1245
1659
|
};
|
|
1246
1660
|
const createProject = {
|
|
1247
1661
|
name: "create-project",
|
|
1248
1662
|
description: "Create a new project",
|
|
1663
|
+
action: action$6,
|
|
1664
|
+
command: command$3
|
|
1665
|
+
};
|
|
1666
|
+
const action$2 = async (ctx) => {
|
|
1667
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1668
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1669
|
+
const { logger } = ctx;
|
|
1670
|
+
if (!token) {
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1674
|
+
const spinner = logger.spinner("Fetching your projects...").start();
|
|
1675
|
+
try {
|
|
1676
|
+
const {
|
|
1677
|
+
data: { data: projectList }
|
|
1678
|
+
} = await cloudApiService.listProjects();
|
|
1679
|
+
spinner.succeed();
|
|
1680
|
+
logger.log(projectList);
|
|
1681
|
+
} catch (e) {
|
|
1682
|
+
ctx.logger.debug("Failed to list projects", e);
|
|
1683
|
+
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1687
|
+
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$2)(ctx));
|
|
1688
|
+
};
|
|
1689
|
+
const listProjects = {
|
|
1690
|
+
name: "list-projects",
|
|
1691
|
+
description: "List Strapi Cloud projects",
|
|
1249
1692
|
action: action$2,
|
|
1693
|
+
command: command$2
|
|
1694
|
+
};
|
|
1695
|
+
const action$1 = async (ctx) => {
|
|
1696
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1697
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1698
|
+
const { logger } = ctx;
|
|
1699
|
+
if (!token) {
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
const project = await getLocalProject(ctx);
|
|
1703
|
+
if (!project) {
|
|
1704
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1708
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1709
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1710
|
+
projectInternalName: project.name
|
|
1711
|
+
});
|
|
1712
|
+
try {
|
|
1713
|
+
const {
|
|
1714
|
+
data: { data: environmentsList }
|
|
1715
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1716
|
+
spinner.succeed();
|
|
1717
|
+
logger.log(environmentsList);
|
|
1718
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1719
|
+
projectInternalName: project.name
|
|
1720
|
+
});
|
|
1721
|
+
} catch (e) {
|
|
1722
|
+
if (e.response && e.response.status === 404) {
|
|
1723
|
+
spinner.succeed();
|
|
1724
|
+
logger.warn(
|
|
1725
|
+
`
|
|
1726
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1727
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1728
|
+
"link"
|
|
1729
|
+
)} command`
|
|
1730
|
+
);
|
|
1731
|
+
} else {
|
|
1732
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1733
|
+
logger.debug("Failed to list environments", e);
|
|
1734
|
+
}
|
|
1735
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1736
|
+
projectInternalName: project.name
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1741
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1742
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1743
|
+
return cloud;
|
|
1744
|
+
}
|
|
1745
|
+
let environmentCmd = null;
|
|
1746
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1747
|
+
if (!environmentCmd) {
|
|
1748
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1749
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1750
|
+
}
|
|
1751
|
+
return environmentCmd;
|
|
1752
|
+
};
|
|
1753
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1754
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1755
|
+
environmentCmd2.command("list").description("List Strapi Cloud project environments").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("list", action$1)(ctx));
|
|
1756
|
+
};
|
|
1757
|
+
const listEnvironments = {
|
|
1758
|
+
name: "list-environments",
|
|
1759
|
+
description: "List Strapi Cloud environments",
|
|
1760
|
+
action: action$1,
|
|
1761
|
+
command: command$1
|
|
1762
|
+
};
|
|
1763
|
+
const QUIT_OPTION = "Quit";
|
|
1764
|
+
const action = async (ctx) => {
|
|
1765
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1766
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1767
|
+
const { logger } = ctx;
|
|
1768
|
+
if (!token) {
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
const project = await getLocalProject(ctx);
|
|
1772
|
+
if (!project) {
|
|
1773
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1777
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1778
|
+
if (!environments) {
|
|
1779
|
+
logger.debug(`Fetching environments failed.`);
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
if (environments.length === 0) {
|
|
1783
|
+
logger.log(
|
|
1784
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1785
|
+
);
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1789
|
+
if (!answer) {
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1793
|
+
projectName: project.name,
|
|
1794
|
+
environmentName: answer.targetEnvironment
|
|
1795
|
+
});
|
|
1796
|
+
try {
|
|
1797
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1798
|
+
} catch (e) {
|
|
1799
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1800
|
+
projectName: project.name,
|
|
1801
|
+
environmentName: answer.targetEnvironment
|
|
1802
|
+
});
|
|
1803
|
+
logger.debug("Failed to link environment", e);
|
|
1804
|
+
logger.error(
|
|
1805
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1806
|
+
);
|
|
1807
|
+
process.exit(1);
|
|
1808
|
+
}
|
|
1809
|
+
logger.log(
|
|
1810
|
+
` You have successfully linked your project to ${chalk__default.default.cyan(answer.targetEnvironment)}, on ${chalk__default.default.cyan(project.displayName)}. You are now able to deploy your project.`
|
|
1811
|
+
);
|
|
1812
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1813
|
+
projectName: project.name,
|
|
1814
|
+
environmentName: answer.targetEnvironment
|
|
1815
|
+
});
|
|
1816
|
+
};
|
|
1817
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1818
|
+
const { logger } = ctx;
|
|
1819
|
+
try {
|
|
1820
|
+
const answer = await inquirer__default.default.prompt([
|
|
1821
|
+
{
|
|
1822
|
+
type: "list",
|
|
1823
|
+
name: "targetEnvironment",
|
|
1824
|
+
message: "Which environment do you want to link?",
|
|
1825
|
+
choices: [...environments, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1826
|
+
}
|
|
1827
|
+
]);
|
|
1828
|
+
if (!answer.targetEnvironment) {
|
|
1829
|
+
return null;
|
|
1830
|
+
}
|
|
1831
|
+
return answer;
|
|
1832
|
+
} catch (e) {
|
|
1833
|
+
logger.debug("Failed to get user input", e);
|
|
1834
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1835
|
+
return null;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1839
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1840
|
+
try {
|
|
1841
|
+
const {
|
|
1842
|
+
data: { data: environmentsList }
|
|
1843
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1844
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1845
|
+
throw new Error("Environments not found in server response");
|
|
1846
|
+
}
|
|
1847
|
+
spinner.succeed();
|
|
1848
|
+
return environmentsList.filter(
|
|
1849
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1850
|
+
);
|
|
1851
|
+
} catch (e) {
|
|
1852
|
+
if (e.response && e.response.status === 404) {
|
|
1853
|
+
spinner.succeed();
|
|
1854
|
+
ctx.logger.warn(
|
|
1855
|
+
`
|
|
1856
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1857
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
|
|
1858
|
+
"link"
|
|
1859
|
+
)} command.`
|
|
1860
|
+
);
|
|
1861
|
+
} else {
|
|
1862
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1863
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
const command = ({ command: command2, ctx }) => {
|
|
1868
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1869
|
+
environmentCmd2.command("link").description("Link project to a specific Strapi Cloud project environment").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("link", action)(ctx));
|
|
1870
|
+
};
|
|
1871
|
+
const linkEnvironment = {
|
|
1872
|
+
name: "link-environment",
|
|
1873
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1874
|
+
action,
|
|
1250
1875
|
command
|
|
1251
1876
|
};
|
|
1252
1877
|
const cli = {
|
|
1253
1878
|
deployProject,
|
|
1879
|
+
link,
|
|
1254
1880
|
login,
|
|
1255
1881
|
logout,
|
|
1256
|
-
createProject
|
|
1882
|
+
createProject,
|
|
1883
|
+
linkEnvironment,
|
|
1884
|
+
listProjects,
|
|
1885
|
+
listEnvironments
|
|
1257
1886
|
};
|
|
1258
|
-
const cloudCommands = [
|
|
1887
|
+
const cloudCommands = [
|
|
1888
|
+
deployProject,
|
|
1889
|
+
link,
|
|
1890
|
+
login,
|
|
1891
|
+
logout,
|
|
1892
|
+
linkEnvironment,
|
|
1893
|
+
listProjects,
|
|
1894
|
+
listEnvironments
|
|
1895
|
+
];
|
|
1259
1896
|
async function initCloudCLIConfig() {
|
|
1260
|
-
const localConfig = await getLocalConfig();
|
|
1897
|
+
const localConfig = await getLocalConfig$1();
|
|
1261
1898
|
if (!localConfig.deviceId) {
|
|
1262
1899
|
localConfig.deviceId = crypto__default.default.randomUUID();
|
|
1263
1900
|
}
|
|
@@ -1271,7 +1908,10 @@ async function buildStrapiCloudCommands({
|
|
|
1271
1908
|
await initCloudCLIConfig();
|
|
1272
1909
|
for (const cloudCommand of cloudCommands) {
|
|
1273
1910
|
try {
|
|
1274
|
-
await cloudCommand.command({ command: command2, ctx, argv });
|
|
1911
|
+
const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
|
|
1912
|
+
if (subCommand) {
|
|
1913
|
+
command2.addCommand(subCommand);
|
|
1914
|
+
}
|
|
1275
1915
|
} catch (e) {
|
|
1276
1916
|
console.error(`Failed to load command ${cloudCommand.name}`, e);
|
|
1277
1917
|
}
|