@8medusa/cli 2.7.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.
@@ -0,0 +1,115 @@
1
+ import ora from "ora";
2
+ import winston from "winston";
3
+ export declare class Reporter {
4
+ protected activities_: Record<string, any>;
5
+ protected loggerInstance_: winston.Logger;
6
+ protected ora_: typeof ora;
7
+ constructor({ logger, activityLogger }: {
8
+ logger: any;
9
+ activityLogger: any;
10
+ });
11
+ panic(data: any): void;
12
+ /**
13
+ * Determines if the logger should log at a given level.
14
+ * @param {string} level - the level to check if logger is configured for
15
+ * @return {boolean} whether we should log
16
+ */
17
+ shouldLog: (level: string) => boolean;
18
+ /**
19
+ * Sets the log level of the logger.
20
+ * @param {string} level - the level to set the logger to
21
+ */
22
+ setLogLevel(level: string): void;
23
+ /**
24
+ * Resets the logger to the value specified by the LOG_LEVEL env var. If no
25
+ * LOG_LEVEL is set it defaults to "silly".
26
+ */
27
+ unsetLogLevel(): void;
28
+ /**
29
+ * Begin an activity. In development an activity is displayed as a spinner;
30
+ * in other environments it will log the activity at the info level.
31
+ * @param {string} message - the message to log the activity under
32
+ * @param {any} config
33
+ * @returns {string} the id of the activity; this should be passed to do
34
+ * further operations on the activity such as success, failure, progress.
35
+ */
36
+ activity(message: string, config?: any): string;
37
+ /**
38
+ * Reports progress on an activity. In development this will update the
39
+ * activity log message, in other environments a log message will be issued
40
+ * at the info level. Logging will include the activityId.
41
+ * @param {string} activityId - the id of the activity as returned by activity
42
+ * @param {string} message - the message to log
43
+ */
44
+ progress(activityId: string, message: string): void;
45
+ /**
46
+ * Logs an error. If an error object is provided the stack trace for the error
47
+ * will also be logged.
48
+ * @param {String | Error} messageOrError - can either be a string with a
49
+ * message to log the error under; or an error object.
50
+ * @param {Error?} error - an error object to log message with
51
+ * Level 0
52
+ */
53
+ error(messageOrError: string | Error, error?: Error): void;
54
+ /**
55
+ * Reports failure of an activity. In development the activity will be udpated
56
+ * with the failure message in other environments the failure will be logged
57
+ * at the error level.
58
+ * @param {string} activityId - the id of the activity as returned by activity
59
+ * @param {string} message - the message to log
60
+ * @returns {object} data about the activity
61
+ */
62
+ failure(activityId: string, message: string): any;
63
+ /**
64
+ * Reports success of an activity. In development the activity will be udpated
65
+ * with the failure message in other environments the failure will be logged
66
+ * at the info level.
67
+ * @param {string} activityId - the id of the activity as returned by activity
68
+ * @param {string} message - the message to log
69
+ * @returns {Record<string, any>} data about the activity
70
+ */
71
+ success(activityId: string, message: string): any;
72
+ /**
73
+ * Logs a message at the silly level.
74
+ * @param {string} message - the message to log
75
+ * Level 6
76
+ */
77
+ silly(message: string): void;
78
+ /**
79
+ * Logs a message at the info level.
80
+ * @param {string} message - the message to log
81
+ * Level 5
82
+ */
83
+ debug(message: string): void;
84
+ /**
85
+ * Logs a message at the vebose level.
86
+ * @param {string} message - the message to log
87
+ * Level 4
88
+ */
89
+ verbose(message: string): void;
90
+ /**
91
+ * Logs a message at the http level.
92
+ * @param {string} message - the message to log
93
+ * Level 3
94
+ */
95
+ http(message: string): void;
96
+ /**
97
+ * Logs a message at the info level.
98
+ * @param {string} message - the message to log
99
+ * Level 2
100
+ */
101
+ info(message: string): void;
102
+ /**
103
+ * Logs a message at the warn level.
104
+ * @param {string} message - the message to log
105
+ * Level 1
106
+ */
107
+ warn(message: string): void;
108
+ /**
109
+ * A wrapper around winston's log method.
110
+ */
111
+ log(...args: any[]): void;
112
+ }
113
+ declare const logger: Reporter;
114
+ export default logger;
115
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reporter/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,OAAO,MAAM,SAAS,CAAA;AAkD7B,qBAAa,QAAQ;IACnB,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1C,SAAS,CAAC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAA;IACzC,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,CAAA;gBAEd,EAAE,MAAM,EAAE,cAAc,EAAE;;;KAAA;IAMtC,KAAK,CAAC,IAAI,KAAA;IAgBV;;;;OAIG;IACH,SAAS,UAAW,MAAM,aAIzB;IAED;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM;IAIzB;;;OAGG;IACH,aAAa;IAIb;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,GAAQ;IA4B1C;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAmB5C;;;;;;;OAOG;IACH,KAAK,CAAC,cAAc,EAAE,MAAM,GAAG,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK;IAsDnD;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IA+B3C;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IA+B3C;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAOrB;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAOrB;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM;IAOvB;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM;IAOpB;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM;IAOpB;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM;IAOpB;;OAEG;IACH,GAAG,CAAC,GAAG,IAAI,OAAA;CAYZ;AAED,QAAA,MAAM,MAAM,UAGV,CAAA;AAEF,eAAe,MAAM,CAAA"}
@@ -0,0 +1,364 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Reporter = void 0;
7
+ const ora_1 = __importDefault(require("ora"));
8
+ const ulid_1 = require("ulid");
9
+ const winston_1 = __importDefault(require("winston"));
10
+ const util_1 = require("util");
11
+ const stack_trace_1 = __importDefault(require("stack-trace"));
12
+ const telemetry_1 = require("@8medusa/telemetry");
13
+ const panic_handler_1 = require("./panic-handler");
14
+ const LOG_LEVEL = process.env.LOG_LEVEL || "http";
15
+ const LOG_FILE = process.env.LOG_FILE || "";
16
+ const NODE_ENV = process.env.NODE_ENV || "development";
17
+ const IS_DEV = NODE_ENV.startsWith("dev");
18
+ let transports = [];
19
+ if (!IS_DEV) {
20
+ transports.push(new winston_1.default.transports.Console());
21
+ }
22
+ else {
23
+ transports.push(new winston_1.default.transports.Console({
24
+ format: winston_1.default.format.combine(winston_1.default.format.cli({
25
+ levels: winston_1.default.config.npm.levels,
26
+ }), winston_1.default.format.splat()),
27
+ }));
28
+ }
29
+ if (LOG_FILE) {
30
+ transports.push(new winston_1.default.transports.File({
31
+ filename: LOG_FILE,
32
+ }));
33
+ }
34
+ const loggerInstance = winston_1.default.createLogger({
35
+ level: LOG_LEVEL,
36
+ levels: winston_1.default.config.npm.levels,
37
+ format: winston_1.default.format.combine(winston_1.default.format.timestamp({
38
+ format: "YYYY-MM-DD HH:mm:ss",
39
+ }), winston_1.default.format.errors({ stack: true }), winston_1.default.format.splat(), winston_1.default.format.json()),
40
+ transports,
41
+ });
42
+ class Reporter {
43
+ constructor({ logger, activityLogger }) {
44
+ /**
45
+ * Determines if the logger should log at a given level.
46
+ * @param {string} level - the level to check if logger is configured for
47
+ * @return {boolean} whether we should log
48
+ */
49
+ this.shouldLog = (level) => {
50
+ const levelValue = this.loggerInstance_.levels[level];
51
+ const logLevel = this.loggerInstance_.levels[this.loggerInstance_.level];
52
+ return levelValue <= logLevel;
53
+ };
54
+ this.activities_ = {};
55
+ this.loggerInstance_ = logger;
56
+ this.ora_ = activityLogger;
57
+ }
58
+ panic(data) {
59
+ const parsedPanic = (0, panic_handler_1.panicHandler)(data);
60
+ this.loggerInstance_.log({
61
+ level: "error",
62
+ details: data,
63
+ message: parsedPanic.message,
64
+ });
65
+ (0, telemetry_1.track)("PANIC_ERROR_REACHED", {
66
+ id: data.id,
67
+ });
68
+ process.exit(1);
69
+ }
70
+ /**
71
+ * Sets the log level of the logger.
72
+ * @param {string} level - the level to set the logger to
73
+ */
74
+ setLogLevel(level) {
75
+ this.loggerInstance_.level = level;
76
+ }
77
+ /**
78
+ * Resets the logger to the value specified by the LOG_LEVEL env var. If no
79
+ * LOG_LEVEL is set it defaults to "silly".
80
+ */
81
+ unsetLogLevel() {
82
+ this.loggerInstance_.level = LOG_LEVEL;
83
+ }
84
+ /**
85
+ * Begin an activity. In development an activity is displayed as a spinner;
86
+ * in other environments it will log the activity at the info level.
87
+ * @param {string} message - the message to log the activity under
88
+ * @param {any} config
89
+ * @returns {string} the id of the activity; this should be passed to do
90
+ * further operations on the activity such as success, failure, progress.
91
+ */
92
+ activity(message, config = {}) {
93
+ const id = (0, ulid_1.ulid)();
94
+ if (IS_DEV && this.shouldLog("info")) {
95
+ const activity = this.ora_(message).start();
96
+ this.activities_[id] = {
97
+ activity,
98
+ config,
99
+ start: Date.now(),
100
+ };
101
+ return id;
102
+ }
103
+ else {
104
+ this.activities_[id] = {
105
+ start: Date.now(),
106
+ config,
107
+ };
108
+ this.loggerInstance_.log({
109
+ activity_id: id,
110
+ level: "info",
111
+ config,
112
+ message,
113
+ });
114
+ return id;
115
+ }
116
+ }
117
+ /**
118
+ * Reports progress on an activity. In development this will update the
119
+ * activity log message, in other environments a log message will be issued
120
+ * at the info level. Logging will include the activityId.
121
+ * @param {string} activityId - the id of the activity as returned by activity
122
+ * @param {string} message - the message to log
123
+ */
124
+ progress(activityId, message) {
125
+ const toLog = {
126
+ level: "info",
127
+ message,
128
+ };
129
+ if (this.activities_[activityId]) {
130
+ const activity = this.activities_[activityId];
131
+ if (activity.activity) {
132
+ activity.text = message;
133
+ }
134
+ else {
135
+ toLog["activity_id"] = activityId;
136
+ this.loggerInstance_.log(toLog);
137
+ }
138
+ }
139
+ else {
140
+ this.loggerInstance_.log(toLog);
141
+ }
142
+ }
143
+ /**
144
+ * Logs an error. If an error object is provided the stack trace for the error
145
+ * will also be logged.
146
+ * @param {String | Error} messageOrError - can either be a string with a
147
+ * message to log the error under; or an error object.
148
+ * @param {Error?} error - an error object to log message with
149
+ * Level 0
150
+ */
151
+ error(messageOrError, error) {
152
+ let message;
153
+ let errorAsObject;
154
+ if (messageOrError && typeof messageOrError === "object") {
155
+ errorAsObject = messageOrError;
156
+ message = messageOrError.message;
157
+ }
158
+ else if (error) {
159
+ message = messageOrError;
160
+ errorAsObject = error;
161
+ }
162
+ else {
163
+ message = messageOrError;
164
+ }
165
+ const toLog = {
166
+ level: "error",
167
+ message,
168
+ };
169
+ if (errorAsObject) {
170
+ toLog["message"] = errorAsObject.message;
171
+ toLog["stack"] = stack_trace_1.default.parse(errorAsObject);
172
+ /**
173
+ * Winston only logs the error properties when they are
174
+ * string values. Hence we will have to self convert
175
+ * the error cause to a string
176
+ */
177
+ if ("cause" in errorAsObject) {
178
+ toLog["cause"] = (0, util_1.inspect)(errorAsObject.cause);
179
+ }
180
+ }
181
+ /**
182
+ * If "errorAsObject" has a message property, then we will
183
+ * print the standalone message as one log item and then
184
+ * the actual error object as another log item.
185
+ *
186
+ * Otherwise, we always loose the message property from the
187
+ * actual error object
188
+ */
189
+ if (errorAsObject?.message && errorAsObject?.message !== message) {
190
+ this.loggerInstance_.log({ level: "error", message });
191
+ }
192
+ this.loggerInstance_.log(toLog);
193
+ /**
194
+ * In dev we print the error using `console.error`, because Winston
195
+ * CLI formatter does not print the error stack in that case
196
+ */
197
+ if (errorAsObject && IS_DEV) {
198
+ console.error(errorAsObject);
199
+ }
200
+ }
201
+ /**
202
+ * Reports failure of an activity. In development the activity will be udpated
203
+ * with the failure message in other environments the failure will be logged
204
+ * at the error level.
205
+ * @param {string} activityId - the id of the activity as returned by activity
206
+ * @param {string} message - the message to log
207
+ * @returns {object} data about the activity
208
+ */
209
+ failure(activityId, message) {
210
+ const time = Date.now();
211
+ const toLog = {
212
+ level: "error",
213
+ message,
214
+ };
215
+ if (this.activities_[activityId]) {
216
+ const activity = this.activities_[activityId];
217
+ if (activity.activity) {
218
+ activity.activity.fail(`${message} – ${time - activity.start}`);
219
+ }
220
+ else {
221
+ toLog["duration"] = time - activity.start;
222
+ toLog["activity_id"] = activityId;
223
+ this.loggerInstance_.log(toLog);
224
+ }
225
+ }
226
+ else {
227
+ this.loggerInstance_.log(toLog);
228
+ }
229
+ if (this.activities_[activityId]) {
230
+ const activity = this.activities_[activityId];
231
+ return {
232
+ ...activity,
233
+ duration: time - activity.start,
234
+ };
235
+ }
236
+ return null;
237
+ }
238
+ /**
239
+ * Reports success of an activity. In development the activity will be udpated
240
+ * with the failure message in other environments the failure will be logged
241
+ * at the info level.
242
+ * @param {string} activityId - the id of the activity as returned by activity
243
+ * @param {string} message - the message to log
244
+ * @returns {Record<string, any>} data about the activity
245
+ */
246
+ success(activityId, message) {
247
+ const time = Date.now();
248
+ const toLog = {
249
+ level: "info",
250
+ message,
251
+ };
252
+ if (this.activities_[activityId]) {
253
+ const activity = this.activities_[activityId];
254
+ if (activity.activity) {
255
+ activity.activity.succeed(`${message} – ${time - activity.start}ms`);
256
+ }
257
+ else {
258
+ toLog["duration"] = time - activity.start;
259
+ toLog["activity_id"] = activityId;
260
+ this.loggerInstance_.log(toLog);
261
+ }
262
+ }
263
+ else {
264
+ this.loggerInstance_.log(toLog);
265
+ }
266
+ if (this.activities_[activityId]) {
267
+ const activity = this.activities_[activityId];
268
+ return {
269
+ ...activity,
270
+ duration: time - activity.start,
271
+ };
272
+ }
273
+ return null;
274
+ }
275
+ /**
276
+ * Logs a message at the silly level.
277
+ * @param {string} message - the message to log
278
+ * Level 6
279
+ */
280
+ silly(message) {
281
+ this.loggerInstance_.log({
282
+ level: "silly",
283
+ message,
284
+ });
285
+ }
286
+ /**
287
+ * Logs a message at the info level.
288
+ * @param {string} message - the message to log
289
+ * Level 5
290
+ */
291
+ debug(message) {
292
+ this.loggerInstance_.log({
293
+ level: "debug",
294
+ message,
295
+ });
296
+ }
297
+ /**
298
+ * Logs a message at the vebose level.
299
+ * @param {string} message - the message to log
300
+ * Level 4
301
+ */
302
+ verbose(message) {
303
+ this.loggerInstance_.log({
304
+ level: "vebose",
305
+ message,
306
+ });
307
+ }
308
+ /**
309
+ * Logs a message at the http level.
310
+ * @param {string} message - the message to log
311
+ * Level 3
312
+ */
313
+ http(message) {
314
+ this.loggerInstance_.log({
315
+ level: "http",
316
+ message,
317
+ });
318
+ }
319
+ /**
320
+ * Logs a message at the info level.
321
+ * @param {string} message - the message to log
322
+ * Level 2
323
+ */
324
+ info(message) {
325
+ this.loggerInstance_.log({
326
+ level: "info",
327
+ message,
328
+ });
329
+ }
330
+ /**
331
+ * Logs a message at the warn level.
332
+ * @param {string} message - the message to log
333
+ * Level 1
334
+ */
335
+ warn(message) {
336
+ this.loggerInstance_.warn({
337
+ level: "warn",
338
+ message,
339
+ });
340
+ }
341
+ /**
342
+ * A wrapper around winston's log method.
343
+ */
344
+ log(...args) {
345
+ if (args.length > 1) {
346
+ // @ts-ignore
347
+ this.loggerInstance_.log(...args);
348
+ }
349
+ else {
350
+ let message = args[0];
351
+ this.loggerInstance_.log({
352
+ level: "info",
353
+ message,
354
+ });
355
+ }
356
+ }
357
+ }
358
+ exports.Reporter = Reporter;
359
+ const logger = new Reporter({
360
+ logger: loggerInstance,
361
+ activityLogger: ora_1.default,
362
+ });
363
+ exports.default = logger;
364
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporter/index.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,+BAA2B;AAC3B,sDAA6B;AAC7B,+BAA8B;AAC9B,8DAAoC;AACpC,kDAA0C;AAC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ACR,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAAe;QACrB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;YACvB,KAAK,EAAE,QAAQ;YACf,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;YACvB,KAAK,EAAE,MAAM;YACb,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;YACvB,KAAK,EAAE,MAAM;YACb,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;YACxB,KAAK,EAAE,MAAM;YACb,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAG,IAAI;QACT,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,aAAa;YACb,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;QACnC,CAAC;aAAM,CAAC;YACN,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YACrB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;gBACvB,KAAK,EAAE,MAAM;gBACb,OAAO;aACR,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF;AAvVD,4BAuVC;AAED,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC;IAC1B,MAAM,EAAE,cAAc;IACtB,cAAc,EAAE,aAAG;CACpB,CAAC,CAAA;AAEF,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,16 @@
1
+ export type PanicData = {
2
+ id: string;
3
+ context: {
4
+ rootPath: string;
5
+ path: string;
6
+ };
7
+ };
8
+ export declare enum PanicId {
9
+ InvalidProjectName = "10000",
10
+ InvalidPath = "10002",
11
+ AlreadyNodeProject = "10003"
12
+ }
13
+ export declare const panicHandler: (panicData?: PanicData) => {
14
+ message: string;
15
+ };
16
+ //# sourceMappingURL=panic-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panic-handler.d.ts","sourceRoot":"","sources":["../../src/reporter/panic-handler.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;CACF,CAAA;AAED,oBAAY,OAAO;IACjB,kBAAkB,UAAU;IAC5B,WAAW,UAAU;IACrB,kBAAkB,UAAU;CAC7B;AAED,eAAO,MAAM,YAAY,eAAe,SAAS;;CAoBhD,CAAA"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.panicHandler = exports.PanicId = void 0;
4
+ var PanicId;
5
+ (function (PanicId) {
6
+ PanicId["InvalidProjectName"] = "10000";
7
+ PanicId["InvalidPath"] = "10002";
8
+ PanicId["AlreadyNodeProject"] = "10003";
9
+ })(PanicId || (exports.PanicId = PanicId = {}));
10
+ const panicHandler = (panicData = {}) => {
11
+ const { id, context } = panicData;
12
+ switch (id) {
13
+ case "10000":
14
+ return {
15
+ message: `Looks like you provided a URL as your project name. Try "medusa new my-medusa-store ${context.rootPath}" instead.`,
16
+ };
17
+ case "10002":
18
+ return {
19
+ message: `Could not create project because ${context.path} is not a valid path.`,
20
+ };
21
+ case "10003":
22
+ return {
23
+ message: `Directory ${context.rootPath} is already a Node project.`,
24
+ };
25
+ default:
26
+ return {
27
+ message: "Unknown error",
28
+ };
29
+ }
30
+ };
31
+ exports.panicHandler = panicHandler;
32
+ //# sourceMappingURL=panic-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panic-handler.js","sourceRoot":"","sources":["../../src/reporter/panic-handler.ts"],"names":[],"mappings":";;;AAQA,IAAY,OAIX;AAJD,WAAY,OAAO;IACjB,uCAA4B,CAAA;IAC5B,gCAAqB,CAAA;IACrB,uCAA4B,CAAA;AAC9B,CAAC,EAJW,OAAO,uBAAP,OAAO,QAIlB;AAEM,MAAM,YAAY,GAAG,CAAC,YAAuB,EAAe,EAAE,EAAE;IACrE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;IACjC,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,OAAO;YACV,OAAO;gBACL,OAAO,EAAE,uFAAuF,OAAO,CAAC,QAAQ,YAAY;aAC7H,CAAA;QACH,KAAK,OAAO;YACV,OAAO;gBACL,OAAO,EAAE,oCAAoC,OAAO,CAAC,IAAI,uBAAuB;aACjF,CAAA;QACH,KAAK,OAAO;YACV,OAAO;gBACL,OAAO,EAAE,aAAa,OAAO,CAAC,QAAQ,6BAA6B;aACpE,CAAA;QACH;YACE,OAAO;gBACL,OAAO,EAAE,eAAe;aACzB,CAAA;IACL,CAAC;AACH,CAAC,CAAA;AApBY,QAAA,YAAY,gBAoBxB"}
@@ -0,0 +1 @@
1
+ {"root":["../src/create-cli.ts","../src/did-you-mean.ts","../src/index.ts","../src/commands/new.ts","../src/reporter/index.ts","../src/reporter/panic-handler.ts","../src/reporter/__tests__/index.js","../src/util/clear-project.ts","../src/util/package-manager.ts"],"version":"5.6.2"}
@@ -0,0 +1,2 @@
1
+ export declare function clearProject(directory: string): void;
2
+ //# sourceMappingURL=clear-project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clear-project.d.ts","sourceRoot":"","sources":["../../src/util/clear-project.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,QAoB7C"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clearProject = clearProject;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const glob_1 = __importDefault(require("glob"));
9
+ const path_1 = __importDefault(require("path"));
10
+ function clearProject(directory) {
11
+ const adminFiles = glob_1.default.sync(path_1.default.join(directory, `src`, `admin/**/*`));
12
+ const onboardingFiles = glob_1.default.sync(path_1.default.join(directory, `src`, `**/onboarding/`));
13
+ const typeFiles = glob_1.default.sync(path_1.default.join(directory, `src`, `types`));
14
+ const srcFiles = glob_1.default.sync(path_1.default.join(directory, `src`, `**/*.{ts,tsx,js,jsx}`));
15
+ const files = [...adminFiles, ...onboardingFiles, ...typeFiles, ...srcFiles];
16
+ files.forEach((file) => fs_1.default.rmSync(file, {
17
+ recursive: true,
18
+ force: true,
19
+ }));
20
+ // add empty typescript file to avoid build errors
21
+ fs_1.default.openSync(path_1.default.join(directory, "src", "index.ts"), "w");
22
+ }
23
+ //# sourceMappingURL=clear-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clear-project.js","sourceRoot":"","sources":["../../src/util/clear-project.ts"],"names":[],"mappings":";;;;;AAIA,oCAoBC;AAxBD,4CAAmB;AACnB,gDAAuB;AACvB,gDAAuB;AAEvB,SAAgB,YAAY,CAAC,SAAiB;IAC5C,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;IACvE,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAC/B,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAC9C,CAAA;IACD,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;IACjE,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CACxB,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,sBAAsB,CAAC,CACpD,CAAA;IAED,MAAM,KAAK,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,eAAe,EAAE,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAA;IAE5E,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACrB,YAAE,CAAC,MAAM,CAAC,IAAI,EAAE;QACd,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,IAAI;KACZ,CAAC,CACH,CAAA;IACD,kDAAkD;IAClD,YAAE,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,UAAU,CAAC,EAAE,GAAG,CAAC,CAAA;AAC3D,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const getPackageManager: () => any;
2
+ export declare const setPackageManager: (packageManager: any) => void;
3
+ //# sourceMappingURL=package-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../src/util/package-manager.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,iBAAiB,WAE7B,CAAA;AAED,eAAO,MAAM,iBAAiB,+BAG7B,CAAA"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setPackageManager = exports.getPackageManager = void 0;
7
+ // @ts-ignore
8
+ const configstore_1 = __importDefault(require("configstore"));
9
+ const reporter_1 = __importDefault(require("../reporter"));
10
+ const config = new configstore_1.default(`medusa`, {}, { globalConfigPath: true });
11
+ const packageMangerConfigKey = `cli.packageManager`;
12
+ const getPackageManager = () => {
13
+ return config.get(packageMangerConfigKey);
14
+ };
15
+ exports.getPackageManager = getPackageManager;
16
+ const setPackageManager = (packageManager) => {
17
+ config.set(packageMangerConfigKey, packageManager);
18
+ reporter_1.default.info(`Preferred package manager set to "${packageManager}"`);
19
+ };
20
+ exports.setPackageManager = setPackageManager;
21
+ //# sourceMappingURL=package-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../src/util/package-manager.ts"],"names":[],"mappings":";;;;;;AAAA,aAAa;AACb,8DAAqC;AACrC,2DAAkC;AAElC,MAAM,MAAM,GAAG,IAAI,qBAAW,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAA;AAExE,MAAM,sBAAsB,GAAG,oBAAoB,CAAA;AAE5C,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,OAAO,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;AAC3C,CAAC,CAAA;AAFY,QAAA,iBAAiB,qBAE7B;AAEM,MAAM,iBAAiB,GAAG,CAAC,cAAc,EAAE,EAAE;IAClD,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAA;IAClD,kBAAQ,CAAC,IAAI,CAAC,qCAAqC,cAAc,GAAG,CAAC,CAAA;AACvE,CAAC,CAAA;AAHY,QAAA,iBAAiB,qBAG7B"}