create-react-router 0.0.0-experimental-8cee090e4 → 0.0.0-experimental-dd63c14ca
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/cli.d.ts +1 -2
- package/dist/cli.js +1907 -1527
- package/package.json +21 -19
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* create-react-router v0.0.0-experimental-
|
|
3
|
+
* create-react-router v0.0.0-experimental-dd63c14ca
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -9,1628 +9,1996 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
12
|
+
"use strict";
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
35
|
+
|
|
36
|
+
// cli.ts
|
|
37
|
+
var import_node_process7 = __toESM(require("process"));
|
|
38
|
+
|
|
39
|
+
// index.ts
|
|
40
|
+
var import_node_process6 = __toESM(require("process"));
|
|
41
|
+
var import_node_fs3 = require("fs");
|
|
42
|
+
var import_promises2 = require("fs/promises");
|
|
43
|
+
var import_node_os2 = __toESM(require("os"));
|
|
44
|
+
var import_node_path3 = __toESM(require("path"));
|
|
45
|
+
var import_strip_ansi = __toESM(require("strip-ansi"));
|
|
46
|
+
var import_execa = __toESM(require("execa"));
|
|
47
|
+
var import_arg = __toESM(require("arg"));
|
|
48
|
+
var semver = __toESM(require("semver"));
|
|
49
|
+
var import_sort_package_json = __toESM(require("sort-package-json"));
|
|
50
|
+
|
|
51
|
+
// package.json
|
|
52
|
+
var version = "0.0.0-experimental-dd63c14ca";
|
|
53
|
+
|
|
54
|
+
// prompt.ts
|
|
55
|
+
var import_node_process3 = __toESM(require("process"));
|
|
56
|
+
|
|
57
|
+
// prompts-confirm.ts
|
|
58
|
+
var import_sisteransi3 = require("sisteransi");
|
|
59
|
+
|
|
60
|
+
// prompts-prompt-base.ts
|
|
61
|
+
var import_node_process2 = __toESM(require("process"));
|
|
62
|
+
var import_node_events = __toESM(require("events"));
|
|
63
|
+
var import_node_readline = __toESM(require("readline"));
|
|
64
|
+
var import_sisteransi2 = require("sisteransi");
|
|
65
|
+
|
|
66
|
+
// utils.ts
|
|
67
|
+
var import_node_fs = __toESM(require("fs"));
|
|
68
|
+
var import_promises = require("fs/promises");
|
|
69
|
+
var import_node_path = __toESM(require("path"));
|
|
70
|
+
var import_node_process = __toESM(require("process"));
|
|
71
|
+
var import_node_os = __toESM(require("os"));
|
|
72
|
+
var import_sisteransi = require("sisteransi");
|
|
73
|
+
var import_picocolors = __toESM(require("picocolors"));
|
|
74
|
+
var SUPPORTS_COLOR = import_picocolors.default.isColorSupported;
|
|
75
|
+
var color = {
|
|
76
|
+
supportsColor: SUPPORTS_COLOR,
|
|
77
|
+
heading: safeColor(import_picocolors.default.bold),
|
|
78
|
+
arg: safeColor(import_picocolors.default.yellowBright),
|
|
79
|
+
error: safeColor(import_picocolors.default.red),
|
|
80
|
+
warning: safeColor(import_picocolors.default.yellow),
|
|
81
|
+
hint: safeColor(import_picocolors.default.blue),
|
|
82
|
+
bold: safeColor(import_picocolors.default.bold),
|
|
83
|
+
black: safeColor(import_picocolors.default.black),
|
|
84
|
+
white: safeColor(import_picocolors.default.white),
|
|
85
|
+
blue: safeColor(import_picocolors.default.blue),
|
|
86
|
+
cyan: safeColor(import_picocolors.default.cyan),
|
|
87
|
+
red: safeColor(import_picocolors.default.red),
|
|
88
|
+
yellow: safeColor(import_picocolors.default.yellow),
|
|
89
|
+
green: safeColor(import_picocolors.default.green),
|
|
90
|
+
blackBright: safeColor(import_picocolors.default.blackBright),
|
|
91
|
+
whiteBright: safeColor(import_picocolors.default.whiteBright),
|
|
92
|
+
blueBright: safeColor(import_picocolors.default.blueBright),
|
|
93
|
+
cyanBright: safeColor(import_picocolors.default.cyanBright),
|
|
94
|
+
redBright: safeColor(import_picocolors.default.redBright),
|
|
95
|
+
yellowBright: safeColor(import_picocolors.default.yellowBright),
|
|
96
|
+
greenBright: safeColor(import_picocolors.default.greenBright),
|
|
97
|
+
bgBlack: safeColor(import_picocolors.default.bgBlack),
|
|
98
|
+
bgWhite: safeColor(import_picocolors.default.bgWhite),
|
|
99
|
+
bgBlue: safeColor(import_picocolors.default.bgBlue),
|
|
100
|
+
bgCyan: safeColor(import_picocolors.default.bgCyan),
|
|
101
|
+
bgRed: safeColor(import_picocolors.default.bgRed),
|
|
102
|
+
bgYellow: safeColor(import_picocolors.default.bgYellow),
|
|
103
|
+
bgGreen: safeColor(import_picocolors.default.bgGreen),
|
|
104
|
+
bgBlackBright: safeColor(import_picocolors.default.bgBlackBright),
|
|
105
|
+
bgWhiteBright: safeColor(import_picocolors.default.bgWhiteBright),
|
|
106
|
+
bgBlueBright: safeColor(import_picocolors.default.bgBlueBright),
|
|
107
|
+
bgCyanBright: safeColor(import_picocolors.default.bgCyanBright),
|
|
108
|
+
bgRedBright: safeColor(import_picocolors.default.bgRedBright),
|
|
109
|
+
bgYellowBright: safeColor(import_picocolors.default.bgYellowBright),
|
|
110
|
+
bgGreenBright: safeColor(import_picocolors.default.bgGreenBright),
|
|
111
|
+
gray: safeColor(import_picocolors.default.gray),
|
|
112
|
+
dim: safeColor(import_picocolors.default.dim),
|
|
113
|
+
reset: safeColor(import_picocolors.default.reset),
|
|
114
|
+
inverse: safeColor(import_picocolors.default.inverse),
|
|
115
|
+
hex: (hex) => safeColor(hexColor(hex)),
|
|
116
|
+
underline: import_picocolors.default.underline
|
|
75
117
|
};
|
|
76
|
-
/**
|
|
77
|
-
* Converts a hex color string to an ANSI true-color (24-bit) formatter.
|
|
78
|
-
* Used by the loading indicator gradient animation.
|
|
79
|
-
*/
|
|
80
118
|
function hexColor(hex) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
119
|
+
let h = hex.replace("#", "");
|
|
120
|
+
let r = parseInt(h.substring(0, 2), 16);
|
|
121
|
+
let g = parseInt(h.substring(2, 4), 16);
|
|
122
|
+
let b = parseInt(h.substring(4, 6), 16);
|
|
123
|
+
return (input) => `\x1B[38;2;${r};${g};${b}m${input}\x1B[39m`;
|
|
86
124
|
}
|
|
87
125
|
function safeColor(style) {
|
|
88
|
-
|
|
126
|
+
return SUPPORTS_COLOR ? style : identity;
|
|
89
127
|
}
|
|
90
|
-
|
|
91
|
-
|
|
128
|
+
var unicode = { enabled: import_node_os.default.platform() !== "win32" };
|
|
129
|
+
var shouldUseAscii = () => !unicode.enabled;
|
|
92
130
|
function isInteractive() {
|
|
93
|
-
|
|
94
|
-
|
|
131
|
+
if ("CREATE_REACT_ROUTER_FORCE_INTERACTIVE" in import_node_process.default.env) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return Boolean(
|
|
135
|
+
import_node_process.default.stdout.isTTY && import_node_process.default.env.TERM !== "dumb" && !("CI" in import_node_process.default.env)
|
|
136
|
+
);
|
|
95
137
|
}
|
|
96
138
|
function log(message) {
|
|
97
|
-
|
|
139
|
+
return import_node_process.default.stdout.write(message + "\n");
|
|
98
140
|
}
|
|
99
|
-
|
|
141
|
+
var stderr = import_node_process.default.stderr;
|
|
100
142
|
function logError(message) {
|
|
101
|
-
|
|
143
|
+
return stderr.write(message + "\n");
|
|
102
144
|
}
|
|
103
145
|
function logBullet(logger, colorizePrefix, colorizeText, symbol, prefix, text) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
146
|
+
let textParts = Array.isArray(text) ? text : [text || ""].filter(Boolean);
|
|
147
|
+
let formattedText = textParts.map((textPart) => colorizeText(textPart)).join("");
|
|
148
|
+
if (import_node_process.default.stdout.columns < 80) {
|
|
149
|
+
logger(
|
|
150
|
+
`${" ".repeat(5)} ${colorizePrefix(symbol)} ${colorizePrefix(prefix)}`
|
|
151
|
+
);
|
|
152
|
+
logger(`${" ".repeat(9)}${formattedText}`);
|
|
153
|
+
} else {
|
|
154
|
+
logger(
|
|
155
|
+
`${" ".repeat(5)} ${colorizePrefix(symbol)} ${colorizePrefix(
|
|
156
|
+
prefix
|
|
157
|
+
)} ${formattedText}`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
109
160
|
}
|
|
110
161
|
function debug(prefix, text) {
|
|
111
|
-
|
|
162
|
+
logBullet(log, color.yellow, color.dim, "\u25CF", prefix, text);
|
|
112
163
|
}
|
|
113
164
|
function info(prefix, text) {
|
|
114
|
-
|
|
165
|
+
logBullet(log, color.cyan, color.dim, "\u25FC", prefix, text);
|
|
115
166
|
}
|
|
116
167
|
function error(prefix, text) {
|
|
117
|
-
|
|
118
|
-
|
|
168
|
+
log("");
|
|
169
|
+
logBullet(logError, color.red, color.error, "\u25B2", prefix, text);
|
|
119
170
|
}
|
|
120
171
|
function sleep(ms) {
|
|
121
|
-
|
|
172
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
122
173
|
}
|
|
123
174
|
function toValidProjectName(projectName) {
|
|
124
|
-
|
|
125
|
-
|
|
175
|
+
if (isValidProjectName(projectName)) {
|
|
176
|
+
return projectName;
|
|
177
|
+
}
|
|
178
|
+
return projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z\d\-~]+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
126
179
|
}
|
|
127
180
|
function isValidProjectName(projectName) {
|
|
128
|
-
|
|
181
|
+
return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(
|
|
182
|
+
projectName
|
|
183
|
+
);
|
|
129
184
|
}
|
|
130
185
|
function identity(v) {
|
|
131
|
-
|
|
186
|
+
return v;
|
|
132
187
|
}
|
|
133
188
|
function strip(str) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
189
|
+
let pattern = [
|
|
190
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
191
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
|
192
|
+
].join("|");
|
|
193
|
+
let RGX = new RegExp(pattern, "g");
|
|
194
|
+
return typeof str === "string" ? str.replace(RGX, "") : str;
|
|
137
195
|
}
|
|
138
196
|
function reverse(arr) {
|
|
139
|
-
|
|
197
|
+
return [...arr].reverse();
|
|
140
198
|
}
|
|
141
199
|
function isValidJsonObject(obj) {
|
|
142
|
-
|
|
200
|
+
return !!(obj && typeof obj === "object" && !Array.isArray(obj));
|
|
143
201
|
}
|
|
144
202
|
async function directoryExists(p) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
203
|
+
try {
|
|
204
|
+
let stat = await import_node_fs.default.promises.stat(p);
|
|
205
|
+
return stat.isDirectory();
|
|
206
|
+
} catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
150
209
|
}
|
|
151
210
|
async function ensureDirectory(dir) {
|
|
152
|
-
|
|
211
|
+
if (!await directoryExists(dir)) {
|
|
212
|
+
await import_node_fs.default.promises.mkdir(dir, { recursive: true });
|
|
213
|
+
}
|
|
153
214
|
}
|
|
154
215
|
function isUrl(value) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
function clear(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
216
|
+
try {
|
|
217
|
+
new URL(value);
|
|
218
|
+
return true;
|
|
219
|
+
} catch (e) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function clear(prompt2, perLine) {
|
|
224
|
+
if (!perLine) return import_sisteransi.erase.line + import_sisteransi.cursor.to(0);
|
|
225
|
+
let rows = 0;
|
|
226
|
+
let lines2 = prompt2.split(/\r?\n/);
|
|
227
|
+
for (let line of lines2) {
|
|
228
|
+
rows += 1 + Math.floor(Math.max(strip(line).length - 1, 0) / perLine);
|
|
229
|
+
}
|
|
230
|
+
return import_sisteransi.erase.lines(rows);
|
|
168
231
|
}
|
|
169
232
|
function lines(msg, perLine) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
233
|
+
let lines2 = String(strip(msg) || "").split(/\r?\n/);
|
|
234
|
+
if (!perLine) return lines2.length;
|
|
235
|
+
return lines2.map((l) => Math.ceil(l.length / perLine)).reduce((a, b) => a + b);
|
|
173
236
|
}
|
|
174
237
|
function action(key, isSelect) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
238
|
+
if (key.meta && key.name !== "escape") return;
|
|
239
|
+
if (key.ctrl) {
|
|
240
|
+
if (key.name === "a") return "first";
|
|
241
|
+
if (key.name === "c") return "abort";
|
|
242
|
+
if (key.name === "d") return "abort";
|
|
243
|
+
if (key.name === "e") return "last";
|
|
244
|
+
if (key.name === "g") return "reset";
|
|
245
|
+
}
|
|
246
|
+
if (isSelect) {
|
|
247
|
+
if (key.name === "j") return "down";
|
|
248
|
+
if (key.name === "k") return "up";
|
|
249
|
+
}
|
|
250
|
+
if (key.name === "return") return "submit";
|
|
251
|
+
if (key.name === "enter") return "submit";
|
|
252
|
+
if (key.name === "backspace") return "delete";
|
|
253
|
+
if (key.name === "delete") return "deleteForward";
|
|
254
|
+
if (key.name === "abort") return "abort";
|
|
255
|
+
if (key.name === "escape") return "exit";
|
|
256
|
+
if (key.name === "tab") return "next";
|
|
257
|
+
if (key.name === "pagedown") return "nextPage";
|
|
258
|
+
if (key.name === "pageup") return "prevPage";
|
|
259
|
+
if (key.name === "home") return "home";
|
|
260
|
+
if (key.name === "end") return "end";
|
|
261
|
+
if (key.name === "up") return "up";
|
|
262
|
+
if (key.name === "down") return "down";
|
|
263
|
+
if (key.name === "right") return "right";
|
|
264
|
+
if (key.name === "left") return "left";
|
|
265
|
+
return false;
|
|
203
266
|
}
|
|
204
267
|
function stripDirectoryFromPath(dir, filePath) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
268
|
+
let stripped = filePath;
|
|
269
|
+
if (dir.endsWith(import_node_path.default.sep) && filePath.startsWith(dir) || !dir.endsWith(import_node_path.default.sep) && filePath.startsWith(dir + import_node_path.default.sep)) {
|
|
270
|
+
stripped = filePath.slice(dir.length);
|
|
271
|
+
if (stripped.startsWith(import_node_path.default.sep)) {
|
|
272
|
+
stripped = stripped.slice(1);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return stripped;
|
|
276
|
+
}
|
|
277
|
+
var IGNORED_TEMPLATE_DIRECTORIES = [".git", "node_modules"];
|
|
213
278
|
async function getDirectoryFilesRecursive(dir) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
279
|
+
return (await (0, import_promises.readdir)(dir, { recursive: true })).filter((file) => {
|
|
280
|
+
let parts = file.split(import_node_path.default.sep);
|
|
281
|
+
return parts.length <= 1 || !IGNORED_TEMPLATE_DIRECTORIES.includes(parts[0]);
|
|
282
|
+
});
|
|
218
283
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
|
|
285
|
+
// prompts-prompt-base.ts
|
|
286
|
+
var Prompt = class extends import_node_events.default {
|
|
287
|
+
firstRender;
|
|
288
|
+
in;
|
|
289
|
+
out;
|
|
290
|
+
onRender;
|
|
291
|
+
close;
|
|
292
|
+
aborted;
|
|
293
|
+
exited;
|
|
294
|
+
closed;
|
|
295
|
+
name = "Prompt";
|
|
296
|
+
constructor(opts = {}) {
|
|
297
|
+
super();
|
|
298
|
+
this.firstRender = true;
|
|
299
|
+
this.in = opts.stdin || import_node_process2.default.stdin;
|
|
300
|
+
this.out = opts.stdout || import_node_process2.default.stdout;
|
|
301
|
+
this.onRender = (opts.onRender || (() => void 0)).bind(this);
|
|
302
|
+
let rl = import_node_readline.default.createInterface({
|
|
303
|
+
input: this.in,
|
|
304
|
+
escapeCodeTimeout: 50
|
|
305
|
+
});
|
|
306
|
+
import_node_readline.default.emitKeypressEvents(this.in, rl);
|
|
307
|
+
if (this.in.isTTY) this.in.setRawMode(true);
|
|
308
|
+
let isSelect = ["SelectPrompt", "MultiSelectPrompt"].indexOf(this.constructor.name) > -1;
|
|
309
|
+
let keypress = (str, key) => {
|
|
310
|
+
if (this.in.isTTY) this.in.setRawMode(true);
|
|
311
|
+
let a = action(key, isSelect);
|
|
312
|
+
if (a === false) {
|
|
313
|
+
try {
|
|
314
|
+
this._(str, key);
|
|
315
|
+
} catch (e) {
|
|
316
|
+
}
|
|
317
|
+
} else if (typeof this[a] === "function") {
|
|
318
|
+
this[a](key);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
this.close = () => {
|
|
322
|
+
this.out.write(import_sisteransi2.cursor.show);
|
|
323
|
+
this.in.removeListener("keypress", keypress);
|
|
324
|
+
if (this.in.isTTY) this.in.setRawMode(false);
|
|
325
|
+
rl.close();
|
|
326
|
+
this.emit(
|
|
327
|
+
this.aborted ? "abort" : this.exited ? "exit" : "submit",
|
|
328
|
+
// @ts-expect-error
|
|
329
|
+
this.value
|
|
330
|
+
);
|
|
331
|
+
this.closed = true;
|
|
332
|
+
};
|
|
333
|
+
this.in.on("keypress", keypress);
|
|
334
|
+
}
|
|
335
|
+
get type() {
|
|
336
|
+
throw new Error("Method type not implemented.");
|
|
337
|
+
}
|
|
338
|
+
bell() {
|
|
339
|
+
this.out.write(import_sisteransi2.beep);
|
|
340
|
+
}
|
|
341
|
+
fire() {
|
|
342
|
+
this.emit("state", {
|
|
343
|
+
// @ts-expect-error
|
|
344
|
+
value: this.value,
|
|
345
|
+
aborted: !!this.aborted,
|
|
346
|
+
exited: !!this.exited
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
render() {
|
|
350
|
+
this.onRender(color);
|
|
351
|
+
if (this.firstRender) this.firstRender = false;
|
|
352
|
+
}
|
|
353
|
+
_(c, key) {
|
|
354
|
+
throw new Error("Method _ not implemented.");
|
|
355
|
+
}
|
|
286
356
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Adapted from https://github.com/withastro/cli-kit
|
|
291
|
-
* @license MIT License Copyright (c) 2022 Nate Moore
|
|
292
|
-
*/
|
|
357
|
+
|
|
358
|
+
// prompts-confirm.ts
|
|
293
359
|
var ConfirmPrompt = class extends Prompt {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
360
|
+
label;
|
|
361
|
+
msg;
|
|
362
|
+
value;
|
|
363
|
+
initialValue;
|
|
364
|
+
hint;
|
|
365
|
+
choices;
|
|
366
|
+
cursor;
|
|
367
|
+
done;
|
|
368
|
+
name = "ConfirmPrompt";
|
|
369
|
+
// set by render which is called in constructor
|
|
370
|
+
outputText;
|
|
371
|
+
constructor(opts) {
|
|
372
|
+
super(opts);
|
|
373
|
+
this.label = opts.label;
|
|
374
|
+
this.hint = opts.hint;
|
|
375
|
+
this.msg = opts.message;
|
|
376
|
+
this.value = opts.initial;
|
|
377
|
+
this.initialValue = !!opts.initial;
|
|
378
|
+
this.choices = [
|
|
379
|
+
{ value: true, label: "Yes" },
|
|
380
|
+
{ value: false, label: "No" }
|
|
381
|
+
];
|
|
382
|
+
this.cursor = this.choices.findIndex((c) => c.value === this.initialValue);
|
|
383
|
+
this.render();
|
|
384
|
+
}
|
|
385
|
+
get type() {
|
|
386
|
+
return "confirm";
|
|
387
|
+
}
|
|
388
|
+
exit() {
|
|
389
|
+
this.abort();
|
|
390
|
+
}
|
|
391
|
+
abort() {
|
|
392
|
+
this.done = this.aborted = true;
|
|
393
|
+
this.fire();
|
|
394
|
+
this.render();
|
|
395
|
+
this.out.write("\n");
|
|
396
|
+
this.close();
|
|
397
|
+
}
|
|
398
|
+
submit() {
|
|
399
|
+
this.value = this.value || false;
|
|
400
|
+
this.cursor = this.choices.findIndex((c) => c.value === this.value);
|
|
401
|
+
this.done = true;
|
|
402
|
+
this.aborted = false;
|
|
403
|
+
this.fire();
|
|
404
|
+
this.render();
|
|
405
|
+
this.out.write("\n");
|
|
406
|
+
this.close();
|
|
407
|
+
}
|
|
408
|
+
moveCursor(n) {
|
|
409
|
+
this.cursor = n;
|
|
410
|
+
this.value = this.choices[n].value;
|
|
411
|
+
this.fire();
|
|
412
|
+
}
|
|
413
|
+
reset() {
|
|
414
|
+
this.moveCursor(0);
|
|
415
|
+
this.fire();
|
|
416
|
+
this.render();
|
|
417
|
+
}
|
|
418
|
+
first() {
|
|
419
|
+
this.moveCursor(0);
|
|
420
|
+
this.render();
|
|
421
|
+
}
|
|
422
|
+
last() {
|
|
423
|
+
this.moveCursor(this.choices.length - 1);
|
|
424
|
+
this.render();
|
|
425
|
+
}
|
|
426
|
+
left() {
|
|
427
|
+
if (this.cursor === 0) {
|
|
428
|
+
this.moveCursor(this.choices.length - 1);
|
|
429
|
+
} else {
|
|
430
|
+
this.moveCursor(this.cursor - 1);
|
|
431
|
+
}
|
|
432
|
+
this.render();
|
|
433
|
+
}
|
|
434
|
+
right() {
|
|
435
|
+
if (this.cursor === this.choices.length - 1) {
|
|
436
|
+
this.moveCursor(0);
|
|
437
|
+
} else {
|
|
438
|
+
this.moveCursor(this.cursor + 1);
|
|
439
|
+
}
|
|
440
|
+
this.render();
|
|
441
|
+
}
|
|
442
|
+
_(c, key) {
|
|
443
|
+
if (!Number.isNaN(Number.parseInt(c))) {
|
|
444
|
+
let n = Number.parseInt(c) - 1;
|
|
445
|
+
this.moveCursor(n);
|
|
446
|
+
this.render();
|
|
447
|
+
return this.submit();
|
|
448
|
+
}
|
|
449
|
+
if (c.toLowerCase() === "y") {
|
|
450
|
+
this.value = true;
|
|
451
|
+
return this.submit();
|
|
452
|
+
}
|
|
453
|
+
if (c.toLowerCase() === "n") {
|
|
454
|
+
this.value = false;
|
|
455
|
+
return this.submit();
|
|
456
|
+
}
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
render() {
|
|
460
|
+
if (this.closed) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (this.firstRender) {
|
|
464
|
+
this.out.write(import_sisteransi3.cursor.hide);
|
|
465
|
+
} else {
|
|
466
|
+
this.out.write(clear(this.outputText, this.out.columns));
|
|
467
|
+
}
|
|
468
|
+
super.render();
|
|
469
|
+
let outputText = [
|
|
470
|
+
"\n",
|
|
471
|
+
this.label,
|
|
472
|
+
" ",
|
|
473
|
+
this.msg,
|
|
474
|
+
this.done ? "" : this.hint ? color.dim(` (${this.hint})`) : "",
|
|
475
|
+
"\n"
|
|
476
|
+
];
|
|
477
|
+
outputText.push(" ".repeat(strip(this.label).length));
|
|
478
|
+
if (this.done) {
|
|
479
|
+
outputText.push(" ", color.dim(`${this.choices[this.cursor].label}`));
|
|
480
|
+
} else {
|
|
481
|
+
outputText.push(
|
|
482
|
+
" ",
|
|
483
|
+
this.choices.map(
|
|
484
|
+
(choice, i) => i === this.cursor ? `${color.green("\u25CF")} ${choice.label} ` : color.dim(`\u25CB ${choice.label} `)
|
|
485
|
+
).join(color.dim(" "))
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
this.outputText = outputText.join("");
|
|
489
|
+
this.out.write(import_sisteransi3.erase.line + import_sisteransi3.cursor.to(0) + this.outputText);
|
|
490
|
+
}
|
|
407
491
|
};
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
* Adapted from https://github.com/withastro/cli-kit
|
|
412
|
-
* @license MIT License Copyright (c) 2022 Nate Moore
|
|
413
|
-
*/
|
|
492
|
+
|
|
493
|
+
// prompts-select.ts
|
|
494
|
+
var import_sisteransi4 = require("sisteransi");
|
|
414
495
|
var SelectPrompt = class extends Prompt {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
496
|
+
choices;
|
|
497
|
+
label;
|
|
498
|
+
msg;
|
|
499
|
+
hint;
|
|
500
|
+
value;
|
|
501
|
+
initialValue;
|
|
502
|
+
search;
|
|
503
|
+
done;
|
|
504
|
+
cursor;
|
|
505
|
+
name = "SelectPrompt";
|
|
506
|
+
_timeout;
|
|
507
|
+
// set by render which is called in constructor
|
|
508
|
+
outputText;
|
|
509
|
+
constructor(opts) {
|
|
510
|
+
if (!opts.choices || !Array.isArray(opts.choices) || opts.choices.length < 1) {
|
|
511
|
+
throw new Error("SelectPrompt must contain choices");
|
|
512
|
+
}
|
|
513
|
+
super(opts);
|
|
514
|
+
this.label = opts.label;
|
|
515
|
+
this.hint = opts.hint;
|
|
516
|
+
this.msg = opts.message;
|
|
517
|
+
this.value = opts.initial;
|
|
518
|
+
this.choices = opts.choices;
|
|
519
|
+
this.initialValue = opts.initial || this.choices[0].value;
|
|
520
|
+
this.cursor = this.choices.findIndex((c) => c.value === this.initialValue);
|
|
521
|
+
this.search = null;
|
|
522
|
+
this.render();
|
|
523
|
+
}
|
|
524
|
+
get type() {
|
|
525
|
+
return "select";
|
|
526
|
+
}
|
|
527
|
+
exit() {
|
|
528
|
+
this.abort();
|
|
529
|
+
}
|
|
530
|
+
abort() {
|
|
531
|
+
this.done = this.aborted = true;
|
|
532
|
+
this.cursor = this.choices.findIndex((c) => c.value === this.initialValue);
|
|
533
|
+
this.fire();
|
|
534
|
+
this.render();
|
|
535
|
+
this.out.write("\n");
|
|
536
|
+
this.close();
|
|
537
|
+
}
|
|
538
|
+
submit() {
|
|
539
|
+
this.value = this.value || void 0;
|
|
540
|
+
this.cursor = this.choices.findIndex((c) => c.value === this.value);
|
|
541
|
+
this.done = true;
|
|
542
|
+
this.aborted = false;
|
|
543
|
+
this.fire();
|
|
544
|
+
this.render();
|
|
545
|
+
this.out.write("\n");
|
|
546
|
+
this.close();
|
|
547
|
+
}
|
|
548
|
+
delete() {
|
|
549
|
+
this.search = null;
|
|
550
|
+
this.render();
|
|
551
|
+
}
|
|
552
|
+
_(c, key) {
|
|
553
|
+
if (this._timeout) clearTimeout(this._timeout);
|
|
554
|
+
if (!Number.isNaN(Number.parseInt(c))) {
|
|
555
|
+
let n2 = Number.parseInt(c) - 1;
|
|
556
|
+
this.moveCursor(n2);
|
|
557
|
+
this.render();
|
|
558
|
+
return this.submit();
|
|
559
|
+
}
|
|
560
|
+
this.search = this.search || "";
|
|
561
|
+
this.search += c.toLowerCase();
|
|
562
|
+
let choices = !this.search ? this.choices.slice(this.cursor) : this.choices;
|
|
563
|
+
let n = choices.findIndex(
|
|
564
|
+
(c2) => c2.label.toLowerCase().includes(this.search)
|
|
565
|
+
);
|
|
566
|
+
if (n > -1) {
|
|
567
|
+
this.moveCursor(n);
|
|
568
|
+
this.render();
|
|
569
|
+
}
|
|
570
|
+
this._timeout = setTimeout(() => {
|
|
571
|
+
this.search = null;
|
|
572
|
+
}, 500);
|
|
573
|
+
}
|
|
574
|
+
moveCursor(n) {
|
|
575
|
+
this.cursor = n;
|
|
576
|
+
this.value = this.choices[n].value;
|
|
577
|
+
this.fire();
|
|
578
|
+
}
|
|
579
|
+
reset() {
|
|
580
|
+
this.moveCursor(0);
|
|
581
|
+
this.fire();
|
|
582
|
+
this.render();
|
|
583
|
+
}
|
|
584
|
+
first() {
|
|
585
|
+
this.moveCursor(0);
|
|
586
|
+
this.render();
|
|
587
|
+
}
|
|
588
|
+
last() {
|
|
589
|
+
this.moveCursor(this.choices.length - 1);
|
|
590
|
+
this.render();
|
|
591
|
+
}
|
|
592
|
+
up() {
|
|
593
|
+
if (this.cursor === 0) {
|
|
594
|
+
this.moveCursor(this.choices.length - 1);
|
|
595
|
+
} else {
|
|
596
|
+
this.moveCursor(this.cursor - 1);
|
|
597
|
+
}
|
|
598
|
+
this.render();
|
|
599
|
+
}
|
|
600
|
+
down() {
|
|
601
|
+
if (this.cursor === this.choices.length - 1) {
|
|
602
|
+
this.moveCursor(0);
|
|
603
|
+
} else {
|
|
604
|
+
this.moveCursor(this.cursor + 1);
|
|
605
|
+
}
|
|
606
|
+
this.render();
|
|
607
|
+
}
|
|
608
|
+
highlight(label) {
|
|
609
|
+
if (!this.search) return label;
|
|
610
|
+
let n = label.toLowerCase().indexOf(this.search.toLowerCase());
|
|
611
|
+
if (n === -1) return label;
|
|
612
|
+
return [
|
|
613
|
+
label.slice(0, n),
|
|
614
|
+
color.underline(label.slice(n, n + this.search.length)),
|
|
615
|
+
label.slice(n + this.search.length)
|
|
616
|
+
].join("");
|
|
617
|
+
}
|
|
618
|
+
render() {
|
|
619
|
+
if (this.closed) return;
|
|
620
|
+
if (this.firstRender) this.out.write(import_sisteransi4.cursor.hide);
|
|
621
|
+
else this.out.write(clear(this.outputText, this.out.columns));
|
|
622
|
+
super.render();
|
|
623
|
+
let outputText = [
|
|
624
|
+
"\n",
|
|
625
|
+
this.label,
|
|
626
|
+
" ",
|
|
627
|
+
this.msg,
|
|
628
|
+
this.done ? "" : this.hint ? (this.out.columns < 80 ? "\n" + " ".repeat(8) : "") + color.dim(` (${this.hint})`) : "",
|
|
629
|
+
"\n"
|
|
630
|
+
];
|
|
631
|
+
let prefix = " ".repeat(strip(this.label).length);
|
|
632
|
+
if (this.done) {
|
|
633
|
+
outputText.push(
|
|
634
|
+
`${prefix} `,
|
|
635
|
+
color.dim(`${this.choices[this.cursor]?.label}`)
|
|
636
|
+
);
|
|
637
|
+
} else {
|
|
638
|
+
outputText.push(
|
|
639
|
+
this.choices.map(
|
|
640
|
+
(choice, i) => i === this.cursor ? `${prefix} ${color.green(
|
|
641
|
+
shouldUseAscii() ? ">" : "\u25CF"
|
|
642
|
+
)} ${this.highlight(choice.label)} ${choice.hint ? color.dim(choice.hint) : ""}` : color.dim(
|
|
643
|
+
`${prefix} ${shouldUseAscii() ? "\u2014" : "\u25CB"} ${choice.label} `
|
|
644
|
+
)
|
|
645
|
+
).join("\n")
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
this.outputText = outputText.join("");
|
|
649
|
+
this.out.write(import_sisteransi4.erase.line + import_sisteransi4.cursor.to(0) + this.outputText);
|
|
650
|
+
}
|
|
544
651
|
};
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
* Adapted from https://github.com/withastro/cli-kit
|
|
549
|
-
* @license MIT License Copyright (c) 2022 Nate Moore
|
|
550
|
-
*/
|
|
652
|
+
|
|
653
|
+
// prompts-multi-select.ts
|
|
654
|
+
var import_sisteransi5 = require("sisteransi");
|
|
551
655
|
var MultiSelectPrompt = class extends Prompt {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
656
|
+
choices;
|
|
657
|
+
label;
|
|
658
|
+
msg;
|
|
659
|
+
hint;
|
|
660
|
+
value;
|
|
661
|
+
initialValue;
|
|
662
|
+
done;
|
|
663
|
+
cursor;
|
|
664
|
+
name = "MultiSelectPrompt";
|
|
665
|
+
// set by render which is called in constructor
|
|
666
|
+
outputText;
|
|
667
|
+
constructor(opts) {
|
|
668
|
+
if (!opts.choices || !Array.isArray(opts.choices) || opts.choices.length < 1) {
|
|
669
|
+
throw new Error("MultiSelectPrompt must contain choices");
|
|
670
|
+
}
|
|
671
|
+
super(opts);
|
|
672
|
+
this.label = opts.label;
|
|
673
|
+
this.msg = opts.message;
|
|
674
|
+
this.hint = opts.hint;
|
|
675
|
+
this.value = [];
|
|
676
|
+
this.choices = opts.choices.map((choice) => ({ ...choice, selected: false })) || [];
|
|
677
|
+
this.initialValue = opts.initial || this.choices[0].value;
|
|
678
|
+
this.cursor = this.choices.findIndex((c) => c.value === this.initialValue);
|
|
679
|
+
this.render();
|
|
680
|
+
}
|
|
681
|
+
get type() {
|
|
682
|
+
return "multiselect";
|
|
683
|
+
}
|
|
684
|
+
exit() {
|
|
685
|
+
this.abort();
|
|
686
|
+
}
|
|
687
|
+
abort() {
|
|
688
|
+
this.done = this.aborted = true;
|
|
689
|
+
this.cursor = this.choices.findIndex((c) => c.value === this.initialValue);
|
|
690
|
+
this.fire();
|
|
691
|
+
this.render();
|
|
692
|
+
this.out.write("\n");
|
|
693
|
+
this.close();
|
|
694
|
+
}
|
|
695
|
+
submit() {
|
|
696
|
+
return this.toggle();
|
|
697
|
+
}
|
|
698
|
+
finish() {
|
|
699
|
+
this.value = this.value;
|
|
700
|
+
this.done = true;
|
|
701
|
+
this.aborted = false;
|
|
702
|
+
this.fire();
|
|
703
|
+
this.render();
|
|
704
|
+
this.out.write("\n");
|
|
705
|
+
this.close();
|
|
706
|
+
}
|
|
707
|
+
moveCursor(n) {
|
|
708
|
+
this.cursor = n;
|
|
709
|
+
this.fire();
|
|
710
|
+
}
|
|
711
|
+
toggle() {
|
|
712
|
+
let choice = this.choices[this.cursor];
|
|
713
|
+
if (!choice) return;
|
|
714
|
+
choice.selected = !choice.selected;
|
|
715
|
+
this.render();
|
|
716
|
+
}
|
|
717
|
+
_(c, key) {
|
|
718
|
+
if (c === " ") {
|
|
719
|
+
return this.toggle();
|
|
720
|
+
}
|
|
721
|
+
if (c.toLowerCase() === "c") {
|
|
722
|
+
return this.finish();
|
|
723
|
+
}
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
reset() {
|
|
727
|
+
this.moveCursor(0);
|
|
728
|
+
this.fire();
|
|
729
|
+
this.render();
|
|
730
|
+
}
|
|
731
|
+
first() {
|
|
732
|
+
this.moveCursor(0);
|
|
733
|
+
this.render();
|
|
734
|
+
}
|
|
735
|
+
last() {
|
|
736
|
+
this.moveCursor(this.choices.length - 1);
|
|
737
|
+
this.render();
|
|
738
|
+
}
|
|
739
|
+
up() {
|
|
740
|
+
if (this.cursor === 0) {
|
|
741
|
+
this.moveCursor(this.choices.length - 1);
|
|
742
|
+
} else {
|
|
743
|
+
this.moveCursor(this.cursor - 1);
|
|
744
|
+
}
|
|
745
|
+
this.render();
|
|
746
|
+
}
|
|
747
|
+
down() {
|
|
748
|
+
if (this.cursor === this.choices.length - 1) {
|
|
749
|
+
this.moveCursor(0);
|
|
750
|
+
} else {
|
|
751
|
+
this.moveCursor(this.cursor + 1);
|
|
752
|
+
}
|
|
753
|
+
this.render();
|
|
754
|
+
}
|
|
755
|
+
render() {
|
|
756
|
+
if (this.closed) return;
|
|
757
|
+
if (this.firstRender) {
|
|
758
|
+
this.out.write(import_sisteransi5.cursor.hide);
|
|
759
|
+
} else {
|
|
760
|
+
this.out.write(clear(this.outputText, this.out.columns));
|
|
761
|
+
}
|
|
762
|
+
super.render();
|
|
763
|
+
let outputText = ["\n", this.label, " ", this.msg, "\n"];
|
|
764
|
+
let prefix = " ".repeat(strip(this.label).length);
|
|
765
|
+
if (this.done) {
|
|
766
|
+
outputText.push(
|
|
767
|
+
this.choices.map(
|
|
768
|
+
(choice) => choice.selected ? `${prefix} ${color.dim(`${choice.label}`)}
|
|
769
|
+
` : ""
|
|
770
|
+
).join("").trimEnd()
|
|
771
|
+
);
|
|
772
|
+
} else {
|
|
773
|
+
outputText.push(
|
|
774
|
+
this.choices.map(
|
|
775
|
+
(choice, i) => i === this.cursor ? `${prefix.slice(0, -2)}${color.cyanBright("\u25B6")} ${choice.selected ? color.green("\u25A0") : color.whiteBright("\u25A1")} ${color.underline(choice.label)} ${choice.hint ? color.dim(choice.hint) : ""}` : color[choice.selected ? "reset" : "dim"](
|
|
776
|
+
`${prefix} ${choice.selected ? color.green("\u25A0") : "\u25A1"} ${choice.label} `
|
|
777
|
+
)
|
|
778
|
+
).join("\n")
|
|
779
|
+
);
|
|
780
|
+
outputText.push(
|
|
781
|
+
`
|
|
782
|
+
|
|
783
|
+
${prefix} Press ${color.inverse(" C ")} to continue`
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
this.outputText = outputText.join("");
|
|
787
|
+
this.out.write(import_sisteransi5.erase.line + import_sisteransi5.cursor.to(0) + this.outputText);
|
|
788
|
+
}
|
|
661
789
|
};
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
* Adapted from https://github.com/withastro/cli-kit
|
|
666
|
-
* @license MIT License Copyright (c) 2022 Nate Moore
|
|
667
|
-
*/
|
|
790
|
+
|
|
791
|
+
// prompts-text.ts
|
|
792
|
+
var import_sisteransi6 = require("sisteransi");
|
|
668
793
|
var TextPrompt = class extends Prompt {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
794
|
+
transform;
|
|
795
|
+
label;
|
|
796
|
+
scale;
|
|
797
|
+
msg;
|
|
798
|
+
initial;
|
|
799
|
+
hint;
|
|
800
|
+
validator;
|
|
801
|
+
errorMsg;
|
|
802
|
+
cursor;
|
|
803
|
+
cursorOffset;
|
|
804
|
+
clear;
|
|
805
|
+
done;
|
|
806
|
+
error;
|
|
807
|
+
red;
|
|
808
|
+
outputError;
|
|
809
|
+
name = "TextPrompt";
|
|
810
|
+
// set by value setter, value is set in constructor
|
|
811
|
+
_value;
|
|
812
|
+
placeholder;
|
|
813
|
+
rendered;
|
|
814
|
+
// set by render which is called in constructor
|
|
815
|
+
outputText;
|
|
816
|
+
constructor(opts) {
|
|
817
|
+
super(opts);
|
|
818
|
+
this.transform = { render: (v) => v, scale: 1 };
|
|
819
|
+
this.label = opts.label;
|
|
820
|
+
this.scale = this.transform.scale;
|
|
821
|
+
this.msg = opts.message;
|
|
822
|
+
this.hint = opts.hint;
|
|
823
|
+
this.initial = opts.initial || "";
|
|
824
|
+
this.validator = opts.validate || (() => true);
|
|
825
|
+
this.value = "";
|
|
826
|
+
this.errorMsg = opts.error || "Please enter a valid value";
|
|
827
|
+
this.cursor = Number(!!this.initial);
|
|
828
|
+
this.cursorOffset = 0;
|
|
829
|
+
this.clear = clear(``, this.out.columns);
|
|
830
|
+
this.render();
|
|
831
|
+
}
|
|
832
|
+
get type() {
|
|
833
|
+
return "text";
|
|
834
|
+
}
|
|
835
|
+
set value(v) {
|
|
836
|
+
if (!v && this.initial) {
|
|
837
|
+
this.placeholder = true;
|
|
838
|
+
this.rendered = color.dim(this.initial);
|
|
839
|
+
} else {
|
|
840
|
+
this.placeholder = false;
|
|
841
|
+
this.rendered = this.transform.render(v);
|
|
842
|
+
}
|
|
843
|
+
this._value = v;
|
|
844
|
+
this.fire();
|
|
845
|
+
}
|
|
846
|
+
get value() {
|
|
847
|
+
return this._value;
|
|
848
|
+
}
|
|
849
|
+
reset() {
|
|
850
|
+
this.value = "";
|
|
851
|
+
this.cursor = Number(!!this.initial);
|
|
852
|
+
this.cursorOffset = 0;
|
|
853
|
+
this.fire();
|
|
854
|
+
this.render();
|
|
855
|
+
}
|
|
856
|
+
exit() {
|
|
857
|
+
this.abort();
|
|
858
|
+
}
|
|
859
|
+
abort() {
|
|
860
|
+
this.value = this.value || this.initial;
|
|
861
|
+
this.done = this.aborted = true;
|
|
862
|
+
this.error = false;
|
|
863
|
+
this.red = false;
|
|
864
|
+
this.fire();
|
|
865
|
+
this.render();
|
|
866
|
+
this.out.write("\n");
|
|
867
|
+
this.close();
|
|
868
|
+
}
|
|
869
|
+
async validate() {
|
|
870
|
+
let valid2 = await this.validator(this.value);
|
|
871
|
+
if (typeof valid2 === `string`) {
|
|
872
|
+
this.errorMsg = valid2;
|
|
873
|
+
valid2 = false;
|
|
874
|
+
}
|
|
875
|
+
this.error = !valid2;
|
|
876
|
+
}
|
|
877
|
+
async submit() {
|
|
878
|
+
this.value = this.value || this.initial;
|
|
879
|
+
this.cursorOffset = 0;
|
|
880
|
+
this.cursor = this.rendered.length;
|
|
881
|
+
await this.validate();
|
|
882
|
+
if (this.error) {
|
|
883
|
+
this.red = true;
|
|
884
|
+
this.fire();
|
|
885
|
+
this.render();
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
this.done = true;
|
|
889
|
+
this.aborted = false;
|
|
890
|
+
this.fire();
|
|
891
|
+
this.render();
|
|
892
|
+
this.out.write("\n");
|
|
893
|
+
this.close();
|
|
894
|
+
}
|
|
895
|
+
next() {
|
|
896
|
+
if (!this.placeholder) return this.bell();
|
|
897
|
+
this.value = this.initial;
|
|
898
|
+
this.cursor = this.rendered.length;
|
|
899
|
+
this.fire();
|
|
900
|
+
this.render();
|
|
901
|
+
}
|
|
902
|
+
moveCursor(n) {
|
|
903
|
+
if (this.placeholder) return;
|
|
904
|
+
this.cursor = this.cursor + n;
|
|
905
|
+
this.cursorOffset += n;
|
|
906
|
+
}
|
|
907
|
+
_(c, key) {
|
|
908
|
+
let s1 = this.value.slice(0, this.cursor);
|
|
909
|
+
let s2 = this.value.slice(this.cursor);
|
|
910
|
+
this.value = `${s1}${c}${s2}`;
|
|
911
|
+
this.red = false;
|
|
912
|
+
this.cursor = this.placeholder ? 0 : s1.length + 1;
|
|
913
|
+
this.render();
|
|
914
|
+
}
|
|
915
|
+
delete() {
|
|
916
|
+
if (this.isCursorAtStart()) return this.bell();
|
|
917
|
+
let s1 = this.value.slice(0, this.cursor - 1);
|
|
918
|
+
let s2 = this.value.slice(this.cursor);
|
|
919
|
+
this.value = `${s1}${s2}`;
|
|
920
|
+
this.red = false;
|
|
921
|
+
this.outputError = "";
|
|
922
|
+
this.error = false;
|
|
923
|
+
if (this.isCursorAtStart()) {
|
|
924
|
+
this.cursorOffset = 0;
|
|
925
|
+
} else {
|
|
926
|
+
this.cursorOffset++;
|
|
927
|
+
this.moveCursor(-1);
|
|
928
|
+
}
|
|
929
|
+
this.render();
|
|
930
|
+
}
|
|
931
|
+
deleteForward() {
|
|
932
|
+
if (this.cursor * this.scale >= this.rendered.length || this.placeholder)
|
|
933
|
+
return this.bell();
|
|
934
|
+
let s1 = this.value.slice(0, this.cursor);
|
|
935
|
+
let s2 = this.value.slice(this.cursor + 1);
|
|
936
|
+
this.value = `${s1}${s2}`;
|
|
937
|
+
this.red = false;
|
|
938
|
+
this.outputError = "";
|
|
939
|
+
this.error = false;
|
|
940
|
+
if (this.isCursorAtEnd()) {
|
|
941
|
+
this.cursorOffset = 0;
|
|
942
|
+
} else {
|
|
943
|
+
this.cursorOffset++;
|
|
944
|
+
}
|
|
945
|
+
this.render();
|
|
946
|
+
}
|
|
947
|
+
first() {
|
|
948
|
+
this.cursor = 0;
|
|
949
|
+
this.render();
|
|
950
|
+
}
|
|
951
|
+
last() {
|
|
952
|
+
this.cursor = this.value.length;
|
|
953
|
+
this.render();
|
|
954
|
+
}
|
|
955
|
+
left() {
|
|
956
|
+
if (this.cursor <= 0 || this.placeholder) return this.bell();
|
|
957
|
+
this.moveCursor(-1);
|
|
958
|
+
this.render();
|
|
959
|
+
}
|
|
960
|
+
right() {
|
|
961
|
+
if (this.cursor * this.scale >= this.rendered.length || this.placeholder)
|
|
962
|
+
return this.bell();
|
|
963
|
+
this.moveCursor(1);
|
|
964
|
+
this.render();
|
|
965
|
+
}
|
|
966
|
+
isCursorAtStart() {
|
|
967
|
+
return this.cursor === 0 || this.placeholder && this.cursor === 1;
|
|
968
|
+
}
|
|
969
|
+
isCursorAtEnd() {
|
|
970
|
+
return this.cursor === this.rendered.length || this.placeholder && this.cursor === this.rendered.length + 1;
|
|
971
|
+
}
|
|
972
|
+
render() {
|
|
973
|
+
if (this.closed) return;
|
|
974
|
+
if (!this.firstRender) {
|
|
975
|
+
if (this.outputError)
|
|
976
|
+
this.out.write(
|
|
977
|
+
import_sisteransi6.cursor.down(lines(this.outputError, this.out.columns) - 1) + clear(this.outputError, this.out.columns)
|
|
978
|
+
);
|
|
979
|
+
this.out.write(clear(this.outputText, this.out.columns));
|
|
980
|
+
}
|
|
981
|
+
super.render();
|
|
982
|
+
this.outputError = "";
|
|
983
|
+
let prefix = " ".repeat(strip(this.label).length);
|
|
984
|
+
this.outputText = [
|
|
985
|
+
"\n",
|
|
986
|
+
this.label,
|
|
987
|
+
" ",
|
|
988
|
+
this.msg,
|
|
989
|
+
this.done ? "" : this.hint ? (this.out.columns < 80 ? "\n" + " ".repeat(8) : "") + color.dim(` (${this.hint})`) : "",
|
|
990
|
+
"\n" + prefix,
|
|
991
|
+
" ",
|
|
992
|
+
this.done ? color.dim(this.rendered) : this.rendered
|
|
993
|
+
].join("");
|
|
994
|
+
if (this.error) {
|
|
995
|
+
this.outputError += ` ${color.redBright(
|
|
996
|
+
(shouldUseAscii() ? "> " : "\u25B6 ") + this.errorMsg
|
|
997
|
+
)}`;
|
|
998
|
+
}
|
|
999
|
+
this.out.write(
|
|
1000
|
+
import_sisteransi6.erase.line + import_sisteransi6.cursor.to(0) + this.outputText + import_sisteransi6.cursor.save + this.outputError + import_sisteransi6.cursor.restore + import_sisteransi6.cursor.move(
|
|
1001
|
+
this.placeholder ? (this.rendered.length - 9) * -1 : this.cursorOffset,
|
|
1002
|
+
0
|
|
1003
|
+
)
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
864
1006
|
};
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
1007
|
+
|
|
1008
|
+
// prompt.ts
|
|
1009
|
+
var prompts = {
|
|
1010
|
+
text: (args) => toPrompt(TextPrompt, args),
|
|
1011
|
+
confirm: (args) => toPrompt(ConfirmPrompt, args),
|
|
1012
|
+
select: (args) => toPrompt(SelectPrompt, args),
|
|
1013
|
+
multiselect: (args) => toPrompt(MultiSelectPrompt, args)
|
|
872
1014
|
};
|
|
873
1015
|
async function prompt(questions, opts = {}) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1016
|
+
let {
|
|
1017
|
+
onSubmit = identity,
|
|
1018
|
+
onCancel = () => import_node_process3.default.exit(0),
|
|
1019
|
+
stdin = import_node_process3.default.stdin,
|
|
1020
|
+
stdout = import_node_process3.default.stdout
|
|
1021
|
+
} = opts;
|
|
1022
|
+
let answers = {};
|
|
1023
|
+
let questionsArray = Array.isArray(questions) ? questions : [questions];
|
|
1024
|
+
let answer;
|
|
1025
|
+
let quit;
|
|
1026
|
+
let name;
|
|
1027
|
+
let type;
|
|
1028
|
+
for (let question of questionsArray) {
|
|
1029
|
+
({ name, type } = question);
|
|
1030
|
+
try {
|
|
1031
|
+
answer = await prompts[type](Object.assign({ stdin, stdout }, question));
|
|
1032
|
+
answers[name] = answer;
|
|
1033
|
+
quit = await onSubmit(question, answer, answers);
|
|
1034
|
+
} catch (e) {
|
|
1035
|
+
quit = !await onCancel(question, answers);
|
|
1036
|
+
}
|
|
1037
|
+
if (quit) {
|
|
1038
|
+
return answers;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return answers;
|
|
896
1042
|
}
|
|
897
1043
|
function toPrompt(el, args, opts = {}) {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1044
|
+
if (el !== TextPrompt && el !== ConfirmPrompt && el !== SelectPrompt && el !== MultiSelectPrompt) {
|
|
1045
|
+
throw new Error(`Invalid prompt type: ${el.name}`);
|
|
1046
|
+
}
|
|
1047
|
+
return new Promise((res, rej) => {
|
|
1048
|
+
let p = new el(
|
|
1049
|
+
args,
|
|
1050
|
+
// @ts-expect-error
|
|
1051
|
+
opts
|
|
1052
|
+
);
|
|
1053
|
+
let onAbort = args.onAbort || opts.onAbort || identity;
|
|
1054
|
+
let onSubmit = args.onSubmit || opts.onSubmit || identity;
|
|
1055
|
+
let onExit = args.onExit || opts.onExit || identity;
|
|
1056
|
+
p.on("state", args.onState || identity);
|
|
1057
|
+
p.on("submit", (x) => res(onSubmit(x)));
|
|
1058
|
+
p.on("exit", (x) => res(onExit(x)));
|
|
1059
|
+
p.on("abort", (x) => rej(onAbort(x)));
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// loading-indicator.ts
|
|
1064
|
+
var import_node_process4 = __toESM(require("process"));
|
|
1065
|
+
var import_node_readline2 = __toESM(require("readline"));
|
|
1066
|
+
var import_sisteransi7 = require("sisteransi");
|
|
1067
|
+
var GRADIENT_COLORS = [
|
|
1068
|
+
"#ffffff",
|
|
1069
|
+
"#dadada",
|
|
1070
|
+
"#dadada",
|
|
1071
|
+
"#a8deaa",
|
|
1072
|
+
"#a8deaa",
|
|
1073
|
+
"#a8deaa",
|
|
1074
|
+
"#d0f0bd",
|
|
1075
|
+
"#d0f0bd",
|
|
1076
|
+
"#ffffed",
|
|
1077
|
+
"#ffffed",
|
|
1078
|
+
"#ffffed",
|
|
1079
|
+
"#ffffed",
|
|
1080
|
+
"#ffffed",
|
|
1081
|
+
"#ffffed",
|
|
1082
|
+
"#ffffed",
|
|
1083
|
+
"#ffffed",
|
|
1084
|
+
"#ffffed",
|
|
1085
|
+
"#f7f8ca",
|
|
1086
|
+
"#f7f8ca",
|
|
1087
|
+
"#eae6ba",
|
|
1088
|
+
"#eae6ba",
|
|
1089
|
+
"#eae6ba",
|
|
1090
|
+
"#dadada",
|
|
1091
|
+
"#dadada",
|
|
1092
|
+
"#ffffff"
|
|
938
1093
|
];
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1094
|
+
var MAX_FRAMES = 8;
|
|
1095
|
+
var LEADING_FRAMES = Array.from(
|
|
1096
|
+
{ length: MAX_FRAMES * 2 },
|
|
1097
|
+
() => GRADIENT_COLORS[0]
|
|
1098
|
+
);
|
|
1099
|
+
var TRAILING_FRAMES = Array.from(
|
|
1100
|
+
{ length: MAX_FRAMES * 2 },
|
|
1101
|
+
() => GRADIENT_COLORS[GRADIENT_COLORS.length - 1]
|
|
1102
|
+
);
|
|
1103
|
+
var INDICATOR_FULL_FRAMES = [
|
|
1104
|
+
...LEADING_FRAMES,
|
|
1105
|
+
...GRADIENT_COLORS,
|
|
1106
|
+
...TRAILING_FRAMES,
|
|
1107
|
+
...reverse(GRADIENT_COLORS)
|
|
947
1108
|
];
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1109
|
+
var INDICATOR_GRADIENT = reverse(
|
|
1110
|
+
INDICATOR_FULL_FRAMES.map((_, i) => loadingIndicatorFrame(i))
|
|
1111
|
+
);
|
|
1112
|
+
async function renderLoadingIndicator({
|
|
1113
|
+
start,
|
|
1114
|
+
end,
|
|
1115
|
+
while: update = () => sleep(100),
|
|
1116
|
+
noMotion = false,
|
|
1117
|
+
stdin = import_node_process4.default.stdin,
|
|
1118
|
+
stdout = import_node_process4.default.stdout
|
|
1119
|
+
}) {
|
|
1120
|
+
let act = update();
|
|
1121
|
+
let tooSlow = /* @__PURE__ */ Object.create(null);
|
|
1122
|
+
let result = await Promise.race([sleep(500).then(() => tooSlow), act]);
|
|
1123
|
+
if (result === tooSlow) {
|
|
1124
|
+
let loading = await gradient(color.green(start), {
|
|
1125
|
+
stdin,
|
|
1126
|
+
stdout,
|
|
1127
|
+
noMotion
|
|
1128
|
+
});
|
|
1129
|
+
await act;
|
|
1130
|
+
loading.stop();
|
|
1131
|
+
}
|
|
1132
|
+
stdout.write(`${" ".repeat(5)} ${color.green("\u2714")} ${color.green(end)}
|
|
1133
|
+
`);
|
|
962
1134
|
}
|
|
963
1135
|
function loadingIndicatorFrame(offset = 0) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1136
|
+
let frames = INDICATOR_FULL_FRAMES.slice(offset, offset + (MAX_FRAMES - 2));
|
|
1137
|
+
if (frames.length < MAX_FRAMES - 2) {
|
|
1138
|
+
let filled = new Array(MAX_FRAMES - frames.length - 2).fill(
|
|
1139
|
+
GRADIENT_COLORS[0]
|
|
1140
|
+
);
|
|
1141
|
+
frames.push(...filled);
|
|
1142
|
+
}
|
|
1143
|
+
return frames;
|
|
970
1144
|
}
|
|
971
1145
|
function getGradientAnimationFrames() {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1146
|
+
return INDICATOR_GRADIENT.map(
|
|
1147
|
+
(colors) => " " + colors.map((g, i) => color.hex(g)("\u2588")).join("")
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
async function gradient(text, { stdin = import_node_process4.default.stdin, stdout = import_node_process4.default.stdout, noMotion = false } = {}) {
|
|
1151
|
+
let { createLogUpdate } = await import("log-update");
|
|
1152
|
+
let logUpdate = createLogUpdate(stdout);
|
|
1153
|
+
let frameIndex = 0;
|
|
1154
|
+
let frames = getGradientAnimationFrames();
|
|
1155
|
+
let interval;
|
|
1156
|
+
let rl = import_node_readline2.default.createInterface({ input: stdin, escapeCodeTimeout: 50 });
|
|
1157
|
+
import_node_readline2.default.emitKeypressEvents(stdin, rl);
|
|
1158
|
+
if (stdin.isTTY) stdin.setRawMode(true);
|
|
1159
|
+
function keypress(char) {
|
|
1160
|
+
if (char === "") {
|
|
1161
|
+
loadingIndicator2.stop();
|
|
1162
|
+
import_node_process4.default.exit(0);
|
|
1163
|
+
}
|
|
1164
|
+
if (stdin.isTTY) stdin.setRawMode(true);
|
|
1165
|
+
stdout.write(import_sisteransi7.cursor.hide + import_sisteransi7.erase.lines(1));
|
|
1166
|
+
}
|
|
1167
|
+
let done = false;
|
|
1168
|
+
let loadingIndicator2 = {
|
|
1169
|
+
start() {
|
|
1170
|
+
stdout.write(import_sisteransi7.cursor.hide);
|
|
1171
|
+
stdin.on("keypress", keypress);
|
|
1172
|
+
logUpdate(`${frames[0]} ${text}`);
|
|
1173
|
+
async function loop() {
|
|
1174
|
+
if (done) return;
|
|
1175
|
+
if (frameIndex < frames.length - 1) {
|
|
1176
|
+
frameIndex++;
|
|
1177
|
+
} else {
|
|
1178
|
+
frameIndex = 0;
|
|
1179
|
+
}
|
|
1180
|
+
let frame = frames[frameIndex];
|
|
1181
|
+
logUpdate(
|
|
1182
|
+
`${(noMotion ? getMotionlessFrame(frameIndex) : color.supportsColor ? frame : getColorlessFrame(frameIndex)).padEnd(MAX_FRAMES - 1, " ")} ${text}`
|
|
1183
|
+
);
|
|
1184
|
+
if (!done) await sleep(20);
|
|
1185
|
+
loop();
|
|
1186
|
+
}
|
|
1187
|
+
loop();
|
|
1188
|
+
},
|
|
1189
|
+
stop() {
|
|
1190
|
+
done = true;
|
|
1191
|
+
stdin.removeListener("keypress", keypress);
|
|
1192
|
+
clearInterval(interval);
|
|
1193
|
+
logUpdate.clear();
|
|
1194
|
+
rl.close();
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
loadingIndicator2.start();
|
|
1198
|
+
return loadingIndicator2;
|
|
1019
1199
|
}
|
|
1020
1200
|
function getColorlessFrame(frameIndex) {
|
|
1021
|
-
|
|
1201
|
+
return (frameIndex % 3 === 0 ? ".. .. " : frameIndex % 3 === 1 ? " .. .." : ". .. .").padEnd(MAX_FRAMES - 1 + 20, " ");
|
|
1022
1202
|
}
|
|
1023
1203
|
function getMotionlessFrame(frameIndex) {
|
|
1024
|
-
|
|
1204
|
+
return " ".repeat(MAX_FRAMES - 1);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// copy-template.ts
|
|
1208
|
+
var import_node_process5 = __toESM(require("process"));
|
|
1209
|
+
var import_node_url = __toESM(require("url"));
|
|
1210
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
1211
|
+
var import_node_path2 = __toESM(require("path"));
|
|
1212
|
+
var import_node_stream = __toESM(require("stream"));
|
|
1213
|
+
var import_node_util = require("util");
|
|
1214
|
+
var import_web_fetch = require("@remix-run/web-fetch");
|
|
1215
|
+
var import_gunzip_maybe = __toESM(require("gunzip-maybe"));
|
|
1216
|
+
var import_tar_fs = __toESM(require("tar-fs"));
|
|
1217
|
+
var import_proxy_agent = require("proxy-agent");
|
|
1218
|
+
var defaultAgent = new import_proxy_agent.ProxyAgent();
|
|
1219
|
+
var httpsAgent = new import_proxy_agent.ProxyAgent();
|
|
1220
|
+
httpsAgent.protocol = "https:";
|
|
1221
|
+
function agent(url2) {
|
|
1222
|
+
return new URL(url2).protocol === "https:" ? httpsAgent : defaultAgent;
|
|
1025
1223
|
}
|
|
1026
|
-
//#endregion
|
|
1027
|
-
//#region copy-template.ts
|
|
1028
1224
|
async function copyTemplate(template, destPath, options) {
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
await options.onError(error);
|
|
1062
|
-
}
|
|
1225
|
+
let { log: log2 = () => {
|
|
1226
|
+
} } = options;
|
|
1227
|
+
try {
|
|
1228
|
+
if (isLocalFilePath(template)) {
|
|
1229
|
+
log2(`Using the template from local file at "${template}"`);
|
|
1230
|
+
let filepath = template.startsWith("file://") ? import_node_url.default.fileURLToPath(template) : template;
|
|
1231
|
+
let isLocalDir = await copyTemplateFromLocalFilePath(filepath, destPath);
|
|
1232
|
+
return isLocalDir ? { localTemplateDirectory: filepath } : void 0;
|
|
1233
|
+
}
|
|
1234
|
+
if (isGithubRepoShorthand(template)) {
|
|
1235
|
+
log2(`Using the template from the "${template}" repo`);
|
|
1236
|
+
await copyTemplateFromGithubRepoShorthand(template, destPath, options);
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
if (isValidGithubRepoUrl(template)) {
|
|
1240
|
+
log2(`Using the template from "${template}"`);
|
|
1241
|
+
await copyTemplateFromGithubRepoUrl(template, destPath, options);
|
|
1242
|
+
return;
|
|
1243
|
+
}
|
|
1244
|
+
if (isUrl(template)) {
|
|
1245
|
+
log2(`Using the template from "${template}"`);
|
|
1246
|
+
await copyTemplateFromGenericUrl(template, destPath, options);
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
throw new CopyTemplateError(
|
|
1250
|
+
`"${color.bold(template)}" is an invalid template. Run ${color.bold(
|
|
1251
|
+
"create-react-router --help"
|
|
1252
|
+
)} to see supported template formats.`
|
|
1253
|
+
);
|
|
1254
|
+
} catch (error2) {
|
|
1255
|
+
await options.onError(error2);
|
|
1256
|
+
}
|
|
1063
1257
|
}
|
|
1064
1258
|
function isLocalFilePath(input) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1259
|
+
try {
|
|
1260
|
+
return input.startsWith("file://") || import_node_fs2.default.existsSync(
|
|
1261
|
+
import_node_path2.default.isAbsolute(input) ? input : import_node_path2.default.resolve(import_node_process5.default.cwd(), input)
|
|
1262
|
+
);
|
|
1263
|
+
} catch (e) {
|
|
1264
|
+
return false;
|
|
1265
|
+
}
|
|
1070
1266
|
}
|
|
1071
|
-
async function copyTemplateFromRemoteTarball(
|
|
1072
|
-
|
|
1267
|
+
async function copyTemplateFromRemoteTarball(url2, destPath, options) {
|
|
1268
|
+
return await downloadAndExtractTarball(destPath, url2, options);
|
|
1073
1269
|
}
|
|
1074
1270
|
async function copyTemplateFromGithubRepoShorthand(repoShorthand, destPath, options) {
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1271
|
+
let [owner, name, ...path4] = repoShorthand.split("/");
|
|
1272
|
+
let filePath = path4.length ? path4.join("/") : null;
|
|
1273
|
+
await downloadAndExtractRepoTarball(
|
|
1274
|
+
{ owner, name, filePath },
|
|
1275
|
+
destPath,
|
|
1276
|
+
options
|
|
1277
|
+
);
|
|
1081
1278
|
}
|
|
1082
1279
|
async function copyTemplateFromGithubRepoUrl(repoUrl, destPath, options) {
|
|
1083
|
-
|
|
1280
|
+
await downloadAndExtractRepoTarball(getRepoInfo(repoUrl), destPath, options);
|
|
1084
1281
|
}
|
|
1085
|
-
async function copyTemplateFromGenericUrl(
|
|
1086
|
-
|
|
1282
|
+
async function copyTemplateFromGenericUrl(url2, destPath, options) {
|
|
1283
|
+
await copyTemplateFromRemoteTarball(url2, destPath, options);
|
|
1087
1284
|
}
|
|
1088
1285
|
async function copyTemplateFromLocalFilePath(filePath, destPath) {
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1286
|
+
if (filePath.endsWith(".tar.gz") || filePath.endsWith(".tgz")) {
|
|
1287
|
+
await extractLocalTarball(filePath, destPath);
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
if (import_node_fs2.default.statSync(filePath).isDirectory()) {
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
throw new CopyTemplateError(
|
|
1294
|
+
"The provided template is not a valid local directory or tarball."
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
var pipeline = (0, import_node_util.promisify)(import_node_stream.default.pipeline);
|
|
1097
1298
|
async function extractLocalTarball(tarballPath, destPath) {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1299
|
+
try {
|
|
1300
|
+
await pipeline(
|
|
1301
|
+
import_node_fs2.default.createReadStream(tarballPath),
|
|
1302
|
+
(0, import_gunzip_maybe.default)(),
|
|
1303
|
+
import_tar_fs.default.extract(destPath, { strip: 1 })
|
|
1304
|
+
);
|
|
1305
|
+
} catch (error2) {
|
|
1306
|
+
throw new CopyTemplateError(
|
|
1307
|
+
`There was a problem extracting the file from the provided template. Template filepath: \`${tarballPath}\` Destination directory: \`${destPath}\` ${error2}`
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1103
1310
|
}
|
|
1104
1311
|
async function downloadAndExtractRepoTarball(repo, destPath, options) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1312
|
+
if (repo.branch && repo.filePath) {
|
|
1313
|
+
let tarballURL = `https://codeload.github.com/${repo.owner}/${repo.name}/tar.gz/${repo.branch}`;
|
|
1314
|
+
return await downloadAndExtractTarball(destPath, tarballURL, {
|
|
1315
|
+
...options,
|
|
1316
|
+
filePath: repo.filePath
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
let url2 = `https://api.github.com/repos/${repo.owner}/${repo.name}/tarball`;
|
|
1320
|
+
if (repo.branch) {
|
|
1321
|
+
url2 += `/${repo.branch}`;
|
|
1322
|
+
}
|
|
1323
|
+
return await downloadAndExtractTarball(destPath, url2, {
|
|
1324
|
+
...options,
|
|
1325
|
+
filePath: repo.filePath ?? null
|
|
1326
|
+
});
|
|
1115
1327
|
}
|
|
1116
1328
|
async function downloadAndExtractTarball(downloadPath, tarballUrl, { token, filePath }) {
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1329
|
+
let resourceUrl = tarballUrl;
|
|
1330
|
+
let headers = {};
|
|
1331
|
+
let isGithubUrl = new URL(tarballUrl).host.endsWith("github.com");
|
|
1332
|
+
if (token && isGithubUrl) {
|
|
1333
|
+
headers.Authorization = `token ${token}`;
|
|
1334
|
+
}
|
|
1335
|
+
if (isGithubReleaseAssetUrl(tarballUrl)) {
|
|
1336
|
+
let info2 = getGithubReleaseAssetInfo(tarballUrl);
|
|
1337
|
+
headers.Accept = "application/vnd.github.v3+json";
|
|
1338
|
+
let releaseUrl = info2.tag === "latest" ? `https://api.github.com/repos/${info2.owner}/${info2.name}/releases/latest` : `https://api.github.com/repos/${info2.owner}/${info2.name}/releases/tags/${info2.tag}`;
|
|
1339
|
+
let response2 = await (0, import_web_fetch.fetch)(releaseUrl, {
|
|
1340
|
+
agent: agent("https://api.github.com"),
|
|
1341
|
+
headers
|
|
1342
|
+
});
|
|
1343
|
+
if (response2.status !== 200) {
|
|
1344
|
+
throw new CopyTemplateError(
|
|
1345
|
+
`There was a problem fetching the file from GitHub. The request responded with a ${response2.status} status. Please try again later.`
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
let body = await response2.json();
|
|
1349
|
+
if (!body || typeof body !== "object" || !body.assets || !Array.isArray(body.assets)) {
|
|
1350
|
+
throw new CopyTemplateError(
|
|
1351
|
+
"There was a problem fetching the file from GitHub. No asset was found at that url. Please try again later."
|
|
1352
|
+
);
|
|
1353
|
+
}
|
|
1354
|
+
let assetId = body.assets.find((asset) => {
|
|
1355
|
+
return info2.tag === "latest" ? asset?.browser_download_url?.includes(info2.asset) : asset?.browser_download_url === tarballUrl;
|
|
1356
|
+
})?.id;
|
|
1357
|
+
if (assetId == null) {
|
|
1358
|
+
throw new CopyTemplateError(
|
|
1359
|
+
"There was a problem fetching the file from GitHub. No asset was found at that url. Please try again later."
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
resourceUrl = `https://api.github.com/repos/${info2.owner}/${info2.name}/releases/assets/${assetId}`;
|
|
1363
|
+
headers.Accept = "application/octet-stream";
|
|
1364
|
+
}
|
|
1365
|
+
let response = await (0, import_web_fetch.fetch)(resourceUrl, {
|
|
1366
|
+
agent: agent(resourceUrl),
|
|
1367
|
+
headers
|
|
1368
|
+
});
|
|
1369
|
+
if (!response.body || response.status !== 200) {
|
|
1370
|
+
if (token) {
|
|
1371
|
+
throw new CopyTemplateError(
|
|
1372
|
+
`There was a problem fetching the file${isGithubUrl ? " from GitHub" : ""}. The request responded with a ${response.status} status. Perhaps your \`--token\`is expired or invalid.`
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
throw new CopyTemplateError(
|
|
1376
|
+
`There was a problem fetching the file${isGithubUrl ? " from GitHub" : ""}. The request responded with a ${response.status} status. Please try again later.`
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
if (filePath) {
|
|
1380
|
+
filePath = filePath.split(import_node_path2.default.sep).join(import_node_path2.default.posix.sep);
|
|
1381
|
+
}
|
|
1382
|
+
let filePathHasFiles = false;
|
|
1383
|
+
try {
|
|
1384
|
+
let input = new import_node_stream.default.PassThrough();
|
|
1385
|
+
writeReadableStreamToWritable(response.body, input);
|
|
1386
|
+
await pipeline(
|
|
1387
|
+
input,
|
|
1388
|
+
(0, import_gunzip_maybe.default)(),
|
|
1389
|
+
import_tar_fs.default.extract(downloadPath, {
|
|
1390
|
+
map(header) {
|
|
1391
|
+
let originalDirName = header.name.split("/")[0];
|
|
1392
|
+
header.name = header.name.replace(`${originalDirName}/`, "");
|
|
1393
|
+
if (filePath) {
|
|
1394
|
+
if (filePath.endsWith(import_node_path2.default.posix.sep) && header.name.startsWith(filePath) || !filePath.endsWith(import_node_path2.default.posix.sep) && header.name.startsWith(filePath + import_node_path2.default.posix.sep)) {
|
|
1395
|
+
filePathHasFiles = true;
|
|
1396
|
+
header.name = header.name.replace(filePath, "");
|
|
1397
|
+
} else {
|
|
1398
|
+
header.name = "__IGNORE__";
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
return header;
|
|
1402
|
+
},
|
|
1403
|
+
ignore(_filename, header) {
|
|
1404
|
+
if (!header) {
|
|
1405
|
+
throw Error("Header is undefined");
|
|
1406
|
+
}
|
|
1407
|
+
return header.name === "__IGNORE__";
|
|
1408
|
+
}
|
|
1409
|
+
})
|
|
1410
|
+
);
|
|
1411
|
+
} catch (e) {
|
|
1412
|
+
throw new CopyTemplateError(
|
|
1413
|
+
`There was a problem extracting the file from the provided template. Template URL: \`${tarballUrl}\` Destination directory: \`${downloadPath}\``
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
if (filePath && !filePathHasFiles) {
|
|
1417
|
+
throw new CopyTemplateError(
|
|
1418
|
+
`The path "${filePath}" was not found in this ${isGithubUrl ? "GitHub repo." : "tarball."}`
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
async function writeReadableStreamToWritable(stream2, writable) {
|
|
1423
|
+
let reader = stream2.getReader();
|
|
1424
|
+
let flushable = writable;
|
|
1425
|
+
try {
|
|
1426
|
+
while (true) {
|
|
1427
|
+
let { done, value } = await reader.read();
|
|
1428
|
+
if (done) {
|
|
1429
|
+
writable.end();
|
|
1430
|
+
break;
|
|
1431
|
+
}
|
|
1432
|
+
writable.write(value);
|
|
1433
|
+
if (typeof flushable.flush === "function") {
|
|
1434
|
+
flushable.flush();
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
} catch (error2) {
|
|
1438
|
+
writable.destroy(error2);
|
|
1439
|
+
throw error2;
|
|
1440
|
+
}
|
|
1183
1441
|
}
|
|
1184
1442
|
function isValidGithubRepoUrl(input) {
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1443
|
+
if (!isUrl(input)) {
|
|
1444
|
+
return false;
|
|
1445
|
+
}
|
|
1446
|
+
try {
|
|
1447
|
+
let url2 = new URL(input);
|
|
1448
|
+
let pathSegments = url2.pathname.slice(1).split("/");
|
|
1449
|
+
return url2.protocol === "https:" && url2.hostname === "github.com" && // The pathname must have at least 2 segments. If it has more than 2, the
|
|
1450
|
+
// third must be "tree" and it must have at least 4 segments.
|
|
1451
|
+
// https://github.com/:owner/:repo
|
|
1452
|
+
// https://github.com/:owner/:repo/tree/:ref
|
|
1453
|
+
pathSegments.length >= 2 && (pathSegments.length > 2 ? pathSegments[2] === "tree" && pathSegments.length >= 4 : true);
|
|
1454
|
+
} catch (e) {
|
|
1455
|
+
return false;
|
|
1456
|
+
}
|
|
1193
1457
|
}
|
|
1194
1458
|
function isGithubRepoShorthand(value) {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
* ~or~
|
|
1203
|
-
* https://github.com/owner/repository/releases/latest/download/template.tar.gz
|
|
1204
|
-
*/
|
|
1205
|
-
return url.startsWith("https://github.com") && (url.includes("/releases/download/") || url.includes("/releases/latest/download/"));
|
|
1459
|
+
if (isUrl(value)) {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
return /^[\w-]+\/[\w-.]+(\/[\w-.]+)*$/.test(value);
|
|
1463
|
+
}
|
|
1464
|
+
function isGithubReleaseAssetUrl(url2) {
|
|
1465
|
+
return url2.startsWith("https://github.com") && (url2.includes("/releases/download/") || url2.includes("/releases/latest/download/"));
|
|
1206
1466
|
}
|
|
1207
1467
|
function getGithubReleaseAssetInfo(browserUrl) {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1468
|
+
let url2 = new URL(browserUrl);
|
|
1469
|
+
let [, owner, name, , downloadOrLatest, tag, asset] = url2.pathname.split("/");
|
|
1470
|
+
if (downloadOrLatest === "latest" && tag === "download") {
|
|
1471
|
+
tag = "latest";
|
|
1472
|
+
}
|
|
1473
|
+
return {
|
|
1474
|
+
browserUrl,
|
|
1475
|
+
owner,
|
|
1476
|
+
name,
|
|
1477
|
+
asset,
|
|
1478
|
+
tag
|
|
1479
|
+
};
|
|
1217
1480
|
}
|
|
1218
1481
|
function getRepoInfo(validatedGithubUrl) {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1482
|
+
let url2 = new URL(validatedGithubUrl);
|
|
1483
|
+
let [, owner, name, tree, branch, ...file] = url2.pathname.split("/");
|
|
1484
|
+
let filePath = file.join("/");
|
|
1485
|
+
if (tree === void 0) {
|
|
1486
|
+
return {
|
|
1487
|
+
owner,
|
|
1488
|
+
name,
|
|
1489
|
+
branch: null,
|
|
1490
|
+
filePath: null
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
return {
|
|
1494
|
+
owner,
|
|
1495
|
+
name,
|
|
1496
|
+
// If we've validated the GitHub URL and there is a tree, there will also be
|
|
1497
|
+
// a branch
|
|
1498
|
+
branch,
|
|
1499
|
+
filePath: filePath === "" || filePath === "/" ? null : filePath
|
|
1500
|
+
};
|
|
1233
1501
|
}
|
|
1234
1502
|
var CopyTemplateError = class extends Error {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1503
|
+
constructor(message) {
|
|
1504
|
+
super(message);
|
|
1505
|
+
this.name = "CopyTemplateError";
|
|
1506
|
+
}
|
|
1239
1507
|
};
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1508
|
+
|
|
1509
|
+
// index.ts
|
|
1510
|
+
async function createReactRouter(argv2) {
|
|
1511
|
+
let ctx = await getContext(argv2);
|
|
1512
|
+
if (ctx.help) {
|
|
1513
|
+
printHelp(ctx);
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
if (ctx.versionRequested) {
|
|
1517
|
+
log(version);
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
let steps = [
|
|
1521
|
+
introStep,
|
|
1522
|
+
projectNameStep,
|
|
1523
|
+
copyTemplateToTempDirStep,
|
|
1524
|
+
copyTempDirToAppDirStep,
|
|
1525
|
+
gitInitQuestionStep,
|
|
1526
|
+
installDependenciesQuestionStep,
|
|
1527
|
+
installDependenciesStep,
|
|
1528
|
+
gitInitStep,
|
|
1529
|
+
doneStep
|
|
1530
|
+
];
|
|
1531
|
+
try {
|
|
1532
|
+
for (let step of steps) {
|
|
1533
|
+
await step(ctx);
|
|
1534
|
+
}
|
|
1535
|
+
} catch (err) {
|
|
1536
|
+
if (ctx.debug) {
|
|
1537
|
+
console.error(err);
|
|
1538
|
+
}
|
|
1539
|
+
throw err;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
async function getContext(argv2) {
|
|
1543
|
+
let flags = (0, import_arg.default)(
|
|
1544
|
+
{
|
|
1545
|
+
"--debug": Boolean,
|
|
1546
|
+
"--react-router-version": String,
|
|
1547
|
+
"-v": "--react-router-version",
|
|
1548
|
+
"--template": String,
|
|
1549
|
+
"--token": String,
|
|
1550
|
+
"--yes": Boolean,
|
|
1551
|
+
"-y": "--yes",
|
|
1552
|
+
"--install": Boolean,
|
|
1553
|
+
"--no-install": Boolean,
|
|
1554
|
+
"--package-manager": String,
|
|
1555
|
+
"--show-install-output": Boolean,
|
|
1556
|
+
"--git-init": Boolean,
|
|
1557
|
+
"--no-git-init": Boolean,
|
|
1558
|
+
"--help": Boolean,
|
|
1559
|
+
"-h": "--help",
|
|
1560
|
+
"--version": Boolean,
|
|
1561
|
+
"--V": "--version",
|
|
1562
|
+
"--no-color": Boolean,
|
|
1563
|
+
"--no-motion": Boolean,
|
|
1564
|
+
"--overwrite": Boolean
|
|
1565
|
+
},
|
|
1566
|
+
{ argv: argv2, permissive: true }
|
|
1567
|
+
);
|
|
1568
|
+
let {
|
|
1569
|
+
"--debug": debug2 = false,
|
|
1570
|
+
"--help": help = false,
|
|
1571
|
+
"--react-router-version": selectedReactRouterVersion,
|
|
1572
|
+
"--template": template,
|
|
1573
|
+
"--token": token,
|
|
1574
|
+
"--install": install,
|
|
1575
|
+
"--no-install": noInstall,
|
|
1576
|
+
"--package-manager": pkgManager,
|
|
1577
|
+
"--show-install-output": showInstallOutput = false,
|
|
1578
|
+
"--git-init": git,
|
|
1579
|
+
"--no-git-init": noGit,
|
|
1580
|
+
"--no-motion": noMotion,
|
|
1581
|
+
"--yes": yes,
|
|
1582
|
+
"--version": versionRequested,
|
|
1583
|
+
"--overwrite": overwrite
|
|
1584
|
+
} = flags;
|
|
1585
|
+
let cwd = flags["_"][0];
|
|
1586
|
+
let interactive = isInteractive();
|
|
1587
|
+
let projectName = cwd;
|
|
1588
|
+
if (!interactive) {
|
|
1589
|
+
yes = true;
|
|
1590
|
+
}
|
|
1591
|
+
if (selectedReactRouterVersion) {
|
|
1592
|
+
if (semver.valid(selectedReactRouterVersion)) {
|
|
1593
|
+
} else if (semver.coerce(selectedReactRouterVersion)) {
|
|
1594
|
+
selectedReactRouterVersion = semver.coerce(
|
|
1595
|
+
selectedReactRouterVersion
|
|
1596
|
+
).version;
|
|
1597
|
+
} else {
|
|
1598
|
+
log(
|
|
1599
|
+
`
|
|
1600
|
+
${color.warning(
|
|
1601
|
+
`${selectedReactRouterVersion} is an invalid version specifier. Using React Router v${version}.`
|
|
1602
|
+
)}`
|
|
1603
|
+
);
|
|
1604
|
+
selectedReactRouterVersion = void 0;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
let context = {
|
|
1608
|
+
tempDir: import_node_path3.default.join(
|
|
1609
|
+
await (0, import_promises2.realpath)(import_node_os2.default.tmpdir()),
|
|
1610
|
+
`create-react-router--${Math.random().toString(36).substr(2, 8)}`
|
|
1611
|
+
),
|
|
1612
|
+
cwd,
|
|
1613
|
+
overwrite,
|
|
1614
|
+
interactive,
|
|
1615
|
+
debug: debug2,
|
|
1616
|
+
git: git ?? (noGit ? false : yes),
|
|
1617
|
+
help,
|
|
1618
|
+
install: install ?? (noInstall ? false : yes),
|
|
1619
|
+
showInstallOutput,
|
|
1620
|
+
noMotion,
|
|
1621
|
+
pkgManager: validatePackageManager(
|
|
1622
|
+
pkgManager ?? // npm, pnpm, Yarn, Bun and Deno (v2.0.5+) set the user agent environment variable that can be used
|
|
1623
|
+
// to determine which package manager ran the command.
|
|
1624
|
+
(import_node_process6.default.env.npm_config_user_agent ?? "npm").split("/")[0]
|
|
1625
|
+
),
|
|
1626
|
+
projectName,
|
|
1627
|
+
prompt,
|
|
1628
|
+
reactRouterVersion: selectedReactRouterVersion || version,
|
|
1629
|
+
template,
|
|
1630
|
+
token,
|
|
1631
|
+
versionRequested
|
|
1632
|
+
};
|
|
1633
|
+
return context;
|
|
1328
1634
|
}
|
|
1329
1635
|
async function introStep(ctx) {
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1636
|
+
log(
|
|
1637
|
+
`
|
|
1638
|
+
${" ".repeat(9)}${color.green(
|
|
1639
|
+
color.bold("create-react-router")
|
|
1640
|
+
)} ${color.bold(`v${ctx.reactRouterVersion}`)}`
|
|
1641
|
+
);
|
|
1642
|
+
if (!ctx.interactive) {
|
|
1643
|
+
log("");
|
|
1644
|
+
info("Shell is not interactive.", [
|
|
1645
|
+
`Using default options. This is equivalent to running with the `,
|
|
1646
|
+
color.reset("--yes"),
|
|
1647
|
+
` flag.`
|
|
1648
|
+
]);
|
|
1649
|
+
}
|
|
1339
1650
|
}
|
|
1340
1651
|
async function projectNameStep(ctx) {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1652
|
+
if (!ctx.interactive && !ctx.cwd) {
|
|
1653
|
+
error("Oh no!", "No project directory provided");
|
|
1654
|
+
throw new Error("No project directory provided");
|
|
1655
|
+
}
|
|
1656
|
+
if (ctx.cwd) {
|
|
1657
|
+
await sleep(100);
|
|
1658
|
+
info("Directory:", [
|
|
1659
|
+
"Using ",
|
|
1660
|
+
color.reset(ctx.cwd),
|
|
1661
|
+
" as project directory"
|
|
1662
|
+
]);
|
|
1663
|
+
}
|
|
1664
|
+
if (!ctx.cwd) {
|
|
1665
|
+
let { name: name2 } = await ctx.prompt({
|
|
1666
|
+
name: "name",
|
|
1667
|
+
type: "text",
|
|
1668
|
+
label: title("dir"),
|
|
1669
|
+
message: "Where should we create your new project?",
|
|
1670
|
+
initial: "./my-react-router-app"
|
|
1671
|
+
});
|
|
1672
|
+
ctx.cwd = name2;
|
|
1673
|
+
ctx.projectName = toValidProjectName(name2);
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
let name = ctx.cwd;
|
|
1677
|
+
if (name === "." || name === "./") {
|
|
1678
|
+
let parts = import_node_process6.default.cwd().split(import_node_path3.default.sep);
|
|
1679
|
+
name = parts[parts.length - 1];
|
|
1680
|
+
} else if (name.startsWith("./") || name.startsWith("../")) {
|
|
1681
|
+
let parts = name.split("/");
|
|
1682
|
+
name = parts[parts.length - 1];
|
|
1683
|
+
}
|
|
1684
|
+
ctx.projectName = toValidProjectName(name);
|
|
1374
1685
|
}
|
|
1375
1686
|
async function copyTemplateToTempDirStep(ctx) {
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1687
|
+
if (ctx.template) {
|
|
1688
|
+
log("");
|
|
1689
|
+
info("Template:", ["Using ", color.reset(ctx.template), "..."]);
|
|
1690
|
+
} else {
|
|
1691
|
+
log("");
|
|
1692
|
+
info("Using default template", [
|
|
1693
|
+
"See https://github.com/remix-run/react-router-templates for more"
|
|
1694
|
+
]);
|
|
1695
|
+
}
|
|
1696
|
+
let template = ctx.template ?? "https://github.com/remix-run/react-router-templates/tree/main/default";
|
|
1697
|
+
await loadingIndicator({
|
|
1698
|
+
start: "Template copying...",
|
|
1699
|
+
end: "Template copied",
|
|
1700
|
+
while: async () => {
|
|
1701
|
+
await ensureDirectory(ctx.tempDir);
|
|
1702
|
+
if (ctx.debug) {
|
|
1703
|
+
debug(`Extracting to: ${ctx.tempDir}`);
|
|
1704
|
+
}
|
|
1705
|
+
let result = await copyTemplate(template, ctx.tempDir, {
|
|
1706
|
+
debug: ctx.debug,
|
|
1707
|
+
token: ctx.token,
|
|
1708
|
+
async onError(err) {
|
|
1709
|
+
error(
|
|
1710
|
+
"Oh no!",
|
|
1711
|
+
err instanceof CopyTemplateError ? err.message : "Something went wrong. Run `create-react-router --debug` to see more info.\n\nOpen an issue to report the problem at https://github.com/remix-run/react-router/issues/new"
|
|
1712
|
+
);
|
|
1713
|
+
throw err;
|
|
1714
|
+
},
|
|
1715
|
+
async log(message) {
|
|
1716
|
+
if (ctx.debug) {
|
|
1717
|
+
debug(message);
|
|
1718
|
+
await sleep(500);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
});
|
|
1722
|
+
if (result?.localTemplateDirectory) {
|
|
1723
|
+
ctx.tempDir = import_node_path3.default.resolve(result.localTemplateDirectory);
|
|
1724
|
+
}
|
|
1725
|
+
},
|
|
1726
|
+
ctx
|
|
1727
|
+
});
|
|
1412
1728
|
}
|
|
1413
1729
|
async function copyTempDirToAppDirStep(ctx) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1730
|
+
await ensureDirectory(ctx.cwd);
|
|
1731
|
+
let files1 = await getDirectoryFilesRecursive(ctx.tempDir);
|
|
1732
|
+
let files2 = await getDirectoryFilesRecursive(ctx.cwd);
|
|
1733
|
+
let collisions = files1.filter((f) => files2.includes(f)).sort((a, b) => a.localeCompare(b));
|
|
1734
|
+
if (collisions.length > 0) {
|
|
1735
|
+
let getFileList = (prefix) => {
|
|
1736
|
+
let moreFiles = collisions.length - 5;
|
|
1737
|
+
let lines2 = ["", ...collisions.slice(0, 5)];
|
|
1738
|
+
if (moreFiles > 0) {
|
|
1739
|
+
lines2.push(`and ${moreFiles} more...`);
|
|
1740
|
+
}
|
|
1741
|
+
return lines2.join(`
|
|
1742
|
+
${prefix}`);
|
|
1743
|
+
};
|
|
1744
|
+
if (ctx.overwrite) {
|
|
1745
|
+
info(
|
|
1746
|
+
"Overwrite:",
|
|
1747
|
+
`overwriting files due to \`--overwrite\`:${getFileList(" ")}`
|
|
1748
|
+
);
|
|
1749
|
+
} else if (!ctx.interactive) {
|
|
1750
|
+
error(
|
|
1751
|
+
"Oh no!",
|
|
1752
|
+
`Destination directory contains files that would be overwritten
|
|
1753
|
+
and no \`--overwrite\` flag was included in a non-interactive
|
|
1754
|
+
environment. The following files would be overwritten:` + getFileList(" ")
|
|
1755
|
+
);
|
|
1756
|
+
throw new Error(
|
|
1757
|
+
"File collisions detected in a non-interactive environment"
|
|
1758
|
+
);
|
|
1759
|
+
} else {
|
|
1760
|
+
if (ctx.debug) {
|
|
1761
|
+
debug(`Colliding files:${getFileList(" ")}`);
|
|
1762
|
+
}
|
|
1763
|
+
let { overwrite } = await ctx.prompt({
|
|
1764
|
+
name: "overwrite",
|
|
1765
|
+
type: "confirm",
|
|
1766
|
+
label: title("overwrite"),
|
|
1767
|
+
message: `Your project directory contains files that will be overwritten by
|
|
1436
1768
|
this template (you can force with \`--overwrite\`)
|
|
1437
1769
|
|
|
1438
|
-
Files that would be overwritten:${getFileList(" ")}
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1770
|
+
Files that would be overwritten:${getFileList(" ")}
|
|
1771
|
+
|
|
1772
|
+
Do you wish to continue?
|
|
1773
|
+
`,
|
|
1774
|
+
initial: false
|
|
1775
|
+
});
|
|
1776
|
+
if (!overwrite) {
|
|
1777
|
+
throw new Error("Exiting to avoid overwriting files");
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
await (0, import_promises2.cp)(ctx.tempDir, ctx.cwd, {
|
|
1782
|
+
filter(src) {
|
|
1783
|
+
let file = stripDirectoryFromPath(ctx.tempDir, src);
|
|
1784
|
+
let isIgnored = IGNORED_TEMPLATE_DIRECTORIES.includes(file);
|
|
1785
|
+
if (isIgnored) {
|
|
1786
|
+
if (ctx.debug) {
|
|
1787
|
+
debug(`Skipping copy of ${file} directory from template`);
|
|
1788
|
+
}
|
|
1789
|
+
return false;
|
|
1790
|
+
}
|
|
1791
|
+
return true;
|
|
1792
|
+
},
|
|
1793
|
+
recursive: true
|
|
1794
|
+
});
|
|
1795
|
+
await updatePackageJSON(ctx);
|
|
1456
1796
|
}
|
|
1457
1797
|
async function installDependenciesQuestionStep(ctx) {
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1798
|
+
if (ctx.install === void 0) {
|
|
1799
|
+
let { deps = true } = await ctx.prompt({
|
|
1800
|
+
name: "deps",
|
|
1801
|
+
type: "confirm",
|
|
1802
|
+
label: title("deps"),
|
|
1803
|
+
message: `Install dependencies with ${ctx.pkgManager}?`,
|
|
1804
|
+
hint: "recommended",
|
|
1805
|
+
initial: true
|
|
1806
|
+
});
|
|
1807
|
+
ctx.install = deps;
|
|
1808
|
+
}
|
|
1469
1809
|
}
|
|
1470
1810
|
async function installDependenciesStep(ctx) {
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1811
|
+
let { install, pkgManager, showInstallOutput, cwd } = ctx;
|
|
1812
|
+
if (!install) {
|
|
1813
|
+
await sleep(100);
|
|
1814
|
+
info("Skipping install step.", [
|
|
1815
|
+
"Remember to install dependencies after setup with ",
|
|
1816
|
+
color.reset(`${pkgManager} install`),
|
|
1817
|
+
"."
|
|
1818
|
+
]);
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1821
|
+
function runInstall() {
|
|
1822
|
+
return installDependencies({
|
|
1823
|
+
cwd,
|
|
1824
|
+
pkgManager,
|
|
1825
|
+
showInstallOutput
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
if (showInstallOutput) {
|
|
1829
|
+
log("");
|
|
1830
|
+
info(`Install`, `Dependencies installing with ${pkgManager}...`);
|
|
1831
|
+
log("");
|
|
1832
|
+
await runInstall();
|
|
1833
|
+
log("");
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
log("");
|
|
1837
|
+
await loadingIndicator({
|
|
1838
|
+
start: `Dependencies installing with ${pkgManager}...`,
|
|
1839
|
+
end: "Dependencies installed",
|
|
1840
|
+
while: runInstall,
|
|
1841
|
+
ctx
|
|
1842
|
+
});
|
|
1503
1843
|
}
|
|
1504
1844
|
async function gitInitQuestionStep(ctx) {
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1845
|
+
if ((0, import_node_fs3.existsSync)(import_node_path3.default.join(ctx.cwd, ".git"))) {
|
|
1846
|
+
info("Nice!", `Git has already been initialized`);
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
let git = ctx.git;
|
|
1850
|
+
if (ctx.git === void 0) {
|
|
1851
|
+
({ git } = await ctx.prompt({
|
|
1852
|
+
name: "git",
|
|
1853
|
+
type: "confirm",
|
|
1854
|
+
label: title("git"),
|
|
1855
|
+
message: `Initialize a new git repository?`,
|
|
1856
|
+
hint: "recommended",
|
|
1857
|
+
initial: true
|
|
1858
|
+
}));
|
|
1859
|
+
}
|
|
1860
|
+
ctx.git = git ?? false;
|
|
1519
1861
|
}
|
|
1520
1862
|
async function gitInitStep(ctx) {
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
throw err;
|
|
1548
|
-
}
|
|
1549
|
-
},
|
|
1550
|
-
ctx
|
|
1551
|
-
});
|
|
1863
|
+
if (!ctx.git) {
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
if ((0, import_node_fs3.existsSync)(import_node_path3.default.join(ctx.cwd, ".git"))) {
|
|
1867
|
+
log("");
|
|
1868
|
+
info("Nice!", `Git has already been initialized`);
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
log("");
|
|
1872
|
+
await loadingIndicator({
|
|
1873
|
+
start: "Git initializing...",
|
|
1874
|
+
end: "Git initialized",
|
|
1875
|
+
while: async () => {
|
|
1876
|
+
let options = { cwd: ctx.cwd, stdio: "ignore" };
|
|
1877
|
+
let commitMsg = "Initial commit from create-react-router";
|
|
1878
|
+
try {
|
|
1879
|
+
await (0, import_execa.default)("git", ["init"], options);
|
|
1880
|
+
await (0, import_execa.default)("git", ["add", "."], options);
|
|
1881
|
+
await (0, import_execa.default)("git", ["commit", "-m", commitMsg], options);
|
|
1882
|
+
} catch (err) {
|
|
1883
|
+
error("Oh no!", "Failed to initialize git.");
|
|
1884
|
+
throw err;
|
|
1885
|
+
}
|
|
1886
|
+
},
|
|
1887
|
+
ctx
|
|
1888
|
+
});
|
|
1552
1889
|
}
|
|
1553
1890
|
async function doneStep(ctx) {
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1891
|
+
let projectDir = import_node_path3.default.relative(import_node_process6.default.cwd(), ctx.cwd);
|
|
1892
|
+
let max = import_node_process6.default.stdout.columns;
|
|
1893
|
+
let prefix = max < 80 ? " " : " ".repeat(9);
|
|
1894
|
+
await sleep(200);
|
|
1895
|
+
log(`
|
|
1896
|
+
${color.bgWhite(color.black(" done "))} That's it!`);
|
|
1897
|
+
await sleep(100);
|
|
1898
|
+
if (projectDir !== "") {
|
|
1899
|
+
let enter = [
|
|
1900
|
+
`
|
|
1901
|
+
${prefix}Enter your project directory using`,
|
|
1902
|
+
color.cyan(`cd .${import_node_path3.default.sep}${projectDir}`)
|
|
1903
|
+
];
|
|
1904
|
+
let len = enter[0].length + (0, import_strip_ansi.default)(enter[1]).length;
|
|
1905
|
+
log(enter.join(len > max ? "\n" + prefix : " "));
|
|
1906
|
+
}
|
|
1907
|
+
log(
|
|
1908
|
+
`${prefix}Check out ${color.bold(
|
|
1909
|
+
"README.md"
|
|
1910
|
+
)} for development and deploy instructions.`
|
|
1911
|
+
);
|
|
1912
|
+
await sleep(100);
|
|
1913
|
+
log(
|
|
1914
|
+
`
|
|
1915
|
+
${prefix}Join the community at ${color.cyan(`https://rmx.as/discord`)}
|
|
1916
|
+
`
|
|
1917
|
+
);
|
|
1918
|
+
await sleep(200);
|
|
1919
|
+
}
|
|
1920
|
+
var validPackageManagers = ["npm", "yarn", "pnpm", "bun", "deno"];
|
|
1577
1921
|
function validatePackageManager(pkgManager) {
|
|
1578
|
-
|
|
1579
|
-
}
|
|
1580
|
-
async function installDependencies({
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1922
|
+
return validPackageManagers.find((name) => pkgManager === name) ?? "npm";
|
|
1923
|
+
}
|
|
1924
|
+
async function installDependencies({
|
|
1925
|
+
pkgManager,
|
|
1926
|
+
cwd,
|
|
1927
|
+
showInstallOutput
|
|
1928
|
+
}) {
|
|
1929
|
+
try {
|
|
1930
|
+
await (0, import_execa.default)(pkgManager, ["install"], {
|
|
1931
|
+
cwd,
|
|
1932
|
+
stdio: showInstallOutput ? "inherit" : "ignore"
|
|
1933
|
+
});
|
|
1934
|
+
} catch (err) {
|
|
1935
|
+
error("Oh no!", "Failed to install dependencies.");
|
|
1936
|
+
throw err;
|
|
1937
|
+
}
|
|
1590
1938
|
}
|
|
1591
1939
|
async function updatePackageJSON(ctx) {
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1940
|
+
let packageJSONPath = import_node_path3.default.join(ctx.cwd, "package.json");
|
|
1941
|
+
if (!(0, import_node_fs3.existsSync)(packageJSONPath)) {
|
|
1942
|
+
let relativePath = import_node_path3.default.relative(import_node_process6.default.cwd(), ctx.cwd);
|
|
1943
|
+
error(
|
|
1944
|
+
"Oh no!",
|
|
1945
|
+
`The provided template must be a React Router project with a \`package.json\` file, but that file does not exist in ${color.bold(relativePath)}.`
|
|
1946
|
+
);
|
|
1947
|
+
throw new Error(`package.json does not exist in ${ctx.cwd}`);
|
|
1948
|
+
}
|
|
1949
|
+
let contents = await (0, import_promises2.readFile)(packageJSONPath, "utf-8");
|
|
1950
|
+
let packageJSON;
|
|
1951
|
+
try {
|
|
1952
|
+
packageJSON = JSON.parse(contents);
|
|
1953
|
+
if (!isValidJsonObject(packageJSON)) {
|
|
1954
|
+
throw Error();
|
|
1955
|
+
}
|
|
1956
|
+
} catch (err) {
|
|
1957
|
+
error(
|
|
1958
|
+
"Oh no!",
|
|
1959
|
+
`The provided template must be a React Router project with a \`package.json\` file, but that file is invalid.`
|
|
1960
|
+
);
|
|
1961
|
+
throw err;
|
|
1962
|
+
}
|
|
1963
|
+
for (let pkgKey of ["dependencies", "devDependencies"]) {
|
|
1964
|
+
let dependencies = packageJSON[pkgKey];
|
|
1965
|
+
if (!dependencies) continue;
|
|
1966
|
+
if (!isValidJsonObject(dependencies)) {
|
|
1967
|
+
error(
|
|
1968
|
+
"Oh no!",
|
|
1969
|
+
`The provided template must be a React Router project with a \`package.json\` file, but its ${pkgKey} value is invalid.`
|
|
1970
|
+
);
|
|
1971
|
+
throw new Error(`package.json ${pkgKey} are invalid`);
|
|
1972
|
+
}
|
|
1973
|
+
for (let dependency in dependencies) {
|
|
1974
|
+
let version2 = dependencies[dependency];
|
|
1975
|
+
if ((dependency.startsWith("@react-router/") || dependency === "react-router" || dependency === "react-router-dom") && version2 === "*") {
|
|
1976
|
+
dependencies[dependency] = semver.prerelease(ctx.reactRouterVersion) ? (
|
|
1977
|
+
// Templates created from prereleases should pin to a specific version
|
|
1978
|
+
ctx.reactRouterVersion
|
|
1979
|
+
) : "^" + ctx.reactRouterVersion;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
packageJSON.name = ctx.projectName;
|
|
1984
|
+
(0, import_promises2.writeFile)(
|
|
1985
|
+
packageJSONPath,
|
|
1986
|
+
JSON.stringify((0, import_sort_package_json.default)(packageJSON), null, 2),
|
|
1987
|
+
"utf-8"
|
|
1988
|
+
);
|
|
1621
1989
|
}
|
|
1622
1990
|
async function loadingIndicator(args) {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1991
|
+
let { ctx, ...rest } = args;
|
|
1992
|
+
await renderLoadingIndicator({
|
|
1993
|
+
...rest,
|
|
1994
|
+
noMotion: args.ctx.noMotion
|
|
1995
|
+
});
|
|
1628
1996
|
}
|
|
1629
1997
|
function title(text) {
|
|
1630
|
-
|
|
1998
|
+
return align(color.bgWhite(` ${color.black(text)} `), "end", 7) + " ";
|
|
1631
1999
|
}
|
|
1632
2000
|
function printHelp(ctx) {
|
|
1633
|
-
|
|
2001
|
+
let output = `
|
|
1634
2002
|
${title("create-react-router")}
|
|
1635
2003
|
|
|
1636
2004
|
${color.heading("Usage")}:
|
|
@@ -1666,39 +2034,51 @@ React Router projects are created from templates. A template can be:
|
|
|
1666
2034
|
- a file path to a directory of files
|
|
1667
2035
|
- a file path to a tarball
|
|
1668
2036
|
${[
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
2037
|
+
"remix-run/react-router/templates/basic",
|
|
2038
|
+
"remix-run/react-router/examples/basic",
|
|
2039
|
+
":username/:repo",
|
|
2040
|
+
":username/:repo/:directory",
|
|
2041
|
+
"https://github.com/:username/:repo",
|
|
2042
|
+
"https://github.com/:username/:repo/tree/:branch",
|
|
2043
|
+
"https://github.com/:username/:repo/tree/:branch/:directory",
|
|
2044
|
+
"https://github.com/:username/:repo/archive/refs/tags/:tag.tar.gz",
|
|
2045
|
+
"https://example.com/template.tar.gz",
|
|
2046
|
+
"./path/to/template",
|
|
2047
|
+
"./path/to/template.tar.gz"
|
|
2048
|
+
].reduce((str, example) => {
|
|
2049
|
+
return `${str}
|
|
2050
|
+
${color.dim("$")} ${color.greenBright("create-react-router")} my-app ${color.arg(`--template ${example}`)}`;
|
|
2051
|
+
}, "")}
|
|
1683
2052
|
|
|
1684
2053
|
To create a new project from a template in a private GitHub repo,
|
|
1685
2054
|
pass the \`token\` flag with a personal access token with access
|
|
1686
2055
|
to that repo.
|
|
1687
|
-
|
|
2056
|
+
`;
|
|
2057
|
+
log(output);
|
|
1688
2058
|
}
|
|
1689
2059
|
function align(text, dir, len) {
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
2060
|
+
let pad = Math.max(len - strip(text).length, 0);
|
|
2061
|
+
switch (dir) {
|
|
2062
|
+
case "start":
|
|
2063
|
+
return text + " ".repeat(pad);
|
|
2064
|
+
case "end":
|
|
2065
|
+
return " ".repeat(pad) + text;
|
|
2066
|
+
case "center":
|
|
2067
|
+
return " ".repeat(Math.floor(pad / 2)) + text + " ".repeat(Math.floor(pad / 2));
|
|
2068
|
+
default:
|
|
2069
|
+
return text;
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
// cli.ts
|
|
2074
|
+
import_node_process7.default.on("SIGINT", () => import_node_process7.default.exit(0));
|
|
2075
|
+
import_node_process7.default.on("SIGTERM", () => import_node_process7.default.exit(0));
|
|
2076
|
+
var argv = import_node_process7.default.argv.slice(2).filter((arg2) => arg2 !== "--");
|
|
2077
|
+
createReactRouter(argv).then(
|
|
2078
|
+
() => import_node_process7.default.exit(0),
|
|
2079
|
+
() => import_node_process7.default.exit(1)
|
|
2080
|
+
);
|
|
2081
|
+
/**
|
|
2082
|
+
* Adapted from https://github.com/withastro/cli-kit
|
|
2083
|
+
* @license MIT License Copyright (c) 2022 Nate Moore
|
|
2084
|
+
*/
|