@strapi/cloud-cli 0.0.0-next.7f1333f1967e625c57ab16648c057aea08c9dddb → 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 +394 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +391 -57
- 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/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 +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/link/action.d.ts.map +1 -1
- package/dist/src/services/cli-api.d.ts +30 -3
- 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 +6 -0
- package/dist/src/types.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 +8 -7
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import crypto$1 from "crypto";
|
|
2
2
|
import * as fse from "fs-extra";
|
|
3
3
|
import fse__default from "fs-extra";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import boxen from "boxen";
|
|
4
6
|
import * as path from "path";
|
|
5
7
|
import path__default from "path";
|
|
6
8
|
import chalk from "chalk";
|
|
@@ -9,10 +11,10 @@ import * as crypto from "node:crypto";
|
|
|
9
11
|
import { env } from "@strapi/utils";
|
|
10
12
|
import * as tar from "tar";
|
|
11
13
|
import { minimatch } from "minimatch";
|
|
12
|
-
import inquirer from "inquirer";
|
|
13
14
|
import { defaults, has } from "lodash/fp";
|
|
14
15
|
import os from "os";
|
|
15
16
|
import XDGAppPaths from "xdg-app-paths";
|
|
17
|
+
import { merge } from "lodash";
|
|
16
18
|
import jwksClient from "jwks-rsa";
|
|
17
19
|
import jwt from "jsonwebtoken";
|
|
18
20
|
import stringify from "fast-safe-stringify";
|
|
@@ -78,8 +80,7 @@ const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
|
|
|
78
80
|
const readGitignore = async (folderPath) => {
|
|
79
81
|
const gitignorePath = path.resolve(folderPath, ".gitignore");
|
|
80
82
|
const pathExist = await fse.pathExists(gitignorePath);
|
|
81
|
-
if (!pathExist)
|
|
82
|
-
return [];
|
|
83
|
+
if (!pathExist) return [];
|
|
83
84
|
const gitignoreContent = await fse.readFile(gitignorePath, "utf8");
|
|
84
85
|
return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
85
86
|
};
|
|
@@ -118,7 +119,7 @@ async function getConfigPath() {
|
|
|
118
119
|
}
|
|
119
120
|
return configPath;
|
|
120
121
|
}
|
|
121
|
-
async function getLocalConfig() {
|
|
122
|
+
async function getLocalConfig$1() {
|
|
122
123
|
const configPath = await getConfigPath();
|
|
123
124
|
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
124
125
|
await fse__default.ensureFile(configFilePath);
|
|
@@ -134,7 +135,7 @@ async function saveLocalConfig(data) {
|
|
|
134
135
|
await fse__default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
|
|
135
136
|
}
|
|
136
137
|
const name = "@strapi/cloud-cli";
|
|
137
|
-
const version = "5.
|
|
138
|
+
const version = "5.5.0";
|
|
138
139
|
const description = "Commands to interact with the Strapi Cloud";
|
|
139
140
|
const keywords = [
|
|
140
141
|
"strapi",
|
|
@@ -181,6 +182,7 @@ const scripts = {
|
|
|
181
182
|
const dependencies = {
|
|
182
183
|
"@strapi/utils": "workspace:*",
|
|
183
184
|
axios: "1.7.4",
|
|
185
|
+
boxen: "5.1.2",
|
|
184
186
|
chalk: "4.1.2",
|
|
185
187
|
"cli-progress": "3.12.0",
|
|
186
188
|
commander: "8.3.0",
|
|
@@ -200,7 +202,7 @@ const dependencies = {
|
|
|
200
202
|
yup: "0.32.9"
|
|
201
203
|
};
|
|
202
204
|
const devDependencies = {
|
|
203
|
-
"@strapi/pack-up": "
|
|
205
|
+
"@strapi/pack-up": "5.0.2",
|
|
204
206
|
"@types/cli-progress": "3.11.5",
|
|
205
207
|
"@types/eventsource": "1.1.15",
|
|
206
208
|
"@types/lodash": "^4.14.191",
|
|
@@ -208,9 +210,10 @@ const devDependencies = {
|
|
|
208
210
|
tsconfig: "workspace:*"
|
|
209
211
|
};
|
|
210
212
|
const engines = {
|
|
211
|
-
node: ">=18.0.0 <=
|
|
213
|
+
node: ">=18.0.0 <=22.x.x",
|
|
212
214
|
npm: ">=6.0.0"
|
|
213
215
|
};
|
|
216
|
+
const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
|
|
214
217
|
const packageJson = {
|
|
215
218
|
name,
|
|
216
219
|
version,
|
|
@@ -231,11 +234,12 @@ const packageJson = {
|
|
|
231
234
|
scripts,
|
|
232
235
|
dependencies,
|
|
233
236
|
devDependencies,
|
|
234
|
-
engines
|
|
237
|
+
engines,
|
|
238
|
+
gitHead
|
|
235
239
|
};
|
|
236
240
|
const VERSION = "v1";
|
|
237
241
|
async function cloudApiFactory({ logger }, token) {
|
|
238
|
-
const localConfig = await getLocalConfig();
|
|
242
|
+
const localConfig = await getLocalConfig$1();
|
|
239
243
|
const customHeaders = {
|
|
240
244
|
"x-device-id": localConfig.deviceId,
|
|
241
245
|
"x-app-version": packageJson.version,
|
|
@@ -258,7 +262,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
258
262
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
259
263
|
return axiosCloudAPI.post(
|
|
260
264
|
`/deploy/${project.name}`,
|
|
261
|
-
{ file: fse__default.createReadStream(filePath) },
|
|
265
|
+
{ file: fse__default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
262
266
|
{
|
|
263
267
|
headers: {
|
|
264
268
|
"Content-Type": "multipart/form-data"
|
|
@@ -329,6 +333,34 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
329
333
|
throw error;
|
|
330
334
|
}
|
|
331
335
|
},
|
|
336
|
+
async listEnvironments({ name: name2 }) {
|
|
337
|
+
try {
|
|
338
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
339
|
+
if (response.status !== 200) {
|
|
340
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
341
|
+
}
|
|
342
|
+
return response;
|
|
343
|
+
} catch (error) {
|
|
344
|
+
logger.debug(
|
|
345
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
346
|
+
);
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
351
|
+
try {
|
|
352
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
353
|
+
if (response.status !== 200) {
|
|
354
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
355
|
+
}
|
|
356
|
+
return response;
|
|
357
|
+
} catch (error) {
|
|
358
|
+
logger.debug(
|
|
359
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
360
|
+
);
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
},
|
|
332
364
|
async getProject({ name: name2 }) {
|
|
333
365
|
try {
|
|
334
366
|
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
@@ -352,26 +384,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
352
384
|
};
|
|
353
385
|
}
|
|
354
386
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
387
|
+
const getFilePath = (directoryPath) => path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
355
388
|
async function save(data, { directoryPath } = {}) {
|
|
356
|
-
const
|
|
357
|
-
const storedData = { ...alreadyInFileData, ...data };
|
|
358
|
-
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
389
|
+
const pathToFile = getFilePath(directoryPath);
|
|
359
390
|
await fse__default.ensureDir(path__default.dirname(pathToFile));
|
|
360
|
-
await fse__default.writeJson(pathToFile,
|
|
391
|
+
await fse__default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
361
392
|
}
|
|
362
393
|
async function retrieve({
|
|
363
394
|
directoryPath
|
|
364
395
|
} = {}) {
|
|
365
|
-
const pathToFile =
|
|
396
|
+
const pathToFile = getFilePath(directoryPath);
|
|
366
397
|
const pathExists = await fse__default.pathExists(pathToFile);
|
|
367
398
|
if (!pathExists) {
|
|
368
399
|
return {};
|
|
369
400
|
}
|
|
370
401
|
return fse__default.readJSON(pathToFile, { encoding: "utf8" });
|
|
371
402
|
}
|
|
403
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
404
|
+
const pathToFile = getFilePath(directoryPath);
|
|
405
|
+
const existingData = await retrieve({ directoryPath });
|
|
406
|
+
if (!existingData) {
|
|
407
|
+
throw new Error("No configuration data found to patch.");
|
|
408
|
+
}
|
|
409
|
+
const newData = merge(existingData, patchData);
|
|
410
|
+
await fse__default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
411
|
+
}
|
|
412
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
413
|
+
const pathToFile = getFilePath(directoryPath);
|
|
414
|
+
const pathExists = await fse__default.pathExists(pathToFile);
|
|
415
|
+
if (pathExists) {
|
|
416
|
+
await fse__default.remove(pathToFile);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
372
419
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
373
420
|
__proto__: null,
|
|
374
421
|
LOCAL_SAVE_FILENAME,
|
|
422
|
+
deleteConfig,
|
|
423
|
+
patch,
|
|
375
424
|
retrieve,
|
|
376
425
|
save
|
|
377
426
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -379,7 +428,7 @@ let cliConfig;
|
|
|
379
428
|
async function tokenServiceFactory({ logger }) {
|
|
380
429
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
381
430
|
async function saveToken(str) {
|
|
382
|
-
const appConfig = await getLocalConfig();
|
|
431
|
+
const appConfig = await getLocalConfig$1();
|
|
383
432
|
if (!appConfig) {
|
|
384
433
|
logger.error("There was a problem saving your token. Please try again.");
|
|
385
434
|
return;
|
|
@@ -393,7 +442,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
393
442
|
}
|
|
394
443
|
}
|
|
395
444
|
async function retrieveToken() {
|
|
396
|
-
const appConfig = await getLocalConfig();
|
|
445
|
+
const appConfig = await getLocalConfig$1();
|
|
397
446
|
if (appConfig.token) {
|
|
398
447
|
if (await isTokenValid(appConfig.token)) {
|
|
399
448
|
return appConfig.token;
|
|
@@ -455,7 +504,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
455
504
|
}
|
|
456
505
|
}
|
|
457
506
|
async function eraseToken() {
|
|
458
|
-
const appConfig = await getLocalConfig();
|
|
507
|
+
const appConfig = await getLocalConfig$1();
|
|
459
508
|
if (!appConfig) {
|
|
460
509
|
return;
|
|
461
510
|
}
|
|
@@ -476,8 +525,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
476
525
|
logger.log(
|
|
477
526
|
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."
|
|
478
527
|
);
|
|
479
|
-
if (!await loginAction2(ctx))
|
|
480
|
-
return null;
|
|
528
|
+
if (!await loginAction2(ctx)) return null;
|
|
481
529
|
token = await retrieveToken();
|
|
482
530
|
}
|
|
483
531
|
return token;
|
|
@@ -901,7 +949,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
|
|
|
901
949
|
throw e;
|
|
902
950
|
}
|
|
903
951
|
}
|
|
904
|
-
const action$
|
|
952
|
+
const action$6 = async (ctx) => {
|
|
905
953
|
const { logger } = ctx;
|
|
906
954
|
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
907
955
|
const token = await getValidToken(ctx, promptLogin);
|
|
@@ -1030,6 +1078,29 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1030
1078
|
});
|
|
1031
1079
|
};
|
|
1032
1080
|
};
|
|
1081
|
+
const boxenOptions = {
|
|
1082
|
+
padding: 1,
|
|
1083
|
+
margin: 1,
|
|
1084
|
+
align: "center",
|
|
1085
|
+
borderColor: "yellow",
|
|
1086
|
+
borderStyle: "round"
|
|
1087
|
+
};
|
|
1088
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1089
|
+
async function promptForEnvironment(environments) {
|
|
1090
|
+
const choices = environments.map((env2) => ({ name: env2, value: env2 }));
|
|
1091
|
+
const { selectedEnvironment } = await inquirer.prompt([
|
|
1092
|
+
{
|
|
1093
|
+
type: "list",
|
|
1094
|
+
name: "selectedEnvironment",
|
|
1095
|
+
message: "Select the environment to deploy:",
|
|
1096
|
+
choices: [...choices, { name: chalk.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1097
|
+
}
|
|
1098
|
+
]);
|
|
1099
|
+
if (selectedEnvironment === null) {
|
|
1100
|
+
process.exit(1);
|
|
1101
|
+
}
|
|
1102
|
+
return selectedEnvironment;
|
|
1103
|
+
}
|
|
1033
1104
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1034
1105
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1035
1106
|
try {
|
|
@@ -1112,7 +1183,7 @@ async function getProject(ctx) {
|
|
|
1112
1183
|
const { project } = await retrieve();
|
|
1113
1184
|
if (!project) {
|
|
1114
1185
|
try {
|
|
1115
|
-
return await action$
|
|
1186
|
+
return await action$6(ctx);
|
|
1116
1187
|
} catch (e) {
|
|
1117
1188
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1118
1189
|
ctx.logger.debug(e);
|
|
@@ -1133,7 +1204,33 @@ async function getConfig({
|
|
|
1133
1204
|
return null;
|
|
1134
1205
|
}
|
|
1135
1206
|
}
|
|
1136
|
-
|
|
1207
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1208
|
+
if (!environments.includes(environment)) {
|
|
1209
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1210
|
+
process.exit(1);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1214
|
+
if (opts.env) {
|
|
1215
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1216
|
+
return opts.env;
|
|
1217
|
+
}
|
|
1218
|
+
if (project.targetEnvironment) {
|
|
1219
|
+
return project.targetEnvironment;
|
|
1220
|
+
}
|
|
1221
|
+
if (environments.length > 1) {
|
|
1222
|
+
return promptForEnvironment(environments);
|
|
1223
|
+
}
|
|
1224
|
+
return environments[0];
|
|
1225
|
+
}
|
|
1226
|
+
function hasPendingOrLiveDeployment(environments, targetEnvironment) {
|
|
1227
|
+
const environment = environments.find((env2) => env2.name === targetEnvironment);
|
|
1228
|
+
if (!environment) {
|
|
1229
|
+
throw new Error(`Environment details ${targetEnvironment} not found.`);
|
|
1230
|
+
}
|
|
1231
|
+
return environment.hasPendingDeployment || environment.hasLiveDeployment || false;
|
|
1232
|
+
}
|
|
1233
|
+
const action$5 = async (ctx, opts) => {
|
|
1137
1234
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1138
1235
|
const token = await getValidToken(ctx, promptLogin);
|
|
1139
1236
|
if (!token) {
|
|
@@ -1144,10 +1241,16 @@ const action$3 = async (ctx) => {
|
|
|
1144
1241
|
return;
|
|
1145
1242
|
}
|
|
1146
1243
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1244
|
+
let projectData;
|
|
1245
|
+
let environments;
|
|
1246
|
+
let environmentsDetails;
|
|
1147
1247
|
try {
|
|
1148
1248
|
const {
|
|
1149
|
-
data: { data
|
|
1249
|
+
data: { data, metadata }
|
|
1150
1250
|
} = await cloudApiService.getProject({ name: project.name });
|
|
1251
|
+
projectData = data;
|
|
1252
|
+
environments = projectData.environments;
|
|
1253
|
+
environmentsDetails = projectData.environmentsDetails;
|
|
1151
1254
|
const isProjectSuspended = projectData.suspendedAt;
|
|
1152
1255
|
if (isProjectSuspended) {
|
|
1153
1256
|
ctx.logger.log(
|
|
@@ -1195,11 +1298,34 @@ Please link your local project to an existing Strapi Cloud project using the ${c
|
|
|
1195
1298
|
);
|
|
1196
1299
|
maxSize = 1e8;
|
|
1197
1300
|
}
|
|
1301
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1302
|
+
if (!opts.force) {
|
|
1303
|
+
const shouldDisplayWarning = hasPendingOrLiveDeployment(
|
|
1304
|
+
environmentsDetails,
|
|
1305
|
+
project.targetEnvironment
|
|
1306
|
+
);
|
|
1307
|
+
if (shouldDisplayWarning) {
|
|
1308
|
+
ctx.logger.log(boxen(cliConfig2.projectDeployment.confirmationText, boxenOptions));
|
|
1309
|
+
const { confirm } = await inquirer.prompt([
|
|
1310
|
+
{
|
|
1311
|
+
type: "confirm",
|
|
1312
|
+
name: "confirm",
|
|
1313
|
+
message: `Do you want to proceed with deployment to ${chalk.cyan(projectData.displayName)} on ${chalk.cyan(project.targetEnvironment)} environment?`
|
|
1314
|
+
}
|
|
1315
|
+
]);
|
|
1316
|
+
if (!confirm) {
|
|
1317
|
+
process.exit(1);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1198
1321
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1199
1322
|
if (!buildId) {
|
|
1200
1323
|
return;
|
|
1201
1324
|
}
|
|
1202
1325
|
try {
|
|
1326
|
+
ctx.logger.log(
|
|
1327
|
+
`🚀 Deploying project to ${chalk.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1328
|
+
);
|
|
1203
1329
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1204
1330
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1205
1331
|
ctx.logger.log(
|
|
@@ -1244,17 +1370,16 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1244
1370
|
process.exit(1);
|
|
1245
1371
|
});
|
|
1246
1372
|
};
|
|
1247
|
-
const command$
|
|
1248
|
-
return createCommand("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("deploy", action$
|
|
1373
|
+
const command$7 = ({ ctx }) => {
|
|
1374
|
+
return createCommand("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").option("-f, --force", "Skip confirmation to deploy").option("-e, --env <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$5)(ctx, opts));
|
|
1249
1375
|
};
|
|
1250
1376
|
const deployProject = {
|
|
1251
1377
|
name: "deploy-project",
|
|
1252
1378
|
description: "Deploy a Strapi Cloud project",
|
|
1253
|
-
action: action$
|
|
1254
|
-
command: command$
|
|
1379
|
+
action: action$5,
|
|
1380
|
+
command: command$7
|
|
1255
1381
|
};
|
|
1256
|
-
|
|
1257
|
-
async function getExistingConfig(ctx) {
|
|
1382
|
+
async function getLocalConfig(ctx) {
|
|
1258
1383
|
try {
|
|
1259
1384
|
return await retrieve();
|
|
1260
1385
|
} catch (e) {
|
|
@@ -1263,6 +1388,21 @@ async function getExistingConfig(ctx) {
|
|
|
1263
1388
|
return null;
|
|
1264
1389
|
}
|
|
1265
1390
|
}
|
|
1391
|
+
async function getLocalProject(ctx) {
|
|
1392
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1393
|
+
if (!localConfig || !localConfig.project) {
|
|
1394
|
+
ctx.logger.warn(
|
|
1395
|
+
`
|
|
1396
|
+
We couldn't find a valid local project config.
|
|
1397
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1398
|
+
"link"
|
|
1399
|
+
)} command.`
|
|
1400
|
+
);
|
|
1401
|
+
process.exit(1);
|
|
1402
|
+
}
|
|
1403
|
+
return localConfig.project;
|
|
1404
|
+
}
|
|
1405
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1266
1406
|
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1267
1407
|
if (existingConfig && existingConfig.project) {
|
|
1268
1408
|
const { shouldRelink } = await inquirer.prompt([
|
|
@@ -1292,7 +1432,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1292
1432
|
} = await cloudApiService.listLinkProjects();
|
|
1293
1433
|
spinner.succeed();
|
|
1294
1434
|
if (!Array.isArray(projectList)) {
|
|
1295
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1435
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1296
1436
|
return null;
|
|
1297
1437
|
}
|
|
1298
1438
|
const projects = projectList.filter(
|
|
@@ -1304,7 +1444,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1304
1444
|
};
|
|
1305
1445
|
});
|
|
1306
1446
|
if (projects.length === 0) {
|
|
1307
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1447
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1308
1448
|
return null;
|
|
1309
1449
|
}
|
|
1310
1450
|
return projects;
|
|
@@ -1322,7 +1462,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1322
1462
|
type: "list",
|
|
1323
1463
|
name: "linkProject",
|
|
1324
1464
|
message: "Which project do you want to link?",
|
|
1325
|
-
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1465
|
+
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1326
1466
|
}
|
|
1327
1467
|
]);
|
|
1328
1468
|
if (!answer.linkProject) {
|
|
@@ -1335,7 +1475,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1335
1475
|
return null;
|
|
1336
1476
|
}
|
|
1337
1477
|
}
|
|
1338
|
-
const action$
|
|
1478
|
+
const action$4 = async (ctx) => {
|
|
1339
1479
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1340
1480
|
const token = await getValidToken(ctx, promptLogin);
|
|
1341
1481
|
const { logger } = ctx;
|
|
@@ -1343,7 +1483,7 @@ const action$2 = async (ctx) => {
|
|
|
1343
1483
|
return;
|
|
1344
1484
|
}
|
|
1345
1485
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1346
|
-
const existingConfig = await
|
|
1486
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1347
1487
|
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1348
1488
|
if (!shouldRelink) {
|
|
1349
1489
|
return;
|
|
@@ -1378,7 +1518,9 @@ const action$2 = async (ctx) => {
|
|
|
1378
1518
|
return;
|
|
1379
1519
|
}
|
|
1380
1520
|
await save({ project: answer.linkProject });
|
|
1381
|
-
logger.log(
|
|
1521
|
+
logger.log(
|
|
1522
|
+
` You have successfully linked your project to ${chalk.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1523
|
+
);
|
|
1382
1524
|
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1383
1525
|
projectInternalName: answer.linkProject
|
|
1384
1526
|
});
|
|
@@ -1390,16 +1532,16 @@ const action$2 = async (ctx) => {
|
|
|
1390
1532
|
});
|
|
1391
1533
|
}
|
|
1392
1534
|
};
|
|
1393
|
-
const command$
|
|
1394
|
-
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$
|
|
1535
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1536
|
+
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));
|
|
1395
1537
|
};
|
|
1396
1538
|
const link = {
|
|
1397
1539
|
name: "link-project",
|
|
1398
1540
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1399
|
-
action: action$
|
|
1400
|
-
command: command$
|
|
1541
|
+
action: action$4,
|
|
1542
|
+
command: command$6
|
|
1401
1543
|
};
|
|
1402
|
-
const command$
|
|
1544
|
+
const command$5 = ({ ctx }) => {
|
|
1403
1545
|
return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1404
1546
|
"after",
|
|
1405
1547
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
@@ -1409,10 +1551,10 @@ const login = {
|
|
|
1409
1551
|
name: "login",
|
|
1410
1552
|
description: "Strapi Cloud Login",
|
|
1411
1553
|
action: loginAction,
|
|
1412
|
-
command: command$
|
|
1554
|
+
command: command$5
|
|
1413
1555
|
};
|
|
1414
1556
|
const openModule = import("open");
|
|
1415
|
-
const action$
|
|
1557
|
+
const action$3 = async (ctx) => {
|
|
1416
1558
|
const { logger } = ctx;
|
|
1417
1559
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1418
1560
|
const token = await retrieveToken();
|
|
@@ -1444,25 +1586,25 @@ const action$1 = async (ctx) => {
|
|
|
1444
1586
|
}
|
|
1445
1587
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1446
1588
|
};
|
|
1447
|
-
const command$
|
|
1448
|
-
return createCommand("cloud:logout").alias("logout").description("Strapi Cloud Logout").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("logout", action$
|
|
1589
|
+
const command$4 = ({ ctx }) => {
|
|
1590
|
+
return createCommand("cloud:logout").alias("logout").description("Strapi Cloud Logout").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("logout", action$3)(ctx));
|
|
1449
1591
|
};
|
|
1450
1592
|
const logout = {
|
|
1451
1593
|
name: "logout",
|
|
1452
1594
|
description: "Strapi Cloud Logout",
|
|
1453
|
-
action: action$
|
|
1454
|
-
command: command$
|
|
1595
|
+
action: action$3,
|
|
1596
|
+
command: command$4
|
|
1455
1597
|
};
|
|
1456
|
-
const command$
|
|
1457
|
-
return createCommand("cloud:create-project").description("Create a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("cloud:create-project", action$
|
|
1598
|
+
const command$3 = ({ ctx }) => {
|
|
1599
|
+
return createCommand("cloud:create-project").description("Create a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("cloud:create-project", action$6)(ctx));
|
|
1458
1600
|
};
|
|
1459
1601
|
const createProject = {
|
|
1460
1602
|
name: "create-project",
|
|
1461
1603
|
description: "Create a new project",
|
|
1462
|
-
action: action$
|
|
1463
|
-
command: command$
|
|
1604
|
+
action: action$6,
|
|
1605
|
+
command: command$3
|
|
1464
1606
|
};
|
|
1465
|
-
const action = async (ctx) => {
|
|
1607
|
+
const action$2 = async (ctx) => {
|
|
1466
1608
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1467
1609
|
const token = await getValidToken(ctx, promptLogin);
|
|
1468
1610
|
const { logger } = ctx;
|
|
@@ -1482,12 +1624,194 @@ const action = async (ctx) => {
|
|
|
1482
1624
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1483
1625
|
}
|
|
1484
1626
|
};
|
|
1485
|
-
const command = ({ command: command2, ctx }) => {
|
|
1486
|
-
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));
|
|
1627
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1628
|
+
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));
|
|
1487
1629
|
};
|
|
1488
1630
|
const listProjects = {
|
|
1489
1631
|
name: "list-projects",
|
|
1490
1632
|
description: "List Strapi Cloud projects",
|
|
1633
|
+
action: action$2,
|
|
1634
|
+
command: command$2
|
|
1635
|
+
};
|
|
1636
|
+
const action$1 = async (ctx) => {
|
|
1637
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1638
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1639
|
+
const { logger } = ctx;
|
|
1640
|
+
if (!token) {
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
const project = await getLocalProject(ctx);
|
|
1644
|
+
if (!project) {
|
|
1645
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1646
|
+
return;
|
|
1647
|
+
}
|
|
1648
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1649
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1650
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1651
|
+
projectInternalName: project.name
|
|
1652
|
+
});
|
|
1653
|
+
try {
|
|
1654
|
+
const {
|
|
1655
|
+
data: { data: environmentsList }
|
|
1656
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1657
|
+
spinner.succeed();
|
|
1658
|
+
logger.log(environmentsList);
|
|
1659
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1660
|
+
projectInternalName: project.name
|
|
1661
|
+
});
|
|
1662
|
+
} catch (e) {
|
|
1663
|
+
if (e.response && e.response.status === 404) {
|
|
1664
|
+
spinner.succeed();
|
|
1665
|
+
logger.warn(
|
|
1666
|
+
`
|
|
1667
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1668
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1669
|
+
"link"
|
|
1670
|
+
)} command`
|
|
1671
|
+
);
|
|
1672
|
+
} else {
|
|
1673
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1674
|
+
logger.debug("Failed to list environments", e);
|
|
1675
|
+
}
|
|
1676
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1677
|
+
projectInternalName: project.name
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1682
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1683
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1684
|
+
return cloud;
|
|
1685
|
+
}
|
|
1686
|
+
let environmentCmd = null;
|
|
1687
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1688
|
+
if (!environmentCmd) {
|
|
1689
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1690
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1691
|
+
}
|
|
1692
|
+
return environmentCmd;
|
|
1693
|
+
};
|
|
1694
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1695
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1696
|
+
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));
|
|
1697
|
+
};
|
|
1698
|
+
const listEnvironments = {
|
|
1699
|
+
name: "list-environments",
|
|
1700
|
+
description: "List Strapi Cloud environments",
|
|
1701
|
+
action: action$1,
|
|
1702
|
+
command: command$1
|
|
1703
|
+
};
|
|
1704
|
+
const QUIT_OPTION = "Quit";
|
|
1705
|
+
const action = async (ctx) => {
|
|
1706
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1707
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1708
|
+
const { logger } = ctx;
|
|
1709
|
+
if (!token) {
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const project = await getLocalProject(ctx);
|
|
1713
|
+
if (!project) {
|
|
1714
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1718
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1719
|
+
if (!environments) {
|
|
1720
|
+
logger.debug(`Fetching environments failed.`);
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
if (environments.length === 0) {
|
|
1724
|
+
logger.log(
|
|
1725
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1726
|
+
);
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1730
|
+
if (!answer) {
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1733
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1734
|
+
projectName: project.name,
|
|
1735
|
+
environmentName: answer.targetEnvironment
|
|
1736
|
+
});
|
|
1737
|
+
try {
|
|
1738
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1739
|
+
} catch (e) {
|
|
1740
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1741
|
+
projectName: project.name,
|
|
1742
|
+
environmentName: answer.targetEnvironment
|
|
1743
|
+
});
|
|
1744
|
+
logger.debug("Failed to link environment", e);
|
|
1745
|
+
logger.error(
|
|
1746
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1747
|
+
);
|
|
1748
|
+
process.exit(1);
|
|
1749
|
+
}
|
|
1750
|
+
logger.log(
|
|
1751
|
+
` You have successfully linked your project to ${chalk.cyan(answer.targetEnvironment)}, on ${chalk.cyan(project.displayName)}. You are now able to deploy your project.`
|
|
1752
|
+
);
|
|
1753
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1754
|
+
projectName: project.name,
|
|
1755
|
+
environmentName: answer.targetEnvironment
|
|
1756
|
+
});
|
|
1757
|
+
};
|
|
1758
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1759
|
+
const { logger } = ctx;
|
|
1760
|
+
try {
|
|
1761
|
+
const answer = await inquirer.prompt([
|
|
1762
|
+
{
|
|
1763
|
+
type: "list",
|
|
1764
|
+
name: "targetEnvironment",
|
|
1765
|
+
message: "Which environment do you want to link?",
|
|
1766
|
+
choices: [...environments, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1767
|
+
}
|
|
1768
|
+
]);
|
|
1769
|
+
if (!answer.targetEnvironment) {
|
|
1770
|
+
return null;
|
|
1771
|
+
}
|
|
1772
|
+
return answer;
|
|
1773
|
+
} catch (e) {
|
|
1774
|
+
logger.debug("Failed to get user input", e);
|
|
1775
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1776
|
+
return null;
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1780
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1781
|
+
try {
|
|
1782
|
+
const {
|
|
1783
|
+
data: { data: environmentsList }
|
|
1784
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1785
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1786
|
+
throw new Error("Environments not found in server response");
|
|
1787
|
+
}
|
|
1788
|
+
spinner.succeed();
|
|
1789
|
+
return environmentsList.filter(
|
|
1790
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1791
|
+
);
|
|
1792
|
+
} catch (e) {
|
|
1793
|
+
if (e.response && e.response.status === 404) {
|
|
1794
|
+
spinner.succeed();
|
|
1795
|
+
ctx.logger.warn(
|
|
1796
|
+
`
|
|
1797
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1798
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1799
|
+
"link"
|
|
1800
|
+
)} command.`
|
|
1801
|
+
);
|
|
1802
|
+
} else {
|
|
1803
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1804
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
const command = ({ command: command2, ctx }) => {
|
|
1809
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1810
|
+
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));
|
|
1811
|
+
};
|
|
1812
|
+
const linkEnvironment = {
|
|
1813
|
+
name: "link-environment",
|
|
1814
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1491
1815
|
action,
|
|
1492
1816
|
command
|
|
1493
1817
|
};
|
|
@@ -1497,11 +1821,21 @@ const cli = {
|
|
|
1497
1821
|
login,
|
|
1498
1822
|
logout,
|
|
1499
1823
|
createProject,
|
|
1500
|
-
|
|
1824
|
+
linkEnvironment,
|
|
1825
|
+
listProjects,
|
|
1826
|
+
listEnvironments
|
|
1501
1827
|
};
|
|
1502
|
-
const cloudCommands = [
|
|
1828
|
+
const cloudCommands = [
|
|
1829
|
+
deployProject,
|
|
1830
|
+
link,
|
|
1831
|
+
login,
|
|
1832
|
+
logout,
|
|
1833
|
+
linkEnvironment,
|
|
1834
|
+
listProjects,
|
|
1835
|
+
listEnvironments
|
|
1836
|
+
];
|
|
1503
1837
|
async function initCloudCLIConfig() {
|
|
1504
|
-
const localConfig = await getLocalConfig();
|
|
1838
|
+
const localConfig = await getLocalConfig$1();
|
|
1505
1839
|
if (!localConfig.deviceId) {
|
|
1506
1840
|
localConfig.deviceId = crypto$1.randomUUID();
|
|
1507
1841
|
}
|