@strapi/cloud-cli 0.0.0-experimental.254a2c362362c7aeaa3805bc097faf2634b76414 → 0.1.0
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/LICENSE +1 -1
- package/package.json +8 -54
- package/bin/index.js +0 -7
- package/dist/bin.d.ts +0 -5
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -172
- package/dist/bin.js.map +0 -1
- package/dist/config/api.d.ts +0 -4
- package/dist/config/api.d.ts.map +0 -1
- package/dist/config/local.d.ts +0 -8
- package/dist/config/local.d.ts.map +0 -1
- package/dist/create-project/action.d.ts +0 -4
- package/dist/create-project/action.d.ts.map +0 -1
- package/dist/create-project/index.d.ts +0 -9
- package/dist/create-project/index.d.ts.map +0 -1
- package/dist/deploy-project/action.d.ts +0 -4
- package/dist/deploy-project/action.d.ts.map +0 -1
- package/dist/deploy-project/command.d.ts +0 -7
- package/dist/deploy-project/command.d.ts.map +0 -1
- package/dist/deploy-project/index.d.ts +0 -11
- package/dist/deploy-project/index.d.ts.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1004
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -948
- package/dist/index.mjs.map +0 -1
- package/dist/login/action.d.ts +0 -4
- package/dist/login/action.d.ts.map +0 -1
- package/dist/login/command.d.ts +0 -7
- package/dist/login/command.d.ts.map +0 -1
- package/dist/login/index.d.ts +0 -11
- package/dist/login/index.d.ts.map +0 -1
- package/dist/logout/action.d.ts +0 -4
- package/dist/logout/action.d.ts.map +0 -1
- package/dist/logout/command.d.ts +0 -7
- package/dist/logout/command.d.ts.map +0 -1
- package/dist/logout/index.d.ts +0 -11
- package/dist/logout/index.d.ts.map +0 -1
- package/dist/services/build-logs.d.ts +0 -4
- package/dist/services/build-logs.d.ts.map +0 -1
- package/dist/services/cli-api.d.ts +0 -37
- package/dist/services/cli-api.d.ts.map +0 -1
- package/dist/services/index.d.ts +0 -5
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/logger.d.ts +0 -22
- package/dist/services/logger.d.ts.map +0 -1
- package/dist/services/notification.d.ts +0 -3
- package/dist/services/notification.d.ts.map +0 -1
- package/dist/services/strapi-info-save.d.ts +0 -15
- package/dist/services/strapi-info-save.d.ts.map +0 -1
- package/dist/services/token.d.ts +0 -12
- package/dist/services/token.d.ts.map +0 -1
- package/dist/types.d.ts +0 -33
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/compress-files.d.ts +0 -4
- package/dist/utils/compress-files.d.ts.map +0 -1
- package/dist/utils/helpers.d.ts +0 -3
- package/dist/utils/helpers.d.ts.map +0 -1
- package/dist/utils/pkg.d.ts +0 -121
- package/dist/utils/pkg.d.ts.map +0 -1
- package/dist/utils/tests/compress-files.test.d.ts +0 -2
- package/dist/utils/tests/compress-files.test.d.ts.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,948 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import fs__default from "fs";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import path__default from "path";
|
|
5
|
-
import axios, { AxiosError } from "axios";
|
|
6
|
-
import * as crypto from "node:crypto";
|
|
7
|
-
import { env } from "@strapi/utils";
|
|
8
|
-
import * as tar from "tar";
|
|
9
|
-
import { minimatch } from "minimatch";
|
|
10
|
-
import inquirer from "inquirer";
|
|
11
|
-
import { defaults, has } from "lodash/fp";
|
|
12
|
-
import jwksClient from "jwks-rsa";
|
|
13
|
-
import jwt from "jsonwebtoken";
|
|
14
|
-
import os from "os";
|
|
15
|
-
import XDGAppPaths from "xdg-app-paths";
|
|
16
|
-
import chalk from "chalk";
|
|
17
|
-
import ora from "ora";
|
|
18
|
-
import * as cliProgress from "cli-progress";
|
|
19
|
-
import EventSource from "eventsource";
|
|
20
|
-
import fs$1 from "fs/promises";
|
|
21
|
-
import pkgUp from "pkg-up";
|
|
22
|
-
import * as yup from "yup";
|
|
23
|
-
const apiConfig = {
|
|
24
|
-
apiBaseUrl: env("STRAPI_CLI_CLOUD_API", "https://cli.cloud.strapi.io")
|
|
25
|
-
};
|
|
26
|
-
const IGNORED_PATTERNS = [
|
|
27
|
-
"**/.git/**",
|
|
28
|
-
"**/node_modules/**",
|
|
29
|
-
"**/build/**",
|
|
30
|
-
"**/dist/**",
|
|
31
|
-
"**/.cache/**",
|
|
32
|
-
"**/.circleci/**",
|
|
33
|
-
"**/.github/**",
|
|
34
|
-
"**/.gitignore",
|
|
35
|
-
"**/.gitkeep",
|
|
36
|
-
"**/.gitlab-ci.yml",
|
|
37
|
-
"**/.idea/**",
|
|
38
|
-
"**/.vscode/**"
|
|
39
|
-
];
|
|
40
|
-
const getFiles = (dirPath, ignorePatterns = [], arrayOfFiles = [], subfolder = "") => {
|
|
41
|
-
const entries = fs.readdirSync(path.join(dirPath, subfolder));
|
|
42
|
-
entries.forEach((entry) => {
|
|
43
|
-
const entryPathFromRoot = path.join(subfolder, entry);
|
|
44
|
-
const entryPath = path.relative(dirPath, entryPathFromRoot);
|
|
45
|
-
const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
|
|
46
|
-
if (isIgnored) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (fs.statSync(entryPath).isDirectory()) {
|
|
50
|
-
getFiles(dirPath, ignorePatterns, arrayOfFiles, entryPathFromRoot);
|
|
51
|
-
} else {
|
|
52
|
-
arrayOfFiles.push(entryPath);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return arrayOfFiles;
|
|
56
|
-
};
|
|
57
|
-
const isIgnoredFile = (folderPath, file, ignorePatterns) => {
|
|
58
|
-
ignorePatterns.push(...IGNORED_PATTERNS);
|
|
59
|
-
const relativeFilePath = path.join(folderPath, file);
|
|
60
|
-
let isIgnored = false;
|
|
61
|
-
for (const pattern of ignorePatterns) {
|
|
62
|
-
if (pattern.startsWith("!")) {
|
|
63
|
-
if (minimatch(relativeFilePath, pattern.slice(1), { matchBase: true, dot: true })) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
} else if (minimatch(relativeFilePath, pattern, { matchBase: true, dot: true })) {
|
|
67
|
-
if (path.basename(file) !== ".gitkeep") {
|
|
68
|
-
isIgnored = true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return isIgnored;
|
|
73
|
-
};
|
|
74
|
-
const readGitignore = (folderPath) => {
|
|
75
|
-
const gitignorePath = path.resolve(folderPath, ".gitignore");
|
|
76
|
-
if (!fs.existsSync(gitignorePath))
|
|
77
|
-
return [];
|
|
78
|
-
const gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
|
|
79
|
-
return gitignoreContent.split("\n").filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
|
|
80
|
-
};
|
|
81
|
-
const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
|
|
82
|
-
const ignorePatterns = readGitignore(folderToCompress);
|
|
83
|
-
const filesToCompress = getFiles(folderToCompress, ignorePatterns);
|
|
84
|
-
return tar.c(
|
|
85
|
-
{
|
|
86
|
-
gzip: true,
|
|
87
|
-
file: path.resolve(storagePath, filename)
|
|
88
|
-
},
|
|
89
|
-
filesToCompress
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
const VERSION = "v1";
|
|
93
|
-
function cloudApiFactory(token) {
|
|
94
|
-
const axiosCloudAPI = axios.create({
|
|
95
|
-
baseURL: `${apiConfig.apiBaseUrl}/${VERSION}`,
|
|
96
|
-
headers: {
|
|
97
|
-
"Content-Type": "application/json"
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
if (token) {
|
|
101
|
-
axiosCloudAPI.defaults.headers.Authorization = `Bearer ${token}`;
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
deploy({ filePath, project }, { onUploadProgress }) {
|
|
105
|
-
return axiosCloudAPI.post(
|
|
106
|
-
`/deploy/${project.name}`,
|
|
107
|
-
{ file: fs.createReadStream(filePath) },
|
|
108
|
-
{
|
|
109
|
-
headers: {
|
|
110
|
-
"Content-Type": "multipart/form-data"
|
|
111
|
-
},
|
|
112
|
-
onUploadProgress
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
},
|
|
116
|
-
async createProject({ name, nodeVersion, region, plan }) {
|
|
117
|
-
const response = await axiosCloudAPI.post("/project", {
|
|
118
|
-
projectName: name,
|
|
119
|
-
region,
|
|
120
|
-
nodeVersion,
|
|
121
|
-
plan
|
|
122
|
-
});
|
|
123
|
-
return {
|
|
124
|
-
data: {
|
|
125
|
-
id: response.data.id,
|
|
126
|
-
name: response.data.name,
|
|
127
|
-
nodeVersion: response.data.nodeVersion,
|
|
128
|
-
region: response.data.region
|
|
129
|
-
},
|
|
130
|
-
status: response.status
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
getUserInfo() {
|
|
134
|
-
return axiosCloudAPI.get("/user");
|
|
135
|
-
},
|
|
136
|
-
config() {
|
|
137
|
-
return axiosCloudAPI.get("/config");
|
|
138
|
-
},
|
|
139
|
-
listProjects() {
|
|
140
|
-
return axiosCloudAPI.get("/projects");
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
|
|
145
|
-
function save(data, { directoryPath } = {}) {
|
|
146
|
-
const storedData = { ...retrieve(), ...data };
|
|
147
|
-
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
148
|
-
if (!fs__default.existsSync(path__default.dirname(pathToFile))) {
|
|
149
|
-
fs__default.mkdirSync(path__default.dirname(pathToFile), { recursive: true });
|
|
150
|
-
}
|
|
151
|
-
fs__default.writeFileSync(pathToFile, JSON.stringify(storedData), "utf8");
|
|
152
|
-
}
|
|
153
|
-
function retrieve({ directoryPath } = {}) {
|
|
154
|
-
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
155
|
-
if (!fs__default.existsSync(pathToFile)) {
|
|
156
|
-
return {};
|
|
157
|
-
}
|
|
158
|
-
return JSON.parse(fs__default.readFileSync(pathToFile, "utf8"));
|
|
159
|
-
}
|
|
160
|
-
function erase({ directoryPath } = {}) {
|
|
161
|
-
const pathToFile = path__default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
|
|
162
|
-
if (fs__default.existsSync(pathToFile)) {
|
|
163
|
-
fs__default.unlinkSync(pathToFile);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
167
|
-
__proto__: null,
|
|
168
|
-
LOCAL_SAVE_FILENAME,
|
|
169
|
-
erase,
|
|
170
|
-
retrieve,
|
|
171
|
-
save
|
|
172
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
173
|
-
const APP_FOLDER_NAME = "com.strapi.cli";
|
|
174
|
-
const CONFIG_FILENAME = "config.json";
|
|
175
|
-
function checkDirectoryExists(directoryPath) {
|
|
176
|
-
try {
|
|
177
|
-
return fs__default.lstatSync(directoryPath).isDirectory();
|
|
178
|
-
} catch (e) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function getTmpStoragePath() {
|
|
183
|
-
const storagePath = path__default.join(os.tmpdir(), APP_FOLDER_NAME);
|
|
184
|
-
if (!checkDirectoryExists(storagePath)) {
|
|
185
|
-
fs__default.mkdirSync(storagePath, { recursive: true });
|
|
186
|
-
}
|
|
187
|
-
return storagePath;
|
|
188
|
-
}
|
|
189
|
-
function getConfigPath() {
|
|
190
|
-
const configDirs = XDGAppPaths(APP_FOLDER_NAME).configDirs();
|
|
191
|
-
const configPath = configDirs.find(checkDirectoryExists);
|
|
192
|
-
if (!configPath) {
|
|
193
|
-
fs__default.mkdirSync(configDirs[0], { recursive: true });
|
|
194
|
-
return configDirs[0];
|
|
195
|
-
}
|
|
196
|
-
return configPath;
|
|
197
|
-
}
|
|
198
|
-
function getLocalConfig() {
|
|
199
|
-
const configPath = getConfigPath();
|
|
200
|
-
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
201
|
-
if (!fs__default.existsSync(configFilePath)) {
|
|
202
|
-
return {};
|
|
203
|
-
}
|
|
204
|
-
try {
|
|
205
|
-
return JSON.parse(fs__default.readFileSync(configFilePath, "utf8"));
|
|
206
|
-
} catch (e) {
|
|
207
|
-
return {};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function saveLocalConfig(data) {
|
|
211
|
-
const configPath = getConfigPath();
|
|
212
|
-
const configFilePath = path__default.join(configPath, CONFIG_FILENAME);
|
|
213
|
-
fs__default.writeFileSync(configFilePath, JSON.stringify(data), { encoding: "utf8", mode: 384 });
|
|
214
|
-
}
|
|
215
|
-
const cloudApiService$1 = cloudApiFactory();
|
|
216
|
-
let cliConfig;
|
|
217
|
-
function tokenServiceFactory({ logger }) {
|
|
218
|
-
function saveToken(str) {
|
|
219
|
-
const appConfig = getLocalConfig();
|
|
220
|
-
if (!appConfig) {
|
|
221
|
-
logger.error("There was a problem saving your token. Please try again.");
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
appConfig.token = str;
|
|
225
|
-
try {
|
|
226
|
-
saveLocalConfig(appConfig);
|
|
227
|
-
} catch (error) {
|
|
228
|
-
logger.debug(error);
|
|
229
|
-
logger.error("There was a problem saving your token. Please try again.");
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
async function retrieveToken() {
|
|
233
|
-
const appConfig = getLocalConfig();
|
|
234
|
-
if (appConfig.token) {
|
|
235
|
-
if (await isTokenValid(appConfig.token)) {
|
|
236
|
-
return appConfig.token;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return void 0;
|
|
240
|
-
}
|
|
241
|
-
async function validateToken(idToken, jwksUrl) {
|
|
242
|
-
const client = jwksClient({
|
|
243
|
-
jwksUri: jwksUrl
|
|
244
|
-
});
|
|
245
|
-
const getKey = (header, callback) => {
|
|
246
|
-
client.getSigningKey(header.kid, (err, key) => {
|
|
247
|
-
if (err) {
|
|
248
|
-
callback(err);
|
|
249
|
-
} else if (key) {
|
|
250
|
-
const publicKey = "publicKey" in key ? key.publicKey : key.rsaPublicKey;
|
|
251
|
-
callback(null, publicKey);
|
|
252
|
-
} else {
|
|
253
|
-
callback(new Error("Key not found"));
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
const decodedToken = jwt.decode(idToken, { complete: true });
|
|
258
|
-
if (!decodedToken) {
|
|
259
|
-
if (typeof idToken === "undefined" || idToken === "") {
|
|
260
|
-
logger.warn("You need to be logged in to use this feature. Please log in and try again.");
|
|
261
|
-
} else {
|
|
262
|
-
logger.error(
|
|
263
|
-
"There seems to be a problem with your login information. Please try logging in again."
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return new Promise((resolve, reject) => {
|
|
268
|
-
jwt.verify(idToken, getKey, (err) => {
|
|
269
|
-
if (err) {
|
|
270
|
-
reject(err);
|
|
271
|
-
} else {
|
|
272
|
-
resolve();
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
async function isTokenValid(token) {
|
|
278
|
-
try {
|
|
279
|
-
const config = await cloudApiService$1.config();
|
|
280
|
-
cliConfig = config.data;
|
|
281
|
-
if (token) {
|
|
282
|
-
await validateToken(token, cliConfig.jwksUrl);
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
return false;
|
|
286
|
-
} catch (error) {
|
|
287
|
-
logger.debug(error);
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
function eraseToken() {
|
|
292
|
-
const appConfig = getLocalConfig();
|
|
293
|
-
if (!appConfig) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
delete appConfig.token;
|
|
297
|
-
try {
|
|
298
|
-
saveLocalConfig(appConfig);
|
|
299
|
-
} catch (error) {
|
|
300
|
-
logger.debug(error);
|
|
301
|
-
logger.error(
|
|
302
|
-
"There was an issue removing your login information. Please try logging out again."
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
async function getValidToken() {
|
|
307
|
-
const token = await retrieveToken();
|
|
308
|
-
if (!token) {
|
|
309
|
-
logger.log("No token found. Please login first.");
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
if (!await isTokenValid(token)) {
|
|
313
|
-
logger.log("Unable to proceed: Token is expired or not valid. Please login again.");
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
return token;
|
|
317
|
-
}
|
|
318
|
-
return {
|
|
319
|
-
saveToken,
|
|
320
|
-
retrieveToken,
|
|
321
|
-
validateToken,
|
|
322
|
-
isTokenValid,
|
|
323
|
-
eraseToken,
|
|
324
|
-
getValidToken
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
const createLogger = (options = {}) => {
|
|
328
|
-
const { silent = false, debug = false, timestamp = true } = options;
|
|
329
|
-
const state = { errors: 0, warning: 0 };
|
|
330
|
-
return {
|
|
331
|
-
get warnings() {
|
|
332
|
-
return state.warning;
|
|
333
|
-
},
|
|
334
|
-
get errors() {
|
|
335
|
-
return state.errors;
|
|
336
|
-
},
|
|
337
|
-
debug(...args) {
|
|
338
|
-
if (silent || !debug) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
console.log(
|
|
342
|
-
chalk.cyan(`[DEBUG]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
|
|
343
|
-
...args
|
|
344
|
-
);
|
|
345
|
-
},
|
|
346
|
-
info(...args) {
|
|
347
|
-
if (silent) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
console.info(
|
|
351
|
-
chalk.blue(`[INFO]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
|
|
352
|
-
...args
|
|
353
|
-
);
|
|
354
|
-
},
|
|
355
|
-
log(...args) {
|
|
356
|
-
if (silent) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
console.info(chalk.blue(`${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`), ...args);
|
|
360
|
-
},
|
|
361
|
-
success(...args) {
|
|
362
|
-
if (silent) {
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
console.info(
|
|
366
|
-
chalk.green(`[SUCCESS]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
|
|
367
|
-
...args
|
|
368
|
-
);
|
|
369
|
-
},
|
|
370
|
-
warn(...args) {
|
|
371
|
-
state.warning += 1;
|
|
372
|
-
if (silent) {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
console.warn(
|
|
376
|
-
chalk.yellow(`[WARN]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
|
|
377
|
-
...args
|
|
378
|
-
);
|
|
379
|
-
},
|
|
380
|
-
error(...args) {
|
|
381
|
-
state.errors += 1;
|
|
382
|
-
if (silent) {
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
console.error(
|
|
386
|
-
chalk.red(`[ERROR]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
|
|
387
|
-
...args
|
|
388
|
-
);
|
|
389
|
-
},
|
|
390
|
-
// @ts-expect-error – returning a subpart of ora is fine because the types tell us what is what.
|
|
391
|
-
spinner(text) {
|
|
392
|
-
if (silent) {
|
|
393
|
-
return {
|
|
394
|
-
succeed() {
|
|
395
|
-
return this;
|
|
396
|
-
},
|
|
397
|
-
fail() {
|
|
398
|
-
return this;
|
|
399
|
-
},
|
|
400
|
-
start() {
|
|
401
|
-
return this;
|
|
402
|
-
},
|
|
403
|
-
text: "",
|
|
404
|
-
isSpinning: false
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
return ora(text);
|
|
408
|
-
},
|
|
409
|
-
progressBar(totalSize, text) {
|
|
410
|
-
if (silent) {
|
|
411
|
-
return {
|
|
412
|
-
start() {
|
|
413
|
-
return this;
|
|
414
|
-
},
|
|
415
|
-
stop() {
|
|
416
|
-
return this;
|
|
417
|
-
},
|
|
418
|
-
update() {
|
|
419
|
-
return this;
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
const progressBar = new cliProgress.SingleBar({
|
|
424
|
-
format: `${text ? `${text} |` : ""}${chalk.green("{bar}")}| {percentage}%`,
|
|
425
|
-
barCompleteChar: "█",
|
|
426
|
-
barIncompleteChar: "░",
|
|
427
|
-
hideCursor: true,
|
|
428
|
-
forceRedraw: true
|
|
429
|
-
});
|
|
430
|
-
progressBar.start(totalSize, 0);
|
|
431
|
-
return progressBar;
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
};
|
|
435
|
-
const index$4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
436
|
-
__proto__: null,
|
|
437
|
-
cloudApiFactory,
|
|
438
|
-
createLogger,
|
|
439
|
-
local: strapiInfoSave,
|
|
440
|
-
tokenServiceFactory
|
|
441
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
442
|
-
function handleError(ctx, error) {
|
|
443
|
-
const tokenService = tokenServiceFactory(ctx);
|
|
444
|
-
const { logger } = ctx;
|
|
445
|
-
logger.debug(JSON.stringify(error));
|
|
446
|
-
if (error instanceof AxiosError) {
|
|
447
|
-
switch (error.response?.status) {
|
|
448
|
-
case 401:
|
|
449
|
-
logger.error("Your session has expired. Please log in again.");
|
|
450
|
-
tokenService.eraseToken();
|
|
451
|
-
return;
|
|
452
|
-
case 403:
|
|
453
|
-
logger.error(
|
|
454
|
-
error.response.data || "You do not have permission to create a project. Please contact support for assistance."
|
|
455
|
-
);
|
|
456
|
-
return;
|
|
457
|
-
case 400:
|
|
458
|
-
logger.error("Invalid input. Please check your inputs and try again.");
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
logger.error(
|
|
463
|
-
"We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance."
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
const action$3 = (ctx) => {
|
|
467
|
-
const { getValidToken } = tokenServiceFactory(ctx);
|
|
468
|
-
return async () => {
|
|
469
|
-
const token = await getValidToken();
|
|
470
|
-
if (!token) {
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
const cloudApi = cloudApiFactory(token);
|
|
474
|
-
const { data: config } = await cloudApi.config();
|
|
475
|
-
const { questions, defaults: defaultValues } = config.projectCreation;
|
|
476
|
-
const projectAnswersDefaulted = defaults(defaultValues);
|
|
477
|
-
const projectAnswers = await inquirer.prompt(questions);
|
|
478
|
-
const projectInput = projectAnswersDefaulted(projectAnswers);
|
|
479
|
-
try {
|
|
480
|
-
const { data } = await cloudApi.createProject(projectInput);
|
|
481
|
-
save({ project: data });
|
|
482
|
-
return data;
|
|
483
|
-
} catch (error) {
|
|
484
|
-
handleError(ctx, error);
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
};
|
|
488
|
-
const CONN_TIMEOUT = 5 * 60 * 1e3;
|
|
489
|
-
function notificationServiceFactory({ logger }) {
|
|
490
|
-
return (url, token) => {
|
|
491
|
-
const es = new EventSource(url, {
|
|
492
|
-
headers: {
|
|
493
|
-
Authorization: `Bearer ${token}`
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
let timeoutId;
|
|
497
|
-
const resetTimeout = () => {
|
|
498
|
-
clearTimeout(timeoutId);
|
|
499
|
-
timeoutId = setTimeout(() => {
|
|
500
|
-
logger.log(
|
|
501
|
-
"We were unable to connect to the server at this time. This could be due to a temporary issue. Please try again in a moment."
|
|
502
|
-
);
|
|
503
|
-
es.close();
|
|
504
|
-
}, CONN_TIMEOUT);
|
|
505
|
-
};
|
|
506
|
-
es.onopen = resetTimeout;
|
|
507
|
-
es.onmessage = (event) => {
|
|
508
|
-
resetTimeout();
|
|
509
|
-
const data = JSON.parse(event.data);
|
|
510
|
-
if (data.message) {
|
|
511
|
-
logger.log(data.message);
|
|
512
|
-
}
|
|
513
|
-
if (data.event === "deploymentFinished" || data.event === "deploymentFailed") {
|
|
514
|
-
es.close();
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
yup.object({
|
|
520
|
-
name: yup.string().required(),
|
|
521
|
-
exports: yup.lazy(
|
|
522
|
-
(value) => yup.object(
|
|
523
|
-
typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
|
|
524
|
-
if (typeof value2 === "object") {
|
|
525
|
-
acc[key] = yup.object({
|
|
526
|
-
types: yup.string().optional(),
|
|
527
|
-
source: yup.string().required(),
|
|
528
|
-
module: yup.string().optional(),
|
|
529
|
-
import: yup.string().required(),
|
|
530
|
-
require: yup.string().required(),
|
|
531
|
-
default: yup.string().required()
|
|
532
|
-
}).noUnknown(true);
|
|
533
|
-
} else {
|
|
534
|
-
acc[key] = yup.string().matches(/^\.\/.*\.json$/).required();
|
|
535
|
-
}
|
|
536
|
-
return acc;
|
|
537
|
-
}, {}) : void 0
|
|
538
|
-
).optional()
|
|
539
|
-
)
|
|
540
|
-
});
|
|
541
|
-
const loadPkg = async ({ cwd, logger }) => {
|
|
542
|
-
const pkgPath = await pkgUp({ cwd });
|
|
543
|
-
if (!pkgPath) {
|
|
544
|
-
throw new Error("Could not find a package.json in the current directory");
|
|
545
|
-
}
|
|
546
|
-
const buffer = await fs$1.readFile(pkgPath);
|
|
547
|
-
const pkg = JSON.parse(buffer.toString());
|
|
548
|
-
logger.debug("Loaded package.json:", os.EOL, pkg);
|
|
549
|
-
return pkg;
|
|
550
|
-
};
|
|
551
|
-
const buildLogsServiceFactory = ({ logger }) => {
|
|
552
|
-
return async (url, token) => {
|
|
553
|
-
const CONN_TIMEOUT2 = 12e4;
|
|
554
|
-
const MAX_RETRIES = 5;
|
|
555
|
-
return new Promise((resolve, reject) => {
|
|
556
|
-
let timeoutId = null;
|
|
557
|
-
let retries = 0;
|
|
558
|
-
const connect = (url2) => {
|
|
559
|
-
const spinner = logger.spinner("Connecting to server to get build logs");
|
|
560
|
-
spinner.start();
|
|
561
|
-
const es = new EventSource(`${url2}`, {
|
|
562
|
-
headers: {
|
|
563
|
-
Authorization: `Bearer ${token}`
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
const clearExistingTimeout = () => {
|
|
567
|
-
if (timeoutId) {
|
|
568
|
-
clearTimeout(timeoutId);
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
const resetTimeout = () => {
|
|
572
|
-
clearExistingTimeout();
|
|
573
|
-
timeoutId = setTimeout(() => {
|
|
574
|
-
logger.log(
|
|
575
|
-
"We were unable to connect to the server to get build logs at this time. This could be due to a temporary issue."
|
|
576
|
-
);
|
|
577
|
-
es.close();
|
|
578
|
-
reject(new Error("Connection timed out"));
|
|
579
|
-
}, CONN_TIMEOUT2);
|
|
580
|
-
};
|
|
581
|
-
es.onopen = resetTimeout;
|
|
582
|
-
es.addEventListener("finished", (event) => {
|
|
583
|
-
const data = JSON.parse(event.data);
|
|
584
|
-
logger.log(data.msg);
|
|
585
|
-
es.close();
|
|
586
|
-
clearExistingTimeout();
|
|
587
|
-
resolve(null);
|
|
588
|
-
});
|
|
589
|
-
es.addEventListener("log", (event) => {
|
|
590
|
-
if (spinner.isSpinning) {
|
|
591
|
-
spinner.succeed();
|
|
592
|
-
}
|
|
593
|
-
resetTimeout();
|
|
594
|
-
const data = JSON.parse(event.data);
|
|
595
|
-
logger.log(data.msg);
|
|
596
|
-
});
|
|
597
|
-
es.onerror = async () => {
|
|
598
|
-
retries += 1;
|
|
599
|
-
if (retries > MAX_RETRIES) {
|
|
600
|
-
spinner.fail("We were unable to connect to the server to get build logs at this time.");
|
|
601
|
-
es.close();
|
|
602
|
-
reject(new Error("Max retries reached"));
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
};
|
|
606
|
-
connect(url);
|
|
607
|
-
});
|
|
608
|
-
};
|
|
609
|
-
};
|
|
610
|
-
const FILE_SIZE_LIMIT = 100 * 1024 * 1024;
|
|
611
|
-
async function upload(ctx, project, token) {
|
|
612
|
-
const cloudApi = cloudApiFactory(token);
|
|
613
|
-
try {
|
|
614
|
-
const storagePath = getTmpStoragePath();
|
|
615
|
-
const projectFolder = path__default.resolve(process.cwd());
|
|
616
|
-
const packageJson = await loadPkg(ctx);
|
|
617
|
-
if (!packageJson) {
|
|
618
|
-
ctx.logger.error(
|
|
619
|
-
"Unable to deploy the project. Please make sure the package.json file is correctly formatted."
|
|
620
|
-
);
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
ctx.logger.log("📦 Compressing project...");
|
|
624
|
-
const hashname = crypto.createHash("sha512").update(packageJson.name).digest("hex");
|
|
625
|
-
const compressedFilename = `${hashname}.tar.gz`;
|
|
626
|
-
try {
|
|
627
|
-
ctx.logger.debug(
|
|
628
|
-
"Compression parameters\n",
|
|
629
|
-
`Storage path: ${storagePath}
|
|
630
|
-
`,
|
|
631
|
-
`Project folder: ${projectFolder}
|
|
632
|
-
`,
|
|
633
|
-
`Compressed filename: ${compressedFilename}`
|
|
634
|
-
);
|
|
635
|
-
await compressFilesToTar(storagePath, projectFolder, compressedFilename);
|
|
636
|
-
ctx.logger.log("📦 Project compressed successfully!");
|
|
637
|
-
} catch (error) {
|
|
638
|
-
ctx.logger.error(
|
|
639
|
-
"⚠️ Project compression failed. Try again later or check for large/incompatible files."
|
|
640
|
-
);
|
|
641
|
-
ctx.logger.debug(error);
|
|
642
|
-
process.exit(1);
|
|
643
|
-
}
|
|
644
|
-
const tarFilePath = path__default.resolve(storagePath, compressedFilename);
|
|
645
|
-
const fileStats = fs__default.statSync(tarFilePath);
|
|
646
|
-
if (fileStats.size > FILE_SIZE_LIMIT) {
|
|
647
|
-
return ctx.logger.log(
|
|
648
|
-
"Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
ctx.logger.info("🚀 Uploading project...");
|
|
652
|
-
const progressBar = ctx.logger.progressBar(100, "Upload Progress");
|
|
653
|
-
try {
|
|
654
|
-
const { data } = await cloudApi.deploy(
|
|
655
|
-
{ filePath: tarFilePath, project },
|
|
656
|
-
{
|
|
657
|
-
onUploadProgress(progressEvent) {
|
|
658
|
-
const total = progressEvent.total || fileStats.size;
|
|
659
|
-
const percentage = Math.round(progressEvent.loaded * 100 / total);
|
|
660
|
-
progressBar.update(percentage);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
);
|
|
664
|
-
progressBar.update(100);
|
|
665
|
-
progressBar.stop();
|
|
666
|
-
ctx.logger.success("✨ Upload finished!");
|
|
667
|
-
return data.build_id;
|
|
668
|
-
} catch (error) {
|
|
669
|
-
progressBar.stop();
|
|
670
|
-
if (error instanceof AxiosError && error.response?.data) {
|
|
671
|
-
if (error.response.status === 404) {
|
|
672
|
-
ctx.logger.error(
|
|
673
|
-
`The project does not exist. Remove the ${LOCAL_SAVE_FILENAME} file and try again.`
|
|
674
|
-
);
|
|
675
|
-
} else {
|
|
676
|
-
ctx.logger.error(error.response.data);
|
|
677
|
-
}
|
|
678
|
-
} else {
|
|
679
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
680
|
-
}
|
|
681
|
-
ctx.logger.debug(JSON.stringify(error));
|
|
682
|
-
} finally {
|
|
683
|
-
fs__default.rmSync(tarFilePath, { force: true });
|
|
684
|
-
}
|
|
685
|
-
process.exit(0);
|
|
686
|
-
} catch (e) {
|
|
687
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
688
|
-
ctx.logger.debug(JSON.stringify(e));
|
|
689
|
-
process.exit(1);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
async function getProject(ctx) {
|
|
693
|
-
const { project } = retrieve();
|
|
694
|
-
if (!project) {
|
|
695
|
-
try {
|
|
696
|
-
return await action$3(ctx)();
|
|
697
|
-
} catch (error) {
|
|
698
|
-
ctx.logger.error("An error occurred while deploying the project. Please try again later.");
|
|
699
|
-
ctx.logger.debug(JSON.stringify(error));
|
|
700
|
-
process.exit(1);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
return project;
|
|
704
|
-
}
|
|
705
|
-
const action$2 = async (ctx) => {
|
|
706
|
-
const { getValidToken } = tokenServiceFactory(ctx);
|
|
707
|
-
const token = await getValidToken();
|
|
708
|
-
if (!token) {
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
const project = await getProject(ctx);
|
|
712
|
-
if (!project) {
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
const notificationService = notificationServiceFactory(ctx);
|
|
716
|
-
const buildLogsService = buildLogsServiceFactory(ctx);
|
|
717
|
-
const buildId = await upload(ctx, project, token);
|
|
718
|
-
try {
|
|
719
|
-
await Promise.all([
|
|
720
|
-
notificationService(`${apiConfig.apiBaseUrl}/notifications`, token),
|
|
721
|
-
buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token)
|
|
722
|
-
]);
|
|
723
|
-
} catch (e) {
|
|
724
|
-
if (e instanceof Error) {
|
|
725
|
-
ctx.logger.error(e.message);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
const assertCwdContainsStrapiProject = (name) => {
|
|
730
|
-
const logErrorAndExit = () => {
|
|
731
|
-
console.log(
|
|
732
|
-
`You need to run ${chalk.yellow(
|
|
733
|
-
`strapi ${name}`
|
|
734
|
-
)} in a Strapi project. Make sure you are in the right directory.`
|
|
735
|
-
);
|
|
736
|
-
process.exit(1);
|
|
737
|
-
};
|
|
738
|
-
try {
|
|
739
|
-
const pkgJSON = require(`${process.cwd()}/package.json`);
|
|
740
|
-
if (!has("dependencies.@strapi/strapi", pkgJSON) && !has("devDependencies.@strapi/strapi", pkgJSON)) {
|
|
741
|
-
logErrorAndExit();
|
|
742
|
-
}
|
|
743
|
-
} catch (err) {
|
|
744
|
-
logErrorAndExit();
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
const runAction = (name, action2) => (...args) => {
|
|
748
|
-
assertCwdContainsStrapiProject(name);
|
|
749
|
-
Promise.resolve().then(() => {
|
|
750
|
-
return action2(...args);
|
|
751
|
-
}).catch((error) => {
|
|
752
|
-
console.error(error);
|
|
753
|
-
process.exit(1);
|
|
754
|
-
});
|
|
755
|
-
};
|
|
756
|
-
const command$2 = ({ command: command2, ctx }) => {
|
|
757
|
-
return command2.command("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").action(() => runAction("deploy", action$2)(ctx));
|
|
758
|
-
};
|
|
759
|
-
const index$3 = {
|
|
760
|
-
name: "deploy-project",
|
|
761
|
-
description: "Deploy a Strapi Cloud project",
|
|
762
|
-
action: action$2,
|
|
763
|
-
command: command$2
|
|
764
|
-
};
|
|
765
|
-
const deployProject = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
766
|
-
__proto__: null,
|
|
767
|
-
action: action$2,
|
|
768
|
-
command: command$2,
|
|
769
|
-
default: index$3
|
|
770
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
771
|
-
const openModule = import("open");
|
|
772
|
-
const cloudApiService = cloudApiFactory();
|
|
773
|
-
const action$1 = async (ctx) => {
|
|
774
|
-
const { logger } = ctx;
|
|
775
|
-
const tokenService = tokenServiceFactory(ctx);
|
|
776
|
-
let cliConfig2;
|
|
777
|
-
try {
|
|
778
|
-
logger.info("🔌 Connecting to the Strapi Cloud API...");
|
|
779
|
-
const config = await cloudApiService.config();
|
|
780
|
-
cliConfig2 = config.data;
|
|
781
|
-
} catch (error) {
|
|
782
|
-
logger.error("🥲 Oops! Something went wrong while logging you in. Please try again.");
|
|
783
|
-
logger.debug(error);
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
logger.debug("🔐 Creating device authentication request...", {
|
|
787
|
-
client_id: cliConfig2.clientId,
|
|
788
|
-
scope: cliConfig2.scope,
|
|
789
|
-
audience: cliConfig2.audience
|
|
790
|
-
});
|
|
791
|
-
const deviceAuthResponse = await axios.post(cliConfig2.deviceCodeAuthUrl, {
|
|
792
|
-
client_id: cliConfig2.clientId,
|
|
793
|
-
scope: cliConfig2.scope,
|
|
794
|
-
audience: cliConfig2.audience
|
|
795
|
-
}).catch((error) => {
|
|
796
|
-
logger.error("There was an issue with the authentication process. Please try again.");
|
|
797
|
-
if (error.message) {
|
|
798
|
-
logger.debug(error.message, error);
|
|
799
|
-
} else {
|
|
800
|
-
logger.debug(error);
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
openModule.then((open) => {
|
|
804
|
-
open.default(deviceAuthResponse.data.verification_uri_complete).catch((err) => {
|
|
805
|
-
logger.error("We encountered an issue opening the browser. Please try again later.");
|
|
806
|
-
logger.debug(err.message, err);
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
logger.log("If a browser tab does not open automatically, please follow the next steps:");
|
|
810
|
-
logger.log(
|
|
811
|
-
`1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
|
|
812
|
-
);
|
|
813
|
-
logger.log(
|
|
814
|
-
`2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
|
|
815
|
-
`
|
|
816
|
-
);
|
|
817
|
-
const tokenPayload = {
|
|
818
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
819
|
-
device_code: deviceAuthResponse.data.device_code,
|
|
820
|
-
client_id: cliConfig2.clientId
|
|
821
|
-
};
|
|
822
|
-
let isAuthenticated = false;
|
|
823
|
-
const authenticate = async () => {
|
|
824
|
-
const spinner = logger.spinner("Waiting for authentication");
|
|
825
|
-
spinner.start();
|
|
826
|
-
const spinnerFail = () => spinner.fail("Authentication failed!");
|
|
827
|
-
while (!isAuthenticated) {
|
|
828
|
-
try {
|
|
829
|
-
const tokenResponse = await axios.post(cliConfig2.tokenUrl, tokenPayload);
|
|
830
|
-
const authTokenData = tokenResponse.data;
|
|
831
|
-
if (tokenResponse.status === 200) {
|
|
832
|
-
try {
|
|
833
|
-
logger.debug("🔐 Validating token...");
|
|
834
|
-
await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
|
|
835
|
-
logger.debug("🔐 Token validation successful!");
|
|
836
|
-
} catch (error) {
|
|
837
|
-
logger.debug(error);
|
|
838
|
-
spinnerFail();
|
|
839
|
-
throw new Error("Unable to proceed: Token validation failed");
|
|
840
|
-
}
|
|
841
|
-
const cloudApiService2 = cloudApiFactory(authTokenData.access_token);
|
|
842
|
-
logger.debug("🔍 Fetching user information...");
|
|
843
|
-
await cloudApiService2.getUserInfo();
|
|
844
|
-
logger.debug("🔍 User information fetched successfully!");
|
|
845
|
-
try {
|
|
846
|
-
logger.debug("📝 Saving login information...");
|
|
847
|
-
await tokenService.saveToken(authTokenData.access_token);
|
|
848
|
-
logger.debug("📝 Login information saved successfully!");
|
|
849
|
-
isAuthenticated = true;
|
|
850
|
-
} catch (error) {
|
|
851
|
-
logger.error(
|
|
852
|
-
"There was a problem saving your login information. Please try logging in again."
|
|
853
|
-
);
|
|
854
|
-
logger.debug(error);
|
|
855
|
-
spinnerFail();
|
|
856
|
-
return;
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
} catch (error) {
|
|
860
|
-
if (error.message === "Unable to proceed: Token validation failed") {
|
|
861
|
-
logger.error(
|
|
862
|
-
"There seems to be a problem with your login information. Please try logging in again."
|
|
863
|
-
);
|
|
864
|
-
spinnerFail();
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
if (error.response?.data.error && !["authorization_pending", "slow_down"].includes(error.response.data.error)) {
|
|
868
|
-
logger.debug(error);
|
|
869
|
-
spinnerFail();
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
await new Promise((resolve) => {
|
|
873
|
-
setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
|
|
874
|
-
});
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
spinner.succeed("Authentication successful!");
|
|
878
|
-
logger.log("You are now logged in to Strapi Cloud.");
|
|
879
|
-
};
|
|
880
|
-
await authenticate();
|
|
881
|
-
};
|
|
882
|
-
const command$1 = ({ command: command2, ctx }) => {
|
|
883
|
-
return command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText("after", "\nAfter running this command, you will be prompted to enter your authentication information.").action(() => runAction("login", action$1)(ctx));
|
|
884
|
-
};
|
|
885
|
-
const index$2 = {
|
|
886
|
-
name: "login",
|
|
887
|
-
description: "Strapi Cloud Login",
|
|
888
|
-
action: action$1,
|
|
889
|
-
command: command$1
|
|
890
|
-
};
|
|
891
|
-
const login = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
892
|
-
__proto__: null,
|
|
893
|
-
action: action$1,
|
|
894
|
-
command: command$1,
|
|
895
|
-
default: index$2
|
|
896
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
897
|
-
const action = async (ctx) => {
|
|
898
|
-
const { logger } = ctx;
|
|
899
|
-
const { retrieveToken, eraseToken } = tokenServiceFactory(ctx);
|
|
900
|
-
const token = await retrieveToken();
|
|
901
|
-
if (!token) {
|
|
902
|
-
logger.log("You're already logged out.");
|
|
903
|
-
return;
|
|
904
|
-
}
|
|
905
|
-
try {
|
|
906
|
-
await eraseToken();
|
|
907
|
-
logger.log("🔌 You have been logged out.");
|
|
908
|
-
} catch (error) {
|
|
909
|
-
logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
|
|
910
|
-
logger.debug(error);
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
const command = ({ command: command2, ctx }) => {
|
|
914
|
-
return command2.command("cloud:logout").alias("logout").description("Strapi Cloud Logout").action(() => runAction("logout", action)(ctx));
|
|
915
|
-
};
|
|
916
|
-
const index$1 = {
|
|
917
|
-
name: "logout",
|
|
918
|
-
description: "Strapi Cloud Logout",
|
|
919
|
-
action,
|
|
920
|
-
command
|
|
921
|
-
};
|
|
922
|
-
const logout = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
923
|
-
__proto__: null,
|
|
924
|
-
action,
|
|
925
|
-
command,
|
|
926
|
-
default: index$1
|
|
927
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
928
|
-
const index = {
|
|
929
|
-
name: "create-project",
|
|
930
|
-
description: "Create a new project",
|
|
931
|
-
action: action$3
|
|
932
|
-
};
|
|
933
|
-
const createProject = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
934
|
-
__proto__: null,
|
|
935
|
-
action: action$3,
|
|
936
|
-
default: index
|
|
937
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
938
|
-
const cli = {
|
|
939
|
-
deployProject,
|
|
940
|
-
login,
|
|
941
|
-
logout,
|
|
942
|
-
createProject
|
|
943
|
-
};
|
|
944
|
-
export {
|
|
945
|
-
cli,
|
|
946
|
-
index$4 as services
|
|
947
|
-
};
|
|
948
|
-
//# sourceMappingURL=index.mjs.map
|