@strapi/cloud-cli 0.0.0-next.504076d2165a82f124620a3f1f3e3a6017e97f3f → 0.0.0-next.51dcef446efe662f00da6d85d6bea2218c4c538e
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 +1 -0
- package/dist/bin.js.map +1 -1
- package/dist/index.js +363 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +362 -55
- 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 +4 -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 +23 -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/types.d.ts +3 -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/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
4
5
|
import * as path from "path";
|
|
5
6
|
import path__default from "path";
|
|
6
7
|
import chalk from "chalk";
|
|
@@ -9,10 +10,10 @@ import * as crypto from "node:crypto";
|
|
|
9
10
|
import { env } from "@strapi/utils";
|
|
10
11
|
import * as tar from "tar";
|
|
11
12
|
import { minimatch } from "minimatch";
|
|
12
|
-
import inquirer from "inquirer";
|
|
13
13
|
import { defaults, has } from "lodash/fp";
|
|
14
14
|
import os from "os";
|
|
15
15
|
import XDGAppPaths from "xdg-app-paths";
|
|
16
|
+
import { merge } from "lodash";
|
|
16
17
|
import jwksClient from "jwks-rsa";
|
|
17
18
|
import jwt from "jsonwebtoken";
|
|
18
19
|
import stringify from "fast-safe-stringify";
|
|
@@ -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.4.0";
|
|
138
139
|
const description = "Commands to interact with the Strapi Cloud";
|
|
139
140
|
const keywords = [
|
|
140
141
|
"strapi",
|
|
@@ -179,7 +180,7 @@ const scripts = {
|
|
|
179
180
|
watch: "pack-up watch"
|
|
180
181
|
};
|
|
181
182
|
const dependencies = {
|
|
182
|
-
"@strapi/utils": "
|
|
183
|
+
"@strapi/utils": "5.4.0",
|
|
183
184
|
axios: "1.7.4",
|
|
184
185
|
chalk: "4.1.2",
|
|
185
186
|
"cli-progress": "3.12.0",
|
|
@@ -195,7 +196,7 @@ const dependencies = {
|
|
|
195
196
|
open: "8.4.0",
|
|
196
197
|
ora: "5.4.1",
|
|
197
198
|
"pkg-up": "3.1.0",
|
|
198
|
-
tar: "6.1
|
|
199
|
+
tar: "6.2.1",
|
|
199
200
|
"xdg-app-paths": "8.3.0",
|
|
200
201
|
yup: "0.32.9"
|
|
201
202
|
};
|
|
@@ -204,13 +205,14 @@ const devDependencies = {
|
|
|
204
205
|
"@types/cli-progress": "3.11.5",
|
|
205
206
|
"@types/eventsource": "1.1.15",
|
|
206
207
|
"@types/lodash": "^4.14.191",
|
|
207
|
-
"eslint-config-custom": "
|
|
208
|
-
tsconfig: "
|
|
208
|
+
"eslint-config-custom": "5.4.0",
|
|
209
|
+
tsconfig: "5.4.0"
|
|
209
210
|
};
|
|
210
211
|
const engines = {
|
|
211
|
-
node: ">=18.0.0 <=
|
|
212
|
+
node: ">=18.0.0 <=22.x.x",
|
|
212
213
|
npm: ">=6.0.0"
|
|
213
214
|
};
|
|
215
|
+
const gitHead = "7d785703f52464577d077c4618cbe68b44f8a9cd";
|
|
214
216
|
const packageJson = {
|
|
215
217
|
name,
|
|
216
218
|
version,
|
|
@@ -231,11 +233,12 @@ const packageJson = {
|
|
|
231
233
|
scripts,
|
|
232
234
|
dependencies,
|
|
233
235
|
devDependencies,
|
|
234
|
-
engines
|
|
236
|
+
engines,
|
|
237
|
+
gitHead
|
|
235
238
|
};
|
|
236
239
|
const VERSION = "v1";
|
|
237
240
|
async function cloudApiFactory({ logger }, token) {
|
|
238
|
-
const localConfig = await getLocalConfig();
|
|
241
|
+
const localConfig = await getLocalConfig$1();
|
|
239
242
|
const customHeaders = {
|
|
240
243
|
"x-device-id": localConfig.deviceId,
|
|
241
244
|
"x-app-version": packageJson.version,
|
|
@@ -258,7 +261,7 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
258
261
|
deploy({ filePath, project }, { onUploadProgress }) {
|
|
259
262
|
return axiosCloudAPI.post(
|
|
260
263
|
`/deploy/${project.name}`,
|
|
261
|
-
{ file: fse__default.createReadStream(filePath) },
|
|
264
|
+
{ file: fse__default.createReadStream(filePath), targetEnvironment: project.targetEnvironment },
|
|
262
265
|
{
|
|
263
266
|
headers: {
|
|
264
267
|
"Content-Type": "multipart/form-data"
|
|
@@ -329,6 +332,34 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
329
332
|
throw error;
|
|
330
333
|
}
|
|
331
334
|
},
|
|
335
|
+
async listEnvironments({ name: name2 }) {
|
|
336
|
+
try {
|
|
337
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
|
|
338
|
+
if (response.status !== 200) {
|
|
339
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
340
|
+
}
|
|
341
|
+
return response;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
logger.debug(
|
|
344
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
345
|
+
);
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
async listLinkEnvironments({ name: name2 }) {
|
|
350
|
+
try {
|
|
351
|
+
const response = await axiosCloudAPI.get(`/projects/${name2}/environments-linkable`);
|
|
352
|
+
if (response.status !== 200) {
|
|
353
|
+
throw new Error("Error fetching cloud environments from the server.");
|
|
354
|
+
}
|
|
355
|
+
return response;
|
|
356
|
+
} catch (error) {
|
|
357
|
+
logger.debug(
|
|
358
|
+
"🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
|
|
359
|
+
);
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
},
|
|
332
363
|
async getProject({ name: name2 }) {
|
|
333
364
|
try {
|
|
334
365
|
const response = await axiosCloudAPI.get(`/projects/${name2}`);
|
|
@@ -352,26 +383,43 @@ async function cloudApiFactory({ logger }, token) {
|
|
|
352
383
|
};
|
|
353
384
|
}
|
|
354
385
|
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
386
|
+
const getFilePath = (directoryPath) => path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
355
387
|
async function save(data, { directoryPath } = {}) {
|
|
356
|
-
const
|
|
357
|
-
const storedData = { ...alreadyInFileData, ...data };
|
|
358
|
-
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
388
|
+
const pathToFile = getFilePath(directoryPath);
|
|
359
389
|
await fse__default.ensureDir(path__default.dirname(pathToFile));
|
|
360
|
-
await fse__default.writeJson(pathToFile,
|
|
390
|
+
await fse__default.writeJson(pathToFile, data, { encoding: "utf8" });
|
|
361
391
|
}
|
|
362
392
|
async function retrieve({
|
|
363
393
|
directoryPath
|
|
364
394
|
} = {}) {
|
|
365
|
-
const pathToFile =
|
|
395
|
+
const pathToFile = getFilePath(directoryPath);
|
|
366
396
|
const pathExists = await fse__default.pathExists(pathToFile);
|
|
367
397
|
if (!pathExists) {
|
|
368
398
|
return {};
|
|
369
399
|
}
|
|
370
400
|
return fse__default.readJSON(pathToFile, { encoding: "utf8" });
|
|
371
401
|
}
|
|
402
|
+
async function patch(patchData, { directoryPath } = {}) {
|
|
403
|
+
const pathToFile = getFilePath(directoryPath);
|
|
404
|
+
const existingData = await retrieve({ directoryPath });
|
|
405
|
+
if (!existingData) {
|
|
406
|
+
throw new Error("No configuration data found to patch.");
|
|
407
|
+
}
|
|
408
|
+
const newData = merge(existingData, patchData);
|
|
409
|
+
await fse__default.writeJson(pathToFile, newData, { encoding: "utf8" });
|
|
410
|
+
}
|
|
411
|
+
async function deleteConfig({ directoryPath } = {}) {
|
|
412
|
+
const pathToFile = getFilePath(directoryPath);
|
|
413
|
+
const pathExists = await fse__default.pathExists(pathToFile);
|
|
414
|
+
if (pathExists) {
|
|
415
|
+
await fse__default.remove(pathToFile);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
372
418
|
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
373
419
|
__proto__: null,
|
|
374
420
|
LOCAL_SAVE_FILENAME,
|
|
421
|
+
deleteConfig,
|
|
422
|
+
patch,
|
|
375
423
|
retrieve,
|
|
376
424
|
save
|
|
377
425
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -379,7 +427,7 @@ let cliConfig;
|
|
|
379
427
|
async function tokenServiceFactory({ logger }) {
|
|
380
428
|
const cloudApiService = await cloudApiFactory({ logger });
|
|
381
429
|
async function saveToken(str) {
|
|
382
|
-
const appConfig = await getLocalConfig();
|
|
430
|
+
const appConfig = await getLocalConfig$1();
|
|
383
431
|
if (!appConfig) {
|
|
384
432
|
logger.error("There was a problem saving your token. Please try again.");
|
|
385
433
|
return;
|
|
@@ -393,7 +441,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
393
441
|
}
|
|
394
442
|
}
|
|
395
443
|
async function retrieveToken() {
|
|
396
|
-
const appConfig = await getLocalConfig();
|
|
444
|
+
const appConfig = await getLocalConfig$1();
|
|
397
445
|
if (appConfig.token) {
|
|
398
446
|
if (await isTokenValid(appConfig.token)) {
|
|
399
447
|
return appConfig.token;
|
|
@@ -455,7 +503,7 @@ async function tokenServiceFactory({ logger }) {
|
|
|
455
503
|
}
|
|
456
504
|
}
|
|
457
505
|
async function eraseToken() {
|
|
458
|
-
const appConfig = await getLocalConfig();
|
|
506
|
+
const appConfig = await getLocalConfig$1();
|
|
459
507
|
if (!appConfig) {
|
|
460
508
|
return;
|
|
461
509
|
}
|
|
@@ -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,32 @@ const buildLogsServiceFactory = ({ logger }) => {
|
|
|
1030
1078
|
});
|
|
1031
1079
|
};
|
|
1032
1080
|
};
|
|
1081
|
+
const QUIT_OPTION$2 = "Quit";
|
|
1082
|
+
async function promptForEnvironment(environments) {
|
|
1083
|
+
const choices = environments.map((env2) => ({ name: env2, value: env2 }));
|
|
1084
|
+
const { selectedEnvironment } = await inquirer.prompt([
|
|
1085
|
+
{
|
|
1086
|
+
type: "list",
|
|
1087
|
+
name: "selectedEnvironment",
|
|
1088
|
+
message: "Select the environment to deploy:",
|
|
1089
|
+
choices: [...choices, { name: chalk.grey(`(${QUIT_OPTION$2})`), value: null }]
|
|
1090
|
+
}
|
|
1091
|
+
]);
|
|
1092
|
+
if (selectedEnvironment === null) {
|
|
1093
|
+
process.exit(1);
|
|
1094
|
+
}
|
|
1095
|
+
const { confirm } = await inquirer.prompt([
|
|
1096
|
+
{
|
|
1097
|
+
type: "confirm",
|
|
1098
|
+
name: "confirm",
|
|
1099
|
+
message: `Do you want to proceed with deployment to ${chalk.cyan(selectedEnvironment)}?`
|
|
1100
|
+
}
|
|
1101
|
+
]);
|
|
1102
|
+
if (!confirm) {
|
|
1103
|
+
process.exit(1);
|
|
1104
|
+
}
|
|
1105
|
+
return selectedEnvironment;
|
|
1106
|
+
}
|
|
1033
1107
|
async function upload(ctx, project, token, maxProjectFileSize) {
|
|
1034
1108
|
const cloudApi = await cloudApiFactory(ctx, token);
|
|
1035
1109
|
try {
|
|
@@ -1112,7 +1186,7 @@ async function getProject(ctx) {
|
|
|
1112
1186
|
const { project } = await retrieve();
|
|
1113
1187
|
if (!project) {
|
|
1114
1188
|
try {
|
|
1115
|
-
return await action$
|
|
1189
|
+
return await action$6(ctx);
|
|
1116
1190
|
} catch (e) {
|
|
1117
1191
|
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
1118
1192
|
ctx.logger.debug(e);
|
|
@@ -1133,7 +1207,26 @@ async function getConfig({
|
|
|
1133
1207
|
return null;
|
|
1134
1208
|
}
|
|
1135
1209
|
}
|
|
1136
|
-
|
|
1210
|
+
function validateEnvironment(ctx, environment, environments) {
|
|
1211
|
+
if (!environments.includes(environment)) {
|
|
1212
|
+
ctx.logger.error(`Environment ${environment} does not exist.`);
|
|
1213
|
+
process.exit(1);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
async function getTargetEnvironment(ctx, opts, project, environments) {
|
|
1217
|
+
if (opts.env) {
|
|
1218
|
+
validateEnvironment(ctx, opts.env, environments);
|
|
1219
|
+
return opts.env;
|
|
1220
|
+
}
|
|
1221
|
+
if (project.targetEnvironment) {
|
|
1222
|
+
return project.targetEnvironment;
|
|
1223
|
+
}
|
|
1224
|
+
if (environments.length > 1) {
|
|
1225
|
+
return promptForEnvironment(environments);
|
|
1226
|
+
}
|
|
1227
|
+
return environments[0];
|
|
1228
|
+
}
|
|
1229
|
+
const action$5 = async (ctx, opts) => {
|
|
1137
1230
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1138
1231
|
const token = await getValidToken(ctx, promptLogin);
|
|
1139
1232
|
if (!token) {
|
|
@@ -1144,11 +1237,13 @@ const action$3 = async (ctx) => {
|
|
|
1144
1237
|
return;
|
|
1145
1238
|
}
|
|
1146
1239
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1240
|
+
let environments;
|
|
1147
1241
|
try {
|
|
1148
1242
|
const {
|
|
1149
1243
|
data: { data: projectData, metadata }
|
|
1150
1244
|
} = await cloudApiService.getProject({ name: project.name });
|
|
1151
1245
|
const isProjectSuspended = projectData.suspendedAt;
|
|
1246
|
+
environments = projectData.environments;
|
|
1152
1247
|
if (isProjectSuspended) {
|
|
1153
1248
|
ctx.logger.log(
|
|
1154
1249
|
"\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
|
|
@@ -1195,11 +1290,15 @@ Please link your local project to an existing Strapi Cloud project using the ${c
|
|
|
1195
1290
|
);
|
|
1196
1291
|
maxSize = 1e8;
|
|
1197
1292
|
}
|
|
1293
|
+
project.targetEnvironment = await getTargetEnvironment(ctx, opts, project, environments);
|
|
1198
1294
|
const buildId = await upload(ctx, project, token, maxSize);
|
|
1199
1295
|
if (!buildId) {
|
|
1200
1296
|
return;
|
|
1201
1297
|
}
|
|
1202
1298
|
try {
|
|
1299
|
+
ctx.logger.log(
|
|
1300
|
+
`🚀 Deploying project to ${chalk.cyan(project.targetEnvironment ?? `production`)} environment...`
|
|
1301
|
+
);
|
|
1203
1302
|
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
|
|
1204
1303
|
await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
|
|
1205
1304
|
ctx.logger.log(
|
|
@@ -1244,17 +1343,16 @@ const runAction = (name2, action2) => (...args) => {
|
|
|
1244
1343
|
process.exit(1);
|
|
1245
1344
|
});
|
|
1246
1345
|
};
|
|
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$
|
|
1346
|
+
const command$7 = ({ ctx }) => {
|
|
1347
|
+
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("-e, --env <name>", "Specify the environment to deploy").action((opts) => runAction("deploy", action$5)(ctx, opts));
|
|
1249
1348
|
};
|
|
1250
1349
|
const deployProject = {
|
|
1251
1350
|
name: "deploy-project",
|
|
1252
1351
|
description: "Deploy a Strapi Cloud project",
|
|
1253
|
-
action: action$
|
|
1254
|
-
command: command$
|
|
1352
|
+
action: action$5,
|
|
1353
|
+
command: command$7
|
|
1255
1354
|
};
|
|
1256
|
-
|
|
1257
|
-
async function getExistingConfig(ctx) {
|
|
1355
|
+
async function getLocalConfig(ctx) {
|
|
1258
1356
|
try {
|
|
1259
1357
|
return await retrieve();
|
|
1260
1358
|
} catch (e) {
|
|
@@ -1263,6 +1361,21 @@ async function getExistingConfig(ctx) {
|
|
|
1263
1361
|
return null;
|
|
1264
1362
|
}
|
|
1265
1363
|
}
|
|
1364
|
+
async function getLocalProject(ctx) {
|
|
1365
|
+
const localConfig = await getLocalConfig(ctx);
|
|
1366
|
+
if (!localConfig || !localConfig.project) {
|
|
1367
|
+
ctx.logger.warn(
|
|
1368
|
+
`
|
|
1369
|
+
We couldn't find a valid local project config.
|
|
1370
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1371
|
+
"link"
|
|
1372
|
+
)} command.`
|
|
1373
|
+
);
|
|
1374
|
+
process.exit(1);
|
|
1375
|
+
}
|
|
1376
|
+
return localConfig.project;
|
|
1377
|
+
}
|
|
1378
|
+
const QUIT_OPTION$1 = "Quit";
|
|
1266
1379
|
async function promptForRelink(ctx, cloudApiService, existingConfig) {
|
|
1267
1380
|
if (existingConfig && existingConfig.project) {
|
|
1268
1381
|
const { shouldRelink } = await inquirer.prompt([
|
|
@@ -1292,7 +1405,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1292
1405
|
} = await cloudApiService.listLinkProjects();
|
|
1293
1406
|
spinner.succeed();
|
|
1294
1407
|
if (!Array.isArray(projectList)) {
|
|
1295
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1408
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1296
1409
|
return null;
|
|
1297
1410
|
}
|
|
1298
1411
|
const projects = projectList.filter(
|
|
@@ -1304,7 +1417,7 @@ async function getProjectsList(ctx, cloudApiService, existingConfig) {
|
|
|
1304
1417
|
};
|
|
1305
1418
|
});
|
|
1306
1419
|
if (projects.length === 0) {
|
|
1307
|
-
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
|
|
1420
|
+
ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud.");
|
|
1308
1421
|
return null;
|
|
1309
1422
|
}
|
|
1310
1423
|
return projects;
|
|
@@ -1322,7 +1435,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1322
1435
|
type: "list",
|
|
1323
1436
|
name: "linkProject",
|
|
1324
1437
|
message: "Which project do you want to link?",
|
|
1325
|
-
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1438
|
+
choices: [...projects, { name: chalk.grey(`(${QUIT_OPTION$1})`), value: null }]
|
|
1326
1439
|
}
|
|
1327
1440
|
]);
|
|
1328
1441
|
if (!answer.linkProject) {
|
|
@@ -1335,7 +1448,7 @@ async function getUserSelection(ctx, projects) {
|
|
|
1335
1448
|
return null;
|
|
1336
1449
|
}
|
|
1337
1450
|
}
|
|
1338
|
-
const action$
|
|
1451
|
+
const action$4 = async (ctx) => {
|
|
1339
1452
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1340
1453
|
const token = await getValidToken(ctx, promptLogin);
|
|
1341
1454
|
const { logger } = ctx;
|
|
@@ -1343,7 +1456,7 @@ const action$2 = async (ctx) => {
|
|
|
1343
1456
|
return;
|
|
1344
1457
|
}
|
|
1345
1458
|
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1346
|
-
const existingConfig = await
|
|
1459
|
+
const existingConfig = await getLocalConfig(ctx);
|
|
1347
1460
|
const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
|
|
1348
1461
|
if (!shouldRelink) {
|
|
1349
1462
|
return;
|
|
@@ -1378,7 +1491,9 @@ const action$2 = async (ctx) => {
|
|
|
1378
1491
|
return;
|
|
1379
1492
|
}
|
|
1380
1493
|
await save({ project: answer.linkProject });
|
|
1381
|
-
logger.log(
|
|
1494
|
+
logger.log(
|
|
1495
|
+
` You have successfully linked your project to ${chalk.cyan(answer.linkProject.displayName)}. You are now able to deploy your project.`
|
|
1496
|
+
);
|
|
1382
1497
|
await trackEvent(ctx, cloudApiService, "didLinkProject", {
|
|
1383
1498
|
projectInternalName: answer.linkProject
|
|
1384
1499
|
});
|
|
@@ -1390,16 +1505,16 @@ const action$2 = async (ctx) => {
|
|
|
1390
1505
|
});
|
|
1391
1506
|
}
|
|
1392
1507
|
};
|
|
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$
|
|
1508
|
+
const command$6 = ({ command: command2, ctx }) => {
|
|
1509
|
+
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
1510
|
};
|
|
1396
1511
|
const link = {
|
|
1397
1512
|
name: "link-project",
|
|
1398
1513
|
description: "Link a local directory to a Strapi Cloud project",
|
|
1399
|
-
action: action$
|
|
1400
|
-
command: command$
|
|
1514
|
+
action: action$4,
|
|
1515
|
+
command: command$6
|
|
1401
1516
|
};
|
|
1402
|
-
const command$
|
|
1517
|
+
const command$5 = ({ ctx }) => {
|
|
1403
1518
|
return createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
|
|
1404
1519
|
"after",
|
|
1405
1520
|
"\nAfter running this command, you will be prompted to enter your authentication information."
|
|
@@ -1409,10 +1524,10 @@ const login = {
|
|
|
1409
1524
|
name: "login",
|
|
1410
1525
|
description: "Strapi Cloud Login",
|
|
1411
1526
|
action: loginAction,
|
|
1412
|
-
command: command$
|
|
1527
|
+
command: command$5
|
|
1413
1528
|
};
|
|
1414
1529
|
const openModule = import("open");
|
|
1415
|
-
const action$
|
|
1530
|
+
const action$3 = async (ctx) => {
|
|
1416
1531
|
const { logger } = ctx;
|
|
1417
1532
|
const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
|
|
1418
1533
|
const token = await retrieveToken();
|
|
@@ -1444,25 +1559,25 @@ const action$1 = async (ctx) => {
|
|
|
1444
1559
|
}
|
|
1445
1560
|
await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
|
|
1446
1561
|
};
|
|
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$
|
|
1562
|
+
const command$4 = ({ ctx }) => {
|
|
1563
|
+
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
1564
|
};
|
|
1450
1565
|
const logout = {
|
|
1451
1566
|
name: "logout",
|
|
1452
1567
|
description: "Strapi Cloud Logout",
|
|
1453
|
-
action: action$
|
|
1454
|
-
command: command$
|
|
1568
|
+
action: action$3,
|
|
1569
|
+
command: command$4
|
|
1455
1570
|
};
|
|
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$
|
|
1571
|
+
const command$3 = ({ ctx }) => {
|
|
1572
|
+
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
1573
|
};
|
|
1459
1574
|
const createProject = {
|
|
1460
1575
|
name: "create-project",
|
|
1461
1576
|
description: "Create a new project",
|
|
1462
|
-
action: action$
|
|
1463
|
-
command: command$
|
|
1577
|
+
action: action$6,
|
|
1578
|
+
command: command$3
|
|
1464
1579
|
};
|
|
1465
|
-
const action = async (ctx) => {
|
|
1580
|
+
const action$2 = async (ctx) => {
|
|
1466
1581
|
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1467
1582
|
const token = await getValidToken(ctx, promptLogin);
|
|
1468
1583
|
const { logger } = ctx;
|
|
@@ -1482,12 +1597,194 @@ const action = async (ctx) => {
|
|
|
1482
1597
|
spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
|
|
1483
1598
|
}
|
|
1484
1599
|
};
|
|
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));
|
|
1600
|
+
const command$2 = ({ command: command2, ctx }) => {
|
|
1601
|
+
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
1602
|
};
|
|
1488
1603
|
const listProjects = {
|
|
1489
1604
|
name: "list-projects",
|
|
1490
1605
|
description: "List Strapi Cloud projects",
|
|
1606
|
+
action: action$2,
|
|
1607
|
+
command: command$2
|
|
1608
|
+
};
|
|
1609
|
+
const action$1 = async (ctx) => {
|
|
1610
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1611
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1612
|
+
const { logger } = ctx;
|
|
1613
|
+
if (!token) {
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
const project = await getLocalProject(ctx);
|
|
1617
|
+
if (!project) {
|
|
1618
|
+
ctx.logger.debug(`No valid local project configuration was found.`);
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1622
|
+
const spinner = logger.spinner("Fetching environments...").start();
|
|
1623
|
+
await trackEvent(ctx, cloudApiService, "willListEnvironment", {
|
|
1624
|
+
projectInternalName: project.name
|
|
1625
|
+
});
|
|
1626
|
+
try {
|
|
1627
|
+
const {
|
|
1628
|
+
data: { data: environmentsList }
|
|
1629
|
+
} = await cloudApiService.listEnvironments({ name: project.name });
|
|
1630
|
+
spinner.succeed();
|
|
1631
|
+
logger.log(environmentsList);
|
|
1632
|
+
await trackEvent(ctx, cloudApiService, "didListEnvironment", {
|
|
1633
|
+
projectInternalName: project.name
|
|
1634
|
+
});
|
|
1635
|
+
} catch (e) {
|
|
1636
|
+
if (e.response && e.response.status === 404) {
|
|
1637
|
+
spinner.succeed();
|
|
1638
|
+
logger.warn(
|
|
1639
|
+
`
|
|
1640
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1641
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1642
|
+
"link"
|
|
1643
|
+
)} command`
|
|
1644
|
+
);
|
|
1645
|
+
} else {
|
|
1646
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1647
|
+
logger.debug("Failed to list environments", e);
|
|
1648
|
+
}
|
|
1649
|
+
await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
|
|
1650
|
+
projectInternalName: project.name
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
function defineCloudNamespace(command2, ctx) {
|
|
1655
|
+
const cloud = command2.command("cloud").description("Manage Strapi Cloud projects");
|
|
1656
|
+
cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action$1)(ctx));
|
|
1657
|
+
return cloud;
|
|
1658
|
+
}
|
|
1659
|
+
let environmentCmd = null;
|
|
1660
|
+
const initializeEnvironmentCommand = (command2, ctx) => {
|
|
1661
|
+
if (!environmentCmd) {
|
|
1662
|
+
const cloud = defineCloudNamespace(command2, ctx);
|
|
1663
|
+
environmentCmd = cloud.command("environment").description("Manage environments");
|
|
1664
|
+
}
|
|
1665
|
+
return environmentCmd;
|
|
1666
|
+
};
|
|
1667
|
+
const command$1 = ({ command: command2, ctx }) => {
|
|
1668
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1669
|
+
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));
|
|
1670
|
+
};
|
|
1671
|
+
const listEnvironments = {
|
|
1672
|
+
name: "list-environments",
|
|
1673
|
+
description: "List Strapi Cloud environments",
|
|
1674
|
+
action: action$1,
|
|
1675
|
+
command: command$1
|
|
1676
|
+
};
|
|
1677
|
+
const QUIT_OPTION = "Quit";
|
|
1678
|
+
const action = async (ctx) => {
|
|
1679
|
+
const { getValidToken } = await tokenServiceFactory(ctx);
|
|
1680
|
+
const token = await getValidToken(ctx, promptLogin);
|
|
1681
|
+
const { logger } = ctx;
|
|
1682
|
+
if (!token) {
|
|
1683
|
+
return;
|
|
1684
|
+
}
|
|
1685
|
+
const project = await getLocalProject(ctx);
|
|
1686
|
+
if (!project) {
|
|
1687
|
+
logger.debug(`No valid local project configuration was found.`);
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
const cloudApiService = await cloudApiFactory(ctx, token);
|
|
1691
|
+
const environments = await getEnvironmentsList(ctx, cloudApiService, project);
|
|
1692
|
+
if (!environments) {
|
|
1693
|
+
logger.debug(`Fetching environments failed.`);
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
if (environments.length === 0) {
|
|
1697
|
+
logger.log(
|
|
1698
|
+
`The only available environment is already linked. You can add a new one from your project settings on the Strapi Cloud dashboard.`
|
|
1699
|
+
);
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
const answer = await promptUserForEnvironment(ctx, environments);
|
|
1703
|
+
if (!answer) {
|
|
1704
|
+
return;
|
|
1705
|
+
}
|
|
1706
|
+
await trackEvent(ctx, cloudApiService, "willLinkEnvironment", {
|
|
1707
|
+
projectName: project.name,
|
|
1708
|
+
environmentName: answer.targetEnvironment
|
|
1709
|
+
});
|
|
1710
|
+
try {
|
|
1711
|
+
await patch({ project: { targetEnvironment: answer.targetEnvironment } });
|
|
1712
|
+
} catch (e) {
|
|
1713
|
+
await trackEvent(ctx, cloudApiService, "didNotLinkEnvironment", {
|
|
1714
|
+
projectName: project.name,
|
|
1715
|
+
environmentName: answer.targetEnvironment
|
|
1716
|
+
});
|
|
1717
|
+
logger.debug("Failed to link environment", e);
|
|
1718
|
+
logger.error(
|
|
1719
|
+
"Failed to link the environment. If this issue persists, try re-linking your project or contact support."
|
|
1720
|
+
);
|
|
1721
|
+
process.exit(1);
|
|
1722
|
+
}
|
|
1723
|
+
logger.log(
|
|
1724
|
+
` You have successfully linked your project to ${chalk.cyan(answer.targetEnvironment)}, on ${chalk.cyan(project.displayName)}. You are now able to deploy your project.`
|
|
1725
|
+
);
|
|
1726
|
+
await trackEvent(ctx, cloudApiService, "didLinkEnvironment", {
|
|
1727
|
+
projectName: project.name,
|
|
1728
|
+
environmentName: answer.targetEnvironment
|
|
1729
|
+
});
|
|
1730
|
+
};
|
|
1731
|
+
async function promptUserForEnvironment(ctx, environments) {
|
|
1732
|
+
const { logger } = ctx;
|
|
1733
|
+
try {
|
|
1734
|
+
const answer = await inquirer.prompt([
|
|
1735
|
+
{
|
|
1736
|
+
type: "list",
|
|
1737
|
+
name: "targetEnvironment",
|
|
1738
|
+
message: "Which environment do you want to link?",
|
|
1739
|
+
choices: [...environments, { name: chalk.grey(`(${QUIT_OPTION})`), value: null }]
|
|
1740
|
+
}
|
|
1741
|
+
]);
|
|
1742
|
+
if (!answer.targetEnvironment) {
|
|
1743
|
+
return null;
|
|
1744
|
+
}
|
|
1745
|
+
return answer;
|
|
1746
|
+
} catch (e) {
|
|
1747
|
+
logger.debug("Failed to get user input", e);
|
|
1748
|
+
logger.error("An error occurred while trying to get your environment selection.");
|
|
1749
|
+
return null;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
async function getEnvironmentsList(ctx, cloudApiService, project) {
|
|
1753
|
+
const spinner = ctx.logger.spinner("Fetching environments...\n").start();
|
|
1754
|
+
try {
|
|
1755
|
+
const {
|
|
1756
|
+
data: { data: environmentsList }
|
|
1757
|
+
} = await cloudApiService.listLinkEnvironments({ name: project.name });
|
|
1758
|
+
if (!Array.isArray(environmentsList) || environmentsList.length === 0) {
|
|
1759
|
+
throw new Error("Environments not found in server response");
|
|
1760
|
+
}
|
|
1761
|
+
spinner.succeed();
|
|
1762
|
+
return environmentsList.filter(
|
|
1763
|
+
(environment) => environment.name !== project.targetEnvironment
|
|
1764
|
+
);
|
|
1765
|
+
} catch (e) {
|
|
1766
|
+
if (e.response && e.response.status === 404) {
|
|
1767
|
+
spinner.succeed();
|
|
1768
|
+
ctx.logger.warn(
|
|
1769
|
+
`
|
|
1770
|
+
The project associated with this folder does not exist in Strapi Cloud.
|
|
1771
|
+
Please link your local project to an existing Strapi Cloud project using the ${chalk.cyan(
|
|
1772
|
+
"link"
|
|
1773
|
+
)} command.`
|
|
1774
|
+
);
|
|
1775
|
+
} else {
|
|
1776
|
+
spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
|
|
1777
|
+
ctx.logger.debug("Failed to list environments", e);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
const command = ({ command: command2, ctx }) => {
|
|
1782
|
+
const environmentCmd2 = initializeEnvironmentCommand(command2, ctx);
|
|
1783
|
+
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));
|
|
1784
|
+
};
|
|
1785
|
+
const linkEnvironment = {
|
|
1786
|
+
name: "link-environment",
|
|
1787
|
+
description: "Link Strapi Cloud environment to a local project",
|
|
1491
1788
|
action,
|
|
1492
1789
|
command
|
|
1493
1790
|
};
|
|
@@ -1497,11 +1794,21 @@ const cli = {
|
|
|
1497
1794
|
login,
|
|
1498
1795
|
logout,
|
|
1499
1796
|
createProject,
|
|
1500
|
-
|
|
1797
|
+
linkEnvironment,
|
|
1798
|
+
listProjects,
|
|
1799
|
+
listEnvironments
|
|
1501
1800
|
};
|
|
1502
|
-
const cloudCommands = [
|
|
1801
|
+
const cloudCommands = [
|
|
1802
|
+
deployProject,
|
|
1803
|
+
link,
|
|
1804
|
+
login,
|
|
1805
|
+
logout,
|
|
1806
|
+
linkEnvironment,
|
|
1807
|
+
listProjects,
|
|
1808
|
+
listEnvironments
|
|
1809
|
+
];
|
|
1503
1810
|
async function initCloudCLIConfig() {
|
|
1504
|
-
const localConfig = await getLocalConfig();
|
|
1811
|
+
const localConfig = await getLocalConfig$1();
|
|
1505
1812
|
if (!localConfig.deviceId) {
|
|
1506
1813
|
localConfig.deviceId = crypto$1.randomUUID();
|
|
1507
1814
|
}
|