create-rue 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +539 -0
- package/README.md +22 -0
- package/bundle.js +2862 -0
- package/package.json +58 -0
- package/template/base/.editorconfig +6 -0
- package/template/base/.gitattributes +1 -0
- package/template/base/.oxfmtrc.json +5 -0
- package/template/base/.oxlintrc.json +11 -0
- package/template/base/app/app.tsx +12 -0
- package/template/base/app/main.ts +2 -0
- package/template/base/app/pages/Ecosystem.tsx +47 -0
- package/template/base/app/pages/Guide.tsx +49 -0
- package/template/base/app/pages/Home.tsx +85 -0
- package/template/base/app/pages/Packages.tsx +52 -0
- package/template/base/app/pages/components/Layout.tsx +67 -0
- package/template/base/app/router.ts +14 -0
- package/template/base/index.html +16 -0
- package/template/base/package-lock.json +2425 -0
- package/template/base/package.json +37 -0
- package/template/base/pnpm-lock.yaml +1513 -0
- package/template/base/style.css +433 -0
- package/template/base/tailwind.config.ts +7 -0
- package/template/base/tsconfig.json +22 -0
- package/template/base/vite.config.ts +18 -0
package/bundle.js
ADDED
|
@@ -0,0 +1,2862 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*! create-rue v0.0.1 | MIT */
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import "node:fs";
|
|
6
|
+
import * as path$1 from "node:path";
|
|
7
|
+
import "node:path";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
+
import { parseArgs, stripVTControlCharacters, styleText } from "node:util";
|
|
10
|
+
import P, { stdin, stdout } from "node:process";
|
|
11
|
+
import "node:readline";
|
|
12
|
+
import P$1 from "node:readline";
|
|
13
|
+
import "node:tty";
|
|
14
|
+
import * as path from "path";
|
|
15
|
+
//#region \0rolldown/runtime.js
|
|
16
|
+
var __create = Object.create;
|
|
17
|
+
var __defProp = Object.defineProperty;
|
|
18
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
19
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
20
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
21
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
22
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
25
|
+
key = keys[i];
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
34
|
+
value: mod,
|
|
35
|
+
enumerable: true
|
|
36
|
+
}) : target, mod));
|
|
37
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/utils.js
|
|
40
|
+
const isAmbiguous = (x) => {
|
|
41
|
+
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
42
|
+
};
|
|
43
|
+
const isFullWidth = (x) => {
|
|
44
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
45
|
+
};
|
|
46
|
+
const isWide = (x) => {
|
|
47
|
+
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9800 && x <= 9811 || x === 9855 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 19968 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101632 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129672 || x >= 129680 && x <= 129725 || x >= 129727 && x <= 129733 || x >= 129742 && x <= 129755 || x >= 129760 && x <= 129768 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region node_modules/.pnpm/fast-string-truncated-width@1.2.1/node_modules/fast-string-truncated-width/dist/index.js
|
|
51
|
+
const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
|
|
52
|
+
const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
53
|
+
const TAB_RE = /\t{1,1000}/y;
|
|
54
|
+
const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy;
|
|
55
|
+
const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
56
|
+
const MODIFIER_RE = /\p{M}+/gu;
|
|
57
|
+
const NO_TRUNCATION$1 = {
|
|
58
|
+
limit: Infinity,
|
|
59
|
+
ellipsis: ""
|
|
60
|
+
};
|
|
61
|
+
const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
62
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
63
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
64
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
|
|
65
|
+
const ANSI_WIDTH = widthOptions.ansiWidth ?? 0;
|
|
66
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
67
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
68
|
+
const AMBIGUOUS_WIDTH = widthOptions.ambiguousWidth ?? 1;
|
|
69
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
70
|
+
const FULL_WIDTH_WIDTH = widthOptions.fullWidthWidth ?? 2;
|
|
71
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
72
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? 2;
|
|
73
|
+
let indexPrev = 0;
|
|
74
|
+
let index = 0;
|
|
75
|
+
let length = input.length;
|
|
76
|
+
let lengthExtra = 0;
|
|
77
|
+
let truncationEnabled = false;
|
|
78
|
+
let truncationIndex = length;
|
|
79
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
80
|
+
let unmatchedStart = 0;
|
|
81
|
+
let unmatchedEnd = 0;
|
|
82
|
+
let width = 0;
|
|
83
|
+
let widthExtra = 0;
|
|
84
|
+
outer: while (true) {
|
|
85
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
86
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
87
|
+
lengthExtra = 0;
|
|
88
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
89
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
90
|
+
if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
|
|
91
|
+
else if (isWide(codePoint)) widthExtra = WIDE_WIDTH;
|
|
92
|
+
else if (AMBIGUOUS_WIDTH !== REGULAR_WIDTH && isAmbiguous(codePoint)) widthExtra = AMBIGUOUS_WIDTH;
|
|
93
|
+
else widthExtra = REGULAR_WIDTH;
|
|
94
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
95
|
+
if (width + widthExtra > LIMIT) {
|
|
96
|
+
truncationEnabled = true;
|
|
97
|
+
break outer;
|
|
98
|
+
}
|
|
99
|
+
lengthExtra += char.length;
|
|
100
|
+
width += widthExtra;
|
|
101
|
+
}
|
|
102
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
103
|
+
}
|
|
104
|
+
if (index >= length) break;
|
|
105
|
+
LATIN_RE.lastIndex = index;
|
|
106
|
+
if (LATIN_RE.test(input)) {
|
|
107
|
+
lengthExtra = LATIN_RE.lastIndex - index;
|
|
108
|
+
widthExtra = lengthExtra * REGULAR_WIDTH;
|
|
109
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / REGULAR_WIDTH));
|
|
110
|
+
if (width + widthExtra > LIMIT) {
|
|
111
|
+
truncationEnabled = true;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
width += widthExtra;
|
|
115
|
+
unmatchedStart = indexPrev;
|
|
116
|
+
unmatchedEnd = index;
|
|
117
|
+
index = indexPrev = LATIN_RE.lastIndex;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
ANSI_RE.lastIndex = index;
|
|
121
|
+
if (ANSI_RE.test(input)) {
|
|
122
|
+
if (width + ANSI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
|
|
123
|
+
if (width + ANSI_WIDTH > LIMIT) {
|
|
124
|
+
truncationEnabled = true;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
width += ANSI_WIDTH;
|
|
128
|
+
unmatchedStart = indexPrev;
|
|
129
|
+
unmatchedEnd = index;
|
|
130
|
+
index = indexPrev = ANSI_RE.lastIndex;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
CONTROL_RE.lastIndex = index;
|
|
134
|
+
if (CONTROL_RE.test(input)) {
|
|
135
|
+
lengthExtra = CONTROL_RE.lastIndex - index;
|
|
136
|
+
widthExtra = lengthExtra * CONTROL_WIDTH;
|
|
137
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / CONTROL_WIDTH));
|
|
138
|
+
if (width + widthExtra > LIMIT) {
|
|
139
|
+
truncationEnabled = true;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
width += widthExtra;
|
|
143
|
+
unmatchedStart = indexPrev;
|
|
144
|
+
unmatchedEnd = index;
|
|
145
|
+
index = indexPrev = CONTROL_RE.lastIndex;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
TAB_RE.lastIndex = index;
|
|
149
|
+
if (TAB_RE.test(input)) {
|
|
150
|
+
lengthExtra = TAB_RE.lastIndex - index;
|
|
151
|
+
widthExtra = lengthExtra * TAB_WIDTH;
|
|
152
|
+
if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / TAB_WIDTH));
|
|
153
|
+
if (width + widthExtra > LIMIT) {
|
|
154
|
+
truncationEnabled = true;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
width += widthExtra;
|
|
158
|
+
unmatchedStart = indexPrev;
|
|
159
|
+
unmatchedEnd = index;
|
|
160
|
+
index = indexPrev = TAB_RE.lastIndex;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
EMOJI_RE.lastIndex = index;
|
|
164
|
+
if (EMOJI_RE.test(input)) {
|
|
165
|
+
if (width + EMOJI_WIDTH > truncationLimit) truncationIndex = Math.min(truncationIndex, index);
|
|
166
|
+
if (width + EMOJI_WIDTH > LIMIT) {
|
|
167
|
+
truncationEnabled = true;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
width += EMOJI_WIDTH;
|
|
171
|
+
unmatchedStart = indexPrev;
|
|
172
|
+
unmatchedEnd = index;
|
|
173
|
+
index = indexPrev = EMOJI_RE.lastIndex;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
index += 1;
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
180
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
181
|
+
truncated: truncationEnabled,
|
|
182
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region node_modules/.pnpm/fast-string-width@1.1.0/node_modules/fast-string-width/dist/index.js
|
|
187
|
+
const NO_TRUNCATION = {
|
|
188
|
+
limit: Infinity,
|
|
189
|
+
ellipsis: "",
|
|
190
|
+
ellipsisWidth: 0
|
|
191
|
+
};
|
|
192
|
+
const fastStringWidth = (input, options = {}) => {
|
|
193
|
+
return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
|
|
194
|
+
};
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region node_modules/.pnpm/fast-wrap-ansi@0.1.6/node_modules/fast-wrap-ansi/lib/main.js
|
|
197
|
+
const ESC = "\x1B";
|
|
198
|
+
const CSI = "";
|
|
199
|
+
const END_CODE = 39;
|
|
200
|
+
const ANSI_ESCAPE_BELL = "\x07";
|
|
201
|
+
const ANSI_CSI = "[";
|
|
202
|
+
const ANSI_OSC = "]";
|
|
203
|
+
const ANSI_SGR_TERMINATOR = "m";
|
|
204
|
+
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
205
|
+
const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
206
|
+
const getClosingCode = (openingCode) => {
|
|
207
|
+
if (openingCode >= 30 && openingCode <= 37) return 39;
|
|
208
|
+
if (openingCode >= 90 && openingCode <= 97) return 39;
|
|
209
|
+
if (openingCode >= 40 && openingCode <= 47) return 49;
|
|
210
|
+
if (openingCode >= 100 && openingCode <= 107) return 49;
|
|
211
|
+
if (openingCode === 1 || openingCode === 2) return 22;
|
|
212
|
+
if (openingCode === 3) return 23;
|
|
213
|
+
if (openingCode === 4) return 24;
|
|
214
|
+
if (openingCode === 7) return 27;
|
|
215
|
+
if (openingCode === 8) return 28;
|
|
216
|
+
if (openingCode === 9) return 29;
|
|
217
|
+
if (openingCode === 0) return 0;
|
|
218
|
+
};
|
|
219
|
+
const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
220
|
+
const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
221
|
+
const wrapWord = (rows, word, columns) => {
|
|
222
|
+
const characters = word[Symbol.iterator]();
|
|
223
|
+
let isInsideEscape = false;
|
|
224
|
+
let isInsideLinkEscape = false;
|
|
225
|
+
let lastRow = rows.at(-1);
|
|
226
|
+
let visible = lastRow === void 0 ? 0 : fastStringWidth(lastRow);
|
|
227
|
+
let currentCharacter = characters.next();
|
|
228
|
+
let nextCharacter = characters.next();
|
|
229
|
+
let rawCharacterIndex = 0;
|
|
230
|
+
while (!currentCharacter.done) {
|
|
231
|
+
const character = currentCharacter.value;
|
|
232
|
+
const characterLength = fastStringWidth(character);
|
|
233
|
+
if (visible + characterLength <= columns) rows[rows.length - 1] += character;
|
|
234
|
+
else {
|
|
235
|
+
rows.push(character);
|
|
236
|
+
visible = 0;
|
|
237
|
+
}
|
|
238
|
+
if (character === ESC || character === CSI) {
|
|
239
|
+
isInsideEscape = true;
|
|
240
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
241
|
+
}
|
|
242
|
+
if (isInsideEscape) {
|
|
243
|
+
if (isInsideLinkEscape) {
|
|
244
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
245
|
+
isInsideEscape = false;
|
|
246
|
+
isInsideLinkEscape = false;
|
|
247
|
+
}
|
|
248
|
+
} else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
|
|
249
|
+
} else {
|
|
250
|
+
visible += characterLength;
|
|
251
|
+
if (visible === columns && !nextCharacter.done) {
|
|
252
|
+
rows.push("");
|
|
253
|
+
visible = 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
currentCharacter = nextCharacter;
|
|
257
|
+
nextCharacter = characters.next();
|
|
258
|
+
rawCharacterIndex += character.length;
|
|
259
|
+
}
|
|
260
|
+
lastRow = rows.at(-1);
|
|
261
|
+
if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) rows[rows.length - 2] += rows.pop();
|
|
262
|
+
};
|
|
263
|
+
const stringVisibleTrimSpacesRight = (string) => {
|
|
264
|
+
const words = string.split(" ");
|
|
265
|
+
let last = words.length;
|
|
266
|
+
while (last) {
|
|
267
|
+
if (fastStringWidth(words[last - 1])) break;
|
|
268
|
+
last--;
|
|
269
|
+
}
|
|
270
|
+
if (last === words.length) return string;
|
|
271
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
272
|
+
};
|
|
273
|
+
const exec = (string, columns, options = {}) => {
|
|
274
|
+
if (options.trim !== false && string.trim() === "") return "";
|
|
275
|
+
let returnValue = "";
|
|
276
|
+
let escapeCode;
|
|
277
|
+
let escapeUrl;
|
|
278
|
+
const words = string.split(" ");
|
|
279
|
+
let rows = [""];
|
|
280
|
+
let rowLength = 0;
|
|
281
|
+
for (let index = 0; index < words.length; index++) {
|
|
282
|
+
const word = words[index];
|
|
283
|
+
if (options.trim !== false) {
|
|
284
|
+
const row = rows.at(-1) ?? "";
|
|
285
|
+
const trimmed = row.trimStart();
|
|
286
|
+
if (row.length !== trimmed.length) {
|
|
287
|
+
rows[rows.length - 1] = trimmed;
|
|
288
|
+
rowLength = fastStringWidth(trimmed);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (index !== 0) {
|
|
292
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
293
|
+
rows.push("");
|
|
294
|
+
rowLength = 0;
|
|
295
|
+
}
|
|
296
|
+
if (rowLength || options.trim === false) {
|
|
297
|
+
rows[rows.length - 1] += " ";
|
|
298
|
+
rowLength++;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const wordLength = fastStringWidth(word);
|
|
302
|
+
if (options.hard && wordLength > columns) {
|
|
303
|
+
const remainingColumns = columns - rowLength;
|
|
304
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
305
|
+
if (Math.floor((wordLength - 1) / columns) < breaksStartingThisLine) rows.push("");
|
|
306
|
+
wrapWord(rows, word, columns);
|
|
307
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
311
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
312
|
+
wrapWord(rows, word, columns);
|
|
313
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
rows.push("");
|
|
317
|
+
rowLength = 0;
|
|
318
|
+
}
|
|
319
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
320
|
+
wrapWord(rows, word, columns);
|
|
321
|
+
rowLength = fastStringWidth(rows.at(-1) ?? "");
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
rows[rows.length - 1] += word;
|
|
325
|
+
rowLength += wordLength;
|
|
326
|
+
}
|
|
327
|
+
if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
328
|
+
const preString = rows.join("\n");
|
|
329
|
+
let inSurrogate = false;
|
|
330
|
+
for (let i = 0; i < preString.length; i++) {
|
|
331
|
+
const character = preString[i];
|
|
332
|
+
returnValue += character;
|
|
333
|
+
if (!inSurrogate) inSurrogate = character >= "\ud800" && character <= "\udbff";
|
|
334
|
+
else continue;
|
|
335
|
+
if (character === ESC || character === CSI) {
|
|
336
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
337
|
+
const groups = GROUP_REGEX.exec(preString)?.groups;
|
|
338
|
+
if (groups?.code !== void 0) {
|
|
339
|
+
const code = Number.parseFloat(groups.code);
|
|
340
|
+
escapeCode = code === END_CODE ? void 0 : code;
|
|
341
|
+
} else if (groups?.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
|
|
342
|
+
}
|
|
343
|
+
if (preString[i + 1] === "\n") {
|
|
344
|
+
if (escapeUrl) returnValue += wrapAnsiHyperlink("");
|
|
345
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
|
|
346
|
+
if (escapeCode && closingCode) returnValue += wrapAnsiCode(closingCode);
|
|
347
|
+
} else if (character === "\n") {
|
|
348
|
+
if (escapeCode && getClosingCode(escapeCode)) returnValue += wrapAnsiCode(escapeCode);
|
|
349
|
+
if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return returnValue;
|
|
353
|
+
};
|
|
354
|
+
const CRLF_OR_LF = /\r?\n/;
|
|
355
|
+
function wrapAnsi(string, columns, options) {
|
|
356
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region node_modules/.pnpm/@clack+core@1.2.0/node_modules/@clack/core/dist/index.mjs
|
|
360
|
+
var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
361
|
+
const ESC = "\x1B";
|
|
362
|
+
const CSI = `${ESC}[`;
|
|
363
|
+
const beep = "\x07";
|
|
364
|
+
const cursor = {
|
|
365
|
+
to(x, y) {
|
|
366
|
+
if (!y) return `${CSI}${x + 1}G`;
|
|
367
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
368
|
+
},
|
|
369
|
+
move(x, y) {
|
|
370
|
+
let ret = "";
|
|
371
|
+
if (x < 0) ret += `${CSI}${-x}D`;
|
|
372
|
+
else if (x > 0) ret += `${CSI}${x}C`;
|
|
373
|
+
if (y < 0) ret += `${CSI}${-y}A`;
|
|
374
|
+
else if (y > 0) ret += `${CSI}${y}B`;
|
|
375
|
+
return ret;
|
|
376
|
+
},
|
|
377
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
378
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
379
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
380
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
381
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
382
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
383
|
+
left: `${CSI}G`,
|
|
384
|
+
hide: `${CSI}?25l`,
|
|
385
|
+
show: `${CSI}?25h`,
|
|
386
|
+
save: `${ESC}7`,
|
|
387
|
+
restore: `${ESC}8`
|
|
388
|
+
};
|
|
389
|
+
module.exports = {
|
|
390
|
+
cursor,
|
|
391
|
+
scroll: {
|
|
392
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
393
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
394
|
+
},
|
|
395
|
+
erase: {
|
|
396
|
+
screen: `${CSI}2J`,
|
|
397
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
398
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
399
|
+
line: `${CSI}2K`,
|
|
400
|
+
lineEnd: `${CSI}K`,
|
|
401
|
+
lineStart: `${CSI}1K`,
|
|
402
|
+
lines(count) {
|
|
403
|
+
let clear = "";
|
|
404
|
+
for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
405
|
+
if (count) clear += cursor.left;
|
|
406
|
+
return clear;
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
beep
|
|
410
|
+
};
|
|
411
|
+
})))();
|
|
412
|
+
function d$1(r, t, e) {
|
|
413
|
+
if (!e.some((o) => !o.disabled)) return r;
|
|
414
|
+
const s = r + t, i = Math.max(e.length - 1, 0), n = s < 0 ? i : s > i ? 0 : s;
|
|
415
|
+
return e[n].disabled ? d$1(n, t < 0 ? -1 : 1, e) : n;
|
|
416
|
+
}
|
|
417
|
+
const u = {
|
|
418
|
+
actions: new Set([
|
|
419
|
+
"up",
|
|
420
|
+
"down",
|
|
421
|
+
"left",
|
|
422
|
+
"right",
|
|
423
|
+
"space",
|
|
424
|
+
"enter",
|
|
425
|
+
"cancel"
|
|
426
|
+
]),
|
|
427
|
+
aliases: new Map([
|
|
428
|
+
["k", "up"],
|
|
429
|
+
["j", "down"],
|
|
430
|
+
["h", "left"],
|
|
431
|
+
["l", "right"],
|
|
432
|
+
["", "cancel"],
|
|
433
|
+
["escape", "cancel"]
|
|
434
|
+
]),
|
|
435
|
+
messages: {
|
|
436
|
+
cancel: "Canceled",
|
|
437
|
+
error: "Something went wrong"
|
|
438
|
+
},
|
|
439
|
+
withGuide: !0,
|
|
440
|
+
date: {
|
|
441
|
+
monthNames: [...[
|
|
442
|
+
"January",
|
|
443
|
+
"February",
|
|
444
|
+
"March",
|
|
445
|
+
"April",
|
|
446
|
+
"May",
|
|
447
|
+
"June",
|
|
448
|
+
"July",
|
|
449
|
+
"August",
|
|
450
|
+
"September",
|
|
451
|
+
"October",
|
|
452
|
+
"November",
|
|
453
|
+
"December"
|
|
454
|
+
]],
|
|
455
|
+
messages: {
|
|
456
|
+
required: "Please enter a valid date",
|
|
457
|
+
invalidMonth: "There are only 12 months in a year",
|
|
458
|
+
invalidDay: (r, t) => `There are only ${r} days in ${t}`,
|
|
459
|
+
afterMin: (r) => `Date must be on or after ${r.toISOString().slice(0, 10)}`,
|
|
460
|
+
beforeMax: (r) => `Date must be on or before ${r.toISOString().slice(0, 10)}`
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
function V$1(r, t) {
|
|
465
|
+
if (typeof r == "string") return u.aliases.get(r) === t;
|
|
466
|
+
for (const e of r) if (e !== void 0 && V$1(e, t)) return !0;
|
|
467
|
+
return !1;
|
|
468
|
+
}
|
|
469
|
+
function j(r, t) {
|
|
470
|
+
if (r === t) return;
|
|
471
|
+
const e = r.split(`
|
|
472
|
+
`), s = t.split(`
|
|
473
|
+
`), i = Math.max(e.length, s.length), n = [];
|
|
474
|
+
for (let o = 0; o < i; o++) e[o] !== s[o] && n.push(o);
|
|
475
|
+
return {
|
|
476
|
+
lines: n,
|
|
477
|
+
numLinesBefore: e.length,
|
|
478
|
+
numLinesAfter: s.length,
|
|
479
|
+
numLines: i
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
globalThis.process.platform.startsWith("win");
|
|
483
|
+
const C = Symbol("clack:cancel");
|
|
484
|
+
function q(r) {
|
|
485
|
+
return r === C;
|
|
486
|
+
}
|
|
487
|
+
function w$1(r, t) {
|
|
488
|
+
const e = r;
|
|
489
|
+
e.isTTY && e.setRawMode(t);
|
|
490
|
+
}
|
|
491
|
+
const O$1 = (r) => "columns" in r && typeof r.columns == "number" ? r.columns : 80, A = (r) => "rows" in r && typeof r.rows == "number" ? r.rows : 20;
|
|
492
|
+
function R(r, t, e, s = e) {
|
|
493
|
+
return wrapAnsi(t, O$1(r ?? stdout) - e.length, {
|
|
494
|
+
hard: !0,
|
|
495
|
+
trim: !1
|
|
496
|
+
}).split(`
|
|
497
|
+
`).map((n, o) => `${o === 0 ? s : e}${n}`).join(`
|
|
498
|
+
`);
|
|
499
|
+
}
|
|
500
|
+
let p = class {
|
|
501
|
+
input;
|
|
502
|
+
output;
|
|
503
|
+
_abortSignal;
|
|
504
|
+
rl;
|
|
505
|
+
opts;
|
|
506
|
+
_render;
|
|
507
|
+
_track = !1;
|
|
508
|
+
_prevFrame = "";
|
|
509
|
+
_subscribers = /* @__PURE__ */ new Map();
|
|
510
|
+
_cursor = 0;
|
|
511
|
+
state = "initial";
|
|
512
|
+
error = "";
|
|
513
|
+
value;
|
|
514
|
+
userInput = "";
|
|
515
|
+
constructor(t, e = !0) {
|
|
516
|
+
const { input: s = stdin, output: i = stdout, render: n, signal: o, ...a } = t;
|
|
517
|
+
this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = e, this._abortSignal = o, this.input = s, this.output = i;
|
|
518
|
+
}
|
|
519
|
+
unsubscribe() {
|
|
520
|
+
this._subscribers.clear();
|
|
521
|
+
}
|
|
522
|
+
setSubscriber(t, e) {
|
|
523
|
+
const s = this._subscribers.get(t) ?? [];
|
|
524
|
+
s.push(e), this._subscribers.set(t, s);
|
|
525
|
+
}
|
|
526
|
+
on(t, e) {
|
|
527
|
+
this.setSubscriber(t, { cb: e });
|
|
528
|
+
}
|
|
529
|
+
once(t, e) {
|
|
530
|
+
this.setSubscriber(t, {
|
|
531
|
+
cb: e,
|
|
532
|
+
once: !0
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
emit(t, ...e) {
|
|
536
|
+
const s = this._subscribers.get(t) ?? [], i = [];
|
|
537
|
+
for (const n of s) n.cb(...e), n.once && i.push(() => s.splice(s.indexOf(n), 1));
|
|
538
|
+
for (const n of i) n();
|
|
539
|
+
}
|
|
540
|
+
prompt() {
|
|
541
|
+
return new Promise((t) => {
|
|
542
|
+
if (this._abortSignal) {
|
|
543
|
+
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(C);
|
|
544
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
545
|
+
this.state = "cancel", this.close();
|
|
546
|
+
}, { once: !0 });
|
|
547
|
+
}
|
|
548
|
+
this.rl = P$1.createInterface({
|
|
549
|
+
input: this.input,
|
|
550
|
+
tabSize: 2,
|
|
551
|
+
prompt: "",
|
|
552
|
+
escapeCodeTimeout: 50,
|
|
553
|
+
terminal: !0
|
|
554
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, !0), this.input.on("keypress", this.onKeypress), w$1(this.input, !0), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
555
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), w$1(this.input, !1), t(this.value);
|
|
556
|
+
}), this.once("cancel", () => {
|
|
557
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), w$1(this.input, !1), t(C);
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
_isActionKey(t, e) {
|
|
562
|
+
return t === " ";
|
|
563
|
+
}
|
|
564
|
+
_setValue(t) {
|
|
565
|
+
this.value = t, this.emit("value", this.value);
|
|
566
|
+
}
|
|
567
|
+
_setUserInput(t, e) {
|
|
568
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
569
|
+
}
|
|
570
|
+
_clearUserInput() {
|
|
571
|
+
this.rl?.write(null, {
|
|
572
|
+
ctrl: !0,
|
|
573
|
+
name: "u"
|
|
574
|
+
}), this._setUserInput("");
|
|
575
|
+
}
|
|
576
|
+
onKeypress(t, e) {
|
|
577
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, e) && this.rl?.write(null, {
|
|
578
|
+
ctrl: !0,
|
|
579
|
+
name: "h"
|
|
580
|
+
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && u.aliases.has(e.name) && this.emit("cursor", u.aliases.get(e.name)), u.actions.has(e.name) && this.emit("cursor", e.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t?.toLowerCase(), e), e?.name === "return") {
|
|
581
|
+
if (this.opts.validate) {
|
|
582
|
+
const s = this.opts.validate(this.value);
|
|
583
|
+
s && (this.error = s instanceof Error ? s.message : s, this.state = "error", this.rl?.write(this.userInput));
|
|
584
|
+
}
|
|
585
|
+
this.state !== "error" && (this.state = "submit");
|
|
586
|
+
}
|
|
587
|
+
V$1([
|
|
588
|
+
t,
|
|
589
|
+
e?.name,
|
|
590
|
+
e?.sequence
|
|
591
|
+
], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
592
|
+
}
|
|
593
|
+
close() {
|
|
594
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
595
|
+
`), w$1(this.input, !1), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
596
|
+
}
|
|
597
|
+
restoreCursor() {
|
|
598
|
+
const t = wrapAnsi(this._prevFrame, process.stdout.columns, {
|
|
599
|
+
hard: !0,
|
|
600
|
+
trim: !1
|
|
601
|
+
}).split(`
|
|
602
|
+
`).length - 1;
|
|
603
|
+
this.output.write(import_src.cursor.move(-999, t * -1));
|
|
604
|
+
}
|
|
605
|
+
render() {
|
|
606
|
+
const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
607
|
+
hard: !0,
|
|
608
|
+
trim: !1
|
|
609
|
+
});
|
|
610
|
+
if (t !== this._prevFrame) {
|
|
611
|
+
if (this.state === "initial") this.output.write(import_src.cursor.hide);
|
|
612
|
+
else {
|
|
613
|
+
const e = j(this._prevFrame, t), s = A(this.output);
|
|
614
|
+
if (this.restoreCursor(), e) {
|
|
615
|
+
const i = Math.max(0, e.numLinesAfter - s), n = Math.max(0, e.numLinesBefore - s);
|
|
616
|
+
let o = e.lines.find((a) => a >= i);
|
|
617
|
+
if (o === void 0) {
|
|
618
|
+
this._prevFrame = t;
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
if (e.lines.length === 1) {
|
|
622
|
+
this.output.write(import_src.cursor.move(0, o - n)), this.output.write(import_src.erase.lines(1));
|
|
623
|
+
const a = t.split(`
|
|
624
|
+
`);
|
|
625
|
+
this.output.write(a[o]), this._prevFrame = t, this.output.write(import_src.cursor.move(0, a.length - o - 1));
|
|
626
|
+
return;
|
|
627
|
+
} else if (e.lines.length > 1) {
|
|
628
|
+
if (i < n) o = i;
|
|
629
|
+
else {
|
|
630
|
+
const h = o - n;
|
|
631
|
+
h > 0 && this.output.write(import_src.cursor.move(0, h));
|
|
632
|
+
}
|
|
633
|
+
this.output.write(import_src.erase.down());
|
|
634
|
+
const a = t.split(`
|
|
635
|
+
`).slice(o);
|
|
636
|
+
this.output.write(a.join(`
|
|
637
|
+
`)), this._prevFrame = t;
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
this.output.write(import_src.erase.down());
|
|
642
|
+
}
|
|
643
|
+
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
var Q$1 = class extends p {
|
|
648
|
+
get cursor() {
|
|
649
|
+
return this.value ? 0 : 1;
|
|
650
|
+
}
|
|
651
|
+
get _value() {
|
|
652
|
+
return this.cursor === 0;
|
|
653
|
+
}
|
|
654
|
+
constructor(t) {
|
|
655
|
+
super(t, !1), this.value = !!t.initialValue, this.on("userInput", () => {
|
|
656
|
+
this.value = this._value;
|
|
657
|
+
}), this.on("confirm", (e) => {
|
|
658
|
+
this.output.write(import_src.cursor.move(0, -1)), this.value = e, this.state = "submit", this.close();
|
|
659
|
+
}), this.on("cursor", () => {
|
|
660
|
+
this.value = !this.value;
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
let it$1 = class extends p {
|
|
665
|
+
options;
|
|
666
|
+
cursor = 0;
|
|
667
|
+
get _value() {
|
|
668
|
+
return this.options[this.cursor].value;
|
|
669
|
+
}
|
|
670
|
+
get _enabledOptions() {
|
|
671
|
+
return this.options.filter((t) => t.disabled !== !0);
|
|
672
|
+
}
|
|
673
|
+
toggleAll() {
|
|
674
|
+
const t = this._enabledOptions, e = this.value !== void 0 && this.value.length === t.length;
|
|
675
|
+
this.value = e ? [] : t.map((s) => s.value);
|
|
676
|
+
}
|
|
677
|
+
toggleInvert() {
|
|
678
|
+
const t = this.value;
|
|
679
|
+
if (!t) return;
|
|
680
|
+
const e = this._enabledOptions.filter((s) => !t.includes(s.value));
|
|
681
|
+
this.value = e.map((s) => s.value);
|
|
682
|
+
}
|
|
683
|
+
toggleValue() {
|
|
684
|
+
this.value === void 0 && (this.value = []);
|
|
685
|
+
const t = this.value.includes(this._value);
|
|
686
|
+
this.value = t ? this.value.filter((e) => e !== this._value) : [...this.value, this._value];
|
|
687
|
+
}
|
|
688
|
+
constructor(t) {
|
|
689
|
+
super(t, !1), this.options = t.options, this.value = [...t.initialValues ?? []];
|
|
690
|
+
const e = Math.max(this.options.findIndex(({ value: s }) => s === t.cursorAt), 0);
|
|
691
|
+
this.cursor = this.options[e].disabled ? d$1(e, 1, this.options) : e, this.on("key", (s) => {
|
|
692
|
+
s === "a" && this.toggleAll(), s === "i" && this.toggleInvert();
|
|
693
|
+
}), this.on("cursor", (s) => {
|
|
694
|
+
switch (s) {
|
|
695
|
+
case "left":
|
|
696
|
+
case "up":
|
|
697
|
+
this.cursor = d$1(this.cursor, -1, this.options);
|
|
698
|
+
break;
|
|
699
|
+
case "down":
|
|
700
|
+
case "right":
|
|
701
|
+
this.cursor = d$1(this.cursor, 1, this.options);
|
|
702
|
+
break;
|
|
703
|
+
case "space":
|
|
704
|
+
this.toggleValue();
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
var nt$1 = class extends p {
|
|
711
|
+
options;
|
|
712
|
+
cursor = 0;
|
|
713
|
+
get _selectedValue() {
|
|
714
|
+
return this.options[this.cursor];
|
|
715
|
+
}
|
|
716
|
+
changeValue() {
|
|
717
|
+
this.value = this._selectedValue.value;
|
|
718
|
+
}
|
|
719
|
+
constructor(t) {
|
|
720
|
+
super(t, !1), this.options = t.options;
|
|
721
|
+
const e = this.options.findIndex(({ value: i }) => i === t.initialValue), s = e === -1 ? 0 : e;
|
|
722
|
+
this.cursor = this.options[s].disabled ? d$1(s, 1, this.options) : s, this.changeValue(), this.on("cursor", (i) => {
|
|
723
|
+
switch (i) {
|
|
724
|
+
case "left":
|
|
725
|
+
case "up":
|
|
726
|
+
this.cursor = d$1(this.cursor, -1, this.options);
|
|
727
|
+
break;
|
|
728
|
+
case "down":
|
|
729
|
+
case "right":
|
|
730
|
+
this.cursor = d$1(this.cursor, 1, this.options);
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
this.changeValue();
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
var at$1 = class extends p {
|
|
738
|
+
get userInputWithCursor() {
|
|
739
|
+
if (this.state === "submit") return this.userInput;
|
|
740
|
+
const t = this.userInput;
|
|
741
|
+
if (this.cursor >= t.length) return `${this.userInput}\u2588`;
|
|
742
|
+
const e = t.slice(0, this.cursor), [s, ...i] = t.slice(this.cursor);
|
|
743
|
+
return `${e}${styleText("inverse", s)}${i.join("")}`;
|
|
744
|
+
}
|
|
745
|
+
get cursor() {
|
|
746
|
+
return this._cursor;
|
|
747
|
+
}
|
|
748
|
+
constructor(t) {
|
|
749
|
+
super({
|
|
750
|
+
...t,
|
|
751
|
+
initialUserInput: t.initialUserInput ?? t.initialValue
|
|
752
|
+
}), this.on("userInput", (e) => {
|
|
753
|
+
this._setValue(e);
|
|
754
|
+
}), this.on("finalize", () => {
|
|
755
|
+
this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
//#endregion
|
|
760
|
+
//#region node_modules/.pnpm/@clack+prompts@1.2.0/node_modules/@clack/prompts/dist/index.mjs
|
|
761
|
+
function Ze() {
|
|
762
|
+
return P.platform !== "win32" ? P.env.TERM !== "linux" : !!P.env.CI || !!P.env.WT_SESSION || !!P.env.TERMINUS_SUBLIME || P.env.ConEmuTask === "{cmd::Cmder}" || P.env.TERM_PROGRAM === "Terminus-Sublime" || P.env.TERM_PROGRAM === "vscode" || P.env.TERM === "xterm-256color" || P.env.TERM === "alacritty" || P.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
763
|
+
}
|
|
764
|
+
const ee = Ze(), w = (e, i) => ee ? e : i, _e = w("◆", "*"), oe = w("■", "x"), ue = w("▲", "x"), F = w("◇", "o"), le = w("┌", "T"), d = w("│", "|"), E = w("└", "—");
|
|
765
|
+
w("┐", "T");
|
|
766
|
+
w("┘", "—");
|
|
767
|
+
const z = w("●", ">"), H = w("○", " "), te = w("◻", "[•]"), U = w("◼", "[+]"), J = w("◻", "[ ]");
|
|
768
|
+
w("▪", "•");
|
|
769
|
+
w("─", "-");
|
|
770
|
+
w("╮", "+");
|
|
771
|
+
w("├", "+");
|
|
772
|
+
w("╯", "+");
|
|
773
|
+
w("╰", "+");
|
|
774
|
+
w("╭", "+");
|
|
775
|
+
const he = w("●", "•"), pe = w("◆", "*"), me = w("▲", "!"), ge = w("■", "x"), V = (e) => {
|
|
776
|
+
switch (e) {
|
|
777
|
+
case "initial":
|
|
778
|
+
case "active": return styleText("cyan", _e);
|
|
779
|
+
case "cancel": return styleText("red", oe);
|
|
780
|
+
case "error": return styleText("yellow", ue);
|
|
781
|
+
case "submit": return styleText("green", F);
|
|
782
|
+
}
|
|
783
|
+
}, ye = (e) => {
|
|
784
|
+
switch (e) {
|
|
785
|
+
case "initial":
|
|
786
|
+
case "active": return styleText("cyan", d);
|
|
787
|
+
case "cancel": return styleText("red", d);
|
|
788
|
+
case "error": return styleText("yellow", d);
|
|
789
|
+
case "submit": return styleText("green", d);
|
|
790
|
+
}
|
|
791
|
+
}, et = (e, i, s, r, u) => {
|
|
792
|
+
let n = i, o = 0;
|
|
793
|
+
for (let c = s; c < r; c++) {
|
|
794
|
+
const a = e[c];
|
|
795
|
+
if (n = n - a.length, o++, n <= u) break;
|
|
796
|
+
}
|
|
797
|
+
return {
|
|
798
|
+
lineCount: n,
|
|
799
|
+
removals: o
|
|
800
|
+
};
|
|
801
|
+
}, Y = ({ cursor: e, options: i, style: s, output: r = process.stdout, maxItems: u = Number.POSITIVE_INFINITY, columnPadding: n = 0, rowPadding: o = 4 }) => {
|
|
802
|
+
const c = O$1(r) - n, a = A(r), l = styleText("dim", "..."), $ = Math.max(a - o, 0), y = Math.max(Math.min(u, $), 5);
|
|
803
|
+
let p = 0;
|
|
804
|
+
e >= y - 3 && (p = Math.max(Math.min(e - y + 3, i.length - y), 0));
|
|
805
|
+
let m = y < i.length && p > 0, g = y < i.length && p + y < i.length;
|
|
806
|
+
const S = Math.min(p + y, i.length), h = [];
|
|
807
|
+
let f = 0;
|
|
808
|
+
m && f++, g && f++;
|
|
809
|
+
const v = p + (m ? 1 : 0), T = S - (g ? 1 : 0);
|
|
810
|
+
for (let b = v; b < T; b++) {
|
|
811
|
+
const x = wrapAnsi(s(i[b], b === e), c, {
|
|
812
|
+
hard: !0,
|
|
813
|
+
trim: !1
|
|
814
|
+
}).split(`
|
|
815
|
+
`);
|
|
816
|
+
h.push(x), f += x.length;
|
|
817
|
+
}
|
|
818
|
+
if (f > $) {
|
|
819
|
+
let b = 0, x = 0, G = f;
|
|
820
|
+
const M = e - v, R = (j, D) => et(h, G, j, D, $);
|
|
821
|
+
m ? ({lineCount: G, removals: b} = R(0, M), G > $ && ({lineCount: G, removals: x} = R(M + 1, h.length))) : ({lineCount: G, removals: x} = R(M + 1, h.length), G > $ && ({lineCount: G, removals: b} = R(0, M))), b > 0 && (m = !0, h.splice(0, b)), x > 0 && (g = !0, h.splice(h.length - x, x));
|
|
822
|
+
}
|
|
823
|
+
const C = [];
|
|
824
|
+
m && C.push(l);
|
|
825
|
+
for (const b of h) for (const x of b) C.push(x);
|
|
826
|
+
return g && C.push(l), C;
|
|
827
|
+
};
|
|
828
|
+
const ot = (e) => {
|
|
829
|
+
const i = e.active ?? "Yes", s = e.inactive ?? "No";
|
|
830
|
+
return new Q$1({
|
|
831
|
+
active: i,
|
|
832
|
+
inactive: s,
|
|
833
|
+
signal: e.signal,
|
|
834
|
+
input: e.input,
|
|
835
|
+
output: e.output,
|
|
836
|
+
initialValue: e.initialValue ?? !0,
|
|
837
|
+
render() {
|
|
838
|
+
const r = e.withGuide ?? u.withGuide, u$4 = `${V(this.state)} `, n = r ? `${styleText("gray", d)} ` : "", o = R(e.output, e.message, n, u$4), c = `${r ? `${styleText("gray", d)}
|
|
839
|
+
` : ""}${o}
|
|
840
|
+
`, a = this.value ? i : s;
|
|
841
|
+
switch (this.state) {
|
|
842
|
+
case "submit": return `${c}${r ? `${styleText("gray", d)} ` : ""}${styleText("dim", a)}`;
|
|
843
|
+
case "cancel": return `${c}${r ? `${styleText("gray", d)} ` : ""}${styleText(["strikethrough", "dim"], a)}${r ? `
|
|
844
|
+
${styleText("gray", d)}` : ""}`;
|
|
845
|
+
default: {
|
|
846
|
+
const l = r ? `${styleText("cyan", d)} ` : "", $ = r ? styleText("cyan", E) : "";
|
|
847
|
+
return `${c}${l}${this.value ? `${styleText("green", z)} ${i}` : `${styleText("dim", H)} ${styleText("dim", i)}`}${e.vertical ? r ? `
|
|
848
|
+
${styleText("cyan", d)} ` : `
|
|
849
|
+
` : ` ${styleText("dim", "/")} `}${this.value ? `${styleText("dim", H)} ${styleText("dim", s)}` : `${styleText("green", z)} ${s}`}
|
|
850
|
+
${$}
|
|
851
|
+
`;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}).prompt();
|
|
856
|
+
}, O = {
|
|
857
|
+
message: (e = [], { symbol: i = styleText("gray", d), secondarySymbol: s = styleText("gray", d), output: r = process.stdout, spacing: u$7 = 1, withGuide: n } = {}) => {
|
|
858
|
+
const o = [], c = n ?? u.withGuide, a = c ? s : "", l = c ? `${i} ` : "", $ = c ? `${s} ` : "";
|
|
859
|
+
for (let p = 0; p < u$7; p++) o.push(a);
|
|
860
|
+
const y = Array.isArray(e) ? e : e.split(`
|
|
861
|
+
`);
|
|
862
|
+
if (y.length > 0) {
|
|
863
|
+
const [p, ...m] = y;
|
|
864
|
+
p.length > 0 ? o.push(`${l}${p}`) : o.push(c ? i : "");
|
|
865
|
+
for (const g of m) g.length > 0 ? o.push(`${$}${g}`) : o.push(c ? s : "");
|
|
866
|
+
}
|
|
867
|
+
r.write(`${o.join(`
|
|
868
|
+
`)}
|
|
869
|
+
`);
|
|
870
|
+
},
|
|
871
|
+
info: (e, i) => {
|
|
872
|
+
O.message(e, {
|
|
873
|
+
...i,
|
|
874
|
+
symbol: styleText("blue", he)
|
|
875
|
+
});
|
|
876
|
+
},
|
|
877
|
+
success: (e, i) => {
|
|
878
|
+
O.message(e, {
|
|
879
|
+
...i,
|
|
880
|
+
symbol: styleText("green", pe)
|
|
881
|
+
});
|
|
882
|
+
},
|
|
883
|
+
step: (e, i) => {
|
|
884
|
+
O.message(e, {
|
|
885
|
+
...i,
|
|
886
|
+
symbol: styleText("green", F)
|
|
887
|
+
});
|
|
888
|
+
},
|
|
889
|
+
warn: (e, i) => {
|
|
890
|
+
O.message(e, {
|
|
891
|
+
...i,
|
|
892
|
+
symbol: styleText("yellow", me)
|
|
893
|
+
});
|
|
894
|
+
},
|
|
895
|
+
warning: (e, i) => {
|
|
896
|
+
O.warn(e, i);
|
|
897
|
+
},
|
|
898
|
+
error: (e, i) => {
|
|
899
|
+
O.message(e, {
|
|
900
|
+
...i,
|
|
901
|
+
symbol: styleText("red", ge)
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
}, pt = (e = "", i) => {
|
|
905
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? u.withGuide ? `${styleText("gray", E)} ` : "";
|
|
906
|
+
s.write(`${r}${styleText("red", e)}
|
|
907
|
+
|
|
908
|
+
`);
|
|
909
|
+
}, mt = (e = "", i) => {
|
|
910
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? u.withGuide ? `${styleText("gray", le)} ` : "";
|
|
911
|
+
s.write(`${r}${e}
|
|
912
|
+
`);
|
|
913
|
+
}, gt = (e = "", i) => {
|
|
914
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? u.withGuide ? `${styleText("gray", d)}
|
|
915
|
+
${styleText("gray", E)} ` : "";
|
|
916
|
+
s.write(`${r}${e}
|
|
917
|
+
|
|
918
|
+
`);
|
|
919
|
+
}, Q = (e, i) => e.split(`
|
|
920
|
+
`).map((s) => i(s)).join(`
|
|
921
|
+
`), yt = (e) => {
|
|
922
|
+
const i = (r, u) => {
|
|
923
|
+
const n = r.label ?? String(r.value);
|
|
924
|
+
return u === "disabled" ? `${styleText("gray", J)} ${Q(n, (o) => styleText(["strikethrough", "gray"], o))}${r.hint ? ` ${styleText("dim", `(${r.hint ?? "disabled"})`)}` : ""}` : u === "active" ? `${styleText("cyan", te)} ${n}${r.hint ? ` ${styleText("dim", `(${r.hint})`)}` : ""}` : u === "selected" ? `${styleText("green", U)} ${Q(n, (o) => styleText("dim", o))}${r.hint ? ` ${styleText("dim", `(${r.hint})`)}` : ""}` : u === "cancelled" ? `${Q(n, (o) => styleText(["strikethrough", "dim"], o))}` : u === "active-selected" ? `${styleText("green", U)} ${n}${r.hint ? ` ${styleText("dim", `(${r.hint})`)}` : ""}` : u === "submitted" ? `${Q(n, (o) => styleText("dim", o))}` : `${styleText("dim", J)} ${Q(n, (o) => styleText("dim", o))}`;
|
|
925
|
+
}, s = e.required ?? !0;
|
|
926
|
+
return new it$1({
|
|
927
|
+
options: e.options,
|
|
928
|
+
signal: e.signal,
|
|
929
|
+
input: e.input,
|
|
930
|
+
output: e.output,
|
|
931
|
+
initialValues: e.initialValues,
|
|
932
|
+
required: s,
|
|
933
|
+
cursorAt: e.cursorAt,
|
|
934
|
+
validate(r) {
|
|
935
|
+
if (s && (r === void 0 || r.length === 0)) return `Please select at least one option.
|
|
936
|
+
${styleText("reset", styleText("dim", `Press ${styleText([
|
|
937
|
+
"gray",
|
|
938
|
+
"bgWhite",
|
|
939
|
+
"inverse"
|
|
940
|
+
], " space ")} to select, ${styleText("gray", styleText("bgWhite", styleText("inverse", " enter ")))} to submit`))}`;
|
|
941
|
+
},
|
|
942
|
+
render() {
|
|
943
|
+
const r = e.withGuide ?? u.withGuide, u$8 = R(e.output, e.message, r ? `${ye(this.state)} ` : "", `${V(this.state)} `), n = `${r ? `${styleText("gray", d)}
|
|
944
|
+
` : ""}${u$8}
|
|
945
|
+
`, o = this.value ?? [], c = (a, l) => {
|
|
946
|
+
if (a.disabled) return i(a, "disabled");
|
|
947
|
+
const $ = o.includes(a.value);
|
|
948
|
+
return l && $ ? i(a, "active-selected") : $ ? i(a, "selected") : i(a, l ? "active" : "inactive");
|
|
949
|
+
};
|
|
950
|
+
switch (this.state) {
|
|
951
|
+
case "submit": {
|
|
952
|
+
const a = this.options.filter(({ value: $ }) => o.includes($)).map(($) => i($, "submitted")).join(styleText("dim", ", ")) || styleText("dim", "none");
|
|
953
|
+
return `${n}${R(e.output, a, r ? `${styleText("gray", d)} ` : "")}`;
|
|
954
|
+
}
|
|
955
|
+
case "cancel": {
|
|
956
|
+
const a = this.options.filter(({ value: $ }) => o.includes($)).map(($) => i($, "cancelled")).join(styleText("dim", ", "));
|
|
957
|
+
if (a.trim() === "") return `${n}${styleText("gray", d)}`;
|
|
958
|
+
return `${n}${R(e.output, a, r ? `${styleText("gray", d)} ` : "")}${r ? `
|
|
959
|
+
${styleText("gray", d)}` : ""}`;
|
|
960
|
+
}
|
|
961
|
+
case "error": {
|
|
962
|
+
const a = r ? `${styleText("yellow", d)} ` : "", l = this.error.split(`
|
|
963
|
+
`).map((p, m) => m === 0 ? `${r ? `${styleText("yellow", E)} ` : ""}${styleText("yellow", p)}` : ` ${p}`).join(`
|
|
964
|
+
`), $ = n.split(`
|
|
965
|
+
`).length, y = l.split(`
|
|
966
|
+
`).length + 1;
|
|
967
|
+
return `${n}${a}${Y({
|
|
968
|
+
output: e.output,
|
|
969
|
+
options: this.options,
|
|
970
|
+
cursor: this.cursor,
|
|
971
|
+
maxItems: e.maxItems,
|
|
972
|
+
columnPadding: a.length,
|
|
973
|
+
rowPadding: $ + y,
|
|
974
|
+
style: c
|
|
975
|
+
}).join(`
|
|
976
|
+
${a}`)}
|
|
977
|
+
${l}
|
|
978
|
+
`;
|
|
979
|
+
}
|
|
980
|
+
default: {
|
|
981
|
+
const a = r ? `${styleText("cyan", d)} ` : "", l = n.split(`
|
|
982
|
+
`).length, $ = r ? 2 : 1;
|
|
983
|
+
return `${n}${a}${Y({
|
|
984
|
+
output: e.output,
|
|
985
|
+
options: this.options,
|
|
986
|
+
cursor: this.cursor,
|
|
987
|
+
maxItems: e.maxItems,
|
|
988
|
+
columnPadding: a.length,
|
|
989
|
+
rowPadding: l + $,
|
|
990
|
+
style: c
|
|
991
|
+
}).join(`
|
|
992
|
+
${a}`)}
|
|
993
|
+
${r ? styleText("cyan", E) : ""}
|
|
994
|
+
`;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}).prompt();
|
|
999
|
+
};
|
|
1000
|
+
w("─", "-"), w("━", "="), w("█", "#");
|
|
1001
|
+
const re = (e, i) => e.includes(`
|
|
1002
|
+
`) ? e.split(`
|
|
1003
|
+
`).map((s) => i(s)).join(`
|
|
1004
|
+
`) : i(e), _t = (e) => {
|
|
1005
|
+
const i = (s, r) => {
|
|
1006
|
+
const u = s.label ?? String(s.value);
|
|
1007
|
+
switch (r) {
|
|
1008
|
+
case "disabled": return `${styleText("gray", H)} ${re(u, (n) => styleText("gray", n))}${s.hint ? ` ${styleText("dim", `(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
1009
|
+
case "selected": return `${re(u, (n) => styleText("dim", n))}`;
|
|
1010
|
+
case "active": return `${styleText("green", z)} ${u}${s.hint ? ` ${styleText("dim", `(${s.hint})`)}` : ""}`;
|
|
1011
|
+
case "cancelled": return `${re(u, (n) => styleText(["strikethrough", "dim"], n))}`;
|
|
1012
|
+
default: return `${styleText("dim", H)} ${re(u, (n) => styleText("dim", n))}`;
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
return new nt$1({
|
|
1016
|
+
options: e.options,
|
|
1017
|
+
signal: e.signal,
|
|
1018
|
+
input: e.input,
|
|
1019
|
+
output: e.output,
|
|
1020
|
+
initialValue: e.initialValue,
|
|
1021
|
+
render() {
|
|
1022
|
+
const s = e.withGuide ?? u.withGuide, r = `${V(this.state)} `, u$12 = `${ye(this.state)} `, n = R(e.output, e.message, u$12, r), o = `${s ? `${styleText("gray", d)}
|
|
1023
|
+
` : ""}${n}
|
|
1024
|
+
`;
|
|
1025
|
+
switch (this.state) {
|
|
1026
|
+
case "submit": {
|
|
1027
|
+
const c = s ? `${styleText("gray", d)} ` : "";
|
|
1028
|
+
return `${o}${R(e.output, i(this.options[this.cursor], "selected"), c)}`;
|
|
1029
|
+
}
|
|
1030
|
+
case "cancel": {
|
|
1031
|
+
const c = s ? `${styleText("gray", d)} ` : "";
|
|
1032
|
+
return `${o}${R(e.output, i(this.options[this.cursor], "cancelled"), c)}${s ? `
|
|
1033
|
+
${styleText("gray", d)}` : ""}`;
|
|
1034
|
+
}
|
|
1035
|
+
default: {
|
|
1036
|
+
const c = s ? `${styleText("cyan", d)} ` : "", a = s ? styleText("cyan", E) : "", l = o.split(`
|
|
1037
|
+
`).length, $ = s ? 2 : 1;
|
|
1038
|
+
return `${o}${c}${Y({
|
|
1039
|
+
output: e.output,
|
|
1040
|
+
cursor: this.cursor,
|
|
1041
|
+
options: this.options,
|
|
1042
|
+
maxItems: e.maxItems,
|
|
1043
|
+
columnPadding: c.length,
|
|
1044
|
+
rowPadding: l + $,
|
|
1045
|
+
style: (y, p) => i(y, y.disabled ? "disabled" : p ? "active" : "inactive")
|
|
1046
|
+
}).join(`
|
|
1047
|
+
${c}`)}
|
|
1048
|
+
${a}
|
|
1049
|
+
`;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
}).prompt();
|
|
1054
|
+
}, je = `${styleText("gray", d)} `, K = {
|
|
1055
|
+
message: async (e, { symbol: i = styleText("gray", d) } = {}) => {
|
|
1056
|
+
process.stdout.write(`${styleText("gray", d)}
|
|
1057
|
+
${i} `);
|
|
1058
|
+
let s = 3;
|
|
1059
|
+
for await (let r of e) {
|
|
1060
|
+
r = r.replace(/\n/g, `
|
|
1061
|
+
${je}`), r.includes(`
|
|
1062
|
+
`) && (s = 3 + stripVTControlCharacters(r.slice(r.lastIndexOf(`
|
|
1063
|
+
`))).length);
|
|
1064
|
+
const u = stripVTControlCharacters(r).length;
|
|
1065
|
+
s + u < process.stdout.columns ? (s += u, process.stdout.write(r)) : (process.stdout.write(`
|
|
1066
|
+
${je}${r.trimStart()}`), s = 3 + stripVTControlCharacters(r.trimStart()).length);
|
|
1067
|
+
}
|
|
1068
|
+
process.stdout.write(`
|
|
1069
|
+
`);
|
|
1070
|
+
},
|
|
1071
|
+
info: (e) => K.message(e, { symbol: styleText("blue", he) }),
|
|
1072
|
+
success: (e) => K.message(e, { symbol: styleText("green", pe) }),
|
|
1073
|
+
step: (e) => K.message(e, { symbol: styleText("green", F) }),
|
|
1074
|
+
warn: (e) => K.message(e, { symbol: styleText("yellow", me) }),
|
|
1075
|
+
warning: (e) => K.warn(e),
|
|
1076
|
+
error: (e) => K.message(e, { symbol: styleText("red", ge) })
|
|
1077
|
+
}, Ot = (e) => new at$1({
|
|
1078
|
+
validate: e.validate,
|
|
1079
|
+
placeholder: e.placeholder,
|
|
1080
|
+
defaultValue: e.defaultValue,
|
|
1081
|
+
initialValue: e.initialValue,
|
|
1082
|
+
output: e.output,
|
|
1083
|
+
signal: e.signal,
|
|
1084
|
+
input: e.input,
|
|
1085
|
+
render() {
|
|
1086
|
+
const i = e?.withGuide ?? u.withGuide, s = `${`${i ? `${styleText("gray", d)}
|
|
1087
|
+
` : ""}${V(this.state)} `}${e.message}
|
|
1088
|
+
`, r = e.placeholder ? styleText("inverse", e.placeholder[0]) + styleText("dim", e.placeholder.slice(1)) : styleText(["inverse", "hidden"], "_"), u$13 = this.userInput ? this.userInputWithCursor : r, n = this.value ?? "";
|
|
1089
|
+
switch (this.state) {
|
|
1090
|
+
case "error": {
|
|
1091
|
+
const o = this.error ? ` ${styleText("yellow", this.error)}` : "", c = i ? `${styleText("yellow", d)} ` : "", a = i ? styleText("yellow", E) : "";
|
|
1092
|
+
return `${s.trim()}
|
|
1093
|
+
${c}${u$13}
|
|
1094
|
+
${a}${o}
|
|
1095
|
+
`;
|
|
1096
|
+
}
|
|
1097
|
+
case "submit": {
|
|
1098
|
+
const o = n ? ` ${styleText("dim", n)}` : "";
|
|
1099
|
+
return `${s}${i ? styleText("gray", d) : ""}${o}`;
|
|
1100
|
+
}
|
|
1101
|
+
case "cancel": {
|
|
1102
|
+
const o = n ? ` ${styleText(["strikethrough", "dim"], n)}` : "", c = i ? styleText("gray", d) : "";
|
|
1103
|
+
return `${s}${c}${o}${n.trim() ? `
|
|
1104
|
+
${c}` : ""}`;
|
|
1105
|
+
}
|
|
1106
|
+
default: return `${s}${i ? `${styleText("cyan", d)} ` : ""}${u$13}
|
|
1107
|
+
${i ? styleText("cyan", E) : ""}
|
|
1108
|
+
`;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}).prompt();
|
|
1112
|
+
//#endregion
|
|
1113
|
+
//#region node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
1114
|
+
var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1115
|
+
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
1116
|
+
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
1117
|
+
let formatter = (open, close, replace = open) => (input) => {
|
|
1118
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
1119
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
1120
|
+
};
|
|
1121
|
+
let replaceClose = (string, close, replace, index) => {
|
|
1122
|
+
let result = "", cursor = 0;
|
|
1123
|
+
do {
|
|
1124
|
+
result += string.substring(cursor, index) + replace;
|
|
1125
|
+
cursor = index + close.length;
|
|
1126
|
+
index = string.indexOf(close, cursor);
|
|
1127
|
+
} while (~index);
|
|
1128
|
+
return result + string.substring(cursor);
|
|
1129
|
+
};
|
|
1130
|
+
let createColors = (enabled = isColorSupported) => {
|
|
1131
|
+
let f = enabled ? formatter : () => String;
|
|
1132
|
+
return {
|
|
1133
|
+
isColorSupported: enabled,
|
|
1134
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
1135
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
1136
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
1137
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
1138
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
1139
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
1140
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
1141
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
1142
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
1143
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
1144
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
1145
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
1146
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
1147
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
1148
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
1149
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
1150
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
1151
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
1152
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
1153
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
1154
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
1155
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
1156
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
1157
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
1158
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
1159
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
1160
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
1161
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
1162
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
1163
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
1164
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
1165
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
1166
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
1167
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
1168
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
1169
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
1170
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
1171
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
1172
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
1173
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
1174
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
1175
|
+
};
|
|
1176
|
+
};
|
|
1177
|
+
module.exports = createColors();
|
|
1178
|
+
module.exports.createColors = createColors;
|
|
1179
|
+
}));
|
|
1180
|
+
//#endregion
|
|
1181
|
+
//#region node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/lib/utils.js
|
|
1182
|
+
/**
|
|
1183
|
+
* Private utility functions
|
|
1184
|
+
* @module utils
|
|
1185
|
+
* @private
|
|
1186
|
+
*/
|
|
1187
|
+
var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1188
|
+
var regExpChars = /[|\\{}()[\]^$+*?.]/g;
|
|
1189
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1190
|
+
var hasOwn = function(obj, key) {
|
|
1191
|
+
return hasOwnProperty.apply(obj, [key]);
|
|
1192
|
+
};
|
|
1193
|
+
/**
|
|
1194
|
+
* Escape characters reserved in regular expressions.
|
|
1195
|
+
*
|
|
1196
|
+
* If `string` is `undefined` or `null`, the empty string is returned.
|
|
1197
|
+
*
|
|
1198
|
+
* @param {String} string Input string
|
|
1199
|
+
* @return {String} Escaped string
|
|
1200
|
+
* @static
|
|
1201
|
+
* @private
|
|
1202
|
+
*/
|
|
1203
|
+
exports.escapeRegExpChars = function(string) {
|
|
1204
|
+
// istanbul ignore if
|
|
1205
|
+
if (!string) return "";
|
|
1206
|
+
return String(string).replace(regExpChars, "\\$&");
|
|
1207
|
+
};
|
|
1208
|
+
var _ENCODE_HTML_RULES = {
|
|
1209
|
+
"&": "&",
|
|
1210
|
+
"<": "<",
|
|
1211
|
+
">": ">",
|
|
1212
|
+
"\"": """,
|
|
1213
|
+
"'": "'"
|
|
1214
|
+
};
|
|
1215
|
+
var _MATCH_HTML = /[&<>'"]/g;
|
|
1216
|
+
function encode_char(c) {
|
|
1217
|
+
return _ENCODE_HTML_RULES[c] || c;
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Stringified version of constants used by {@link module:utils.escapeXML}.
|
|
1221
|
+
*
|
|
1222
|
+
* It is used in the process of generating {@link ClientFunction}s.
|
|
1223
|
+
*
|
|
1224
|
+
* @readonly
|
|
1225
|
+
* @type {String}
|
|
1226
|
+
*/
|
|
1227
|
+
var escapeFuncStr = "var _ENCODE_HTML_RULES = {\n \"&\": \"&\"\n , \"<\": \"<\"\n , \">\": \">\"\n , '\"': \""\"\n , \"'\": \"'\"\n }\n , _MATCH_HTML = /[&<>'\"]/g;\nfunction encode_char(c) {\n return _ENCODE_HTML_RULES[c] || c;\n};\n";
|
|
1228
|
+
/**
|
|
1229
|
+
* Escape characters reserved in XML.
|
|
1230
|
+
*
|
|
1231
|
+
* If `markup` is `undefined` or `null`, the empty string is returned.
|
|
1232
|
+
*
|
|
1233
|
+
* @implements {EscapeCallback}
|
|
1234
|
+
* @param {String} markup Input string
|
|
1235
|
+
* @return {String} Escaped string
|
|
1236
|
+
* @static
|
|
1237
|
+
* @private
|
|
1238
|
+
*/
|
|
1239
|
+
exports.escapeXML = function(markup) {
|
|
1240
|
+
return markup == void 0 ? "" : String(markup).replace(_MATCH_HTML, encode_char);
|
|
1241
|
+
};
|
|
1242
|
+
function escapeXMLToString() {
|
|
1243
|
+
return Function.prototype.toString.call(this) + ";\n" + escapeFuncStr;
|
|
1244
|
+
}
|
|
1245
|
+
try {
|
|
1246
|
+
if (typeof Object.defineProperty === "function") Object.defineProperty(exports.escapeXML, "toString", { value: escapeXMLToString });
|
|
1247
|
+
else exports.escapeXML.toString = escapeXMLToString;
|
|
1248
|
+
} catch (err) {
|
|
1249
|
+
console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Naive copy of properties from one object to another.
|
|
1253
|
+
* Does not recurse into non-scalar properties
|
|
1254
|
+
* Does not check to see if the property has a value before copying
|
|
1255
|
+
*
|
|
1256
|
+
* @param {Object} to Destination object
|
|
1257
|
+
* @param {Object} from Source object
|
|
1258
|
+
* @return {Object} Destination object
|
|
1259
|
+
* @static
|
|
1260
|
+
* @private
|
|
1261
|
+
*/
|
|
1262
|
+
exports.shallowCopy = function(to, from) {
|
|
1263
|
+
from = from || {};
|
|
1264
|
+
if (to !== null && to !== void 0) for (var p in from) {
|
|
1265
|
+
if (!hasOwn(from, p)) continue;
|
|
1266
|
+
if (p === "__proto__" || p === "constructor") continue;
|
|
1267
|
+
to[p] = from[p];
|
|
1268
|
+
}
|
|
1269
|
+
return to;
|
|
1270
|
+
};
|
|
1271
|
+
/**
|
|
1272
|
+
* Naive copy of a list of key names, from one object to another.
|
|
1273
|
+
* Only copies property if it is actually defined
|
|
1274
|
+
* Does not recurse into non-scalar properties
|
|
1275
|
+
*
|
|
1276
|
+
* @param {Object} to Destination object
|
|
1277
|
+
* @param {Object} from Source object
|
|
1278
|
+
* @param {Array} list List of properties to copy
|
|
1279
|
+
* @return {Object} Destination object
|
|
1280
|
+
* @static
|
|
1281
|
+
* @private
|
|
1282
|
+
*/
|
|
1283
|
+
exports.shallowCopyFromList = function(to, from, list) {
|
|
1284
|
+
list = list || [];
|
|
1285
|
+
from = from || {};
|
|
1286
|
+
if (to !== null && to !== void 0) for (var i = 0; i < list.length; i++) {
|
|
1287
|
+
var p = list[i];
|
|
1288
|
+
if (typeof from[p] != "undefined") {
|
|
1289
|
+
if (!hasOwn(from, p)) continue;
|
|
1290
|
+
if (p === "__proto__" || p === "constructor") continue;
|
|
1291
|
+
to[p] = from[p];
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return to;
|
|
1295
|
+
};
|
|
1296
|
+
/**
|
|
1297
|
+
* Simple in-process cache implementation. Does not implement limits of any
|
|
1298
|
+
* sort.
|
|
1299
|
+
*
|
|
1300
|
+
* @implements {Cache}
|
|
1301
|
+
* @static
|
|
1302
|
+
* @private
|
|
1303
|
+
*/
|
|
1304
|
+
exports.cache = {
|
|
1305
|
+
_data: {},
|
|
1306
|
+
set: function(key, val) {
|
|
1307
|
+
this._data[key] = val;
|
|
1308
|
+
},
|
|
1309
|
+
get: function(key) {
|
|
1310
|
+
return this._data[key];
|
|
1311
|
+
},
|
|
1312
|
+
remove: function(key) {
|
|
1313
|
+
delete this._data[key];
|
|
1314
|
+
},
|
|
1315
|
+
reset: function() {
|
|
1316
|
+
this._data = {};
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
/**
|
|
1320
|
+
* Transforms hyphen case variable into camel case.
|
|
1321
|
+
*
|
|
1322
|
+
* @param {String} string Hyphen case string
|
|
1323
|
+
* @return {String} Camel case string
|
|
1324
|
+
* @static
|
|
1325
|
+
* @private
|
|
1326
|
+
*/
|
|
1327
|
+
exports.hyphenToCamel = function(str) {
|
|
1328
|
+
return str.replace(/-[a-z]/g, function(match) {
|
|
1329
|
+
return match[1].toUpperCase();
|
|
1330
|
+
});
|
|
1331
|
+
};
|
|
1332
|
+
/**
|
|
1333
|
+
* Returns a null-prototype object in runtimes that support it
|
|
1334
|
+
*
|
|
1335
|
+
* @return {Object} Object, prototype will be set to null where possible
|
|
1336
|
+
* @static
|
|
1337
|
+
* @private
|
|
1338
|
+
*/
|
|
1339
|
+
exports.createNullProtoObjWherePossible = (function() {
|
|
1340
|
+
if (typeof Object.create == "function") return function() {
|
|
1341
|
+
return Object.create(null);
|
|
1342
|
+
};
|
|
1343
|
+
if (!({ __proto__: null } instanceof Object)) return function() {
|
|
1344
|
+
return { __proto__: null };
|
|
1345
|
+
};
|
|
1346
|
+
return function() {
|
|
1347
|
+
return {};
|
|
1348
|
+
};
|
|
1349
|
+
})();
|
|
1350
|
+
exports.hasOwnOnlyObject = function(obj) {
|
|
1351
|
+
var o = exports.createNullProtoObjWherePossible();
|
|
1352
|
+
for (var p in obj) if (hasOwn(obj, p)) o[p] = obj[p];
|
|
1353
|
+
return o;
|
|
1354
|
+
};
|
|
1355
|
+
}));
|
|
1356
|
+
//#endregion
|
|
1357
|
+
//#region node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/package.json
|
|
1358
|
+
var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1359
|
+
module.exports = {
|
|
1360
|
+
"name": "ejs",
|
|
1361
|
+
"description": "Embedded JavaScript templates",
|
|
1362
|
+
"keywords": [
|
|
1363
|
+
"template",
|
|
1364
|
+
"engine",
|
|
1365
|
+
"ejs"
|
|
1366
|
+
],
|
|
1367
|
+
"version": "3.1.10",
|
|
1368
|
+
"author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
|
|
1369
|
+
"license": "Apache-2.0",
|
|
1370
|
+
"bin": { "ejs": "./bin/cli.js" },
|
|
1371
|
+
"main": "./lib/ejs.js",
|
|
1372
|
+
"jsdelivr": "ejs.min.js",
|
|
1373
|
+
"unpkg": "ejs.min.js",
|
|
1374
|
+
"repository": {
|
|
1375
|
+
"type": "git",
|
|
1376
|
+
"url": "git://github.com/mde/ejs.git"
|
|
1377
|
+
},
|
|
1378
|
+
"bugs": "https://github.com/mde/ejs/issues",
|
|
1379
|
+
"homepage": "https://github.com/mde/ejs",
|
|
1380
|
+
"dependencies": { "jake": "^10.8.5" },
|
|
1381
|
+
"devDependencies": {
|
|
1382
|
+
"browserify": "^16.5.1",
|
|
1383
|
+
"eslint": "^6.8.0",
|
|
1384
|
+
"git-directory-deploy": "^1.5.1",
|
|
1385
|
+
"jsdoc": "^4.0.2",
|
|
1386
|
+
"lru-cache": "^4.0.1",
|
|
1387
|
+
"mocha": "^10.2.0",
|
|
1388
|
+
"uglify-js": "^3.3.16"
|
|
1389
|
+
},
|
|
1390
|
+
"engines": { "node": ">=0.10.0" },
|
|
1391
|
+
"scripts": { "test": "npx jake test" }
|
|
1392
|
+
};
|
|
1393
|
+
}));
|
|
1394
|
+
//#endregion
|
|
1395
|
+
//#region node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/lib/ejs.js
|
|
1396
|
+
var require_ejs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1397
|
+
/**
|
|
1398
|
+
* @file Embedded JavaScript templating engine. {@link http://ejs.co}
|
|
1399
|
+
* @author Matthew Eernisse <mde@fleegix.org>
|
|
1400
|
+
* @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
|
|
1401
|
+
* @project EJS
|
|
1402
|
+
* @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
|
|
1403
|
+
*/
|
|
1404
|
+
/**
|
|
1405
|
+
* EJS internal functions.
|
|
1406
|
+
*
|
|
1407
|
+
* Technically this "module" lies in the same file as {@link module:ejs}, for
|
|
1408
|
+
* the sake of organization all the private functions re grouped into this
|
|
1409
|
+
* module.
|
|
1410
|
+
*
|
|
1411
|
+
* @module ejs-internal
|
|
1412
|
+
* @private
|
|
1413
|
+
*/
|
|
1414
|
+
/**
|
|
1415
|
+
* Embedded JavaScript templating engine.
|
|
1416
|
+
*
|
|
1417
|
+
* @module ejs
|
|
1418
|
+
* @public
|
|
1419
|
+
*/
|
|
1420
|
+
var fs$1 = __require("fs");
|
|
1421
|
+
var path$2 = __require("path");
|
|
1422
|
+
var utils = require_utils();
|
|
1423
|
+
var scopeOptionWarned = false;
|
|
1424
|
+
/** @type {string} */
|
|
1425
|
+
var _VERSION_STRING = require_package().version;
|
|
1426
|
+
var _DEFAULT_OPEN_DELIMITER = "<";
|
|
1427
|
+
var _DEFAULT_CLOSE_DELIMITER = ">";
|
|
1428
|
+
var _DEFAULT_DELIMITER = "%";
|
|
1429
|
+
var _DEFAULT_LOCALS_NAME = "locals";
|
|
1430
|
+
var _NAME = "ejs";
|
|
1431
|
+
var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
|
|
1432
|
+
var _OPTS_PASSABLE_WITH_DATA = [
|
|
1433
|
+
"delimiter",
|
|
1434
|
+
"scope",
|
|
1435
|
+
"context",
|
|
1436
|
+
"debug",
|
|
1437
|
+
"compileDebug",
|
|
1438
|
+
"client",
|
|
1439
|
+
"_with",
|
|
1440
|
+
"rmWhitespace",
|
|
1441
|
+
"strict",
|
|
1442
|
+
"filename",
|
|
1443
|
+
"async"
|
|
1444
|
+
];
|
|
1445
|
+
var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
|
|
1446
|
+
var _BOM = /^\uFEFF/;
|
|
1447
|
+
var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
1448
|
+
/**
|
|
1449
|
+
* EJS template function cache. This can be a LRU object from lru-cache NPM
|
|
1450
|
+
* module. By default, it is {@link module:utils.cache}, a simple in-process
|
|
1451
|
+
* cache that grows continuously.
|
|
1452
|
+
*
|
|
1453
|
+
* @type {Cache}
|
|
1454
|
+
*/
|
|
1455
|
+
exports.cache = utils.cache;
|
|
1456
|
+
/**
|
|
1457
|
+
* Custom file loader. Useful for template preprocessing or restricting access
|
|
1458
|
+
* to a certain part of the filesystem.
|
|
1459
|
+
*
|
|
1460
|
+
* @type {fileLoader}
|
|
1461
|
+
*/
|
|
1462
|
+
exports.fileLoader = fs$1.readFileSync;
|
|
1463
|
+
/**
|
|
1464
|
+
* Name of the object containing the locals.
|
|
1465
|
+
*
|
|
1466
|
+
* This variable is overridden by {@link Options}`.localsName` if it is not
|
|
1467
|
+
* `undefined`.
|
|
1468
|
+
*
|
|
1469
|
+
* @type {String}
|
|
1470
|
+
* @public
|
|
1471
|
+
*/
|
|
1472
|
+
exports.localsName = _DEFAULT_LOCALS_NAME;
|
|
1473
|
+
/**
|
|
1474
|
+
* Promise implementation -- defaults to the native implementation if available
|
|
1475
|
+
* This is mostly just for testability
|
|
1476
|
+
*
|
|
1477
|
+
* @type {PromiseConstructorLike}
|
|
1478
|
+
* @public
|
|
1479
|
+
*/
|
|
1480
|
+
exports.promiseImpl = new Function("return this;")().Promise;
|
|
1481
|
+
/**
|
|
1482
|
+
* Get the path to the included file from the parent file path and the
|
|
1483
|
+
* specified path.
|
|
1484
|
+
*
|
|
1485
|
+
* @param {String} name specified path
|
|
1486
|
+
* @param {String} filename parent file path
|
|
1487
|
+
* @param {Boolean} [isDir=false] whether the parent file path is a directory
|
|
1488
|
+
* @return {String}
|
|
1489
|
+
*/
|
|
1490
|
+
exports.resolveInclude = function(name, filename, isDir) {
|
|
1491
|
+
var dirname = path$2.dirname;
|
|
1492
|
+
var extname = path$2.extname;
|
|
1493
|
+
var resolve = path$2.resolve;
|
|
1494
|
+
var includePath = resolve(isDir ? filename : dirname(filename), name);
|
|
1495
|
+
if (!extname(name)) includePath += ".ejs";
|
|
1496
|
+
return includePath;
|
|
1497
|
+
};
|
|
1498
|
+
/**
|
|
1499
|
+
* Try to resolve file path on multiple directories
|
|
1500
|
+
*
|
|
1501
|
+
* @param {String} name specified path
|
|
1502
|
+
* @param {Array<String>} paths list of possible parent directory paths
|
|
1503
|
+
* @return {String}
|
|
1504
|
+
*/
|
|
1505
|
+
function resolvePaths(name, paths) {
|
|
1506
|
+
var filePath;
|
|
1507
|
+
if (paths.some(function(v) {
|
|
1508
|
+
filePath = exports.resolveInclude(name, v, true);
|
|
1509
|
+
return fs$1.existsSync(filePath);
|
|
1510
|
+
})) return filePath;
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
* Get the path to the included file by Options
|
|
1514
|
+
*
|
|
1515
|
+
* @param {String} path specified path
|
|
1516
|
+
* @param {Options} options compilation options
|
|
1517
|
+
* @return {String}
|
|
1518
|
+
*/
|
|
1519
|
+
function getIncludePath(path, options) {
|
|
1520
|
+
var includePath;
|
|
1521
|
+
var filePath;
|
|
1522
|
+
var views = options.views;
|
|
1523
|
+
var match = /^[A-Za-z]+:\\|^\//.exec(path);
|
|
1524
|
+
if (match && match.length) {
|
|
1525
|
+
path = path.replace(/^\/*/, "");
|
|
1526
|
+
if (Array.isArray(options.root)) includePath = resolvePaths(path, options.root);
|
|
1527
|
+
else includePath = exports.resolveInclude(path, options.root || "/", true);
|
|
1528
|
+
} else {
|
|
1529
|
+
if (options.filename) {
|
|
1530
|
+
filePath = exports.resolveInclude(path, options.filename);
|
|
1531
|
+
if (fs$1.existsSync(filePath)) includePath = filePath;
|
|
1532
|
+
}
|
|
1533
|
+
if (!includePath && Array.isArray(views)) includePath = resolvePaths(path, views);
|
|
1534
|
+
if (!includePath && typeof options.includer !== "function") throw new Error("Could not find the include file \"" + options.escapeFunction(path) + "\"");
|
|
1535
|
+
}
|
|
1536
|
+
return includePath;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Get the template from a string or a file, either compiled on-the-fly or
|
|
1540
|
+
* read from cache (if enabled), and cache the template if needed.
|
|
1541
|
+
*
|
|
1542
|
+
* If `template` is not set, the file specified in `options.filename` will be
|
|
1543
|
+
* read.
|
|
1544
|
+
*
|
|
1545
|
+
* If `options.cache` is true, this function reads the file from
|
|
1546
|
+
* `options.filename` so it must be set prior to calling this function.
|
|
1547
|
+
*
|
|
1548
|
+
* @memberof module:ejs-internal
|
|
1549
|
+
* @param {Options} options compilation options
|
|
1550
|
+
* @param {String} [template] template source
|
|
1551
|
+
* @return {(TemplateFunction|ClientFunction)}
|
|
1552
|
+
* Depending on the value of `options.client`, either type might be returned.
|
|
1553
|
+
* @static
|
|
1554
|
+
*/
|
|
1555
|
+
function handleCache(options, template) {
|
|
1556
|
+
var func;
|
|
1557
|
+
var filename = options.filename;
|
|
1558
|
+
var hasTemplate = arguments.length > 1;
|
|
1559
|
+
if (options.cache) {
|
|
1560
|
+
if (!filename) throw new Error("cache option requires a filename");
|
|
1561
|
+
func = exports.cache.get(filename);
|
|
1562
|
+
if (func) return func;
|
|
1563
|
+
if (!hasTemplate) template = fileLoader(filename).toString().replace(_BOM, "");
|
|
1564
|
+
} else if (!hasTemplate) {
|
|
1565
|
+
// istanbul ignore if: should not happen at all
|
|
1566
|
+
if (!filename) throw new Error("Internal EJS error: no file name or template provided");
|
|
1567
|
+
template = fileLoader(filename).toString().replace(_BOM, "");
|
|
1568
|
+
}
|
|
1569
|
+
func = exports.compile(template, options);
|
|
1570
|
+
if (options.cache) exports.cache.set(filename, func);
|
|
1571
|
+
return func;
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Try calling handleCache with the given options and data and call the
|
|
1575
|
+
* callback with the result. If an error occurs, call the callback with
|
|
1576
|
+
* the error. Used by renderFile().
|
|
1577
|
+
*
|
|
1578
|
+
* @memberof module:ejs-internal
|
|
1579
|
+
* @param {Options} options compilation options
|
|
1580
|
+
* @param {Object} data template data
|
|
1581
|
+
* @param {RenderFileCallback} cb callback
|
|
1582
|
+
* @static
|
|
1583
|
+
*/
|
|
1584
|
+
function tryHandleCache(options, data, cb) {
|
|
1585
|
+
var result;
|
|
1586
|
+
if (!cb) if (typeof exports.promiseImpl == "function") return new exports.promiseImpl(function(resolve, reject) {
|
|
1587
|
+
try {
|
|
1588
|
+
result = handleCache(options)(data);
|
|
1589
|
+
resolve(result);
|
|
1590
|
+
} catch (err) {
|
|
1591
|
+
reject(err);
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
else throw new Error("Please provide a callback function");
|
|
1595
|
+
else {
|
|
1596
|
+
try {
|
|
1597
|
+
result = handleCache(options)(data);
|
|
1598
|
+
} catch (err) {
|
|
1599
|
+
return cb(err);
|
|
1600
|
+
}
|
|
1601
|
+
cb(null, result);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* fileLoader is independent
|
|
1606
|
+
*
|
|
1607
|
+
* @param {String} filePath ejs file path.
|
|
1608
|
+
* @return {String} The contents of the specified file.
|
|
1609
|
+
* @static
|
|
1610
|
+
*/
|
|
1611
|
+
function fileLoader(filePath) {
|
|
1612
|
+
return exports.fileLoader(filePath);
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Get the template function.
|
|
1616
|
+
*
|
|
1617
|
+
* If `options.cache` is `true`, then the template is cached.
|
|
1618
|
+
*
|
|
1619
|
+
* @memberof module:ejs-internal
|
|
1620
|
+
* @param {String} path path for the specified file
|
|
1621
|
+
* @param {Options} options compilation options
|
|
1622
|
+
* @return {(TemplateFunction|ClientFunction)}
|
|
1623
|
+
* Depending on the value of `options.client`, either type might be returned
|
|
1624
|
+
* @static
|
|
1625
|
+
*/
|
|
1626
|
+
function includeFile(path, options) {
|
|
1627
|
+
var opts = utils.shallowCopy(utils.createNullProtoObjWherePossible(), options);
|
|
1628
|
+
opts.filename = getIncludePath(path, opts);
|
|
1629
|
+
if (typeof options.includer === "function") {
|
|
1630
|
+
var includerResult = options.includer(path, opts.filename);
|
|
1631
|
+
if (includerResult) {
|
|
1632
|
+
if (includerResult.filename) opts.filename = includerResult.filename;
|
|
1633
|
+
if (includerResult.template) return handleCache(opts, includerResult.template);
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
return handleCache(opts);
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Re-throw the given `err` in context to the `str` of ejs, `filename`, and
|
|
1640
|
+
* `lineno`.
|
|
1641
|
+
*
|
|
1642
|
+
* @implements {RethrowCallback}
|
|
1643
|
+
* @memberof module:ejs-internal
|
|
1644
|
+
* @param {Error} err Error object
|
|
1645
|
+
* @param {String} str EJS source
|
|
1646
|
+
* @param {String} flnm file name of the EJS file
|
|
1647
|
+
* @param {Number} lineno line number of the error
|
|
1648
|
+
* @param {EscapeCallback} esc
|
|
1649
|
+
* @static
|
|
1650
|
+
*/
|
|
1651
|
+
function rethrow(err, str, flnm, lineno, esc) {
|
|
1652
|
+
var lines = str.split("\n");
|
|
1653
|
+
var start = Math.max(lineno - 3, 0);
|
|
1654
|
+
var end = Math.min(lines.length, lineno + 3);
|
|
1655
|
+
var filename = esc(flnm);
|
|
1656
|
+
var context = lines.slice(start, end).map(function(line, i) {
|
|
1657
|
+
var curr = i + start + 1;
|
|
1658
|
+
return (curr == lineno ? " >> " : " ") + curr + "| " + line;
|
|
1659
|
+
}).join("\n");
|
|
1660
|
+
err.path = filename;
|
|
1661
|
+
err.message = (filename || "ejs") + ":" + lineno + "\n" + context + "\n\n" + err.message;
|
|
1662
|
+
throw err;
|
|
1663
|
+
}
|
|
1664
|
+
function stripSemi(str) {
|
|
1665
|
+
return str.replace(/;(\s*$)/, "$1");
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Compile the given `str` of ejs into a template function.
|
|
1669
|
+
*
|
|
1670
|
+
* @param {String} template EJS template
|
|
1671
|
+
*
|
|
1672
|
+
* @param {Options} [opts] compilation options
|
|
1673
|
+
*
|
|
1674
|
+
* @return {(TemplateFunction|ClientFunction)}
|
|
1675
|
+
* Depending on the value of `opts.client`, either type might be returned.
|
|
1676
|
+
* Note that the return type of the function also depends on the value of `opts.async`.
|
|
1677
|
+
* @public
|
|
1678
|
+
*/
|
|
1679
|
+
exports.compile = function compile(template, opts) {
|
|
1680
|
+
var templ;
|
|
1681
|
+
if (opts && opts.scope) {
|
|
1682
|
+
if (!scopeOptionWarned) {
|
|
1683
|
+
console.warn("`scope` option is deprecated and will be removed in EJS 3");
|
|
1684
|
+
scopeOptionWarned = true;
|
|
1685
|
+
}
|
|
1686
|
+
if (!opts.context) opts.context = opts.scope;
|
|
1687
|
+
delete opts.scope;
|
|
1688
|
+
}
|
|
1689
|
+
templ = new Template(template, opts);
|
|
1690
|
+
return templ.compile();
|
|
1691
|
+
};
|
|
1692
|
+
/**
|
|
1693
|
+
* Render the given `template` of ejs.
|
|
1694
|
+
*
|
|
1695
|
+
* If you would like to include options but not data, you need to explicitly
|
|
1696
|
+
* call this function with `data` being an empty object or `null`.
|
|
1697
|
+
*
|
|
1698
|
+
* @param {String} template EJS template
|
|
1699
|
+
* @param {Object} [data={}] template data
|
|
1700
|
+
* @param {Options} [opts={}] compilation and rendering options
|
|
1701
|
+
* @return {(String|Promise<String>)}
|
|
1702
|
+
* Return value type depends on `opts.async`.
|
|
1703
|
+
* @public
|
|
1704
|
+
*/
|
|
1705
|
+
exports.render = function(template, d, o) {
|
|
1706
|
+
var data = d || utils.createNullProtoObjWherePossible();
|
|
1707
|
+
var opts = o || utils.createNullProtoObjWherePossible();
|
|
1708
|
+
if (arguments.length == 2) utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
|
|
1709
|
+
return handleCache(opts, template)(data);
|
|
1710
|
+
};
|
|
1711
|
+
/**
|
|
1712
|
+
* Render an EJS file at the given `path` and callback `cb(err, str)`.
|
|
1713
|
+
*
|
|
1714
|
+
* If you would like to include options but not data, you need to explicitly
|
|
1715
|
+
* call this function with `data` being an empty object or `null`.
|
|
1716
|
+
*
|
|
1717
|
+
* @param {String} path path to the EJS file
|
|
1718
|
+
* @param {Object} [data={}] template data
|
|
1719
|
+
* @param {Options} [opts={}] compilation and rendering options
|
|
1720
|
+
* @param {RenderFileCallback} cb callback
|
|
1721
|
+
* @public
|
|
1722
|
+
*/
|
|
1723
|
+
exports.renderFile = function() {
|
|
1724
|
+
var args = Array.prototype.slice.call(arguments);
|
|
1725
|
+
var filename = args.shift();
|
|
1726
|
+
var cb;
|
|
1727
|
+
var opts = { filename };
|
|
1728
|
+
var data;
|
|
1729
|
+
var viewOpts;
|
|
1730
|
+
if (typeof arguments[arguments.length - 1] == "function") cb = args.pop();
|
|
1731
|
+
if (args.length) {
|
|
1732
|
+
data = args.shift();
|
|
1733
|
+
if (args.length) utils.shallowCopy(opts, args.pop());
|
|
1734
|
+
else {
|
|
1735
|
+
if (data.settings) {
|
|
1736
|
+
if (data.settings.views) opts.views = data.settings.views;
|
|
1737
|
+
if (data.settings["view cache"]) opts.cache = true;
|
|
1738
|
+
viewOpts = data.settings["view options"];
|
|
1739
|
+
if (viewOpts) utils.shallowCopy(opts, viewOpts);
|
|
1740
|
+
}
|
|
1741
|
+
utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
|
|
1742
|
+
}
|
|
1743
|
+
opts.filename = filename;
|
|
1744
|
+
} else data = utils.createNullProtoObjWherePossible();
|
|
1745
|
+
return tryHandleCache(opts, data, cb);
|
|
1746
|
+
};
|
|
1747
|
+
/**
|
|
1748
|
+
* Clear intermediate JavaScript cache. Calls {@link Cache#reset}.
|
|
1749
|
+
* @public
|
|
1750
|
+
*/
|
|
1751
|
+
/**
|
|
1752
|
+
* EJS template class
|
|
1753
|
+
* @public
|
|
1754
|
+
*/
|
|
1755
|
+
exports.Template = Template;
|
|
1756
|
+
exports.clearCache = function() {
|
|
1757
|
+
exports.cache.reset();
|
|
1758
|
+
};
|
|
1759
|
+
function Template(text, optsParam) {
|
|
1760
|
+
var opts = utils.hasOwnOnlyObject(optsParam);
|
|
1761
|
+
var options = utils.createNullProtoObjWherePossible();
|
|
1762
|
+
this.templateText = text;
|
|
1763
|
+
/** @type {string | null} */
|
|
1764
|
+
this.mode = null;
|
|
1765
|
+
this.truncate = false;
|
|
1766
|
+
this.currentLine = 1;
|
|
1767
|
+
this.source = "";
|
|
1768
|
+
options.client = opts.client || false;
|
|
1769
|
+
options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
|
|
1770
|
+
options.compileDebug = opts.compileDebug !== false;
|
|
1771
|
+
options.debug = !!opts.debug;
|
|
1772
|
+
options.filename = opts.filename;
|
|
1773
|
+
options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
|
|
1774
|
+
options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
|
|
1775
|
+
options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
|
|
1776
|
+
options.strict = opts.strict || false;
|
|
1777
|
+
options.context = opts.context;
|
|
1778
|
+
options.cache = opts.cache || false;
|
|
1779
|
+
options.rmWhitespace = opts.rmWhitespace;
|
|
1780
|
+
options.root = opts.root;
|
|
1781
|
+
options.includer = opts.includer;
|
|
1782
|
+
options.outputFunctionName = opts.outputFunctionName;
|
|
1783
|
+
options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
|
|
1784
|
+
options.views = opts.views;
|
|
1785
|
+
options.async = opts.async;
|
|
1786
|
+
options.destructuredLocals = opts.destructuredLocals;
|
|
1787
|
+
options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
|
|
1788
|
+
if (options.strict) options._with = false;
|
|
1789
|
+
else options._with = typeof opts._with != "undefined" ? opts._with : true;
|
|
1790
|
+
this.opts = options;
|
|
1791
|
+
this.regex = this.createRegex();
|
|
1792
|
+
}
|
|
1793
|
+
Template.modes = {
|
|
1794
|
+
EVAL: "eval",
|
|
1795
|
+
ESCAPED: "escaped",
|
|
1796
|
+
RAW: "raw",
|
|
1797
|
+
COMMENT: "comment",
|
|
1798
|
+
LITERAL: "literal"
|
|
1799
|
+
};
|
|
1800
|
+
Template.prototype = {
|
|
1801
|
+
createRegex: function() {
|
|
1802
|
+
var str = _REGEX_STRING;
|
|
1803
|
+
var delim = utils.escapeRegExpChars(this.opts.delimiter);
|
|
1804
|
+
var open = utils.escapeRegExpChars(this.opts.openDelimiter);
|
|
1805
|
+
var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
|
|
1806
|
+
str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
|
|
1807
|
+
return new RegExp(str);
|
|
1808
|
+
},
|
|
1809
|
+
compile: function() {
|
|
1810
|
+
/** @type {string} */
|
|
1811
|
+
var src;
|
|
1812
|
+
/** @type {ClientFunction} */
|
|
1813
|
+
var fn;
|
|
1814
|
+
var opts = this.opts;
|
|
1815
|
+
var prepended = "";
|
|
1816
|
+
var appended = "";
|
|
1817
|
+
/** @type {EscapeCallback} */
|
|
1818
|
+
var escapeFn = opts.escapeFunction;
|
|
1819
|
+
/** @type {FunctionConstructor} */
|
|
1820
|
+
var ctor;
|
|
1821
|
+
/** @type {string} */
|
|
1822
|
+
var sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
|
|
1823
|
+
if (!this.source) {
|
|
1824
|
+
this.generateSource();
|
|
1825
|
+
prepended += " var __output = \"\";\n function __append(s) { if (s !== undefined && s !== null) __output += s }\n";
|
|
1826
|
+
if (opts.outputFunctionName) {
|
|
1827
|
+
if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) throw new Error("outputFunctionName is not a valid JS identifier.");
|
|
1828
|
+
prepended += " var " + opts.outputFunctionName + " = __append;\n";
|
|
1829
|
+
}
|
|
1830
|
+
if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) throw new Error("localsName is not a valid JS identifier.");
|
|
1831
|
+
if (opts.destructuredLocals && opts.destructuredLocals.length) {
|
|
1832
|
+
var destructuring = " var __locals = (" + opts.localsName + " || {}),\n";
|
|
1833
|
+
for (var i = 0; i < opts.destructuredLocals.length; i++) {
|
|
1834
|
+
var name = opts.destructuredLocals[i];
|
|
1835
|
+
if (!_JS_IDENTIFIER.test(name)) throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
|
|
1836
|
+
if (i > 0) destructuring += ",\n ";
|
|
1837
|
+
destructuring += name + " = __locals." + name;
|
|
1838
|
+
}
|
|
1839
|
+
prepended += destructuring + ";\n";
|
|
1840
|
+
}
|
|
1841
|
+
if (opts._with !== false) {
|
|
1842
|
+
prepended += " with (" + opts.localsName + " || {}) {\n";
|
|
1843
|
+
appended += " }\n";
|
|
1844
|
+
}
|
|
1845
|
+
appended += " return __output;\n";
|
|
1846
|
+
this.source = prepended + this.source + appended;
|
|
1847
|
+
}
|
|
1848
|
+
if (opts.compileDebug) src = "var __line = 1\n , __lines = " + JSON.stringify(this.templateText) + "\n , __filename = " + sanitizedFilename + ";\ntry {\n" + this.source + "} catch (e) {\n rethrow(e, __lines, __filename, __line, escapeFn);\n}\n";
|
|
1849
|
+
else src = this.source;
|
|
1850
|
+
if (opts.client) {
|
|
1851
|
+
src = "escapeFn = escapeFn || " + escapeFn.toString() + ";\n" + src;
|
|
1852
|
+
if (opts.compileDebug) src = "rethrow = rethrow || " + rethrow.toString() + ";\n" + src;
|
|
1853
|
+
}
|
|
1854
|
+
if (opts.strict) src = "\"use strict\";\n" + src;
|
|
1855
|
+
if (opts.debug) console.log(src);
|
|
1856
|
+
if (opts.compileDebug && opts.filename) src = src + "\n//# sourceURL=" + sanitizedFilename + "\n";
|
|
1857
|
+
try {
|
|
1858
|
+
if (opts.async) try {
|
|
1859
|
+
ctor = new Function("return (async function(){}).constructor;")();
|
|
1860
|
+
} catch (e) {
|
|
1861
|
+
if (e instanceof SyntaxError) throw new Error("This environment does not support async/await");
|
|
1862
|
+
else throw e;
|
|
1863
|
+
}
|
|
1864
|
+
else ctor = Function;
|
|
1865
|
+
fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
|
|
1866
|
+
} catch (e) {
|
|
1867
|
+
// istanbul ignore else
|
|
1868
|
+
if (e instanceof SyntaxError) {
|
|
1869
|
+
if (opts.filename) e.message += " in " + opts.filename;
|
|
1870
|
+
e.message += " while compiling ejs\n\n";
|
|
1871
|
+
e.message += "If the above error is not helpful, you may want to try EJS-Lint:\n";
|
|
1872
|
+
e.message += "https://github.com/RyanZim/EJS-Lint";
|
|
1873
|
+
if (!opts.async) {
|
|
1874
|
+
e.message += "\n";
|
|
1875
|
+
e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
throw e;
|
|
1879
|
+
}
|
|
1880
|
+
var returnedFn = opts.client ? fn : function anonymous(data) {
|
|
1881
|
+
var include = function(path, includeData) {
|
|
1882
|
+
var d = utils.shallowCopy(utils.createNullProtoObjWherePossible(), data);
|
|
1883
|
+
if (includeData) d = utils.shallowCopy(d, includeData);
|
|
1884
|
+
return includeFile(path, opts)(d);
|
|
1885
|
+
};
|
|
1886
|
+
return fn.apply(opts.context, [
|
|
1887
|
+
data || utils.createNullProtoObjWherePossible(),
|
|
1888
|
+
escapeFn,
|
|
1889
|
+
include,
|
|
1890
|
+
rethrow
|
|
1891
|
+
]);
|
|
1892
|
+
};
|
|
1893
|
+
if (opts.filename && typeof Object.defineProperty === "function") {
|
|
1894
|
+
var filename = opts.filename;
|
|
1895
|
+
var basename = path$2.basename(filename, path$2.extname(filename));
|
|
1896
|
+
try {
|
|
1897
|
+
Object.defineProperty(returnedFn, "name", {
|
|
1898
|
+
value: basename,
|
|
1899
|
+
writable: false,
|
|
1900
|
+
enumerable: false,
|
|
1901
|
+
configurable: true
|
|
1902
|
+
});
|
|
1903
|
+
} catch (e) {}
|
|
1904
|
+
}
|
|
1905
|
+
return returnedFn;
|
|
1906
|
+
},
|
|
1907
|
+
generateSource: function() {
|
|
1908
|
+
if (this.opts.rmWhitespace) this.templateText = this.templateText.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
|
|
1909
|
+
this.templateText = this.templateText.replace(/[ \t]*<%_/gm, "<%_").replace(/_%>[ \t]*/gm, "_%>");
|
|
1910
|
+
var self = this;
|
|
1911
|
+
var matches = this.parseTemplateText();
|
|
1912
|
+
var d = this.opts.delimiter;
|
|
1913
|
+
var o = this.opts.openDelimiter;
|
|
1914
|
+
var c = this.opts.closeDelimiter;
|
|
1915
|
+
if (matches && matches.length) matches.forEach(function(line, index) {
|
|
1916
|
+
var closing;
|
|
1917
|
+
if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
|
|
1918
|
+
closing = matches[index + 2];
|
|
1919
|
+
if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) throw new Error("Could not find matching close tag for \"" + line + "\".");
|
|
1920
|
+
}
|
|
1921
|
+
self.scanLine(line);
|
|
1922
|
+
});
|
|
1923
|
+
},
|
|
1924
|
+
parseTemplateText: function() {
|
|
1925
|
+
var str = this.templateText;
|
|
1926
|
+
var pat = this.regex;
|
|
1927
|
+
var result = pat.exec(str);
|
|
1928
|
+
var arr = [];
|
|
1929
|
+
var firstPos;
|
|
1930
|
+
while (result) {
|
|
1931
|
+
firstPos = result.index;
|
|
1932
|
+
if (firstPos !== 0) {
|
|
1933
|
+
arr.push(str.substring(0, firstPos));
|
|
1934
|
+
str = str.slice(firstPos);
|
|
1935
|
+
}
|
|
1936
|
+
arr.push(result[0]);
|
|
1937
|
+
str = str.slice(result[0].length);
|
|
1938
|
+
result = pat.exec(str);
|
|
1939
|
+
}
|
|
1940
|
+
if (str) arr.push(str);
|
|
1941
|
+
return arr;
|
|
1942
|
+
},
|
|
1943
|
+
_addOutput: function(line) {
|
|
1944
|
+
if (this.truncate) {
|
|
1945
|
+
line = line.replace(/^(?:\r\n|\r|\n)/, "");
|
|
1946
|
+
this.truncate = false;
|
|
1947
|
+
}
|
|
1948
|
+
if (!line) return line;
|
|
1949
|
+
line = line.replace(/\\/g, "\\\\");
|
|
1950
|
+
line = line.replace(/\n/g, "\\n");
|
|
1951
|
+
line = line.replace(/\r/g, "\\r");
|
|
1952
|
+
line = line.replace(/"/g, "\\\"");
|
|
1953
|
+
this.source += " ; __append(\"" + line + "\")\n";
|
|
1954
|
+
},
|
|
1955
|
+
scanLine: function(line) {
|
|
1956
|
+
var self = this;
|
|
1957
|
+
var d = this.opts.delimiter;
|
|
1958
|
+
var o = this.opts.openDelimiter;
|
|
1959
|
+
var c = this.opts.closeDelimiter;
|
|
1960
|
+
var newLineCount = 0;
|
|
1961
|
+
newLineCount = line.split("\n").length - 1;
|
|
1962
|
+
switch (line) {
|
|
1963
|
+
case o + d:
|
|
1964
|
+
case o + d + "_":
|
|
1965
|
+
this.mode = Template.modes.EVAL;
|
|
1966
|
+
break;
|
|
1967
|
+
case o + d + "=":
|
|
1968
|
+
this.mode = Template.modes.ESCAPED;
|
|
1969
|
+
break;
|
|
1970
|
+
case o + d + "-":
|
|
1971
|
+
this.mode = Template.modes.RAW;
|
|
1972
|
+
break;
|
|
1973
|
+
case o + d + "#":
|
|
1974
|
+
this.mode = Template.modes.COMMENT;
|
|
1975
|
+
break;
|
|
1976
|
+
case o + d + d:
|
|
1977
|
+
this.mode = Template.modes.LITERAL;
|
|
1978
|
+
this.source += " ; __append(\"" + line.replace(o + d + d, o + d) + "\")\n";
|
|
1979
|
+
break;
|
|
1980
|
+
case d + d + c:
|
|
1981
|
+
this.mode = Template.modes.LITERAL;
|
|
1982
|
+
this.source += " ; __append(\"" + line.replace(d + d + c, d + c) + "\")\n";
|
|
1983
|
+
break;
|
|
1984
|
+
case d + c:
|
|
1985
|
+
case "-" + d + c:
|
|
1986
|
+
case "_" + d + c:
|
|
1987
|
+
if (this.mode == Template.modes.LITERAL) this._addOutput(line);
|
|
1988
|
+
this.mode = null;
|
|
1989
|
+
this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
|
|
1990
|
+
break;
|
|
1991
|
+
default: if (this.mode) {
|
|
1992
|
+
switch (this.mode) {
|
|
1993
|
+
case Template.modes.EVAL:
|
|
1994
|
+
case Template.modes.ESCAPED:
|
|
1995
|
+
case Template.modes.RAW: if (line.lastIndexOf("//") > line.lastIndexOf("\n")) line += "\n";
|
|
1996
|
+
}
|
|
1997
|
+
switch (this.mode) {
|
|
1998
|
+
case Template.modes.EVAL:
|
|
1999
|
+
this.source += " ; " + line + "\n";
|
|
2000
|
+
break;
|
|
2001
|
+
case Template.modes.ESCAPED:
|
|
2002
|
+
this.source += " ; __append(escapeFn(" + stripSemi(line) + "))\n";
|
|
2003
|
+
break;
|
|
2004
|
+
case Template.modes.RAW:
|
|
2005
|
+
this.source += " ; __append(" + stripSemi(line) + ")\n";
|
|
2006
|
+
break;
|
|
2007
|
+
case Template.modes.COMMENT: break;
|
|
2008
|
+
case Template.modes.LITERAL:
|
|
2009
|
+
this._addOutput(line);
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
} else this._addOutput(line);
|
|
2013
|
+
}
|
|
2014
|
+
if (self.opts.compileDebug && newLineCount) {
|
|
2015
|
+
this.currentLine += newLineCount;
|
|
2016
|
+
this.source += " ; __line = " + this.currentLine + "\n";
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
/**
|
|
2021
|
+
* Escape characters reserved in XML.
|
|
2022
|
+
*
|
|
2023
|
+
* This is simply an export of {@link module:utils.escapeXML}.
|
|
2024
|
+
*
|
|
2025
|
+
* If `markup` is `undefined` or `null`, the empty string is returned.
|
|
2026
|
+
*
|
|
2027
|
+
* @param {String} markup Input string
|
|
2028
|
+
* @return {String} Escaped string
|
|
2029
|
+
* @public
|
|
2030
|
+
* @func
|
|
2031
|
+
* */
|
|
2032
|
+
exports.escapeXML = utils.escapeXML;
|
|
2033
|
+
/**
|
|
2034
|
+
* Express.js support.
|
|
2035
|
+
*
|
|
2036
|
+
* This is an alias for {@link module:ejs.renderFile}, in order to support
|
|
2037
|
+
* Express.js out-of-the-box.
|
|
2038
|
+
*
|
|
2039
|
+
* @func
|
|
2040
|
+
*/
|
|
2041
|
+
exports.__express = exports.renderFile;
|
|
2042
|
+
/**
|
|
2043
|
+
* Version of EJS.
|
|
2044
|
+
*
|
|
2045
|
+
* @readonly
|
|
2046
|
+
* @type {String}
|
|
2047
|
+
* @public
|
|
2048
|
+
*/
|
|
2049
|
+
exports.VERSION = _VERSION_STRING;
|
|
2050
|
+
/**
|
|
2051
|
+
* Name for detection of EJS.
|
|
2052
|
+
*
|
|
2053
|
+
* @readonly
|
|
2054
|
+
* @type {String}
|
|
2055
|
+
* @public
|
|
2056
|
+
*/
|
|
2057
|
+
exports.name = _NAME;
|
|
2058
|
+
/* istanbul ignore if */
|
|
2059
|
+
if (typeof window != "undefined") window.ejs = exports;
|
|
2060
|
+
}));
|
|
2061
|
+
//#endregion
|
|
2062
|
+
//#region utils/banners.ts
|
|
2063
|
+
var import_picocolors = require_picocolors();
|
|
2064
|
+
var import_ejs = /* @__PURE__ */ __toESM(require_ejs(), 1);
|
|
2065
|
+
const defaultBanner = "Rue.js - The Progressive JavaScript Framework";
|
|
2066
|
+
const gradientBanner = "\x1B[38;2;66;211;146mV\x1B[39m\x1B[38;2;66;211;146mu\x1B[39m\x1B[38;2;66;211;146me\x1B[39m\x1B[38;2;66;211;146m.\x1B[39m\x1B[38;2;66;211;146mj\x1B[39m\x1B[38;2;67;209;149ms\x1B[39m \x1B[38;2;68;206;152m-\x1B[39m \x1B[38;2;69;204;155mT\x1B[39m\x1B[38;2;70;201;158mh\x1B[39m\x1B[38;2;71;199;162me\x1B[39m \x1B[38;2;72;196;165mP\x1B[39m\x1B[38;2;73;194;168mr\x1B[39m\x1B[38;2;74;192;171mo\x1B[39m\x1B[38;2;75;189;174mg\x1B[39m\x1B[38;2;76;187;177mr\x1B[39m\x1B[38;2;77;184;180me\x1B[39m\x1B[38;2;78;182;183ms\x1B[39m\x1B[38;2;79;179;186ms\x1B[39m\x1B[38;2;80;177;190mi\x1B[39m\x1B[38;2;81;175;193mv\x1B[39m\x1B[38;2;82;172;196me\x1B[39m \x1B[38;2;83;170;199mJ\x1B[39m\x1B[38;2;83;167;202ma\x1B[39m\x1B[38;2;84;165;205mv\x1B[39m\x1B[38;2;85;162;208ma\x1B[39m\x1B[38;2;86;160;211mS\x1B[39m\x1B[38;2;87;158;215mc\x1B[39m\x1B[38;2;88;155;218mr\x1B[39m\x1B[38;2;89;153;221mi\x1B[39m\x1B[38;2;90;150;224mp\x1B[39m\x1B[38;2;91;148;227mt\x1B[39m \x1B[38;2;92;145;230mF\x1B[39m\x1B[38;2;93;143;233mr\x1B[39m\x1B[38;2;94;141;236ma\x1B[39m\x1B[38;2;95;138;239mm\x1B[39m\x1B[38;2;96;136;243me\x1B[39m\x1B[38;2;97;133;246mw\x1B[39m\x1B[38;2;98;131;249mo\x1B[39m\x1B[38;2;99;128;252mr\x1B[39m\x1B[38;2;100;126;255mk\x1B[39m";
|
|
2067
|
+
//#endregion
|
|
2068
|
+
//#region utils/deepMerge.ts
|
|
2069
|
+
const isObject = (val) => val && typeof val === "object";
|
|
2070
|
+
const mergeArrayWithDedupe = (a, b) => Array.from(new Set([...a, ...b]));
|
|
2071
|
+
/**
|
|
2072
|
+
* Recursively merge the content of the new object to the existing one
|
|
2073
|
+
* @param {Object} target the existing object
|
|
2074
|
+
* @param {Object} obj the new object
|
|
2075
|
+
*/
|
|
2076
|
+
function deepMerge(target, obj) {
|
|
2077
|
+
for (const key of Object.keys(obj)) {
|
|
2078
|
+
const oldVal = target[key];
|
|
2079
|
+
const newVal = obj[key];
|
|
2080
|
+
if (Array.isArray(oldVal) && Array.isArray(newVal)) target[key] = mergeArrayWithDedupe(oldVal, newVal);
|
|
2081
|
+
else if (isObject(oldVal) && isObject(newVal)) target[key] = deepMerge(oldVal, newVal);
|
|
2082
|
+
else target[key] = newVal;
|
|
2083
|
+
}
|
|
2084
|
+
return target;
|
|
2085
|
+
}
|
|
2086
|
+
//#endregion
|
|
2087
|
+
//#region utils/sortDependencies.ts
|
|
2088
|
+
function sortDependencies(packageJson) {
|
|
2089
|
+
const sorted = {};
|
|
2090
|
+
for (const depType of [
|
|
2091
|
+
"dependencies",
|
|
2092
|
+
"devDependencies",
|
|
2093
|
+
"peerDependencies",
|
|
2094
|
+
"optionalDependencies"
|
|
2095
|
+
]) if (packageJson[depType]) {
|
|
2096
|
+
sorted[depType] = {};
|
|
2097
|
+
Object.keys(packageJson[depType]).sort().forEach((name) => {
|
|
2098
|
+
sorted[depType][name] = packageJson[depType][name];
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
return {
|
|
2102
|
+
...packageJson,
|
|
2103
|
+
...sorted
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
//#endregion
|
|
2107
|
+
//#region utils/renderTemplate.ts
|
|
2108
|
+
/**
|
|
2109
|
+
* Renders a template folder/file to the file system,
|
|
2110
|
+
* by recursively copying all files under the `src` directory,
|
|
2111
|
+
* with the following exception:
|
|
2112
|
+
* - `_filename` should be renamed to `.filename`
|
|
2113
|
+
* - Fields in `package.json` should be recursively merged
|
|
2114
|
+
* @param {string} src source filename to copy
|
|
2115
|
+
* @param {string} dest destination filename of the copy operation
|
|
2116
|
+
*/
|
|
2117
|
+
function renderTemplate(src, dest, callbacks) {
|
|
2118
|
+
if (fs.statSync(src).isDirectory()) {
|
|
2119
|
+
if (path$1.basename(src) === "node_modules") return;
|
|
2120
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
2121
|
+
for (const file of fs.readdirSync(src)) renderTemplate(path$1.resolve(src, file), path$1.resolve(dest, file), callbacks);
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
const filename = path$1.basename(src);
|
|
2125
|
+
if (filename === "package.json" && fs.existsSync(dest)) {
|
|
2126
|
+
const pkg = sortDependencies(deepMerge(JSON.parse(fs.readFileSync(dest, "utf8")), JSON.parse(fs.readFileSync(src, "utf8"))));
|
|
2127
|
+
fs.writeFileSync(dest, JSON.stringify(pkg, null, 2) + "\n");
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2130
|
+
if (filename === "extensions.json" && fs.existsSync(dest)) {
|
|
2131
|
+
const extensions = deepMerge(JSON.parse(fs.readFileSync(dest, "utf8")), JSON.parse(fs.readFileSync(src, "utf8")));
|
|
2132
|
+
fs.writeFileSync(dest, JSON.stringify(extensions, null, 2) + "\n");
|
|
2133
|
+
return;
|
|
2134
|
+
}
|
|
2135
|
+
if (filename === "settings.json" && fs.existsSync(dest)) {
|
|
2136
|
+
const settings = deepMerge(JSON.parse(fs.readFileSync(dest, "utf8")), JSON.parse(fs.readFileSync(src, "utf8")));
|
|
2137
|
+
fs.writeFileSync(dest, JSON.stringify(settings, null, 2) + "\n");
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
if (filename.startsWith("_")) dest = path$1.resolve(path$1.dirname(dest), filename.replace(/^_/, "."));
|
|
2141
|
+
if (filename === "_gitignore" && fs.existsSync(dest)) {
|
|
2142
|
+
const existing = fs.readFileSync(dest, "utf8");
|
|
2143
|
+
const newGitignore = fs.readFileSync(src, "utf8");
|
|
2144
|
+
fs.writeFileSync(dest, existing + "\n" + newGitignore);
|
|
2145
|
+
return;
|
|
2146
|
+
}
|
|
2147
|
+
if (filename.endsWith(".data.mjs")) {
|
|
2148
|
+
dest = dest.replace(/\.data\.mjs$/, "");
|
|
2149
|
+
callbacks.push(async (dataStore) => {
|
|
2150
|
+
const getData = (await import(pathToFileURL(src).toString())).default;
|
|
2151
|
+
dataStore[dest] = await getData({ oldData: dataStore[dest] || {} });
|
|
2152
|
+
});
|
|
2153
|
+
return;
|
|
2154
|
+
}
|
|
2155
|
+
fs.copyFileSync(src, dest);
|
|
2156
|
+
}
|
|
2157
|
+
//#endregion
|
|
2158
|
+
//#region utils/directoryTraverse.ts
|
|
2159
|
+
function preOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
|
|
2160
|
+
for (const filename of fs.readdirSync(dir)) {
|
|
2161
|
+
if (filename === ".git") continue;
|
|
2162
|
+
const fullpath = path$1.resolve(dir, filename);
|
|
2163
|
+
if (fs.lstatSync(fullpath).isDirectory()) {
|
|
2164
|
+
dirCallback(fullpath);
|
|
2165
|
+
if (fs.existsSync(fullpath)) preOrderDirectoryTraverse(fullpath, dirCallback, fileCallback);
|
|
2166
|
+
continue;
|
|
2167
|
+
}
|
|
2168
|
+
fileCallback(fullpath);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
const dotGitDirectoryState = { hasDotGitDirectory: false };
|
|
2172
|
+
function postOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
|
|
2173
|
+
for (const filename of fs.readdirSync(dir)) {
|
|
2174
|
+
if (filename === ".git") {
|
|
2175
|
+
dotGitDirectoryState.hasDotGitDirectory = true;
|
|
2176
|
+
continue;
|
|
2177
|
+
}
|
|
2178
|
+
const fullpath = path$1.resolve(dir, filename);
|
|
2179
|
+
if (fs.lstatSync(fullpath).isDirectory()) {
|
|
2180
|
+
postOrderDirectoryTraverse(fullpath, dirCallback, fileCallback);
|
|
2181
|
+
dirCallback(fullpath);
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
fileCallback(fullpath);
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
//#endregion
|
|
2188
|
+
//#region utils/getCommand.ts
|
|
2189
|
+
function getCommand(packageManager, scriptName, args) {
|
|
2190
|
+
if (scriptName === "install") return packageManager === "yarn" ? "yarn" : `${packageManager} install`;
|
|
2191
|
+
if (scriptName === "build") return packageManager === "npm" || packageManager === "bun" ? `${packageManager} run build` : `${packageManager} build`;
|
|
2192
|
+
if (args) return packageManager === "npm" ? `npm run ${scriptName} -- ${args}` : `${packageManager} ${scriptName} ${args}`;
|
|
2193
|
+
else return packageManager === "npm" ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`;
|
|
2194
|
+
}
|
|
2195
|
+
//#endregion
|
|
2196
|
+
//#region utils/generateReadme.ts
|
|
2197
|
+
const sfcTypeSupportDoc = [
|
|
2198
|
+
"",
|
|
2199
|
+
"## Type Support for `.rue` Imports in TS",
|
|
2200
|
+
"",
|
|
2201
|
+
"TypeScript cannot handle type information for `.rue` imports by default, so we replace the `tsc` CLI with `rue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Rue.volar) to make the TypeScript language service aware of `.rue` types.",
|
|
2202
|
+
""
|
|
2203
|
+
].join("\n");
|
|
2204
|
+
function generateReadme({ projectName, packageManager, needsTypeScript, needsCypress, needsCypressCT, needsPlaywright, needsVitest, needsEslint }) {
|
|
2205
|
+
const commandFor = (scriptName, args) => getCommand(packageManager, scriptName, args);
|
|
2206
|
+
let readme = `# ${projectName}
|
|
2207
|
+
|
|
2208
|
+
This template should help get you started developing with Rue 3 in Vite.
|
|
2209
|
+
|
|
2210
|
+
## Recommended IDE Setup
|
|
2211
|
+
|
|
2212
|
+
[VS Code](https://code.visualstudio.com/) + [Rue (Official)](https://marketplace.visualstudio.com/items?itemName=Rue.volar) (and disable Vetur).
|
|
2213
|
+
|
|
2214
|
+
## Recommended Browser Setup
|
|
2215
|
+
|
|
2216
|
+
- Chromium-based browsers (Chrome, Edge, Brave, etc.):
|
|
2217
|
+
- [Rue.js devtools](https://chromewebstore.google.com/detail/ruejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)
|
|
2218
|
+
- [Turn on Custom Object Formatter in Chrome DevTools](http://bit.ly/object-formatters)
|
|
2219
|
+
- Firefox:
|
|
2220
|
+
- [Rue.js devtools](https://addons.mozilla.org/en-US/firefox/addon/rue-js-devtools/)
|
|
2221
|
+
- [Turn on Custom Object Formatter in Firefox DevTools](https://fxdx.dev/firefox-devtools-custom-object-formatters/)
|
|
2222
|
+
${needsTypeScript ? sfcTypeSupportDoc : ""}
|
|
2223
|
+
## Customize configuration
|
|
2224
|
+
|
|
2225
|
+
See [Vite Configuration Reference](https://vite.dev/config/).
|
|
2226
|
+
|
|
2227
|
+
## Project Setup
|
|
2228
|
+
|
|
2229
|
+
`;
|
|
2230
|
+
let npmScriptsDescriptions = `\`\`\`sh
|
|
2231
|
+
${commandFor("install")}
|
|
2232
|
+
\`\`\`
|
|
2233
|
+
|
|
2234
|
+
### Compile and Hot-Reload for Development
|
|
2235
|
+
|
|
2236
|
+
\`\`\`sh
|
|
2237
|
+
${commandFor("dev")}
|
|
2238
|
+
\`\`\`
|
|
2239
|
+
|
|
2240
|
+
### ${needsTypeScript ? "Type-Check, " : ""}Compile and Minify for Production
|
|
2241
|
+
|
|
2242
|
+
\`\`\`sh
|
|
2243
|
+
${commandFor("build")}
|
|
2244
|
+
\`\`\`
|
|
2245
|
+
`;
|
|
2246
|
+
if (needsVitest) npmScriptsDescriptions += `
|
|
2247
|
+
### Run Unit Tests with [Vitest](https://vitest.dev/)
|
|
2248
|
+
|
|
2249
|
+
\`\`\`sh
|
|
2250
|
+
${commandFor("test:unit")}
|
|
2251
|
+
\`\`\`
|
|
2252
|
+
`;
|
|
2253
|
+
if (needsCypressCT) npmScriptsDescriptions += `
|
|
2254
|
+
### Run Headed Component Tests with [Cypress Component Testing](https://on.cypress.io/component)
|
|
2255
|
+
|
|
2256
|
+
\`\`\`sh
|
|
2257
|
+
${commandFor("test:unit:dev")} # or \`${commandFor("test:unit")}\` for headless testing
|
|
2258
|
+
\`\`\`
|
|
2259
|
+
`;
|
|
2260
|
+
if (needsCypress) npmScriptsDescriptions += `
|
|
2261
|
+
### Run End-to-End Tests with [Cypress](https://www.cypress.io/)
|
|
2262
|
+
|
|
2263
|
+
\`\`\`sh
|
|
2264
|
+
${commandFor("test:e2e:dev")}
|
|
2265
|
+
\`\`\`
|
|
2266
|
+
|
|
2267
|
+
This runs the end-to-end tests against the Vite development server.
|
|
2268
|
+
It is much faster than the production build.
|
|
2269
|
+
|
|
2270
|
+
But it's still recommended to test the production build with \`test:e2e\` before deploying (e.g. in CI environments):
|
|
2271
|
+
|
|
2272
|
+
\`\`\`sh
|
|
2273
|
+
${commandFor("build")}
|
|
2274
|
+
${commandFor("test:e2e")}
|
|
2275
|
+
\`\`\`
|
|
2276
|
+
`;
|
|
2277
|
+
if (needsPlaywright) npmScriptsDescriptions += `
|
|
2278
|
+
### Run End-to-End Tests with [Playwright](https://playwright.dev)
|
|
2279
|
+
|
|
2280
|
+
\`\`\`sh
|
|
2281
|
+
# Install browsers for the first run
|
|
2282
|
+
npx playwright install
|
|
2283
|
+
|
|
2284
|
+
# When testing on CI, must build the project first
|
|
2285
|
+
${commandFor("build")}
|
|
2286
|
+
|
|
2287
|
+
# Runs the end-to-end tests
|
|
2288
|
+
${commandFor("test:e2e")}
|
|
2289
|
+
# Runs the tests only on Chromium
|
|
2290
|
+
${commandFor("test:e2e", "--project=chromium")}
|
|
2291
|
+
# Runs the tests of a specific file
|
|
2292
|
+
${commandFor("test:e2e", "tests/example.spec.ts")}
|
|
2293
|
+
# Runs the tests in debug mode
|
|
2294
|
+
${commandFor("test:e2e", "--debug")}
|
|
2295
|
+
\`\`\`
|
|
2296
|
+
`;
|
|
2297
|
+
if (needsEslint) npmScriptsDescriptions += `
|
|
2298
|
+
### Lint with [ESLint](https://eslint.org/)
|
|
2299
|
+
|
|
2300
|
+
\`\`\`sh
|
|
2301
|
+
${commandFor("lint")}
|
|
2302
|
+
\`\`\`
|
|
2303
|
+
`;
|
|
2304
|
+
readme += npmScriptsDescriptions;
|
|
2305
|
+
return readme;
|
|
2306
|
+
}
|
|
2307
|
+
//#endregion
|
|
2308
|
+
//#region utils/getLanguage.ts
|
|
2309
|
+
/**
|
|
2310
|
+
*
|
|
2311
|
+
* This function is used to link obtained locale with correct locale file in order to make locales reusable
|
|
2312
|
+
*
|
|
2313
|
+
* @param locale the obtained locale
|
|
2314
|
+
* @returns locale that linked with correct name
|
|
2315
|
+
*/
|
|
2316
|
+
function linkLocale(locale) {
|
|
2317
|
+
if (locale === "C") return "en-US";
|
|
2318
|
+
let linkedLocale;
|
|
2319
|
+
try {
|
|
2320
|
+
linkedLocale = Intl.getCanonicalLocales(locale)[0];
|
|
2321
|
+
} catch (error) {
|
|
2322
|
+
console.log(`${error.toString()}, invalid language tag: "${locale}"\n`);
|
|
2323
|
+
}
|
|
2324
|
+
switch (linkedLocale) {
|
|
2325
|
+
case "zh-TW":
|
|
2326
|
+
case "zh-HK":
|
|
2327
|
+
case "zh-MO":
|
|
2328
|
+
linkedLocale = "zh-Hant";
|
|
2329
|
+
break;
|
|
2330
|
+
case "zh-CN":
|
|
2331
|
+
case "zh-SG":
|
|
2332
|
+
linkedLocale = "zh-Hans";
|
|
2333
|
+
break;
|
|
2334
|
+
default: linkedLocale = locale;
|
|
2335
|
+
}
|
|
2336
|
+
return linkedLocale;
|
|
2337
|
+
}
|
|
2338
|
+
function getLocale() {
|
|
2339
|
+
return linkLocale((process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || Intl.DateTimeFormat().resolvedOptions().locale || "en-US").split(".")[0].replace("_", "-"));
|
|
2340
|
+
}
|
|
2341
|
+
async function loadLanguageFile(filePath) {
|
|
2342
|
+
return await fs.promises.readFile(filePath, "utf-8").then((data) => {
|
|
2343
|
+
const parsedData = JSON.parse(data);
|
|
2344
|
+
if (parsedData) return parsedData;
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
async function getLanguage(localesRoot) {
|
|
2348
|
+
const locale = getLocale();
|
|
2349
|
+
const languageFilePath = path$1.resolve(localesRoot, `${locale}.json`);
|
|
2350
|
+
const fallbackPath = path$1.resolve(localesRoot, "en-US.json");
|
|
2351
|
+
return fs.existsSync(languageFilePath) ? await loadLanguageFile(languageFilePath) : await loadLanguageFile(fallbackPath);
|
|
2352
|
+
}
|
|
2353
|
+
//#endregion
|
|
2354
|
+
//#region utils/trimBoilerplate.ts
|
|
2355
|
+
function replaceContent(filepath, replacer) {
|
|
2356
|
+
const content = fs.readFileSync(filepath, "utf8");
|
|
2357
|
+
fs.writeFileSync(filepath, replacer(content));
|
|
2358
|
+
}
|
|
2359
|
+
function trimBoilerplate(rootDir) {
|
|
2360
|
+
const srcDir = path.resolve(rootDir, "src");
|
|
2361
|
+
for (const filename of fs.readdirSync(srcDir)) {
|
|
2362
|
+
if ([
|
|
2363
|
+
"main.js",
|
|
2364
|
+
"main.ts",
|
|
2365
|
+
"router",
|
|
2366
|
+
"stores"
|
|
2367
|
+
].includes(filename)) continue;
|
|
2368
|
+
const fullpath = path.resolve(srcDir, filename);
|
|
2369
|
+
fs.rmSync(fullpath, { recursive: true });
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
function removeCSSImport(rootDir, needsTypeScript, needsCypressCT) {
|
|
2373
|
+
replaceContent(path.resolve(rootDir, needsTypeScript ? "src/main.ts" : "src/main.js"), (content) => content.replace("import './assets/main.css'\n\n", ""));
|
|
2374
|
+
if (needsCypressCT) replaceContent(path.resolve(rootDir, needsTypeScript ? "cypress/support/component.ts" : "cypress/support/component.js"), (content) => content.replace("import '@/assets/main.css'", "// import '@/assets/main.css'"));
|
|
2375
|
+
}
|
|
2376
|
+
function emptyRouterConfig(rootDir, needsTypeScript) {
|
|
2377
|
+
const srcDir = path.resolve(rootDir, "src");
|
|
2378
|
+
replaceContent(path.resolve(srcDir, needsTypeScript ? "router/index.ts" : "router/index.js"), (content) => content.replace(`import HomeView from '../views/HomeView.rue'\n`, "").replace(/routes:\s*\[[\s\S]*?\],/, "routes: [],"));
|
|
2379
|
+
}
|
|
2380
|
+
//#endregion
|
|
2381
|
+
//#region utils/applyRueBeta.ts
|
|
2382
|
+
const CORE_RUE_PACKAGES = [
|
|
2383
|
+
"rue",
|
|
2384
|
+
"@rue/compiler-core",
|
|
2385
|
+
"@rue/compiler-dom",
|
|
2386
|
+
"@rue/compiler-sfc",
|
|
2387
|
+
"@rue/compiler-ssr",
|
|
2388
|
+
"@rue/compiler-vapor",
|
|
2389
|
+
"@rue/reactivity",
|
|
2390
|
+
"@rue/runtime-core",
|
|
2391
|
+
"@rue/runtime-dom",
|
|
2392
|
+
"@rue/runtime-vapor",
|
|
2393
|
+
"@rue/server-renderer",
|
|
2394
|
+
"@rue/shared",
|
|
2395
|
+
"@rue/compat"
|
|
2396
|
+
];
|
|
2397
|
+
function generateOverridesMap() {
|
|
2398
|
+
return Object.fromEntries(CORE_RUE_PACKAGES.map((name) => [name, "beta"]));
|
|
2399
|
+
}
|
|
2400
|
+
/**
|
|
2401
|
+
* Apply Rue 3.6 beta overrides to the project based on the package manager.
|
|
2402
|
+
* Different package managers have different mechanisms for version overrides:
|
|
2403
|
+
* - npm/bun: uses `overrides` field in package.json
|
|
2404
|
+
* - yarn: uses `resolutions` field in package.json
|
|
2405
|
+
* - pnpm: uses `overrides` and `peerDependencyRules` in pnpm-workspace.yaml
|
|
2406
|
+
*/
|
|
2407
|
+
function applyRueBeta(root, packageManager, pkg) {
|
|
2408
|
+
const overrides = generateOverridesMap();
|
|
2409
|
+
if (packageManager === "npm" || packageManager === "bun") {
|
|
2410
|
+
pkg.overrides = {
|
|
2411
|
+
...pkg.overrides,
|
|
2412
|
+
...overrides
|
|
2413
|
+
};
|
|
2414
|
+
for (const dependencyName of CORE_RUE_PACKAGES) for (const dependencyType of [
|
|
2415
|
+
"dependencies",
|
|
2416
|
+
"devDependencies",
|
|
2417
|
+
"optionalDependencies"
|
|
2418
|
+
]) if (pkg[dependencyType]?.[dependencyName]) pkg[dependencyType][dependencyName] = overrides[dependencyName];
|
|
2419
|
+
} else if (packageManager === "yarn") pkg.resolutions = {
|
|
2420
|
+
...pkg.resolutions,
|
|
2421
|
+
...overrides
|
|
2422
|
+
};
|
|
2423
|
+
else if (packageManager === "pnpm") {
|
|
2424
|
+
const yamlContent = `overrides:
|
|
2425
|
+
${Object.entries(overrides).map(([key, value]) => ` '${key}': '${value}'`).join("\n")}
|
|
2426
|
+
|
|
2427
|
+
peerDependencyRules:
|
|
2428
|
+
allowAny:
|
|
2429
|
+
- 'rue'
|
|
2430
|
+
`;
|
|
2431
|
+
fs.writeFileSync(path$1.resolve(root, "pnpm-workspace.yaml"), yamlContent, "utf-8");
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
//#endregion
|
|
2435
|
+
//#region utils/packageManager.ts
|
|
2436
|
+
/**
|
|
2437
|
+
* Infers the package manager from the user agent string.
|
|
2438
|
+
* Falls back to npm if unable to detect.
|
|
2439
|
+
*/
|
|
2440
|
+
function inferPackageManager() {
|
|
2441
|
+
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
2442
|
+
if (/pnpm/.test(userAgent)) return "pnpm";
|
|
2443
|
+
if (/yarn/.test(userAgent)) return "yarn";
|
|
2444
|
+
if (/bun/.test(userAgent)) return "bun";
|
|
2445
|
+
return "npm";
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Creates an ordered list of package managers with the preferred one first.
|
|
2449
|
+
*/
|
|
2450
|
+
function getPackageManagerOptions(preferred) {
|
|
2451
|
+
return [preferred, ...[
|
|
2452
|
+
"npm",
|
|
2453
|
+
"pnpm",
|
|
2454
|
+
"yarn",
|
|
2455
|
+
"bun"
|
|
2456
|
+
].filter((pm) => pm !== preferred)];
|
|
2457
|
+
}
|
|
2458
|
+
//#endregion
|
|
2459
|
+
//#region package.json
|
|
2460
|
+
var name = "create-rue";
|
|
2461
|
+
var version = "0.0.1";
|
|
2462
|
+
//#endregion
|
|
2463
|
+
//#region index.ts
|
|
2464
|
+
const language = await getLanguage(fileURLToPath(new URL("./locales", import.meta.url)));
|
|
2465
|
+
const FEATURE_FLAGS = [
|
|
2466
|
+
"default",
|
|
2467
|
+
"ts",
|
|
2468
|
+
"typescript",
|
|
2469
|
+
"jsx",
|
|
2470
|
+
"router",
|
|
2471
|
+
"rue-router",
|
|
2472
|
+
"pinia",
|
|
2473
|
+
"tests",
|
|
2474
|
+
"with-tests",
|
|
2475
|
+
"vitest",
|
|
2476
|
+
"cypress",
|
|
2477
|
+
"playwright",
|
|
2478
|
+
"eslint",
|
|
2479
|
+
"prettier",
|
|
2480
|
+
"eslint-with-prettier",
|
|
2481
|
+
"oxlint",
|
|
2482
|
+
"oxfmt",
|
|
2483
|
+
"rue-beta"
|
|
2484
|
+
];
|
|
2485
|
+
const FEATURE_OPTIONS = [
|
|
2486
|
+
{
|
|
2487
|
+
value: "jsx",
|
|
2488
|
+
label: language.needsJsx.message
|
|
2489
|
+
},
|
|
2490
|
+
{
|
|
2491
|
+
value: "router",
|
|
2492
|
+
label: language.needsRouter.message
|
|
2493
|
+
},
|
|
2494
|
+
{
|
|
2495
|
+
value: "pinia",
|
|
2496
|
+
label: language.needsPinia.message
|
|
2497
|
+
},
|
|
2498
|
+
{
|
|
2499
|
+
value: "vitest",
|
|
2500
|
+
label: language.needsVitest.message
|
|
2501
|
+
},
|
|
2502
|
+
{
|
|
2503
|
+
value: "e2e",
|
|
2504
|
+
label: language.needsE2eTesting.message
|
|
2505
|
+
},
|
|
2506
|
+
{
|
|
2507
|
+
value: "eslint",
|
|
2508
|
+
label: language.needsEslint.message
|
|
2509
|
+
},
|
|
2510
|
+
{
|
|
2511
|
+
value: "prettier",
|
|
2512
|
+
label: language.needsPrettier.message
|
|
2513
|
+
}
|
|
2514
|
+
];
|
|
2515
|
+
const EXPERIMENTAL_FEATURE_OPTIONS = [{
|
|
2516
|
+
value: "oxfmt",
|
|
2517
|
+
label: language.needsOxfmt.message
|
|
2518
|
+
}, {
|
|
2519
|
+
value: "rue-beta",
|
|
2520
|
+
label: language.needsRueBeta.message
|
|
2521
|
+
}];
|
|
2522
|
+
function isValidPackageName(projectName) {
|
|
2523
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
|
|
2524
|
+
}
|
|
2525
|
+
function toValidPackageName(projectName) {
|
|
2526
|
+
return projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9-~]+/g, "-");
|
|
2527
|
+
}
|
|
2528
|
+
function canSkipEmptying(dir) {
|
|
2529
|
+
if (!fs.existsSync(dir)) return true;
|
|
2530
|
+
const files = fs.readdirSync(dir);
|
|
2531
|
+
if (files.length === 0) return true;
|
|
2532
|
+
if (files.length === 1 && files[0] === ".git") {
|
|
2533
|
+
dotGitDirectoryState.hasDotGitDirectory = true;
|
|
2534
|
+
return true;
|
|
2535
|
+
}
|
|
2536
|
+
return false;
|
|
2537
|
+
}
|
|
2538
|
+
function emptyDir(dir) {
|
|
2539
|
+
if (!fs.existsSync(dir)) return;
|
|
2540
|
+
postOrderDirectoryTraverse(dir, (dir) => fs.rmdirSync(dir), (file) => fs.unlinkSync(file));
|
|
2541
|
+
}
|
|
2542
|
+
async function unwrapPrompt(maybeCancelPromise) {
|
|
2543
|
+
const result = await maybeCancelPromise;
|
|
2544
|
+
if (q(result)) {
|
|
2545
|
+
pt((0, import_picocolors.red)("✖") + ` ${language.errors.operationCancelled}`);
|
|
2546
|
+
process.exit(0);
|
|
2547
|
+
}
|
|
2548
|
+
return result;
|
|
2549
|
+
}
|
|
2550
|
+
const helpMessage = `\
|
|
2551
|
+
Usage: create-rue [FEATURE_FLAGS...] [OPTIONS...] [DIRECTORY]
|
|
2552
|
+
|
|
2553
|
+
Create a new Rue.js project.
|
|
2554
|
+
Runs in interactive mode if started without feature flags, or if DIRECTORY is missing or not a valid package name.
|
|
2555
|
+
|
|
2556
|
+
Options:
|
|
2557
|
+
--force
|
|
2558
|
+
Create the project even if the directory is not empty.
|
|
2559
|
+
--bare
|
|
2560
|
+
Create a barebone project without example code.
|
|
2561
|
+
--help
|
|
2562
|
+
Display this help message.
|
|
2563
|
+
--version
|
|
2564
|
+
Display the version number of this CLI.
|
|
2565
|
+
|
|
2566
|
+
Available feature flags:
|
|
2567
|
+
--default
|
|
2568
|
+
Create a project with the default configuration without any additional features.
|
|
2569
|
+
--ts, --typescript
|
|
2570
|
+
Add TypeScript support.
|
|
2571
|
+
--jsx
|
|
2572
|
+
Add JSX support.
|
|
2573
|
+
--router, --rue-router
|
|
2574
|
+
Add Rue Router for SPA development.
|
|
2575
|
+
--pinia
|
|
2576
|
+
Add Pinia for state management.
|
|
2577
|
+
--vitest
|
|
2578
|
+
Add Vitest for unit testing.
|
|
2579
|
+
--cypress
|
|
2580
|
+
Add Cypress for end-to-end testing.
|
|
2581
|
+
If used without ${(0, import_picocolors.cyan)("--vitest")}, it will also add Cypress Component Testing.
|
|
2582
|
+
--playwright
|
|
2583
|
+
Add Playwright for end-to-end testing.
|
|
2584
|
+
--eslint
|
|
2585
|
+
Add ESLint for code quality.
|
|
2586
|
+
--prettier
|
|
2587
|
+
Add Prettier for code formatting.
|
|
2588
|
+
--oxfmt
|
|
2589
|
+
Add Oxfmt for code formatting.
|
|
2590
|
+
--rue-beta
|
|
2591
|
+
Use Rue 3.6 Beta. Requires specifying a package manager in interactive mode.
|
|
2592
|
+
|
|
2593
|
+
Unstable feature flags:
|
|
2594
|
+
--tests, --with-tests
|
|
2595
|
+
Add both unit testing and end-to-end testing support.
|
|
2596
|
+
Currently equivalent to ${(0, import_picocolors.cyan)("--vitest --cypress")}, but may change in the future.
|
|
2597
|
+
|
|
2598
|
+
Deprecated feature flags:
|
|
2599
|
+
--eslint-with-prettier
|
|
2600
|
+
Please use ${(0, import_picocolors.cyan)("--eslint --prettier")} instead.
|
|
2601
|
+
--oxlint
|
|
2602
|
+
Oxlint is now always included when ESLint is selected.
|
|
2603
|
+
`;
|
|
2604
|
+
async function init() {
|
|
2605
|
+
const cwd = process.cwd();
|
|
2606
|
+
const args = process.argv.slice(2);
|
|
2607
|
+
const flags = [
|
|
2608
|
+
...FEATURE_FLAGS,
|
|
2609
|
+
"force",
|
|
2610
|
+
"bare",
|
|
2611
|
+
"help",
|
|
2612
|
+
"version"
|
|
2613
|
+
];
|
|
2614
|
+
const { values: argv, positionals } = parseArgs({
|
|
2615
|
+
args,
|
|
2616
|
+
options: Object.fromEntries(flags.map((key) => [key, { type: "boolean" }])),
|
|
2617
|
+
strict: true,
|
|
2618
|
+
allowPositionals: true
|
|
2619
|
+
});
|
|
2620
|
+
if (argv.help) {
|
|
2621
|
+
console.log(helpMessage);
|
|
2622
|
+
process.exit(0);
|
|
2623
|
+
}
|
|
2624
|
+
if (argv.version) {
|
|
2625
|
+
console.log(`${name} v${version}`);
|
|
2626
|
+
process.exit(0);
|
|
2627
|
+
}
|
|
2628
|
+
const isFeatureFlagsUsed = FEATURE_FLAGS.some((flag) => typeof argv[flag] === "boolean");
|
|
2629
|
+
let targetDir = positionals[0];
|
|
2630
|
+
const defaultProjectName = targetDir || "rue-project";
|
|
2631
|
+
const forceOverwrite = argv.force;
|
|
2632
|
+
const inferredPackageManager = inferPackageManager();
|
|
2633
|
+
const result = {
|
|
2634
|
+
projectName: defaultProjectName,
|
|
2635
|
+
shouldOverwrite: forceOverwrite,
|
|
2636
|
+
packageName: defaultProjectName,
|
|
2637
|
+
features: [],
|
|
2638
|
+
e2eFramework: void 0,
|
|
2639
|
+
experimentFeatures: [],
|
|
2640
|
+
needsBareboneTemplates: false
|
|
2641
|
+
};
|
|
2642
|
+
mt(process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : defaultBanner);
|
|
2643
|
+
if (!targetDir) targetDir = result.projectName = result.packageName = (await unwrapPrompt(Ot({
|
|
2644
|
+
message: language.projectName.message,
|
|
2645
|
+
placeholder: defaultProjectName,
|
|
2646
|
+
defaultValue: defaultProjectName,
|
|
2647
|
+
validate: (value) => !value || value.trim().length > 0 ? void 0 : language.projectName.invalidMessage
|
|
2648
|
+
})))?.trim() || defaultProjectName;
|
|
2649
|
+
if (!canSkipEmptying(targetDir) && !forceOverwrite) {
|
|
2650
|
+
result.shouldOverwrite = await unwrapPrompt(ot({
|
|
2651
|
+
message: `${targetDir === "." ? language.shouldOverwrite.dirForPrompts.current : `${language.shouldOverwrite.dirForPrompts.target} "${targetDir}"`} ${language.shouldOverwrite.message}`,
|
|
2652
|
+
initialValue: false
|
|
2653
|
+
}));
|
|
2654
|
+
if (!result.shouldOverwrite) {
|
|
2655
|
+
pt((0, import_picocolors.red)("✖") + ` ${language.errors.operationCancelled}`);
|
|
2656
|
+
process.exit(0);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
if (!isValidPackageName(targetDir)) result.packageName = await unwrapPrompt(Ot({
|
|
2660
|
+
message: language.packageName.message,
|
|
2661
|
+
initialValue: toValidPackageName(targetDir),
|
|
2662
|
+
validate: (value) => isValidPackageName(value) ? void 0 : language.packageName.invalidMessage
|
|
2663
|
+
}));
|
|
2664
|
+
if (!isFeatureFlagsUsed) {
|
|
2665
|
+
result.needsTypeScript = await unwrapPrompt(ot({
|
|
2666
|
+
message: language.needsTypeScript.message,
|
|
2667
|
+
initialValue: true
|
|
2668
|
+
}));
|
|
2669
|
+
result.features = await unwrapPrompt(yt({
|
|
2670
|
+
message: `${language.featureSelection.message} ${(0, import_picocolors.dim)(language.featureSelection.hint)}`,
|
|
2671
|
+
options: FEATURE_OPTIONS,
|
|
2672
|
+
required: false
|
|
2673
|
+
}));
|
|
2674
|
+
if (result.features.includes("e2e")) {
|
|
2675
|
+
const hasVitest = result.features.includes("vitest");
|
|
2676
|
+
result.e2eFramework = await unwrapPrompt(_t({
|
|
2677
|
+
message: `${language.e2eSelection.message} ${(0, import_picocolors.dim)(language.e2eSelection.hint)}`,
|
|
2678
|
+
options: [{
|
|
2679
|
+
value: "playwright",
|
|
2680
|
+
label: language.e2eSelection.selectOptions.playwright.title,
|
|
2681
|
+
hint: language.e2eSelection.selectOptions.playwright.desc
|
|
2682
|
+
}, {
|
|
2683
|
+
value: "cypress",
|
|
2684
|
+
label: language.e2eSelection.selectOptions.cypress.title,
|
|
2685
|
+
hint: hasVitest ? language.e2eSelection.selectOptions.cypress.desc : language.e2eSelection.selectOptions.cypress.hintOnComponentTesting
|
|
2686
|
+
}]
|
|
2687
|
+
}));
|
|
2688
|
+
}
|
|
2689
|
+
result.experimentFeatures = await unwrapPrompt(yt({
|
|
2690
|
+
message: `${language.needsExperimentalFeatures.message} ${(0, import_picocolors.dim)(language.needsExperimentalFeatures.hint)}`,
|
|
2691
|
+
options: EXPERIMENTAL_FEATURE_OPTIONS,
|
|
2692
|
+
required: false
|
|
2693
|
+
}));
|
|
2694
|
+
if (result.experimentFeatures.includes("rue-beta")) {
|
|
2695
|
+
const packageManagerOptions = getPackageManagerOptions(inferredPackageManager).map((pm) => ({
|
|
2696
|
+
value: pm,
|
|
2697
|
+
label: pm
|
|
2698
|
+
}));
|
|
2699
|
+
result.packageManager = await unwrapPrompt(_t({
|
|
2700
|
+
message: `${language.packageManagerSelection.message} ${(0, import_picocolors.dim)(language.packageManagerSelection.hint)}`,
|
|
2701
|
+
options: packageManagerOptions
|
|
2702
|
+
}));
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
if (argv.bare) result.needsBareboneTemplates = true;
|
|
2706
|
+
else if (!isFeatureFlagsUsed) result.needsBareboneTemplates = await unwrapPrompt(ot({
|
|
2707
|
+
message: language.needsBareboneTemplates.message,
|
|
2708
|
+
initialValue: false
|
|
2709
|
+
}));
|
|
2710
|
+
const { features, experimentFeatures, needsBareboneTemplates } = result;
|
|
2711
|
+
const needsTypeScript = argv.ts || argv.typescript || result.needsTypeScript;
|
|
2712
|
+
const needsJsx = argv.jsx || features.includes("jsx");
|
|
2713
|
+
const needsRouter = argv.router || argv["rue-router"] || features.includes("router");
|
|
2714
|
+
const needsPinia = argv.pinia || features.includes("pinia");
|
|
2715
|
+
const needsVitest = argv.vitest || argv.tests || argv["with-tests"] || features.includes("vitest");
|
|
2716
|
+
const needsEslint = argv.eslint || argv["eslint-with-prettier"] || features.includes("eslint");
|
|
2717
|
+
const needsPrettier = argv.prettier || argv["eslint-with-prettier"] || features.includes("prettier");
|
|
2718
|
+
const needsOxfmt = experimentFeatures.includes("oxfmt") || argv["oxfmt"];
|
|
2719
|
+
const needsRueBeta = experimentFeatures.includes("rue-beta") || argv["rue-beta"];
|
|
2720
|
+
const { e2eFramework } = result;
|
|
2721
|
+
const needsCypress = argv.cypress || argv.tests || argv["with-tests"] || e2eFramework === "cypress";
|
|
2722
|
+
const needsCypressCT = needsCypress && !needsVitest;
|
|
2723
|
+
const needsPlaywright = argv.playwright || e2eFramework === "playwright";
|
|
2724
|
+
const root = path$1.join(cwd, targetDir);
|
|
2725
|
+
if (fs.existsSync(root) && result.shouldOverwrite) emptyDir(root);
|
|
2726
|
+
else if (!fs.existsSync(root)) fs.mkdirSync(root);
|
|
2727
|
+
console.log(`\n${language.infos.scaffolding} ${root}...`);
|
|
2728
|
+
const pkg = {
|
|
2729
|
+
name: result.packageName,
|
|
2730
|
+
version: "0.0.0"
|
|
2731
|
+
};
|
|
2732
|
+
fs.writeFileSync(path$1.resolve(root, "package.json"), JSON.stringify(pkg, null, 2));
|
|
2733
|
+
const templateRoot = fileURLToPath(new URL("./template", import.meta.url));
|
|
2734
|
+
const callbacks = [];
|
|
2735
|
+
const render = function render(templateName) {
|
|
2736
|
+
renderTemplate(path$1.resolve(templateRoot, templateName), root, callbacks);
|
|
2737
|
+
};
|
|
2738
|
+
render("base");
|
|
2739
|
+
if (needsJsx) render("config/jsx");
|
|
2740
|
+
if (needsRouter) render("config/router");
|
|
2741
|
+
if (needsPinia) render("config/pinia");
|
|
2742
|
+
if (needsVitest) render("config/vitest");
|
|
2743
|
+
if (needsCypress) render("config/cypress");
|
|
2744
|
+
if (needsCypressCT) render("config/cypress-ct");
|
|
2745
|
+
if (needsPlaywright) render("config/playwright");
|
|
2746
|
+
if (needsTypeScript) {
|
|
2747
|
+
render("config/typescript");
|
|
2748
|
+
render("tsconfig/base");
|
|
2749
|
+
const rootTsConfig = {
|
|
2750
|
+
files: [],
|
|
2751
|
+
references: [{ path: "./tsconfig.node.json" }, { path: "./tsconfig.app.json" }]
|
|
2752
|
+
};
|
|
2753
|
+
if (needsCypress) render("tsconfig/cypress");
|
|
2754
|
+
if (needsCypressCT) {
|
|
2755
|
+
render("tsconfig/cypress-ct");
|
|
2756
|
+
rootTsConfig.references.push({ path: "./tsconfig.cypress-ct.json" });
|
|
2757
|
+
}
|
|
2758
|
+
if (needsPlaywright) render("tsconfig/playwright");
|
|
2759
|
+
if (needsVitest) {
|
|
2760
|
+
render("tsconfig/vitest");
|
|
2761
|
+
rootTsConfig.references.push({ path: "./tsconfig.vitest.json" });
|
|
2762
|
+
}
|
|
2763
|
+
fs.writeFileSync(path$1.resolve(root, "tsconfig.json"), JSON.stringify(rootTsConfig, null, 2) + "\n", "utf-8");
|
|
2764
|
+
}
|
|
2765
|
+
if (needsEslint) {
|
|
2766
|
+
render("linting/base");
|
|
2767
|
+
if (needsTypeScript) render("linting/core/ts");
|
|
2768
|
+
else render("linting/core/js");
|
|
2769
|
+
if (needsCypress) render("linting/cypress");
|
|
2770
|
+
if (needsCypressCT) render("linting/cypress-ct");
|
|
2771
|
+
if (needsPlaywright) render("linting/playwright");
|
|
2772
|
+
if (needsVitest) render("linting/vitest");
|
|
2773
|
+
render("linting/oxlint");
|
|
2774
|
+
callbacks.push(async (dataStore) => {
|
|
2775
|
+
const oxlintrcPath = path$1.resolve(root, ".oxlintrc.json");
|
|
2776
|
+
dataStore[oxlintrcPath] = {
|
|
2777
|
+
needsTypeScript,
|
|
2778
|
+
needsVitest
|
|
2779
|
+
};
|
|
2780
|
+
});
|
|
2781
|
+
if (needsPrettier || needsOxfmt) render("linting/formatter");
|
|
2782
|
+
}
|
|
2783
|
+
if (needsOxfmt) render("formatting/oxfmt");
|
|
2784
|
+
else if (needsPrettier) render("formatting/prettier");
|
|
2785
|
+
render(`code/${(needsTypeScript ? "typescript-" : "") + (needsRouter ? "router" : "default")}`);
|
|
2786
|
+
if (needsPinia && needsRouter) render("entry/router-and-pinia");
|
|
2787
|
+
else if (needsPinia) render("entry/pinia");
|
|
2788
|
+
else if (needsRouter) render("entry/router");
|
|
2789
|
+
else render("entry/default");
|
|
2790
|
+
const dataStore = {};
|
|
2791
|
+
for (const cb of callbacks) await cb(dataStore);
|
|
2792
|
+
preOrderDirectoryTraverse(root, () => {}, (filepath) => {
|
|
2793
|
+
if (filepath.endsWith(".ejs")) {
|
|
2794
|
+
const template = fs.readFileSync(filepath, "utf-8");
|
|
2795
|
+
const dest = filepath.replace(/\.ejs$/, "");
|
|
2796
|
+
const content = import_ejs.render(template, dataStore[dest]);
|
|
2797
|
+
fs.writeFileSync(dest, content);
|
|
2798
|
+
fs.unlinkSync(filepath);
|
|
2799
|
+
}
|
|
2800
|
+
});
|
|
2801
|
+
if (needsBareboneTemplates) {
|
|
2802
|
+
trimBoilerplate(root);
|
|
2803
|
+
render("bare/base");
|
|
2804
|
+
if (needsTypeScript) render("bare/typescript");
|
|
2805
|
+
if (needsVitest) render("bare/vitest");
|
|
2806
|
+
if (needsCypressCT) render("bare/cypress-ct");
|
|
2807
|
+
}
|
|
2808
|
+
if (needsTypeScript) {
|
|
2809
|
+
preOrderDirectoryTraverse(root, () => {}, (filepath) => {
|
|
2810
|
+
if (filepath.endsWith(".js")) {
|
|
2811
|
+
const tsFilePath = filepath.replace(/\.js$/, ".ts");
|
|
2812
|
+
if (fs.existsSync(tsFilePath)) fs.unlinkSync(filepath);
|
|
2813
|
+
else fs.renameSync(filepath, tsFilePath);
|
|
2814
|
+
} else if (path$1.basename(filepath) === "jsconfig.json") fs.unlinkSync(filepath);
|
|
2815
|
+
});
|
|
2816
|
+
const indexHtmlPath = path$1.resolve(root, "index.html");
|
|
2817
|
+
const indexHtmlContent = fs.readFileSync(indexHtmlPath, "utf8");
|
|
2818
|
+
fs.writeFileSync(indexHtmlPath, indexHtmlContent.replace("src/main.js", "src/main.ts"));
|
|
2819
|
+
} else preOrderDirectoryTraverse(root, () => {}, (filepath) => {
|
|
2820
|
+
if (filepath.endsWith(".ts")) fs.unlinkSync(filepath);
|
|
2821
|
+
});
|
|
2822
|
+
if (needsBareboneTemplates) {
|
|
2823
|
+
removeCSSImport(root, needsTypeScript, needsCypressCT);
|
|
2824
|
+
if (needsRouter) emptyRouterConfig(root, needsTypeScript);
|
|
2825
|
+
}
|
|
2826
|
+
const packageManager = result.packageManager ?? inferredPackageManager;
|
|
2827
|
+
if (needsRueBeta) {
|
|
2828
|
+
const pkgPath = path$1.resolve(root, "package.json");
|
|
2829
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
2830
|
+
applyRueBeta(root, packageManager, pkg);
|
|
2831
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
2832
|
+
}
|
|
2833
|
+
fs.writeFileSync(path$1.resolve(root, "README.md"), generateReadme({
|
|
2834
|
+
projectName: result.projectName ?? result.packageName ?? defaultProjectName,
|
|
2835
|
+
packageManager,
|
|
2836
|
+
needsTypeScript,
|
|
2837
|
+
needsVitest,
|
|
2838
|
+
needsCypress,
|
|
2839
|
+
needsPlaywright,
|
|
2840
|
+
needsCypressCT,
|
|
2841
|
+
needsEslint
|
|
2842
|
+
}));
|
|
2843
|
+
let outroMessage = `${language.infos.done}\n\n`;
|
|
2844
|
+
if (root !== cwd) {
|
|
2845
|
+
const cdProjectName = path$1.relative(cwd, root);
|
|
2846
|
+
outroMessage += ` ${(0, import_picocolors.bold)((0, import_picocolors.green)(`cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`))}\n`;
|
|
2847
|
+
}
|
|
2848
|
+
outroMessage += ` ${(0, import_picocolors.bold)((0, import_picocolors.green)(getCommand(packageManager, "install")))}\n`;
|
|
2849
|
+
if (needsPrettier || needsOxfmt) outroMessage += ` ${(0, import_picocolors.bold)((0, import_picocolors.green)(getCommand(packageManager, "format")))}\n`;
|
|
2850
|
+
outroMessage += ` ${(0, import_picocolors.bold)((0, import_picocolors.green)(getCommand(packageManager, "dev")))}\n`;
|
|
2851
|
+
if (!dotGitDirectoryState.hasDotGitDirectory) outroMessage += `
|
|
2852
|
+
${(0, import_picocolors.dim)("|")} ${language.infos.optionalGitCommand}
|
|
2853
|
+
|
|
2854
|
+
${(0, import_picocolors.bold)((0, import_picocolors.green)("git init && git add -A && git commit -m \"initial commit\""))}`;
|
|
2855
|
+
gt(outroMessage);
|
|
2856
|
+
}
|
|
2857
|
+
init().catch((e) => {
|
|
2858
|
+
console.error(e);
|
|
2859
|
+
process.exit(1);
|
|
2860
|
+
});
|
|
2861
|
+
//#endregion
|
|
2862
|
+
export {};
|