@chatbi-v/cli 2.0.1 → 2.0.2
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/README.md +45 -0
- package/dist/bench-ACSHVGHE.mjs +77 -0
- package/dist/build-UB4D3WNI.mjs +11 -0
- package/dist/chunk-4OD6C56P.mjs +89 -0
- package/dist/chunk-7A54IJI5.mjs +6368 -0
- package/dist/chunk-LJFX6MNO.mjs +255 -0
- package/dist/chunk-SBGVKO4C.mjs +2255 -0
- package/dist/chunk-TX5M36S5.mjs +55 -0
- package/dist/chunk-V7IEPMC4.mjs +52 -0
- package/dist/chunk-WCPZB47I.mjs +262 -0
- package/dist/chunk-WIVHOK75.mjs +5292 -0
- package/dist/chunk-Y24V4GQG.mjs +9577 -0
- package/dist/commands/add.js +182 -0
- package/dist/commands/bench.js +100 -0
- package/dist/commands/build.js +290 -0
- package/dist/commands/dev.js +8 -0
- package/dist/commands/discover.js +25 -0
- package/dist/commands/doctor.js +231 -0
- package/dist/commands/fetch.js +41 -0
- package/dist/commands/gl.js +151 -0
- package/dist/commands/init.js +253 -0
- package/dist/commands/install.js +85 -0
- package/dist/commands/ls.js +46 -0
- package/dist/commands/sync.js +78 -0
- package/dist/commands/use.js +31 -0
- package/dist/config.js +70 -0
- package/dist/corekit.js +370 -0
- package/dist/execa-METROS6Z.mjs +17 -0
- package/dist/fetch-7X2UFWIV.mjs +10 -0
- package/dist/index.cjs +27278 -0
- package/dist/index.js +193 -23981
- package/dist/index.mjs +2769 -0
- package/dist/init-QFRFYEA5.mjs +12 -0
- package/dist/sandbox.js +522 -0
- package/dist/sync-7HPKGVFY.mjs +11 -0
- package/dist/utils.js +99 -0
- package/package.json +4 -3
- package/templates/app/.env.hbs +2 -2
- package/templates/app/README.md.hbs +29 -11
- package/templates/app/chatbi.config.ts.hbs +10 -33
- package/templates/app/index.html.hbs +1 -1
- package/templates/app/package.json.hbs +12 -14
- package/templates/app/postcss.config.cjs.hbs +5 -1
- package/templates/app/src/App.tsx.hbs +66 -36
- package/templates/app/src/components/GlobalSettingsModal.tsx.hbs +11 -1
- package/templates/app/src/hooks/useAppRoutes.ts.hbs +3 -6
- package/templates/app/src/hooks/usePluginLoader.ts.hbs +54 -7
- package/templates/app/src/hooks/usePluginStateSync.ts.hbs +81 -0
- package/templates/app/src/hooks/useThemeSync.ts.hbs +25 -74
- package/templates/app/src/layouts/MainContent.tsx.hbs +1 -1
- package/templates/app/src/layouts/SidebarNav.tsx.hbs +15 -14
- package/templates/app/src/main.tsx.hbs +2 -9
- package/templates/app/src/providers/AppProviders.tsx.hbs +2 -0
- package/templates/app/src/stores/useSessionStore.ts.hbs +1 -1
- package/templates/app/src/stores/useUIStore.ts.hbs +22 -3
- package/templates/app/src/vite-env.d.ts.hbs +1 -0
- package/templates/app/tailwind.config.cjs.hbs +26 -7
- package/templates/app/tsconfig.json.hbs +2 -5
- package/templates/app/vite.config.ts.hbs +67 -52
- package/templates/monorepo/package.json.hbs +1 -1
- package/templates/plugin/README.md.hbs +36 -0
- package/templates/plugin/package.json.hbs +26 -21
- package/templates/plugin/src/api/index.ts.hbs +3 -0
- package/templates/plugin/src/components/MainView.tsx.hbs +12 -0
- package/templates/plugin/src/index.tsx.hbs +39 -72
- package/templates/plugin/tsconfig.json.hbs +4 -15
- package/templates/app/src/services/api/modules/auth.ts.hbs +0 -18
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2769 @@
|
|
|
1
|
+
import {
|
|
2
|
+
build
|
|
3
|
+
} from "./chunk-WCPZB47I.mjs";
|
|
4
|
+
import {
|
|
5
|
+
init
|
|
6
|
+
} from "./chunk-LJFX6MNO.mjs";
|
|
7
|
+
import {
|
|
8
|
+
sync
|
|
9
|
+
} from "./chunk-4OD6C56P.mjs";
|
|
10
|
+
import {
|
|
11
|
+
ConfigManager,
|
|
12
|
+
CoreKit,
|
|
13
|
+
require_prompts
|
|
14
|
+
} from "./chunk-WIVHOK75.mjs";
|
|
15
|
+
import {
|
|
16
|
+
fetch
|
|
17
|
+
} from "./chunk-V7IEPMC4.mjs";
|
|
18
|
+
import {
|
|
19
|
+
Sandbox,
|
|
20
|
+
require_lib as require_lib2
|
|
21
|
+
} from "./chunk-7A54IJI5.mjs";
|
|
22
|
+
import {
|
|
23
|
+
execa
|
|
24
|
+
} from "./chunk-SBGVKO4C.mjs";
|
|
25
|
+
import {
|
|
26
|
+
boxen,
|
|
27
|
+
createSpinner,
|
|
28
|
+
getCliRoot,
|
|
29
|
+
logger,
|
|
30
|
+
printBox,
|
|
31
|
+
require_lib,
|
|
32
|
+
require_picocolors,
|
|
33
|
+
source_default
|
|
34
|
+
} from "./chunk-Y24V4GQG.mjs";
|
|
35
|
+
import {
|
|
36
|
+
__commonJS,
|
|
37
|
+
__toESM,
|
|
38
|
+
init_esm_shims
|
|
39
|
+
} from "./chunk-TX5M36S5.mjs";
|
|
40
|
+
|
|
41
|
+
// ../../node_modules/.pnpm/tinycolor2@1.6.0/node_modules/tinycolor2/cjs/tinycolor.js
|
|
42
|
+
var require_tinycolor = __commonJS({
|
|
43
|
+
"../../node_modules/.pnpm/tinycolor2@1.6.0/node_modules/tinycolor2/cjs/tinycolor.js"(exports, module) {
|
|
44
|
+
"use strict";
|
|
45
|
+
init_esm_shims();
|
|
46
|
+
(function(global, factory) {
|
|
47
|
+
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.tinycolor = factory());
|
|
48
|
+
})(exports, (function() {
|
|
49
|
+
"use strict";
|
|
50
|
+
function _typeof(obj) {
|
|
51
|
+
"@babel/helpers - typeof";
|
|
52
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
53
|
+
return typeof obj2;
|
|
54
|
+
} : function(obj2) {
|
|
55
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
56
|
+
}, _typeof(obj);
|
|
57
|
+
}
|
|
58
|
+
var trimLeft = /^\s+/;
|
|
59
|
+
var trimRight = /\s+$/;
|
|
60
|
+
function tinycolor(color, opts) {
|
|
61
|
+
color = color ? color : "";
|
|
62
|
+
opts = opts || {};
|
|
63
|
+
if (color instanceof tinycolor) {
|
|
64
|
+
return color;
|
|
65
|
+
}
|
|
66
|
+
if (!(this instanceof tinycolor)) {
|
|
67
|
+
return new tinycolor(color, opts);
|
|
68
|
+
}
|
|
69
|
+
var rgb = inputToRGB(color);
|
|
70
|
+
this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
|
|
71
|
+
this._gradientType = opts.gradientType;
|
|
72
|
+
if (this._r < 1) this._r = Math.round(this._r);
|
|
73
|
+
if (this._g < 1) this._g = Math.round(this._g);
|
|
74
|
+
if (this._b < 1) this._b = Math.round(this._b);
|
|
75
|
+
this._ok = rgb.ok;
|
|
76
|
+
}
|
|
77
|
+
tinycolor.prototype = {
|
|
78
|
+
isDark: function isDark() {
|
|
79
|
+
return this.getBrightness() < 128;
|
|
80
|
+
},
|
|
81
|
+
isLight: function isLight() {
|
|
82
|
+
return !this.isDark();
|
|
83
|
+
},
|
|
84
|
+
isValid: function isValid() {
|
|
85
|
+
return this._ok;
|
|
86
|
+
},
|
|
87
|
+
getOriginalInput: function getOriginalInput() {
|
|
88
|
+
return this._originalInput;
|
|
89
|
+
},
|
|
90
|
+
getFormat: function getFormat() {
|
|
91
|
+
return this._format;
|
|
92
|
+
},
|
|
93
|
+
getAlpha: function getAlpha() {
|
|
94
|
+
return this._a;
|
|
95
|
+
},
|
|
96
|
+
getBrightness: function getBrightness() {
|
|
97
|
+
var rgb = this.toRgb();
|
|
98
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
|
|
99
|
+
},
|
|
100
|
+
getLuminance: function getLuminance() {
|
|
101
|
+
var rgb = this.toRgb();
|
|
102
|
+
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
103
|
+
RsRGB = rgb.r / 255;
|
|
104
|
+
GsRGB = rgb.g / 255;
|
|
105
|
+
BsRGB = rgb.b / 255;
|
|
106
|
+
if (RsRGB <= 0.03928) R = RsRGB / 12.92;
|
|
107
|
+
else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
108
|
+
if (GsRGB <= 0.03928) G = GsRGB / 12.92;
|
|
109
|
+
else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
110
|
+
if (BsRGB <= 0.03928) B = BsRGB / 12.92;
|
|
111
|
+
else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
112
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
113
|
+
},
|
|
114
|
+
setAlpha: function setAlpha(value) {
|
|
115
|
+
this._a = boundAlpha(value);
|
|
116
|
+
this._roundA = Math.round(100 * this._a) / 100;
|
|
117
|
+
return this;
|
|
118
|
+
},
|
|
119
|
+
toHsv: function toHsv() {
|
|
120
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
121
|
+
return {
|
|
122
|
+
h: hsv.h * 360,
|
|
123
|
+
s: hsv.s,
|
|
124
|
+
v: hsv.v,
|
|
125
|
+
a: this._a
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
toHsvString: function toHsvString() {
|
|
129
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
130
|
+
var h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
|
131
|
+
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
132
|
+
},
|
|
133
|
+
toHsl: function toHsl() {
|
|
134
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
135
|
+
return {
|
|
136
|
+
h: hsl.h * 360,
|
|
137
|
+
s: hsl.s,
|
|
138
|
+
l: hsl.l,
|
|
139
|
+
a: this._a
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
toHslString: function toHslString() {
|
|
143
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
144
|
+
var h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
|
145
|
+
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
146
|
+
},
|
|
147
|
+
toHex: function toHex(allow3Char) {
|
|
148
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
149
|
+
},
|
|
150
|
+
toHexString: function toHexString(allow3Char) {
|
|
151
|
+
return "#" + this.toHex(allow3Char);
|
|
152
|
+
},
|
|
153
|
+
toHex8: function toHex8(allow4Char) {
|
|
154
|
+
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
155
|
+
},
|
|
156
|
+
toHex8String: function toHex8String(allow4Char) {
|
|
157
|
+
return "#" + this.toHex8(allow4Char);
|
|
158
|
+
},
|
|
159
|
+
toRgb: function toRgb() {
|
|
160
|
+
return {
|
|
161
|
+
r: Math.round(this._r),
|
|
162
|
+
g: Math.round(this._g),
|
|
163
|
+
b: Math.round(this._b),
|
|
164
|
+
a: this._a
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
toRgbString: function toRgbString() {
|
|
168
|
+
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
|
|
169
|
+
},
|
|
170
|
+
toPercentageRgb: function toPercentageRgb() {
|
|
171
|
+
return {
|
|
172
|
+
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
173
|
+
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
174
|
+
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
175
|
+
a: this._a
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
toPercentageRgbString: function toPercentageRgbString() {
|
|
179
|
+
return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
|
180
|
+
},
|
|
181
|
+
toName: function toName() {
|
|
182
|
+
if (this._a === 0) {
|
|
183
|
+
return "transparent";
|
|
184
|
+
}
|
|
185
|
+
if (this._a < 1) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
189
|
+
},
|
|
190
|
+
toFilter: function toFilter(secondColor) {
|
|
191
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
192
|
+
var secondHex8String = hex8String;
|
|
193
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
194
|
+
if (secondColor) {
|
|
195
|
+
var s = tinycolor(secondColor);
|
|
196
|
+
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
197
|
+
}
|
|
198
|
+
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
199
|
+
},
|
|
200
|
+
toString: function toString(format) {
|
|
201
|
+
var formatSet = !!format;
|
|
202
|
+
format = format || this._format;
|
|
203
|
+
var formattedString = false;
|
|
204
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
205
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
206
|
+
if (needsAlphaFormat) {
|
|
207
|
+
if (format === "name" && this._a === 0) {
|
|
208
|
+
return this.toName();
|
|
209
|
+
}
|
|
210
|
+
return this.toRgbString();
|
|
211
|
+
}
|
|
212
|
+
if (format === "rgb") {
|
|
213
|
+
formattedString = this.toRgbString();
|
|
214
|
+
}
|
|
215
|
+
if (format === "prgb") {
|
|
216
|
+
formattedString = this.toPercentageRgbString();
|
|
217
|
+
}
|
|
218
|
+
if (format === "hex" || format === "hex6") {
|
|
219
|
+
formattedString = this.toHexString();
|
|
220
|
+
}
|
|
221
|
+
if (format === "hex3") {
|
|
222
|
+
formattedString = this.toHexString(true);
|
|
223
|
+
}
|
|
224
|
+
if (format === "hex4") {
|
|
225
|
+
formattedString = this.toHex8String(true);
|
|
226
|
+
}
|
|
227
|
+
if (format === "hex8") {
|
|
228
|
+
formattedString = this.toHex8String();
|
|
229
|
+
}
|
|
230
|
+
if (format === "name") {
|
|
231
|
+
formattedString = this.toName();
|
|
232
|
+
}
|
|
233
|
+
if (format === "hsl") {
|
|
234
|
+
formattedString = this.toHslString();
|
|
235
|
+
}
|
|
236
|
+
if (format === "hsv") {
|
|
237
|
+
formattedString = this.toHsvString();
|
|
238
|
+
}
|
|
239
|
+
return formattedString || this.toHexString();
|
|
240
|
+
},
|
|
241
|
+
clone: function clone() {
|
|
242
|
+
return tinycolor(this.toString());
|
|
243
|
+
},
|
|
244
|
+
_applyModification: function _applyModification(fn, args) {
|
|
245
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
246
|
+
this._r = color._r;
|
|
247
|
+
this._g = color._g;
|
|
248
|
+
this._b = color._b;
|
|
249
|
+
this.setAlpha(color._a);
|
|
250
|
+
return this;
|
|
251
|
+
},
|
|
252
|
+
lighten: function lighten() {
|
|
253
|
+
return this._applyModification(_lighten, arguments);
|
|
254
|
+
},
|
|
255
|
+
brighten: function brighten() {
|
|
256
|
+
return this._applyModification(_brighten, arguments);
|
|
257
|
+
},
|
|
258
|
+
darken: function darken() {
|
|
259
|
+
return this._applyModification(_darken, arguments);
|
|
260
|
+
},
|
|
261
|
+
desaturate: function desaturate() {
|
|
262
|
+
return this._applyModification(_desaturate, arguments);
|
|
263
|
+
},
|
|
264
|
+
saturate: function saturate() {
|
|
265
|
+
return this._applyModification(_saturate, arguments);
|
|
266
|
+
},
|
|
267
|
+
greyscale: function greyscale() {
|
|
268
|
+
return this._applyModification(_greyscale, arguments);
|
|
269
|
+
},
|
|
270
|
+
spin: function spin() {
|
|
271
|
+
return this._applyModification(_spin, arguments);
|
|
272
|
+
},
|
|
273
|
+
_applyCombination: function _applyCombination(fn, args) {
|
|
274
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
275
|
+
},
|
|
276
|
+
analogous: function analogous() {
|
|
277
|
+
return this._applyCombination(_analogous, arguments);
|
|
278
|
+
},
|
|
279
|
+
complement: function complement() {
|
|
280
|
+
return this._applyCombination(_complement, arguments);
|
|
281
|
+
},
|
|
282
|
+
monochromatic: function monochromatic() {
|
|
283
|
+
return this._applyCombination(_monochromatic, arguments);
|
|
284
|
+
},
|
|
285
|
+
splitcomplement: function splitcomplement() {
|
|
286
|
+
return this._applyCombination(_splitcomplement, arguments);
|
|
287
|
+
},
|
|
288
|
+
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
289
|
+
// polyad: function (number) {
|
|
290
|
+
// return this._applyCombination(polyad, [number]);
|
|
291
|
+
// },
|
|
292
|
+
triad: function triad() {
|
|
293
|
+
return this._applyCombination(polyad, [3]);
|
|
294
|
+
},
|
|
295
|
+
tetrad: function tetrad() {
|
|
296
|
+
return this._applyCombination(polyad, [4]);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
tinycolor.fromRatio = function(color, opts) {
|
|
300
|
+
if (_typeof(color) == "object") {
|
|
301
|
+
var newColor = {};
|
|
302
|
+
for (var i in color) {
|
|
303
|
+
if (color.hasOwnProperty(i)) {
|
|
304
|
+
if (i === "a") {
|
|
305
|
+
newColor[i] = color[i];
|
|
306
|
+
} else {
|
|
307
|
+
newColor[i] = convertToPercentage(color[i]);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
color = newColor;
|
|
312
|
+
}
|
|
313
|
+
return tinycolor(color, opts);
|
|
314
|
+
};
|
|
315
|
+
function inputToRGB(color) {
|
|
316
|
+
var rgb = {
|
|
317
|
+
r: 0,
|
|
318
|
+
g: 0,
|
|
319
|
+
b: 0
|
|
320
|
+
};
|
|
321
|
+
var a = 1;
|
|
322
|
+
var s = null;
|
|
323
|
+
var v = null;
|
|
324
|
+
var l = null;
|
|
325
|
+
var ok = false;
|
|
326
|
+
var format = false;
|
|
327
|
+
if (typeof color == "string") {
|
|
328
|
+
color = stringInputToObject(color);
|
|
329
|
+
}
|
|
330
|
+
if (_typeof(color) == "object") {
|
|
331
|
+
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
332
|
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
333
|
+
ok = true;
|
|
334
|
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
335
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
336
|
+
s = convertToPercentage(color.s);
|
|
337
|
+
v = convertToPercentage(color.v);
|
|
338
|
+
rgb = hsvToRgb(color.h, s, v);
|
|
339
|
+
ok = true;
|
|
340
|
+
format = "hsv";
|
|
341
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
342
|
+
s = convertToPercentage(color.s);
|
|
343
|
+
l = convertToPercentage(color.l);
|
|
344
|
+
rgb = hslToRgb(color.h, s, l);
|
|
345
|
+
ok = true;
|
|
346
|
+
format = "hsl";
|
|
347
|
+
}
|
|
348
|
+
if (color.hasOwnProperty("a")) {
|
|
349
|
+
a = color.a;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
a = boundAlpha(a);
|
|
353
|
+
return {
|
|
354
|
+
ok,
|
|
355
|
+
format: color.format || format,
|
|
356
|
+
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
357
|
+
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
358
|
+
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
359
|
+
a
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function rgbToRgb(r, g, b) {
|
|
363
|
+
return {
|
|
364
|
+
r: bound01(r, 255) * 255,
|
|
365
|
+
g: bound01(g, 255) * 255,
|
|
366
|
+
b: bound01(b, 255) * 255
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function rgbToHsl(r, g, b) {
|
|
370
|
+
r = bound01(r, 255);
|
|
371
|
+
g = bound01(g, 255);
|
|
372
|
+
b = bound01(b, 255);
|
|
373
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
374
|
+
var h, s, l = (max + min) / 2;
|
|
375
|
+
if (max == min) {
|
|
376
|
+
h = s = 0;
|
|
377
|
+
} else {
|
|
378
|
+
var d = max - min;
|
|
379
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
380
|
+
switch (max) {
|
|
381
|
+
case r:
|
|
382
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
383
|
+
break;
|
|
384
|
+
case g:
|
|
385
|
+
h = (b - r) / d + 2;
|
|
386
|
+
break;
|
|
387
|
+
case b:
|
|
388
|
+
h = (r - g) / d + 4;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
h /= 6;
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
h,
|
|
395
|
+
s,
|
|
396
|
+
l
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function hslToRgb(h, s, l) {
|
|
400
|
+
var r, g, b;
|
|
401
|
+
h = bound01(h, 360);
|
|
402
|
+
s = bound01(s, 100);
|
|
403
|
+
l = bound01(l, 100);
|
|
404
|
+
function hue2rgb(p2, q2, t) {
|
|
405
|
+
if (t < 0) t += 1;
|
|
406
|
+
if (t > 1) t -= 1;
|
|
407
|
+
if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
|
|
408
|
+
if (t < 1 / 2) return q2;
|
|
409
|
+
if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
410
|
+
return p2;
|
|
411
|
+
}
|
|
412
|
+
if (s === 0) {
|
|
413
|
+
r = g = b = l;
|
|
414
|
+
} else {
|
|
415
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
416
|
+
var p = 2 * l - q;
|
|
417
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
418
|
+
g = hue2rgb(p, q, h);
|
|
419
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
r: r * 255,
|
|
423
|
+
g: g * 255,
|
|
424
|
+
b: b * 255
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function rgbToHsv(r, g, b) {
|
|
428
|
+
r = bound01(r, 255);
|
|
429
|
+
g = bound01(g, 255);
|
|
430
|
+
b = bound01(b, 255);
|
|
431
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
432
|
+
var h, s, v = max;
|
|
433
|
+
var d = max - min;
|
|
434
|
+
s = max === 0 ? 0 : d / max;
|
|
435
|
+
if (max == min) {
|
|
436
|
+
h = 0;
|
|
437
|
+
} else {
|
|
438
|
+
switch (max) {
|
|
439
|
+
case r:
|
|
440
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
441
|
+
break;
|
|
442
|
+
case g:
|
|
443
|
+
h = (b - r) / d + 2;
|
|
444
|
+
break;
|
|
445
|
+
case b:
|
|
446
|
+
h = (r - g) / d + 4;
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
h /= 6;
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
h,
|
|
453
|
+
s,
|
|
454
|
+
v
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function hsvToRgb(h, s, v) {
|
|
458
|
+
h = bound01(h, 360) * 6;
|
|
459
|
+
s = bound01(s, 100);
|
|
460
|
+
v = bound01(v, 100);
|
|
461
|
+
var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
|
|
462
|
+
return {
|
|
463
|
+
r: r * 255,
|
|
464
|
+
g: g * 255,
|
|
465
|
+
b: b * 255
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
469
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
470
|
+
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
471
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
472
|
+
}
|
|
473
|
+
return hex.join("");
|
|
474
|
+
}
|
|
475
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
476
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
477
|
+
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
478
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
479
|
+
}
|
|
480
|
+
return hex.join("");
|
|
481
|
+
}
|
|
482
|
+
function rgbaToArgbHex(r, g, b, a) {
|
|
483
|
+
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
484
|
+
return hex.join("");
|
|
485
|
+
}
|
|
486
|
+
tinycolor.equals = function(color1, color2) {
|
|
487
|
+
if (!color1 || !color2) return false;
|
|
488
|
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
489
|
+
};
|
|
490
|
+
tinycolor.random = function() {
|
|
491
|
+
return tinycolor.fromRatio({
|
|
492
|
+
r: Math.random(),
|
|
493
|
+
g: Math.random(),
|
|
494
|
+
b: Math.random()
|
|
495
|
+
});
|
|
496
|
+
};
|
|
497
|
+
function _desaturate(color, amount) {
|
|
498
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
499
|
+
var hsl = tinycolor(color).toHsl();
|
|
500
|
+
hsl.s -= amount / 100;
|
|
501
|
+
hsl.s = clamp01(hsl.s);
|
|
502
|
+
return tinycolor(hsl);
|
|
503
|
+
}
|
|
504
|
+
function _saturate(color, amount) {
|
|
505
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
506
|
+
var hsl = tinycolor(color).toHsl();
|
|
507
|
+
hsl.s += amount / 100;
|
|
508
|
+
hsl.s = clamp01(hsl.s);
|
|
509
|
+
return tinycolor(hsl);
|
|
510
|
+
}
|
|
511
|
+
function _greyscale(color) {
|
|
512
|
+
return tinycolor(color).desaturate(100);
|
|
513
|
+
}
|
|
514
|
+
function _lighten(color, amount) {
|
|
515
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
516
|
+
var hsl = tinycolor(color).toHsl();
|
|
517
|
+
hsl.l += amount / 100;
|
|
518
|
+
hsl.l = clamp01(hsl.l);
|
|
519
|
+
return tinycolor(hsl);
|
|
520
|
+
}
|
|
521
|
+
function _brighten(color, amount) {
|
|
522
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
523
|
+
var rgb = tinycolor(color).toRgb();
|
|
524
|
+
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
525
|
+
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
526
|
+
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
527
|
+
return tinycolor(rgb);
|
|
528
|
+
}
|
|
529
|
+
function _darken(color, amount) {
|
|
530
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
531
|
+
var hsl = tinycolor(color).toHsl();
|
|
532
|
+
hsl.l -= amount / 100;
|
|
533
|
+
hsl.l = clamp01(hsl.l);
|
|
534
|
+
return tinycolor(hsl);
|
|
535
|
+
}
|
|
536
|
+
function _spin(color, amount) {
|
|
537
|
+
var hsl = tinycolor(color).toHsl();
|
|
538
|
+
var hue = (hsl.h + amount) % 360;
|
|
539
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
540
|
+
return tinycolor(hsl);
|
|
541
|
+
}
|
|
542
|
+
function _complement(color) {
|
|
543
|
+
var hsl = tinycolor(color).toHsl();
|
|
544
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
545
|
+
return tinycolor(hsl);
|
|
546
|
+
}
|
|
547
|
+
function polyad(color, number) {
|
|
548
|
+
if (isNaN(number) || number <= 0) {
|
|
549
|
+
throw new Error("Argument to polyad must be a positive number");
|
|
550
|
+
}
|
|
551
|
+
var hsl = tinycolor(color).toHsl();
|
|
552
|
+
var result = [tinycolor(color)];
|
|
553
|
+
var step = 360 / number;
|
|
554
|
+
for (var i = 1; i < number; i++) {
|
|
555
|
+
result.push(tinycolor({
|
|
556
|
+
h: (hsl.h + i * step) % 360,
|
|
557
|
+
s: hsl.s,
|
|
558
|
+
l: hsl.l
|
|
559
|
+
}));
|
|
560
|
+
}
|
|
561
|
+
return result;
|
|
562
|
+
}
|
|
563
|
+
function _splitcomplement(color) {
|
|
564
|
+
var hsl = tinycolor(color).toHsl();
|
|
565
|
+
var h = hsl.h;
|
|
566
|
+
return [tinycolor(color), tinycolor({
|
|
567
|
+
h: (h + 72) % 360,
|
|
568
|
+
s: hsl.s,
|
|
569
|
+
l: hsl.l
|
|
570
|
+
}), tinycolor({
|
|
571
|
+
h: (h + 216) % 360,
|
|
572
|
+
s: hsl.s,
|
|
573
|
+
l: hsl.l
|
|
574
|
+
})];
|
|
575
|
+
}
|
|
576
|
+
function _analogous(color, results, slices) {
|
|
577
|
+
results = results || 6;
|
|
578
|
+
slices = slices || 30;
|
|
579
|
+
var hsl = tinycolor(color).toHsl();
|
|
580
|
+
var part = 360 / slices;
|
|
581
|
+
var ret = [tinycolor(color)];
|
|
582
|
+
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; ) {
|
|
583
|
+
hsl.h = (hsl.h + part) % 360;
|
|
584
|
+
ret.push(tinycolor(hsl));
|
|
585
|
+
}
|
|
586
|
+
return ret;
|
|
587
|
+
}
|
|
588
|
+
function _monochromatic(color, results) {
|
|
589
|
+
results = results || 6;
|
|
590
|
+
var hsv = tinycolor(color).toHsv();
|
|
591
|
+
var h = hsv.h, s = hsv.s, v = hsv.v;
|
|
592
|
+
var ret = [];
|
|
593
|
+
var modification = 1 / results;
|
|
594
|
+
while (results--) {
|
|
595
|
+
ret.push(tinycolor({
|
|
596
|
+
h,
|
|
597
|
+
s,
|
|
598
|
+
v
|
|
599
|
+
}));
|
|
600
|
+
v = (v + modification) % 1;
|
|
601
|
+
}
|
|
602
|
+
return ret;
|
|
603
|
+
}
|
|
604
|
+
tinycolor.mix = function(color1, color2, amount) {
|
|
605
|
+
amount = amount === 0 ? 0 : amount || 50;
|
|
606
|
+
var rgb1 = tinycolor(color1).toRgb();
|
|
607
|
+
var rgb2 = tinycolor(color2).toRgb();
|
|
608
|
+
var p = amount / 100;
|
|
609
|
+
var rgba = {
|
|
610
|
+
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
611
|
+
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
612
|
+
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
613
|
+
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
614
|
+
};
|
|
615
|
+
return tinycolor(rgba);
|
|
616
|
+
};
|
|
617
|
+
tinycolor.readability = function(color1, color2) {
|
|
618
|
+
var c1 = tinycolor(color1);
|
|
619
|
+
var c2 = tinycolor(color2);
|
|
620
|
+
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
621
|
+
};
|
|
622
|
+
tinycolor.isReadable = function(color1, color2, wcag2) {
|
|
623
|
+
var readability = tinycolor.readability(color1, color2);
|
|
624
|
+
var wcag2Parms, out;
|
|
625
|
+
out = false;
|
|
626
|
+
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
627
|
+
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
628
|
+
case "AAsmall":
|
|
629
|
+
case "AAAlarge":
|
|
630
|
+
out = readability >= 4.5;
|
|
631
|
+
break;
|
|
632
|
+
case "AAlarge":
|
|
633
|
+
out = readability >= 3;
|
|
634
|
+
break;
|
|
635
|
+
case "AAAsmall":
|
|
636
|
+
out = readability >= 7;
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
return out;
|
|
640
|
+
};
|
|
641
|
+
tinycolor.mostReadable = function(baseColor, colorList, args) {
|
|
642
|
+
var bestColor = null;
|
|
643
|
+
var bestScore = 0;
|
|
644
|
+
var readability;
|
|
645
|
+
var includeFallbackColors, level, size;
|
|
646
|
+
args = args || {};
|
|
647
|
+
includeFallbackColors = args.includeFallbackColors;
|
|
648
|
+
level = args.level;
|
|
649
|
+
size = args.size;
|
|
650
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
651
|
+
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
652
|
+
if (readability > bestScore) {
|
|
653
|
+
bestScore = readability;
|
|
654
|
+
bestColor = tinycolor(colorList[i]);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
658
|
+
level,
|
|
659
|
+
size
|
|
660
|
+
}) || !includeFallbackColors) {
|
|
661
|
+
return bestColor;
|
|
662
|
+
} else {
|
|
663
|
+
args.includeFallbackColors = false;
|
|
664
|
+
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
var names = tinycolor.names = {
|
|
668
|
+
aliceblue: "f0f8ff",
|
|
669
|
+
antiquewhite: "faebd7",
|
|
670
|
+
aqua: "0ff",
|
|
671
|
+
aquamarine: "7fffd4",
|
|
672
|
+
azure: "f0ffff",
|
|
673
|
+
beige: "f5f5dc",
|
|
674
|
+
bisque: "ffe4c4",
|
|
675
|
+
black: "000",
|
|
676
|
+
blanchedalmond: "ffebcd",
|
|
677
|
+
blue: "00f",
|
|
678
|
+
blueviolet: "8a2be2",
|
|
679
|
+
brown: "a52a2a",
|
|
680
|
+
burlywood: "deb887",
|
|
681
|
+
burntsienna: "ea7e5d",
|
|
682
|
+
cadetblue: "5f9ea0",
|
|
683
|
+
chartreuse: "7fff00",
|
|
684
|
+
chocolate: "d2691e",
|
|
685
|
+
coral: "ff7f50",
|
|
686
|
+
cornflowerblue: "6495ed",
|
|
687
|
+
cornsilk: "fff8dc",
|
|
688
|
+
crimson: "dc143c",
|
|
689
|
+
cyan: "0ff",
|
|
690
|
+
darkblue: "00008b",
|
|
691
|
+
darkcyan: "008b8b",
|
|
692
|
+
darkgoldenrod: "b8860b",
|
|
693
|
+
darkgray: "a9a9a9",
|
|
694
|
+
darkgreen: "006400",
|
|
695
|
+
darkgrey: "a9a9a9",
|
|
696
|
+
darkkhaki: "bdb76b",
|
|
697
|
+
darkmagenta: "8b008b",
|
|
698
|
+
darkolivegreen: "556b2f",
|
|
699
|
+
darkorange: "ff8c00",
|
|
700
|
+
darkorchid: "9932cc",
|
|
701
|
+
darkred: "8b0000",
|
|
702
|
+
darksalmon: "e9967a",
|
|
703
|
+
darkseagreen: "8fbc8f",
|
|
704
|
+
darkslateblue: "483d8b",
|
|
705
|
+
darkslategray: "2f4f4f",
|
|
706
|
+
darkslategrey: "2f4f4f",
|
|
707
|
+
darkturquoise: "00ced1",
|
|
708
|
+
darkviolet: "9400d3",
|
|
709
|
+
deeppink: "ff1493",
|
|
710
|
+
deepskyblue: "00bfff",
|
|
711
|
+
dimgray: "696969",
|
|
712
|
+
dimgrey: "696969",
|
|
713
|
+
dodgerblue: "1e90ff",
|
|
714
|
+
firebrick: "b22222",
|
|
715
|
+
floralwhite: "fffaf0",
|
|
716
|
+
forestgreen: "228b22",
|
|
717
|
+
fuchsia: "f0f",
|
|
718
|
+
gainsboro: "dcdcdc",
|
|
719
|
+
ghostwhite: "f8f8ff",
|
|
720
|
+
gold: "ffd700",
|
|
721
|
+
goldenrod: "daa520",
|
|
722
|
+
gray: "808080",
|
|
723
|
+
green: "008000",
|
|
724
|
+
greenyellow: "adff2f",
|
|
725
|
+
grey: "808080",
|
|
726
|
+
honeydew: "f0fff0",
|
|
727
|
+
hotpink: "ff69b4",
|
|
728
|
+
indianred: "cd5c5c",
|
|
729
|
+
indigo: "4b0082",
|
|
730
|
+
ivory: "fffff0",
|
|
731
|
+
khaki: "f0e68c",
|
|
732
|
+
lavender: "e6e6fa",
|
|
733
|
+
lavenderblush: "fff0f5",
|
|
734
|
+
lawngreen: "7cfc00",
|
|
735
|
+
lemonchiffon: "fffacd",
|
|
736
|
+
lightblue: "add8e6",
|
|
737
|
+
lightcoral: "f08080",
|
|
738
|
+
lightcyan: "e0ffff",
|
|
739
|
+
lightgoldenrodyellow: "fafad2",
|
|
740
|
+
lightgray: "d3d3d3",
|
|
741
|
+
lightgreen: "90ee90",
|
|
742
|
+
lightgrey: "d3d3d3",
|
|
743
|
+
lightpink: "ffb6c1",
|
|
744
|
+
lightsalmon: "ffa07a",
|
|
745
|
+
lightseagreen: "20b2aa",
|
|
746
|
+
lightskyblue: "87cefa",
|
|
747
|
+
lightslategray: "789",
|
|
748
|
+
lightslategrey: "789",
|
|
749
|
+
lightsteelblue: "b0c4de",
|
|
750
|
+
lightyellow: "ffffe0",
|
|
751
|
+
lime: "0f0",
|
|
752
|
+
limegreen: "32cd32",
|
|
753
|
+
linen: "faf0e6",
|
|
754
|
+
magenta: "f0f",
|
|
755
|
+
maroon: "800000",
|
|
756
|
+
mediumaquamarine: "66cdaa",
|
|
757
|
+
mediumblue: "0000cd",
|
|
758
|
+
mediumorchid: "ba55d3",
|
|
759
|
+
mediumpurple: "9370db",
|
|
760
|
+
mediumseagreen: "3cb371",
|
|
761
|
+
mediumslateblue: "7b68ee",
|
|
762
|
+
mediumspringgreen: "00fa9a",
|
|
763
|
+
mediumturquoise: "48d1cc",
|
|
764
|
+
mediumvioletred: "c71585",
|
|
765
|
+
midnightblue: "191970",
|
|
766
|
+
mintcream: "f5fffa",
|
|
767
|
+
mistyrose: "ffe4e1",
|
|
768
|
+
moccasin: "ffe4b5",
|
|
769
|
+
navajowhite: "ffdead",
|
|
770
|
+
navy: "000080",
|
|
771
|
+
oldlace: "fdf5e6",
|
|
772
|
+
olive: "808000",
|
|
773
|
+
olivedrab: "6b8e23",
|
|
774
|
+
orange: "ffa500",
|
|
775
|
+
orangered: "ff4500",
|
|
776
|
+
orchid: "da70d6",
|
|
777
|
+
palegoldenrod: "eee8aa",
|
|
778
|
+
palegreen: "98fb98",
|
|
779
|
+
paleturquoise: "afeeee",
|
|
780
|
+
palevioletred: "db7093",
|
|
781
|
+
papayawhip: "ffefd5",
|
|
782
|
+
peachpuff: "ffdab9",
|
|
783
|
+
peru: "cd853f",
|
|
784
|
+
pink: "ffc0cb",
|
|
785
|
+
plum: "dda0dd",
|
|
786
|
+
powderblue: "b0e0e6",
|
|
787
|
+
purple: "800080",
|
|
788
|
+
rebeccapurple: "663399",
|
|
789
|
+
red: "f00",
|
|
790
|
+
rosybrown: "bc8f8f",
|
|
791
|
+
royalblue: "4169e1",
|
|
792
|
+
saddlebrown: "8b4513",
|
|
793
|
+
salmon: "fa8072",
|
|
794
|
+
sandybrown: "f4a460",
|
|
795
|
+
seagreen: "2e8b57",
|
|
796
|
+
seashell: "fff5ee",
|
|
797
|
+
sienna: "a0522d",
|
|
798
|
+
silver: "c0c0c0",
|
|
799
|
+
skyblue: "87ceeb",
|
|
800
|
+
slateblue: "6a5acd",
|
|
801
|
+
slategray: "708090",
|
|
802
|
+
slategrey: "708090",
|
|
803
|
+
snow: "fffafa",
|
|
804
|
+
springgreen: "00ff7f",
|
|
805
|
+
steelblue: "4682b4",
|
|
806
|
+
tan: "d2b48c",
|
|
807
|
+
teal: "008080",
|
|
808
|
+
thistle: "d8bfd8",
|
|
809
|
+
tomato: "ff6347",
|
|
810
|
+
turquoise: "40e0d0",
|
|
811
|
+
violet: "ee82ee",
|
|
812
|
+
wheat: "f5deb3",
|
|
813
|
+
white: "fff",
|
|
814
|
+
whitesmoke: "f5f5f5",
|
|
815
|
+
yellow: "ff0",
|
|
816
|
+
yellowgreen: "9acd32"
|
|
817
|
+
};
|
|
818
|
+
var hexNames = tinycolor.hexNames = flip(names);
|
|
819
|
+
function flip(o) {
|
|
820
|
+
var flipped = {};
|
|
821
|
+
for (var i in o) {
|
|
822
|
+
if (o.hasOwnProperty(i)) {
|
|
823
|
+
flipped[o[i]] = i;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return flipped;
|
|
827
|
+
}
|
|
828
|
+
function boundAlpha(a) {
|
|
829
|
+
a = parseFloat(a);
|
|
830
|
+
if (isNaN(a) || a < 0 || a > 1) {
|
|
831
|
+
a = 1;
|
|
832
|
+
}
|
|
833
|
+
return a;
|
|
834
|
+
}
|
|
835
|
+
function bound01(n, max) {
|
|
836
|
+
if (isOnePointZero(n)) n = "100%";
|
|
837
|
+
var processPercent = isPercentage(n);
|
|
838
|
+
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
839
|
+
if (processPercent) {
|
|
840
|
+
n = parseInt(n * max, 10) / 100;
|
|
841
|
+
}
|
|
842
|
+
if (Math.abs(n - max) < 1e-6) {
|
|
843
|
+
return 1;
|
|
844
|
+
}
|
|
845
|
+
return n % max / parseFloat(max);
|
|
846
|
+
}
|
|
847
|
+
function clamp01(val) {
|
|
848
|
+
return Math.min(1, Math.max(0, val));
|
|
849
|
+
}
|
|
850
|
+
function parseIntFromHex(val) {
|
|
851
|
+
return parseInt(val, 16);
|
|
852
|
+
}
|
|
853
|
+
function isOnePointZero(n) {
|
|
854
|
+
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
855
|
+
}
|
|
856
|
+
function isPercentage(n) {
|
|
857
|
+
return typeof n === "string" && n.indexOf("%") != -1;
|
|
858
|
+
}
|
|
859
|
+
function pad2(c) {
|
|
860
|
+
return c.length == 1 ? "0" + c : "" + c;
|
|
861
|
+
}
|
|
862
|
+
function convertToPercentage(n) {
|
|
863
|
+
if (n <= 1) {
|
|
864
|
+
n = n * 100 + "%";
|
|
865
|
+
}
|
|
866
|
+
return n;
|
|
867
|
+
}
|
|
868
|
+
function convertDecimalToHex(d) {
|
|
869
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
870
|
+
}
|
|
871
|
+
function convertHexToDecimal(h) {
|
|
872
|
+
return parseIntFromHex(h) / 255;
|
|
873
|
+
}
|
|
874
|
+
var matchers = (function() {
|
|
875
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
876
|
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
877
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
878
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
879
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
880
|
+
return {
|
|
881
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
882
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
883
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
884
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
885
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
886
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
887
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
888
|
+
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
889
|
+
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
890
|
+
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
891
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
892
|
+
};
|
|
893
|
+
})();
|
|
894
|
+
function isValidCSSUnit(color) {
|
|
895
|
+
return !!matchers.CSS_UNIT.exec(color);
|
|
896
|
+
}
|
|
897
|
+
function stringInputToObject(color) {
|
|
898
|
+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
899
|
+
var named = false;
|
|
900
|
+
if (names[color]) {
|
|
901
|
+
color = names[color];
|
|
902
|
+
named = true;
|
|
903
|
+
} else if (color == "transparent") {
|
|
904
|
+
return {
|
|
905
|
+
r: 0,
|
|
906
|
+
g: 0,
|
|
907
|
+
b: 0,
|
|
908
|
+
a: 0,
|
|
909
|
+
format: "name"
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
var match;
|
|
913
|
+
if (match = matchers.rgb.exec(color)) {
|
|
914
|
+
return {
|
|
915
|
+
r: match[1],
|
|
916
|
+
g: match[2],
|
|
917
|
+
b: match[3]
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
if (match = matchers.rgba.exec(color)) {
|
|
921
|
+
return {
|
|
922
|
+
r: match[1],
|
|
923
|
+
g: match[2],
|
|
924
|
+
b: match[3],
|
|
925
|
+
a: match[4]
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
if (match = matchers.hsl.exec(color)) {
|
|
929
|
+
return {
|
|
930
|
+
h: match[1],
|
|
931
|
+
s: match[2],
|
|
932
|
+
l: match[3]
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
if (match = matchers.hsla.exec(color)) {
|
|
936
|
+
return {
|
|
937
|
+
h: match[1],
|
|
938
|
+
s: match[2],
|
|
939
|
+
l: match[3],
|
|
940
|
+
a: match[4]
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
if (match = matchers.hsv.exec(color)) {
|
|
944
|
+
return {
|
|
945
|
+
h: match[1],
|
|
946
|
+
s: match[2],
|
|
947
|
+
v: match[3]
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
if (match = matchers.hsva.exec(color)) {
|
|
951
|
+
return {
|
|
952
|
+
h: match[1],
|
|
953
|
+
s: match[2],
|
|
954
|
+
v: match[3],
|
|
955
|
+
a: match[4]
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
if (match = matchers.hex8.exec(color)) {
|
|
959
|
+
return {
|
|
960
|
+
r: parseIntFromHex(match[1]),
|
|
961
|
+
g: parseIntFromHex(match[2]),
|
|
962
|
+
b: parseIntFromHex(match[3]),
|
|
963
|
+
a: convertHexToDecimal(match[4]),
|
|
964
|
+
format: named ? "name" : "hex8"
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
if (match = matchers.hex6.exec(color)) {
|
|
968
|
+
return {
|
|
969
|
+
r: parseIntFromHex(match[1]),
|
|
970
|
+
g: parseIntFromHex(match[2]),
|
|
971
|
+
b: parseIntFromHex(match[3]),
|
|
972
|
+
format: named ? "name" : "hex"
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
if (match = matchers.hex4.exec(color)) {
|
|
976
|
+
return {
|
|
977
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
978
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
979
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
980
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
981
|
+
format: named ? "name" : "hex8"
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
if (match = matchers.hex3.exec(color)) {
|
|
985
|
+
return {
|
|
986
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
987
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
988
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
989
|
+
format: named ? "name" : "hex"
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
return false;
|
|
993
|
+
}
|
|
994
|
+
function validateWCAG2Parms(parms) {
|
|
995
|
+
var level, size;
|
|
996
|
+
parms = parms || {
|
|
997
|
+
level: "AA",
|
|
998
|
+
size: "small"
|
|
999
|
+
};
|
|
1000
|
+
level = (parms.level || "AA").toUpperCase();
|
|
1001
|
+
size = (parms.size || "small").toLowerCase();
|
|
1002
|
+
if (level !== "AA" && level !== "AAA") {
|
|
1003
|
+
level = "AA";
|
|
1004
|
+
}
|
|
1005
|
+
if (size !== "small" && size !== "large") {
|
|
1006
|
+
size = "small";
|
|
1007
|
+
}
|
|
1008
|
+
return {
|
|
1009
|
+
level,
|
|
1010
|
+
size
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
return tinycolor;
|
|
1014
|
+
}));
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
// ../../node_modules/.pnpm/tinygradient@1.1.5/node_modules/tinygradient/index.js
|
|
1019
|
+
var require_tinygradient = __commonJS({
|
|
1020
|
+
"../../node_modules/.pnpm/tinygradient@1.1.5/node_modules/tinygradient/index.js"(exports, module) {
|
|
1021
|
+
"use strict";
|
|
1022
|
+
init_esm_shims();
|
|
1023
|
+
var tinycolor = require_tinycolor();
|
|
1024
|
+
var RGBA_MAX = { r: 256, g: 256, b: 256, a: 1 };
|
|
1025
|
+
var HSVA_MAX = { h: 360, s: 1, v: 1, a: 1 };
|
|
1026
|
+
function stepize(start, end, steps) {
|
|
1027
|
+
let step = {};
|
|
1028
|
+
for (let k in start) {
|
|
1029
|
+
if (start.hasOwnProperty(k)) {
|
|
1030
|
+
step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return step;
|
|
1034
|
+
}
|
|
1035
|
+
function interpolate(step, start, i, max) {
|
|
1036
|
+
let color = {};
|
|
1037
|
+
for (let k in start) {
|
|
1038
|
+
if (start.hasOwnProperty(k)) {
|
|
1039
|
+
color[k] = step[k] * i + start[k];
|
|
1040
|
+
color[k] = color[k] < 0 ? color[k] + max[k] : max[k] !== 1 ? color[k] % max[k] : color[k];
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return color;
|
|
1044
|
+
}
|
|
1045
|
+
function interpolateRgb(stop1, stop2, steps) {
|
|
1046
|
+
const start = stop1.color.toRgb();
|
|
1047
|
+
const end = stop2.color.toRgb();
|
|
1048
|
+
const step = stepize(start, end, steps);
|
|
1049
|
+
let gradient2 = [stop1.color];
|
|
1050
|
+
for (let i = 1; i < steps; i++) {
|
|
1051
|
+
const color = interpolate(step, start, i, RGBA_MAX);
|
|
1052
|
+
gradient2.push(tinycolor(color));
|
|
1053
|
+
}
|
|
1054
|
+
return gradient2;
|
|
1055
|
+
}
|
|
1056
|
+
function interpolateHsv(stop1, stop2, steps, mode) {
|
|
1057
|
+
const start = stop1.color.toHsv();
|
|
1058
|
+
const end = stop2.color.toHsv();
|
|
1059
|
+
if (start.s === 0 || end.s === 0) {
|
|
1060
|
+
return interpolateRgb(stop1, stop2, steps);
|
|
1061
|
+
}
|
|
1062
|
+
let trigonometric;
|
|
1063
|
+
if (typeof mode === "boolean") {
|
|
1064
|
+
trigonometric = mode;
|
|
1065
|
+
} else {
|
|
1066
|
+
const trigShortest = start.h < end.h && end.h - start.h < 180 || start.h > end.h && start.h - end.h > 180;
|
|
1067
|
+
trigonometric = mode === "long" && trigShortest || mode === "short" && !trigShortest;
|
|
1068
|
+
}
|
|
1069
|
+
const step = stepize(start, end, steps);
|
|
1070
|
+
let gradient2 = [stop1.color];
|
|
1071
|
+
let diff;
|
|
1072
|
+
if (start.h <= end.h && !trigonometric || start.h >= end.h && trigonometric) {
|
|
1073
|
+
diff = end.h - start.h;
|
|
1074
|
+
} else if (trigonometric) {
|
|
1075
|
+
diff = 360 - end.h + start.h;
|
|
1076
|
+
} else {
|
|
1077
|
+
diff = 360 - start.h + end.h;
|
|
1078
|
+
}
|
|
1079
|
+
step.h = Math.pow(-1, trigonometric ? 1 : 0) * Math.abs(diff) / steps;
|
|
1080
|
+
for (let i = 1; i < steps; i++) {
|
|
1081
|
+
const color = interpolate(step, start, i, HSVA_MAX);
|
|
1082
|
+
gradient2.push(tinycolor(color));
|
|
1083
|
+
}
|
|
1084
|
+
return gradient2;
|
|
1085
|
+
}
|
|
1086
|
+
function computeSubsteps(stops, steps) {
|
|
1087
|
+
const l = stops.length;
|
|
1088
|
+
steps = parseInt(steps, 10);
|
|
1089
|
+
if (isNaN(steps) || steps < 2) {
|
|
1090
|
+
throw new Error("Invalid number of steps (< 2)");
|
|
1091
|
+
}
|
|
1092
|
+
if (steps < l) {
|
|
1093
|
+
throw new Error("Number of steps cannot be inferior to number of stops");
|
|
1094
|
+
}
|
|
1095
|
+
let substeps = [];
|
|
1096
|
+
for (let i = 1; i < l; i++) {
|
|
1097
|
+
const step = (steps - 1) * (stops[i].pos - stops[i - 1].pos);
|
|
1098
|
+
substeps.push(Math.max(1, Math.round(step)));
|
|
1099
|
+
}
|
|
1100
|
+
let totalSubsteps = 1;
|
|
1101
|
+
for (let n = l - 1; n--; ) totalSubsteps += substeps[n];
|
|
1102
|
+
while (totalSubsteps !== steps) {
|
|
1103
|
+
if (totalSubsteps < steps) {
|
|
1104
|
+
const min = Math.min.apply(null, substeps);
|
|
1105
|
+
substeps[substeps.indexOf(min)]++;
|
|
1106
|
+
totalSubsteps++;
|
|
1107
|
+
} else {
|
|
1108
|
+
const max = Math.max.apply(null, substeps);
|
|
1109
|
+
substeps[substeps.indexOf(max)]--;
|
|
1110
|
+
totalSubsteps--;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return substeps;
|
|
1114
|
+
}
|
|
1115
|
+
function computeAt(stops, pos, method, max) {
|
|
1116
|
+
if (pos < 0 || pos > 1) {
|
|
1117
|
+
throw new Error("Position must be between 0 and 1");
|
|
1118
|
+
}
|
|
1119
|
+
let start, end;
|
|
1120
|
+
for (let i = 0, l = stops.length; i < l - 1; i++) {
|
|
1121
|
+
if (pos >= stops[i].pos && pos < stops[i + 1].pos) {
|
|
1122
|
+
start = stops[i];
|
|
1123
|
+
end = stops[i + 1];
|
|
1124
|
+
break;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
if (!start) {
|
|
1128
|
+
start = end = stops[stops.length - 1];
|
|
1129
|
+
}
|
|
1130
|
+
const step = stepize(start.color[method](), end.color[method](), (end.pos - start.pos) * 100);
|
|
1131
|
+
const color = interpolate(step, start.color[method](), (pos - start.pos) * 100, max);
|
|
1132
|
+
return tinycolor(color);
|
|
1133
|
+
}
|
|
1134
|
+
var TinyGradient = class _TinyGradient {
|
|
1135
|
+
/**
|
|
1136
|
+
* @param {StopInput[]|ColorInput[]} stops
|
|
1137
|
+
* @returns {TinyGradient}
|
|
1138
|
+
*/
|
|
1139
|
+
constructor(stops) {
|
|
1140
|
+
if (stops.length < 2) {
|
|
1141
|
+
throw new Error("Invalid number of stops (< 2)");
|
|
1142
|
+
}
|
|
1143
|
+
const havingPositions = stops[0].pos !== void 0;
|
|
1144
|
+
let l = stops.length;
|
|
1145
|
+
let p = -1;
|
|
1146
|
+
let lastColorLess = false;
|
|
1147
|
+
this.stops = stops.map((stop, i) => {
|
|
1148
|
+
const hasPosition = stop.pos !== void 0;
|
|
1149
|
+
if (havingPositions ^ hasPosition) {
|
|
1150
|
+
throw new Error("Cannot mix positionned and not posionned color stops");
|
|
1151
|
+
}
|
|
1152
|
+
if (hasPosition) {
|
|
1153
|
+
const hasColor = stop.color !== void 0;
|
|
1154
|
+
if (!hasColor && (lastColorLess || i === 0 || i === l - 1)) {
|
|
1155
|
+
throw new Error("Cannot define two consecutive position-only stops");
|
|
1156
|
+
}
|
|
1157
|
+
lastColorLess = !hasColor;
|
|
1158
|
+
stop = {
|
|
1159
|
+
color: hasColor ? tinycolor(stop.color) : null,
|
|
1160
|
+
colorLess: !hasColor,
|
|
1161
|
+
pos: stop.pos
|
|
1162
|
+
};
|
|
1163
|
+
if (stop.pos < 0 || stop.pos > 1) {
|
|
1164
|
+
throw new Error("Color stops positions must be between 0 and 1");
|
|
1165
|
+
} else if (stop.pos < p) {
|
|
1166
|
+
throw new Error("Color stops positions are not ordered");
|
|
1167
|
+
}
|
|
1168
|
+
p = stop.pos;
|
|
1169
|
+
} else {
|
|
1170
|
+
stop = {
|
|
1171
|
+
color: tinycolor(stop.color !== void 0 ? stop.color : stop),
|
|
1172
|
+
pos: i / (l - 1)
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
return stop;
|
|
1176
|
+
});
|
|
1177
|
+
if (this.stops[0].pos !== 0) {
|
|
1178
|
+
this.stops.unshift({
|
|
1179
|
+
color: this.stops[0].color,
|
|
1180
|
+
pos: 0
|
|
1181
|
+
});
|
|
1182
|
+
l++;
|
|
1183
|
+
}
|
|
1184
|
+
if (this.stops[l - 1].pos !== 1) {
|
|
1185
|
+
this.stops.push({
|
|
1186
|
+
color: this.stops[l - 1].color,
|
|
1187
|
+
pos: 1
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Return new instance with reversed stops
|
|
1193
|
+
* @return {TinyGradient}
|
|
1194
|
+
*/
|
|
1195
|
+
reverse() {
|
|
1196
|
+
let stops = [];
|
|
1197
|
+
this.stops.forEach(function(stop) {
|
|
1198
|
+
stops.push({
|
|
1199
|
+
color: stop.color,
|
|
1200
|
+
pos: 1 - stop.pos
|
|
1201
|
+
});
|
|
1202
|
+
});
|
|
1203
|
+
return new _TinyGradient(stops.reverse());
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Return new instance with looped stops
|
|
1207
|
+
* @return {TinyGradient}
|
|
1208
|
+
*/
|
|
1209
|
+
loop() {
|
|
1210
|
+
let stops1 = [];
|
|
1211
|
+
let stops2 = [];
|
|
1212
|
+
this.stops.forEach((stop) => {
|
|
1213
|
+
stops1.push({
|
|
1214
|
+
color: stop.color,
|
|
1215
|
+
pos: stop.pos / 2
|
|
1216
|
+
});
|
|
1217
|
+
});
|
|
1218
|
+
this.stops.slice(0, -1).forEach((stop) => {
|
|
1219
|
+
stops2.push({
|
|
1220
|
+
color: stop.color,
|
|
1221
|
+
pos: 1 - stop.pos / 2
|
|
1222
|
+
});
|
|
1223
|
+
});
|
|
1224
|
+
return new _TinyGradient(stops1.concat(stops2.reverse()));
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Generate gradient with RGBa interpolation
|
|
1228
|
+
* @param {number} steps
|
|
1229
|
+
* @return {tinycolor[]}
|
|
1230
|
+
*/
|
|
1231
|
+
rgb(steps) {
|
|
1232
|
+
const substeps = computeSubsteps(this.stops, steps);
|
|
1233
|
+
let gradient2 = [];
|
|
1234
|
+
this.stops.forEach((stop, i) => {
|
|
1235
|
+
if (stop.colorLess) {
|
|
1236
|
+
stop.color = interpolateRgb(this.stops[i - 1], this.stops[i + 1], 2)[1];
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
for (let i = 0, l = this.stops.length; i < l - 1; i++) {
|
|
1240
|
+
const rgb = interpolateRgb(this.stops[i], this.stops[i + 1], substeps[i]);
|
|
1241
|
+
gradient2.splice(gradient2.length, 0, ...rgb);
|
|
1242
|
+
}
|
|
1243
|
+
gradient2.push(this.stops[this.stops.length - 1].color);
|
|
1244
|
+
return gradient2;
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Generate gradient with HSVa interpolation
|
|
1248
|
+
* @param {number} steps
|
|
1249
|
+
* @param {boolean|'long'|'short'} [mode=false]
|
|
1250
|
+
* - false to step in clockwise
|
|
1251
|
+
* - true to step in trigonometric order
|
|
1252
|
+
* - 'short' to use the shortest way
|
|
1253
|
+
* - 'long' to use the longest way
|
|
1254
|
+
* @return {tinycolor[]}
|
|
1255
|
+
*/
|
|
1256
|
+
hsv(steps, mode) {
|
|
1257
|
+
const substeps = computeSubsteps(this.stops, steps);
|
|
1258
|
+
let gradient2 = [];
|
|
1259
|
+
this.stops.forEach((stop, i) => {
|
|
1260
|
+
if (stop.colorLess) {
|
|
1261
|
+
stop.color = interpolateHsv(this.stops[i - 1], this.stops[i + 1], 2, mode)[1];
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
for (let i = 0, l = this.stops.length; i < l - 1; i++) {
|
|
1265
|
+
const hsv = interpolateHsv(this.stops[i], this.stops[i + 1], substeps[i], mode);
|
|
1266
|
+
gradient2.splice(gradient2.length, 0, ...hsv);
|
|
1267
|
+
}
|
|
1268
|
+
gradient2.push(this.stops[this.stops.length - 1].color);
|
|
1269
|
+
return gradient2;
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Generate CSS3 command (no prefix) for this gradient
|
|
1273
|
+
* @param {String} [mode=linear] - 'linear' or 'radial'
|
|
1274
|
+
* @param {String} [direction] - default is 'to right' or 'ellipse at center'
|
|
1275
|
+
* @return {String}
|
|
1276
|
+
*/
|
|
1277
|
+
css(mode, direction) {
|
|
1278
|
+
mode = mode || "linear";
|
|
1279
|
+
direction = direction || (mode === "linear" ? "to right" : "ellipse at center");
|
|
1280
|
+
let css = mode + "-gradient(" + direction;
|
|
1281
|
+
this.stops.forEach(function(stop) {
|
|
1282
|
+
css += ", " + (stop.colorLess ? "" : stop.color.toRgbString() + " ") + stop.pos * 100 + "%";
|
|
1283
|
+
});
|
|
1284
|
+
css += ")";
|
|
1285
|
+
return css;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Returns the color at specific position with RGBa interpolation
|
|
1289
|
+
* @param {number} pos, between 0 and 1
|
|
1290
|
+
* @return {tinycolor}
|
|
1291
|
+
*/
|
|
1292
|
+
rgbAt(pos) {
|
|
1293
|
+
return computeAt(this.stops, pos, "toRgb", RGBA_MAX);
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Returns the color at specific position with HSVa interpolation
|
|
1297
|
+
* @param {number} pos, between 0 and 1
|
|
1298
|
+
* @return {tinycolor}
|
|
1299
|
+
*/
|
|
1300
|
+
hsvAt(pos) {
|
|
1301
|
+
return computeAt(this.stops, pos, "toHsv", HSVA_MAX);
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
module.exports = function(stops) {
|
|
1305
|
+
if (arguments.length === 1) {
|
|
1306
|
+
if (!Array.isArray(arguments[0])) {
|
|
1307
|
+
throw new Error('"stops" is not an array');
|
|
1308
|
+
}
|
|
1309
|
+
stops = arguments[0];
|
|
1310
|
+
} else {
|
|
1311
|
+
stops = Array.prototype.slice.call(arguments);
|
|
1312
|
+
}
|
|
1313
|
+
return new TinyGradient(stops);
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
// src/index.ts
|
|
1319
|
+
init_esm_shims();
|
|
1320
|
+
|
|
1321
|
+
// ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
1322
|
+
init_esm_shims();
|
|
1323
|
+
import { EventEmitter } from "events";
|
|
1324
|
+
function toArr(any) {
|
|
1325
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
1326
|
+
}
|
|
1327
|
+
function toVal(out, key, val, opts) {
|
|
1328
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
1329
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
1330
|
+
}
|
|
1331
|
+
function mri2(args, opts) {
|
|
1332
|
+
args = args || [];
|
|
1333
|
+
opts = opts || {};
|
|
1334
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
1335
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
1336
|
+
const alibi = opts.alias !== void 0;
|
|
1337
|
+
const strict = opts.unknown !== void 0;
|
|
1338
|
+
const defaults = opts.default !== void 0;
|
|
1339
|
+
opts.alias = opts.alias || {};
|
|
1340
|
+
opts.string = toArr(opts.string);
|
|
1341
|
+
opts.boolean = toArr(opts.boolean);
|
|
1342
|
+
if (alibi) {
|
|
1343
|
+
for (k in opts.alias) {
|
|
1344
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
1345
|
+
for (i = 0; i < arr.length; i++) {
|
|
1346
|
+
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
for (i = opts.boolean.length; i-- > 0; ) {
|
|
1351
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
1352
|
+
for (j = arr.length; j-- > 0; ) opts.boolean.push(arr[j]);
|
|
1353
|
+
}
|
|
1354
|
+
for (i = opts.string.length; i-- > 0; ) {
|
|
1355
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
1356
|
+
for (j = arr.length; j-- > 0; ) opts.string.push(arr[j]);
|
|
1357
|
+
}
|
|
1358
|
+
if (defaults) {
|
|
1359
|
+
for (k in opts.default) {
|
|
1360
|
+
name = typeof opts.default[k];
|
|
1361
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
1362
|
+
if (opts[name] !== void 0) {
|
|
1363
|
+
opts[name].push(k);
|
|
1364
|
+
for (i = 0; i < arr.length; i++) {
|
|
1365
|
+
opts[name].push(arr[i]);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
1371
|
+
for (i = 0; i < len; i++) {
|
|
1372
|
+
arg = args[i];
|
|
1373
|
+
if (arg === "--") {
|
|
1374
|
+
out._ = out._.concat(args.slice(++i));
|
|
1375
|
+
break;
|
|
1376
|
+
}
|
|
1377
|
+
for (j = 0; j < arg.length; j++) {
|
|
1378
|
+
if (arg.charCodeAt(j) !== 45) break;
|
|
1379
|
+
}
|
|
1380
|
+
if (j === 0) {
|
|
1381
|
+
out._.push(arg);
|
|
1382
|
+
} else if (arg.substring(j, j + 3) === "no-") {
|
|
1383
|
+
name = arg.substring(j + 3);
|
|
1384
|
+
if (strict && !~keys.indexOf(name)) {
|
|
1385
|
+
return opts.unknown(arg);
|
|
1386
|
+
}
|
|
1387
|
+
out[name] = false;
|
|
1388
|
+
} else {
|
|
1389
|
+
for (idx = j + 1; idx < arg.length; idx++) {
|
|
1390
|
+
if (arg.charCodeAt(idx) === 61) break;
|
|
1391
|
+
}
|
|
1392
|
+
name = arg.substring(j, idx);
|
|
1393
|
+
val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
|
|
1394
|
+
arr = j === 2 ? [name] : name;
|
|
1395
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
1396
|
+
name = arr[idx];
|
|
1397
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
1398
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (defaults) {
|
|
1403
|
+
for (k in opts.default) {
|
|
1404
|
+
if (out[k] === void 0) {
|
|
1405
|
+
out[k] = opts.default[k];
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
if (alibi) {
|
|
1410
|
+
for (k in out) {
|
|
1411
|
+
arr = opts.alias[k] || [];
|
|
1412
|
+
while (arr.length > 0) {
|
|
1413
|
+
out[arr.shift()] = out[k];
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
return out;
|
|
1418
|
+
}
|
|
1419
|
+
var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
1420
|
+
var findAllBrackets = (v) => {
|
|
1421
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
1422
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
1423
|
+
const res = [];
|
|
1424
|
+
const parse = (match) => {
|
|
1425
|
+
let variadic = false;
|
|
1426
|
+
let value = match[1];
|
|
1427
|
+
if (value.startsWith("...")) {
|
|
1428
|
+
value = value.slice(3);
|
|
1429
|
+
variadic = true;
|
|
1430
|
+
}
|
|
1431
|
+
return {
|
|
1432
|
+
required: match[0].startsWith("<"),
|
|
1433
|
+
value,
|
|
1434
|
+
variadic
|
|
1435
|
+
};
|
|
1436
|
+
};
|
|
1437
|
+
let angledMatch;
|
|
1438
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
|
|
1439
|
+
res.push(parse(angledMatch));
|
|
1440
|
+
}
|
|
1441
|
+
let squareMatch;
|
|
1442
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
|
|
1443
|
+
res.push(parse(squareMatch));
|
|
1444
|
+
}
|
|
1445
|
+
return res;
|
|
1446
|
+
};
|
|
1447
|
+
var getMriOptions = (options) => {
|
|
1448
|
+
const result = { alias: {}, boolean: [] };
|
|
1449
|
+
for (const [index, option] of options.entries()) {
|
|
1450
|
+
if (option.names.length > 1) {
|
|
1451
|
+
result.alias[option.names[0]] = option.names.slice(1);
|
|
1452
|
+
}
|
|
1453
|
+
if (option.isBoolean) {
|
|
1454
|
+
if (option.negated) {
|
|
1455
|
+
const hasStringTypeOption = options.some((o, i) => {
|
|
1456
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
1457
|
+
});
|
|
1458
|
+
if (!hasStringTypeOption) {
|
|
1459
|
+
result.boolean.push(option.names[0]);
|
|
1460
|
+
}
|
|
1461
|
+
} else {
|
|
1462
|
+
result.boolean.push(option.names[0]);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return result;
|
|
1467
|
+
};
|
|
1468
|
+
var findLongest = (arr) => {
|
|
1469
|
+
return arr.sort((a, b) => {
|
|
1470
|
+
return a.length > b.length ? -1 : 1;
|
|
1471
|
+
})[0];
|
|
1472
|
+
};
|
|
1473
|
+
var padRight = (str, length) => {
|
|
1474
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
1475
|
+
};
|
|
1476
|
+
var camelcase = (input) => {
|
|
1477
|
+
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
1478
|
+
return p1 + p2.toUpperCase();
|
|
1479
|
+
});
|
|
1480
|
+
};
|
|
1481
|
+
var setDotProp = (obj, keys, val) => {
|
|
1482
|
+
let i = 0;
|
|
1483
|
+
let length = keys.length;
|
|
1484
|
+
let t = obj;
|
|
1485
|
+
let x;
|
|
1486
|
+
for (; i < length; ++i) {
|
|
1487
|
+
x = t[keys[i]];
|
|
1488
|
+
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
var setByType = (obj, transforms) => {
|
|
1492
|
+
for (const key of Object.keys(transforms)) {
|
|
1493
|
+
const transform = transforms[key];
|
|
1494
|
+
if (transform.shouldTransform) {
|
|
1495
|
+
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
1496
|
+
if (typeof transform.transformFunction === "function") {
|
|
1497
|
+
obj[key] = obj[key].map(transform.transformFunction);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
var getFileName = (input) => {
|
|
1503
|
+
const m = /([^\\\/]+)$/.exec(input);
|
|
1504
|
+
return m ? m[1] : "";
|
|
1505
|
+
};
|
|
1506
|
+
var camelcaseOptionName = (name) => {
|
|
1507
|
+
return name.split(".").map((v, i) => {
|
|
1508
|
+
return i === 0 ? camelcase(v) : v;
|
|
1509
|
+
}).join(".");
|
|
1510
|
+
};
|
|
1511
|
+
var CACError = class extends Error {
|
|
1512
|
+
constructor(message) {
|
|
1513
|
+
super(message);
|
|
1514
|
+
this.name = this.constructor.name;
|
|
1515
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
1516
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1517
|
+
} else {
|
|
1518
|
+
this.stack = new Error(message).stack;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
var Option = class {
|
|
1523
|
+
constructor(rawName, description, config) {
|
|
1524
|
+
this.rawName = rawName;
|
|
1525
|
+
this.description = description;
|
|
1526
|
+
this.config = Object.assign({}, config);
|
|
1527
|
+
rawName = rawName.replace(/\.\*/g, "");
|
|
1528
|
+
this.negated = false;
|
|
1529
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
1530
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
1531
|
+
if (name.startsWith("no-")) {
|
|
1532
|
+
this.negated = true;
|
|
1533
|
+
name = name.replace(/^no-/, "");
|
|
1534
|
+
}
|
|
1535
|
+
return camelcaseOptionName(name);
|
|
1536
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
1537
|
+
this.name = this.names[this.names.length - 1];
|
|
1538
|
+
if (this.negated && this.config.default == null) {
|
|
1539
|
+
this.config.default = true;
|
|
1540
|
+
}
|
|
1541
|
+
if (rawName.includes("<")) {
|
|
1542
|
+
this.required = true;
|
|
1543
|
+
} else if (rawName.includes("[")) {
|
|
1544
|
+
this.required = false;
|
|
1545
|
+
} else {
|
|
1546
|
+
this.isBoolean = true;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
var processArgs = process.argv;
|
|
1551
|
+
var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
1552
|
+
var Command = class {
|
|
1553
|
+
constructor(rawName, description, config = {}, cli2) {
|
|
1554
|
+
this.rawName = rawName;
|
|
1555
|
+
this.description = description;
|
|
1556
|
+
this.config = config;
|
|
1557
|
+
this.cli = cli2;
|
|
1558
|
+
this.options = [];
|
|
1559
|
+
this.aliasNames = [];
|
|
1560
|
+
this.name = removeBrackets(rawName);
|
|
1561
|
+
this.args = findAllBrackets(rawName);
|
|
1562
|
+
this.examples = [];
|
|
1563
|
+
}
|
|
1564
|
+
usage(text) {
|
|
1565
|
+
this.usageText = text;
|
|
1566
|
+
return this;
|
|
1567
|
+
}
|
|
1568
|
+
allowUnknownOptions() {
|
|
1569
|
+
this.config.allowUnknownOptions = true;
|
|
1570
|
+
return this;
|
|
1571
|
+
}
|
|
1572
|
+
ignoreOptionDefaultValue() {
|
|
1573
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
1574
|
+
return this;
|
|
1575
|
+
}
|
|
1576
|
+
version(version, customFlags = "-v, --version") {
|
|
1577
|
+
this.versionNumber = version;
|
|
1578
|
+
this.option(customFlags, "Display version number");
|
|
1579
|
+
return this;
|
|
1580
|
+
}
|
|
1581
|
+
example(example) {
|
|
1582
|
+
this.examples.push(example);
|
|
1583
|
+
return this;
|
|
1584
|
+
}
|
|
1585
|
+
option(rawName, description, config) {
|
|
1586
|
+
const option = new Option(rawName, description, config);
|
|
1587
|
+
this.options.push(option);
|
|
1588
|
+
return this;
|
|
1589
|
+
}
|
|
1590
|
+
alias(name) {
|
|
1591
|
+
this.aliasNames.push(name);
|
|
1592
|
+
return this;
|
|
1593
|
+
}
|
|
1594
|
+
action(callback) {
|
|
1595
|
+
this.commandAction = callback;
|
|
1596
|
+
return this;
|
|
1597
|
+
}
|
|
1598
|
+
isMatched(name) {
|
|
1599
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
1600
|
+
}
|
|
1601
|
+
get isDefaultCommand() {
|
|
1602
|
+
return this.name === "" || this.aliasNames.includes("!");
|
|
1603
|
+
}
|
|
1604
|
+
get isGlobalCommand() {
|
|
1605
|
+
return this instanceof GlobalCommand;
|
|
1606
|
+
}
|
|
1607
|
+
hasOption(name) {
|
|
1608
|
+
name = name.split(".")[0];
|
|
1609
|
+
return this.options.find((option) => {
|
|
1610
|
+
return option.names.includes(name);
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
outputHelp() {
|
|
1614
|
+
const { name, commands } = this.cli;
|
|
1615
|
+
const {
|
|
1616
|
+
versionNumber,
|
|
1617
|
+
options: globalOptions,
|
|
1618
|
+
helpCallback
|
|
1619
|
+
} = this.cli.globalCommand;
|
|
1620
|
+
let sections = [
|
|
1621
|
+
{
|
|
1622
|
+
body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
|
|
1623
|
+
}
|
|
1624
|
+
];
|
|
1625
|
+
sections.push({
|
|
1626
|
+
title: "Usage",
|
|
1627
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
1628
|
+
});
|
|
1629
|
+
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
1630
|
+
if (showCommands) {
|
|
1631
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
1632
|
+
sections.push({
|
|
1633
|
+
title: "Commands",
|
|
1634
|
+
body: commands.map((command) => {
|
|
1635
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
1636
|
+
}).join("\n")
|
|
1637
|
+
});
|
|
1638
|
+
sections.push({
|
|
1639
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
|
1640
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
1644
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) {
|
|
1645
|
+
options = options.filter((option) => option.name !== "version");
|
|
1646
|
+
}
|
|
1647
|
+
if (options.length > 0) {
|
|
1648
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
1649
|
+
sections.push({
|
|
1650
|
+
title: "Options",
|
|
1651
|
+
body: options.map((option) => {
|
|
1652
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
1653
|
+
}).join("\n")
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
if (this.examples.length > 0) {
|
|
1657
|
+
sections.push({
|
|
1658
|
+
title: "Examples",
|
|
1659
|
+
body: this.examples.map((example) => {
|
|
1660
|
+
if (typeof example === "function") {
|
|
1661
|
+
return example(name);
|
|
1662
|
+
}
|
|
1663
|
+
return example;
|
|
1664
|
+
}).join("\n")
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
if (helpCallback) {
|
|
1668
|
+
sections = helpCallback(sections) || sections;
|
|
1669
|
+
}
|
|
1670
|
+
console.log(sections.map((section) => {
|
|
1671
|
+
return section.title ? `${section.title}:
|
|
1672
|
+
${section.body}` : section.body;
|
|
1673
|
+
}).join("\n\n"));
|
|
1674
|
+
}
|
|
1675
|
+
outputVersion() {
|
|
1676
|
+
const { name } = this.cli;
|
|
1677
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
1678
|
+
if (versionNumber) {
|
|
1679
|
+
console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
checkRequiredArgs() {
|
|
1683
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
1684
|
+
if (this.cli.args.length < minimalArgsCount) {
|
|
1685
|
+
throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
checkUnknownOptions() {
|
|
1689
|
+
const { options, globalCommand } = this.cli;
|
|
1690
|
+
if (!this.config.allowUnknownOptions) {
|
|
1691
|
+
for (const name of Object.keys(options)) {
|
|
1692
|
+
if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
|
|
1693
|
+
throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
checkOptionValue() {
|
|
1699
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
1700
|
+
const options = [...globalCommand.options, ...this.options];
|
|
1701
|
+
for (const option of options) {
|
|
1702
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
1703
|
+
if (option.required) {
|
|
1704
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
1705
|
+
if (value === true || value === false && !hasNegated) {
|
|
1706
|
+
throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
var GlobalCommand = class extends Command {
|
|
1713
|
+
constructor(cli2) {
|
|
1714
|
+
super("@@global@@", "", {}, cli2);
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
var __assign = Object.assign;
|
|
1718
|
+
var CAC = class extends EventEmitter {
|
|
1719
|
+
constructor(name = "") {
|
|
1720
|
+
super();
|
|
1721
|
+
this.name = name;
|
|
1722
|
+
this.commands = [];
|
|
1723
|
+
this.rawArgs = [];
|
|
1724
|
+
this.args = [];
|
|
1725
|
+
this.options = {};
|
|
1726
|
+
this.globalCommand = new GlobalCommand(this);
|
|
1727
|
+
this.globalCommand.usage("<command> [options]");
|
|
1728
|
+
}
|
|
1729
|
+
usage(text) {
|
|
1730
|
+
this.globalCommand.usage(text);
|
|
1731
|
+
return this;
|
|
1732
|
+
}
|
|
1733
|
+
command(rawName, description, config) {
|
|
1734
|
+
const command = new Command(rawName, description || "", config, this);
|
|
1735
|
+
command.globalCommand = this.globalCommand;
|
|
1736
|
+
this.commands.push(command);
|
|
1737
|
+
return command;
|
|
1738
|
+
}
|
|
1739
|
+
option(rawName, description, config) {
|
|
1740
|
+
this.globalCommand.option(rawName, description, config);
|
|
1741
|
+
return this;
|
|
1742
|
+
}
|
|
1743
|
+
help(callback) {
|
|
1744
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
1745
|
+
this.globalCommand.helpCallback = callback;
|
|
1746
|
+
this.showHelpOnExit = true;
|
|
1747
|
+
return this;
|
|
1748
|
+
}
|
|
1749
|
+
version(version, customFlags = "-v, --version") {
|
|
1750
|
+
this.globalCommand.version(version, customFlags);
|
|
1751
|
+
this.showVersionOnExit = true;
|
|
1752
|
+
return this;
|
|
1753
|
+
}
|
|
1754
|
+
example(example) {
|
|
1755
|
+
this.globalCommand.example(example);
|
|
1756
|
+
return this;
|
|
1757
|
+
}
|
|
1758
|
+
outputHelp() {
|
|
1759
|
+
if (this.matchedCommand) {
|
|
1760
|
+
this.matchedCommand.outputHelp();
|
|
1761
|
+
} else {
|
|
1762
|
+
this.globalCommand.outputHelp();
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
outputVersion() {
|
|
1766
|
+
this.globalCommand.outputVersion();
|
|
1767
|
+
}
|
|
1768
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
1769
|
+
this.args = args;
|
|
1770
|
+
this.options = options;
|
|
1771
|
+
if (matchedCommand) {
|
|
1772
|
+
this.matchedCommand = matchedCommand;
|
|
1773
|
+
}
|
|
1774
|
+
if (matchedCommandName) {
|
|
1775
|
+
this.matchedCommandName = matchedCommandName;
|
|
1776
|
+
}
|
|
1777
|
+
return this;
|
|
1778
|
+
}
|
|
1779
|
+
unsetMatchedCommand() {
|
|
1780
|
+
this.matchedCommand = void 0;
|
|
1781
|
+
this.matchedCommandName = void 0;
|
|
1782
|
+
}
|
|
1783
|
+
parse(argv = processArgs, {
|
|
1784
|
+
run = true
|
|
1785
|
+
} = {}) {
|
|
1786
|
+
this.rawArgs = argv;
|
|
1787
|
+
if (!this.name) {
|
|
1788
|
+
this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
1789
|
+
}
|
|
1790
|
+
let shouldParse = true;
|
|
1791
|
+
for (const command of this.commands) {
|
|
1792
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
1793
|
+
const commandName = parsed.args[0];
|
|
1794
|
+
if (command.isMatched(commandName)) {
|
|
1795
|
+
shouldParse = false;
|
|
1796
|
+
const parsedInfo = __assign(__assign({}, parsed), {
|
|
1797
|
+
args: parsed.args.slice(1)
|
|
1798
|
+
});
|
|
1799
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
1800
|
+
this.emit(`command:${commandName}`, command);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
if (shouldParse) {
|
|
1804
|
+
for (const command of this.commands) {
|
|
1805
|
+
if (command.name === "") {
|
|
1806
|
+
shouldParse = false;
|
|
1807
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
1808
|
+
this.setParsedInfo(parsed, command);
|
|
1809
|
+
this.emit(`command:!`, command);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
if (shouldParse) {
|
|
1814
|
+
const parsed = this.mri(argv.slice(2));
|
|
1815
|
+
this.setParsedInfo(parsed);
|
|
1816
|
+
}
|
|
1817
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
1818
|
+
this.outputHelp();
|
|
1819
|
+
run = false;
|
|
1820
|
+
this.unsetMatchedCommand();
|
|
1821
|
+
}
|
|
1822
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
1823
|
+
this.outputVersion();
|
|
1824
|
+
run = false;
|
|
1825
|
+
this.unsetMatchedCommand();
|
|
1826
|
+
}
|
|
1827
|
+
const parsedArgv = { args: this.args, options: this.options };
|
|
1828
|
+
if (run) {
|
|
1829
|
+
this.runMatchedCommand();
|
|
1830
|
+
}
|
|
1831
|
+
if (!this.matchedCommand && this.args[0]) {
|
|
1832
|
+
this.emit("command:*");
|
|
1833
|
+
}
|
|
1834
|
+
return parsedArgv;
|
|
1835
|
+
}
|
|
1836
|
+
mri(argv, command) {
|
|
1837
|
+
const cliOptions = [
|
|
1838
|
+
...this.globalCommand.options,
|
|
1839
|
+
...command ? command.options : []
|
|
1840
|
+
];
|
|
1841
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
1842
|
+
let argsAfterDoubleDashes = [];
|
|
1843
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
1844
|
+
if (doubleDashesIndex > -1) {
|
|
1845
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
1846
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
1847
|
+
}
|
|
1848
|
+
let parsed = mri2(argv, mriOptions);
|
|
1849
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
1850
|
+
return __assign(__assign({}, res), {
|
|
1851
|
+
[camelcaseOptionName(name)]: parsed[name]
|
|
1852
|
+
});
|
|
1853
|
+
}, { _: [] });
|
|
1854
|
+
const args = parsed._;
|
|
1855
|
+
const options = {
|
|
1856
|
+
"--": argsAfterDoubleDashes
|
|
1857
|
+
};
|
|
1858
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
1859
|
+
let transforms = /* @__PURE__ */ Object.create(null);
|
|
1860
|
+
for (const cliOption of cliOptions) {
|
|
1861
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) {
|
|
1862
|
+
for (const name of cliOption.names) {
|
|
1863
|
+
options[name] = cliOption.config.default;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
if (Array.isArray(cliOption.config.type)) {
|
|
1867
|
+
if (transforms[cliOption.name] === void 0) {
|
|
1868
|
+
transforms[cliOption.name] = /* @__PURE__ */ Object.create(null);
|
|
1869
|
+
transforms[cliOption.name]["shouldTransform"] = true;
|
|
1870
|
+
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
for (const key of Object.keys(parsed)) {
|
|
1875
|
+
if (key !== "_") {
|
|
1876
|
+
const keys = key.split(".");
|
|
1877
|
+
setDotProp(options, keys, parsed[key]);
|
|
1878
|
+
setByType(options, transforms);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
return {
|
|
1882
|
+
args,
|
|
1883
|
+
options
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
runMatchedCommand() {
|
|
1887
|
+
const { args, options, matchedCommand: command } = this;
|
|
1888
|
+
if (!command || !command.commandAction)
|
|
1889
|
+
return;
|
|
1890
|
+
command.checkUnknownOptions();
|
|
1891
|
+
command.checkOptionValue();
|
|
1892
|
+
command.checkRequiredArgs();
|
|
1893
|
+
const actionArgs = [];
|
|
1894
|
+
command.args.forEach((arg, index) => {
|
|
1895
|
+
if (arg.variadic) {
|
|
1896
|
+
actionArgs.push(args.slice(index));
|
|
1897
|
+
} else {
|
|
1898
|
+
actionArgs.push(args[index]);
|
|
1899
|
+
}
|
|
1900
|
+
});
|
|
1901
|
+
actionArgs.push(options);
|
|
1902
|
+
return command.commandAction.apply(this, actionArgs);
|
|
1903
|
+
}
|
|
1904
|
+
};
|
|
1905
|
+
var cac = (name = "") => new CAC(name);
|
|
1906
|
+
var dist_default = cac;
|
|
1907
|
+
|
|
1908
|
+
// src/index.ts
|
|
1909
|
+
var import_picocolors7 = __toESM(require_picocolors());
|
|
1910
|
+
import figlet from "figlet";
|
|
1911
|
+
|
|
1912
|
+
// ../../node_modules/.pnpm/gradient-string@3.0.0/node_modules/gradient-string/dist/index.js
|
|
1913
|
+
init_esm_shims();
|
|
1914
|
+
var import_tinygradient = __toESM(require_tinygradient(), 1);
|
|
1915
|
+
var gradient = (...colors) => {
|
|
1916
|
+
let gradient2;
|
|
1917
|
+
let options;
|
|
1918
|
+
if (colors.length === 0) {
|
|
1919
|
+
throw new Error("Missing gradient colors");
|
|
1920
|
+
}
|
|
1921
|
+
if (!Array.isArray(colors[0])) {
|
|
1922
|
+
if (colors.length === 1) {
|
|
1923
|
+
throw new Error(`Expected an array of colors, received ${JSON.stringify(colors[0])}`);
|
|
1924
|
+
}
|
|
1925
|
+
gradient2 = (0, import_tinygradient.default)(...colors);
|
|
1926
|
+
} else {
|
|
1927
|
+
gradient2 = (0, import_tinygradient.default)(colors[0]);
|
|
1928
|
+
options = validateOptions(colors[1]);
|
|
1929
|
+
}
|
|
1930
|
+
const fn = (str, deprecatedOptions) => {
|
|
1931
|
+
return applyGradient(str ? str.toString() : "", gradient2, deprecatedOptions ?? options);
|
|
1932
|
+
};
|
|
1933
|
+
fn.multiline = (str, deprecatedOptions) => multiline(str ? str.toString() : "", gradient2, deprecatedOptions ?? options);
|
|
1934
|
+
return fn;
|
|
1935
|
+
};
|
|
1936
|
+
var getColors = (gradient2, options, count) => {
|
|
1937
|
+
return options.interpolation?.toLowerCase() === "hsv" ? gradient2.hsv(count, options.hsvSpin?.toLowerCase() || false) : gradient2.rgb(count);
|
|
1938
|
+
};
|
|
1939
|
+
function applyGradient(str, gradient2, opts) {
|
|
1940
|
+
const options = validateOptions(opts);
|
|
1941
|
+
const colorsCount = Math.max(str.replace(/\s/g, "").length, gradient2.stops.length);
|
|
1942
|
+
const colors = getColors(gradient2, options, colorsCount);
|
|
1943
|
+
let result = "";
|
|
1944
|
+
for (const s of str) {
|
|
1945
|
+
result += s.match(/\s/g) ? s : source_default.hex(colors.shift()?.toHex() || "#000")(s);
|
|
1946
|
+
}
|
|
1947
|
+
return result;
|
|
1948
|
+
}
|
|
1949
|
+
function multiline(str, gradient2, opts) {
|
|
1950
|
+
const options = validateOptions(opts);
|
|
1951
|
+
const lines = str.split("\n");
|
|
1952
|
+
const maxLength = Math.max(...lines.map((l) => l.length), gradient2.stops.length);
|
|
1953
|
+
const colors = getColors(gradient2, options, maxLength);
|
|
1954
|
+
const results = [];
|
|
1955
|
+
for (const line of lines) {
|
|
1956
|
+
const lineColors = colors.slice(0);
|
|
1957
|
+
let lineResult = "";
|
|
1958
|
+
for (const l of line) {
|
|
1959
|
+
lineResult += source_default.hex(lineColors.shift()?.toHex() || "#000")(l);
|
|
1960
|
+
}
|
|
1961
|
+
results.push(lineResult);
|
|
1962
|
+
}
|
|
1963
|
+
return results.join("\n");
|
|
1964
|
+
}
|
|
1965
|
+
function validateOptions(opts) {
|
|
1966
|
+
const options = { interpolation: "rgb", hsvSpin: "short", ...opts };
|
|
1967
|
+
if (opts !== void 0 && typeof opts !== "object") {
|
|
1968
|
+
throw new TypeError(`Expected \`options\` to be an \`object\`, got \`${typeof opts}\``);
|
|
1969
|
+
}
|
|
1970
|
+
if (typeof options.interpolation !== "string") {
|
|
1971
|
+
throw new TypeError(`Expected \`options.interpolation\` to be \`rgb\` or \`hsv\`, got \`${typeof options.interpolation}\``);
|
|
1972
|
+
}
|
|
1973
|
+
if (options.interpolation.toLowerCase() === "hsv" && typeof options.hsvSpin !== "string") {
|
|
1974
|
+
throw new TypeError(`Expected \`options.hsvSpin\` to be a \`short\` or \`long\`, got \`${typeof options.hsvSpin}\``);
|
|
1975
|
+
}
|
|
1976
|
+
return options;
|
|
1977
|
+
}
|
|
1978
|
+
var aliases = {
|
|
1979
|
+
atlas: { colors: ["#feac5e", "#c779d0", "#4bc0c8"], options: {} },
|
|
1980
|
+
cristal: { colors: ["#bdfff3", "#4ac29a"], options: {} },
|
|
1981
|
+
teen: { colors: ["#77a1d3", "#79cbca", "#e684ae"], options: {} },
|
|
1982
|
+
mind: { colors: ["#473b7b", "#3584a7", "#30d2be"], options: {} },
|
|
1983
|
+
morning: { colors: ["#ff5f6d", "#ffc371"], options: { interpolation: "hsv" } },
|
|
1984
|
+
vice: { colors: ["#5ee7df", "#b490ca"], options: { interpolation: "hsv" } },
|
|
1985
|
+
passion: { colors: ["#f43b47", "#453a94"], options: {} },
|
|
1986
|
+
fruit: { colors: ["#ff4e50", "#f9d423"], options: {} },
|
|
1987
|
+
instagram: { colors: ["#833ab4", "#fd1d1d", "#fcb045"], options: {} },
|
|
1988
|
+
retro: {
|
|
1989
|
+
colors: ["#3f51b1", "#5a55ae", "#7b5fac", "#8f6aae", "#a86aa4", "#cc6b8e", "#f18271", "#f3a469", "#f7c978"],
|
|
1990
|
+
options: {}
|
|
1991
|
+
},
|
|
1992
|
+
summer: { colors: ["#fdbb2d", "#22c1c3"], options: {} },
|
|
1993
|
+
rainbow: { colors: ["#ff0000", "#ff0100"], options: { interpolation: "hsv", hsvSpin: "long" } },
|
|
1994
|
+
pastel: { colors: ["#74ebd5", "#74ecd5"], options: { interpolation: "hsv", hsvSpin: "long" } }
|
|
1995
|
+
};
|
|
1996
|
+
function gradientAlias(alias) {
|
|
1997
|
+
const result = (str) => gradient(...alias.colors)(str, alias.options);
|
|
1998
|
+
result.multiline = (str = "") => gradient(...alias.colors).multiline(str, alias.options);
|
|
1999
|
+
return result;
|
|
2000
|
+
}
|
|
2001
|
+
var dist_default2 = gradient;
|
|
2002
|
+
var atlas = gradientAlias(aliases.atlas);
|
|
2003
|
+
var cristal = gradientAlias(aliases.cristal);
|
|
2004
|
+
var teen = gradientAlias(aliases.teen);
|
|
2005
|
+
var mind = gradientAlias(aliases.mind);
|
|
2006
|
+
var morning = gradientAlias(aliases.morning);
|
|
2007
|
+
var vice = gradientAlias(aliases.vice);
|
|
2008
|
+
var passion = gradientAlias(aliases.passion);
|
|
2009
|
+
var fruit = gradientAlias(aliases.fruit);
|
|
2010
|
+
var instagram = gradientAlias(aliases.instagram);
|
|
2011
|
+
var retro = gradientAlias(aliases.retro);
|
|
2012
|
+
var summer = gradientAlias(aliases.summer);
|
|
2013
|
+
var rainbow = gradientAlias(aliases.rainbow);
|
|
2014
|
+
var pastel = gradientAlias(aliases.pastel);
|
|
2015
|
+
gradient.atlas = atlas;
|
|
2016
|
+
gradient.cristal = cristal;
|
|
2017
|
+
gradient.teen = teen;
|
|
2018
|
+
gradient.mind = mind;
|
|
2019
|
+
gradient.morning = morning;
|
|
2020
|
+
gradient.vice = vice;
|
|
2021
|
+
gradient.passion = passion;
|
|
2022
|
+
gradient.fruit = fruit;
|
|
2023
|
+
gradient.instagram = instagram;
|
|
2024
|
+
gradient.retro = retro;
|
|
2025
|
+
gradient.summer = summer;
|
|
2026
|
+
gradient.rainbow = rainbow;
|
|
2027
|
+
gradient.pastel = pastel;
|
|
2028
|
+
|
|
2029
|
+
// src/commands/dev.ts
|
|
2030
|
+
init_esm_shims();
|
|
2031
|
+
async function dev(options = {}) {
|
|
2032
|
+
const cwd = process.cwd();
|
|
2033
|
+
await CoreKit.startDev(cwd, options);
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
// src/commands/add.ts
|
|
2037
|
+
init_esm_shims();
|
|
2038
|
+
var import_fs_extra = __toESM(require_lib());
|
|
2039
|
+
var import_picocolors = __toESM(require_picocolors());
|
|
2040
|
+
var import_prompts = __toESM(require_prompts());
|
|
2041
|
+
var import_handlebars = __toESM(require_lib2());
|
|
2042
|
+
import path from "path";
|
|
2043
|
+
async function add(options) {
|
|
2044
|
+
let { name, type, displayName, description } = options;
|
|
2045
|
+
const cwd = process.cwd();
|
|
2046
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
2047
|
+
if (!import_fs_extra.default.existsSync(pkgPath)) {
|
|
2048
|
+
logger.error("\u672A\u627E\u5230 package.json\u3002\u8BF7\u5728 ChatBI-V \u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u8FD0\u884C\u6B64\u547D\u4EE4\u3002");
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
const pkg = await import_fs_extra.default.readJson(pkgPath);
|
|
2052
|
+
const isMonorepo = pkg.workspaces && (pkg.workspaces.includes("plugins/*") || pkg.workspaces.packages?.includes("plugins/*"));
|
|
2053
|
+
if (!isMonorepo) {
|
|
2054
|
+
logger.error("\u5F53\u524D\u4E0D\u662F Monorepo \u9879\u76EE\uFF0C\u65E0\u6CD5\u6DFB\u52A0\u63D2\u4EF6 (\u8BF7\u5728\u5305\u542B plugins/ \u5DE5\u4F5C\u7A7A\u95F4\u7684\u9879\u76EE\u4E2D\u8FD0\u884C)");
|
|
2055
|
+
process.exit(1);
|
|
2056
|
+
}
|
|
2057
|
+
const response = await (0, import_prompts.default)([
|
|
2058
|
+
{
|
|
2059
|
+
type: name ? null : "text",
|
|
2060
|
+
name: "pluginName",
|
|
2061
|
+
message: "\u8BF7\u8F93\u5165\u63D2\u4EF6\u540D\u79F0 (ID, \u5EFA\u8BAE\u5C0F\u5199\u548C\u4E2D\u5212\u7EBF):",
|
|
2062
|
+
initial: "my-custom-plugin",
|
|
2063
|
+
validate: (value) => /^[a-z0-9-]+$/.test(value) || "\u540D\u79F0\u53EA\u80FD\u5305\u542B\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u4E2D\u5212\u7EBF"
|
|
2064
|
+
},
|
|
2065
|
+
{
|
|
2066
|
+
type: displayName ? null : "text",
|
|
2067
|
+
name: "pluginDisplayName",
|
|
2068
|
+
message: "\u8BF7\u8F93\u5165\u63D2\u4EF6\u663E\u793A\u540D\u79F0 (\u4E2D\u6587):",
|
|
2069
|
+
initial: (prev) => prev || name
|
|
2070
|
+
},
|
|
2071
|
+
{
|
|
2072
|
+
type: description ? null : "text",
|
|
2073
|
+
name: "pluginDescription",
|
|
2074
|
+
message: "\u8BF7\u8F93\u5165\u63D2\u4EF6\u63CF\u8FF0:",
|
|
2075
|
+
initial: "\u4E00\u4E2A\u7B80\u5355\u7684 ChatBI-V \u63D2\u4EF6"
|
|
2076
|
+
},
|
|
2077
|
+
{
|
|
2078
|
+
type: type ? null : "select",
|
|
2079
|
+
name: "pluginType",
|
|
2080
|
+
message: "\u8BF7\u9009\u62E9\u63D2\u4EF6\u7C7B\u578B:",
|
|
2081
|
+
choices: [
|
|
2082
|
+
{ title: "Business (\u4E1A\u52A1\u63D2\u4EF6)", value: "business", description: "\u5305\u542B UI \u754C\u9762\u548C\u4E1A\u52A1\u903B\u8F91" },
|
|
2083
|
+
{ title: "System (\u7CFB\u7EDF\u63D2\u4EF6)", value: "system", description: "\u4FA7\u91CD\u4E8E\u5E95\u5C42\u80FD\u529B\u548C\u7CFB\u7EDF\u6269\u5C55" }
|
|
2084
|
+
],
|
|
2085
|
+
initial: 0
|
|
2086
|
+
}
|
|
2087
|
+
], {
|
|
2088
|
+
onCancel: () => {
|
|
2089
|
+
logger.warn("\u5DF2\u53D6\u6D88\u6DFB\u52A0\u63D2\u4EF6");
|
|
2090
|
+
process.exit(0);
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
name = name || response.pluginName;
|
|
2094
|
+
type = type || response.pluginType;
|
|
2095
|
+
displayName = displayName || response.pluginDisplayName || name;
|
|
2096
|
+
description = description || response.pluginDescription || "";
|
|
2097
|
+
let cleanName = name;
|
|
2098
|
+
if (cleanName.endsWith("-plugin")) {
|
|
2099
|
+
cleanName = cleanName.replace(/-plugin$/, "");
|
|
2100
|
+
}
|
|
2101
|
+
const folderName = cleanName.startsWith("plugin-") ? cleanName : `plugin-${cleanName}`;
|
|
2102
|
+
const pluginDir = path.resolve(cwd, "plugins", folderName);
|
|
2103
|
+
if (import_fs_extra.default.existsSync(pluginDir)) {
|
|
2104
|
+
logger.error(`\u63D2\u4EF6\u76EE\u5F55 ${folderName} \u5DF2\u5B58\u5728\u3002`);
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
const spinner = createSpinner(`\u6B63\u5728\u6DFB\u52A0\u65B0\u63D2\u4EF6: ${import_picocolors.default.bold(name)}...`).start();
|
|
2108
|
+
const myCliRoot = await getCliRoot();
|
|
2109
|
+
const templateDir = path.join(myCliRoot, "templates/plugin");
|
|
2110
|
+
if (!import_fs_extra.default.existsSync(templateDir)) {
|
|
2111
|
+
spinner.fail("\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F");
|
|
2112
|
+
throw new Error(`\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F: ${templateDir}`);
|
|
2113
|
+
}
|
|
2114
|
+
const targetDir = pluginDir;
|
|
2115
|
+
spinner.text = "\u6B63\u5728\u52A0\u8F7D\u914D\u7F6E...";
|
|
2116
|
+
const config = await ConfigManager.loadConfig(cwd);
|
|
2117
|
+
const coreSource = config.coreSource || "local";
|
|
2118
|
+
let corePath = "file:../../.chatbi/core";
|
|
2119
|
+
if (coreSource === "npm") {
|
|
2120
|
+
if (!config.coreVersion) {
|
|
2121
|
+
const cliPkg = await import_fs_extra.default.readJson(path.join(myCliRoot, "package.json"));
|
|
2122
|
+
corePath = cliPkg.version;
|
|
2123
|
+
} else {
|
|
2124
|
+
corePath = config.coreVersion;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
const data = {
|
|
2128
|
+
// 兼容旧模板
|
|
2129
|
+
name: `@chatbi-v/${folderName}`,
|
|
2130
|
+
pluginId: cleanName,
|
|
2131
|
+
pluginType: type,
|
|
2132
|
+
className: cleanName.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(""),
|
|
2133
|
+
isBusiness: type === "business",
|
|
2134
|
+
corePath,
|
|
2135
|
+
// 新模板变量
|
|
2136
|
+
pluginName: cleanName,
|
|
2137
|
+
pluginPackageName: `@chatbi-v/${folderName}`,
|
|
2138
|
+
pluginVersion: "0.1.0",
|
|
2139
|
+
pluginDisplayName: displayName,
|
|
2140
|
+
pluginDescription: description,
|
|
2141
|
+
pluginClassName: cleanName.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(""),
|
|
2142
|
+
pluginPath: folderName,
|
|
2143
|
+
pluginFolderName: folderName,
|
|
2144
|
+
// Fix: 注入 tsconfigPath,确保 tsconfig.json 能正确 extend
|
|
2145
|
+
tsconfigPath: "../../.chatbi/tsconfig.json"
|
|
2146
|
+
};
|
|
2147
|
+
const renderFile = async (src, dest) => {
|
|
2148
|
+
const content = await import_fs_extra.default.readFile(src, "utf-8");
|
|
2149
|
+
let result = content;
|
|
2150
|
+
const hasHandlebarsVars = content.includes("{{");
|
|
2151
|
+
if (hasHandlebarsVars) {
|
|
2152
|
+
try {
|
|
2153
|
+
const safeContent = content.replace(/\{\{(?!\s*([#/]?(?:if|else|each|with|unless|name|version|projectName|projectTitle|projectVersion|cliVersion|tsconfigPath|theme|isNebula|isGlass|isBusiness|isApp|isShell|pluginName|pluginPackageName|pluginVersion|pluginDisplayName|pluginDescription|pluginClassName|pluginPath|pluginFolderName|pluginType|pluginId|className))\b)/g, "\\{{");
|
|
2154
|
+
const templateFn = import_handlebars.default.compile(safeContent);
|
|
2155
|
+
result = templateFn(data);
|
|
2156
|
+
} catch (e) {
|
|
2157
|
+
result = content;
|
|
2158
|
+
for (const [key, val] of Object.entries(data)) {
|
|
2159
|
+
const regex = new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}`, "g");
|
|
2160
|
+
result = result.replace(regex, String(val));
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
await import_fs_extra.default.outputFile(dest.replace(".hbs", ""), result);
|
|
2165
|
+
};
|
|
2166
|
+
const processTemplates = async (currentSrc, currentDest) => {
|
|
2167
|
+
const files = await import_fs_extra.default.readdir(currentSrc);
|
|
2168
|
+
for (const file of files) {
|
|
2169
|
+
const srcPath = path.join(currentSrc, file);
|
|
2170
|
+
const destPath = path.join(currentDest, file);
|
|
2171
|
+
const stats = await import_fs_extra.default.stat(srcPath);
|
|
2172
|
+
if (stats.isDirectory()) {
|
|
2173
|
+
await import_fs_extra.default.ensureDir(destPath);
|
|
2174
|
+
await processTemplates(srcPath, destPath);
|
|
2175
|
+
} else if (file.endsWith(".hbs")) {
|
|
2176
|
+
await renderFile(srcPath, destPath);
|
|
2177
|
+
} else {
|
|
2178
|
+
await import_fs_extra.default.copy(srcPath, destPath);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
};
|
|
2182
|
+
spinner.text = "\u6B63\u5728\u751F\u6210\u63D2\u4EF6\u6587\u4EF6...";
|
|
2183
|
+
await processTemplates(templateDir, targetDir);
|
|
2184
|
+
spinner.succeed(`\u63D2\u4EF6 ${import_picocolors.default.bold(name)} \u6DFB\u52A0\u6210\u529F\uFF01`);
|
|
2185
|
+
printBox(
|
|
2186
|
+
`${import_picocolors.default.green(import_picocolors.default.bold("\u2728 \u63D2\u4EF6\u521B\u5EFA\u6210\u529F!"))}
|
|
2187
|
+
|
|
2188
|
+
${import_picocolors.default.white("\u9879\u76EE\u8DEF\u5F84: ")} ${import_picocolors.default.cyan(`plugins/${folderName}`)}
|
|
2189
|
+
${import_picocolors.default.white("\u63D2\u4EF6 ID: ")} ${import_picocolors.default.cyan(cleanName)}
|
|
2190
|
+
${import_picocolors.default.white("\u63D2\u4EF6\u7C7B\u578B: ")} ${import_picocolors.default.cyan(type)}
|
|
2191
|
+
|
|
2192
|
+
${import_picocolors.default.white("\u63A5\u4E0B\u6765\u4F60\u53EF\u4EE5:")}
|
|
2193
|
+
${import_picocolors.default.cyan(" pnpm dev")} \u542F\u52A8\u5F00\u53D1\u73AF\u5883\u67E5\u770B\u6548\u679C`,
|
|
2194
|
+
"Plugin Created"
|
|
2195
|
+
);
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
// src/commands/gl.ts
|
|
2199
|
+
init_esm_shims();
|
|
2200
|
+
var import_fs_extra2 = __toESM(require_lib());
|
|
2201
|
+
var import_picocolors2 = __toESM(require_picocolors());
|
|
2202
|
+
var import_prompts2 = __toESM(require_prompts());
|
|
2203
|
+
import path2 from "path";
|
|
2204
|
+
async function gl(options) {
|
|
2205
|
+
const { type: initialType, prompt: initialPrompt } = options;
|
|
2206
|
+
const cwd = process.cwd();
|
|
2207
|
+
const pkgPath = path2.join(cwd, "package.json");
|
|
2208
|
+
if (!import_fs_extra2.default.existsSync(pkgPath)) {
|
|
2209
|
+
logger.error("\u672A\u627E\u5230 package.json\u3002\u8BF7\u5728 ChatBI-V \u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u8FD0\u884C\u6B64\u547D\u4EE4\u3002");
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
const response = await (0, import_prompts2.default)([
|
|
2213
|
+
{
|
|
2214
|
+
type: initialType ? null : "select",
|
|
2215
|
+
name: "genType",
|
|
2216
|
+
message: "\u8BF7\u9009\u62E9 AI \u811A\u624B\u67B6\u6307\u4EE4:",
|
|
2217
|
+
choices: [
|
|
2218
|
+
{ title: "\u{1F916} smart", value: "smart", description: "\u667A\u80FD\u51B3\u7B56 (\u6839\u636E\u9700\u6C42\u81EA\u52A8\u9009\u62E9\u5DE5\u5177)" },
|
|
2219
|
+
{ title: "\u{1F50C} plugin", value: "plugin", description: "\u751F\u6210\u65B0\u63D2\u4EF6" },
|
|
2220
|
+
{ title: "\u{1F9E9} component", value: "component", description: "\u751F\u6210\u4E1A\u52A1\u7EC4\u4EF6" },
|
|
2221
|
+
{ title: "\u{1F4E1} api", value: "api", description: "\u751F\u6210 API \u5B9A\u4E49\u4E0E\u8BF7\u6C42\u51FD\u6570" },
|
|
2222
|
+
{ title: "\u{1F3AD} mock", value: "mock", description: "\u751F\u6210 Mock \u6D4B\u8BD5\u6570\u636E" },
|
|
2223
|
+
{ title: "\u{1F6E0}\uFE0F util", value: "util", description: "\u751F\u6210\u5DE5\u5177\u51FD\u6570" },
|
|
2224
|
+
{ title: "\u{1F4C4} doc", value: "doc", description: "\u751F\u6210\u9879\u76EE\u6587\u6863" },
|
|
2225
|
+
{ title: "\u2728 chat", value: "chat", description: "\u81EA\u7531\u5BF9\u8BDD" }
|
|
2226
|
+
],
|
|
2227
|
+
initial: 0
|
|
2228
|
+
},
|
|
2229
|
+
{
|
|
2230
|
+
type: (prev, values) => initialPrompt || values.genType === "chat" ? null : "text",
|
|
2231
|
+
name: "userPrompt",
|
|
2232
|
+
message: "\u8BF7\u8F93\u5165\u8BE6\u7EC6\u9700\u6C42\u63CF\u8FF0:",
|
|
2233
|
+
initial: initialPrompt || ""
|
|
2234
|
+
}
|
|
2235
|
+
], {
|
|
2236
|
+
onCancel: () => {
|
|
2237
|
+
logger.warn("\u5DF2\u53D6\u6D88 AI \u751F\u6210");
|
|
2238
|
+
process.exit(0);
|
|
2239
|
+
}
|
|
2240
|
+
});
|
|
2241
|
+
const genType = initialType || response.genType;
|
|
2242
|
+
const userPrompt = initialPrompt || response.userPrompt;
|
|
2243
|
+
if (!userPrompt && genType !== "chat") {
|
|
2244
|
+
logger.error("\u9700\u6C42\u63CF\u8FF0\u4E0D\u80FD\u4E3A\u7A7A\u3002");
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
logger.info(`\u6B63\u5728\u547C\u53EB AI \u5F15\u64CE [\u6A21\u5F0F: ${import_picocolors2.default.bold(genType)}]...`);
|
|
2248
|
+
const toolsContext = `
|
|
2249
|
+
[Available Tools & Capabilities]
|
|
2250
|
+
- Tool: plugin -> For creating new feature modules. Requires: name, type (business|system).
|
|
2251
|
+
- Tool: component -> For UI elements. Tech: AntD5, Tailwind.
|
|
2252
|
+
- Tool: api -> For network requests. Structure: src/api/[name].ts, uses shared request util, defines TS interfaces.
|
|
2253
|
+
- Tool: mock -> For dev data. Structure: mock/[name].ts, follows Mock.js or MSW format.
|
|
2254
|
+
- Tool: util -> For pure functions. Structure: src/utils/[name].ts, requires unit tests.
|
|
2255
|
+
- Tool: doc -> For documentation. Format: Markdown, structure: docs/[type]/[name].md.
|
|
2256
|
+
|
|
2257
|
+
[Tool Functions Implementation Details]
|
|
2258
|
+
- API Function: Should include request method, URL, params/data types, and response type. Use '@chatbi-v/core/request'.
|
|
2259
|
+
- Mock Function: Should provide realistic data based on API definition.
|
|
2260
|
+
- Plugin Function: Should follow the Micro-Kernel architecture, registering to 'pluginManager'.
|
|
2261
|
+
|
|
2262
|
+
[Requirement Slots / Missing Info]
|
|
2263
|
+
If the user's request is ambiguous or missing key information, you MUST output: "SLOT_REQUIRED: [Field Name] | [Question to User]".
|
|
2264
|
+
`.trim();
|
|
2265
|
+
const templatesContext = `
|
|
2266
|
+
[Project Templates Structure]
|
|
2267
|
+
- Plugin: class extends Plugin, metadata: { id, name, version, type, routes, extensions }.
|
|
2268
|
+
- API: export const fetchData = (params: T) => request.get<R>('/url', { params }).
|
|
2269
|
+
- Mock: export default { 'GET /api/test': { code: 200, data: {} } }.
|
|
2270
|
+
- UI: React 18, Ant Design 5, Tailwind CSS 3.
|
|
2271
|
+
`.trim();
|
|
2272
|
+
const systemContext = `[Context: ChatBI-V System | Dir: ${cwd} | Tech: React18, AntD5, Tailwind, Micro-Kernel]
|
|
2273
|
+
${toolsContext}
|
|
2274
|
+
${templatesContext}
|
|
2275
|
+
|
|
2276
|
+
[Decision Logic]
|
|
2277
|
+
If genType is 'smart', you must first decide which tool is most appropriate.
|
|
2278
|
+
If the requirement is clear, proceed with generation.
|
|
2279
|
+
If not, use the SLOT_REQUIRED format.`.trim();
|
|
2280
|
+
const finalPrompt = userPrompt ? `${systemContext}
|
|
2281
|
+
|
|
2282
|
+
[User Request]: ${userPrompt}` : systemContext;
|
|
2283
|
+
const geminiCmd = genType === "smart" ? "chat" : genType;
|
|
2284
|
+
const spinner = createSpinner("AI \u5F15\u64CE\u6B63\u5728\u601D\u8003\u4E2D... (\u53EF\u80FD\u9700\u8981\u51E0\u5341\u79D2\uFF0C\u8BF7\u8010\u5FC3\u7B49\u5F85)");
|
|
2285
|
+
let currentPrompt = finalPrompt;
|
|
2286
|
+
let retry = true;
|
|
2287
|
+
while (retry) {
|
|
2288
|
+
spinner.start();
|
|
2289
|
+
try {
|
|
2290
|
+
const { stdout } = await execa("gemini", [geminiCmd, currentPrompt], {
|
|
2291
|
+
stdio: "pipe"
|
|
2292
|
+
});
|
|
2293
|
+
spinner.stop();
|
|
2294
|
+
if (stdout.includes("SLOT_REQUIRED:")) {
|
|
2295
|
+
const slots = [];
|
|
2296
|
+
const lines = stdout.split("\n");
|
|
2297
|
+
for (const line of lines) {
|
|
2298
|
+
if (line.includes("SLOT_REQUIRED:")) {
|
|
2299
|
+
const match = line.match(/SLOT_REQUIRED:\s*([^|]+)\|\s*(.+)/);
|
|
2300
|
+
if (match) {
|
|
2301
|
+
slots.push({
|
|
2302
|
+
type: "text",
|
|
2303
|
+
name: match[1].trim(),
|
|
2304
|
+
message: match[2].trim()
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
if (slots.length > 0) {
|
|
2310
|
+
logger.info(import_picocolors2.default.yellow("\n\u{1F4DD} AI \u9700\u8981\u66F4\u591A\u4FE1\u606F\u4EE5\u7EE7\u7EED:"));
|
|
2311
|
+
const answers = await (0, import_prompts2.default)(slots, {
|
|
2312
|
+
onCancel: () => process.exit(0)
|
|
2313
|
+
});
|
|
2314
|
+
const answerContext = Object.entries(answers).map(([k, v]) => `[${k}]: ${v}`).join("\n");
|
|
2315
|
+
currentPrompt += `
|
|
2316
|
+
|
|
2317
|
+
[User Answers]:
|
|
2318
|
+
${answerContext}
|
|
2319
|
+
|
|
2320
|
+
Please proceed with generation based on these answers.`;
|
|
2321
|
+
logger.info("\u6B63\u5728\u6839\u636E\u60A8\u7684\u53CD\u9988\u91CD\u65B0\u547C\u53EB AI...");
|
|
2322
|
+
continue;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
console.log("\n" + stdout);
|
|
2326
|
+
retry = false;
|
|
2327
|
+
logger.success(`AI \u547D\u4EE4 [gemini ${geminiCmd}] \u6267\u884C\u5B8C\u6BD5!`);
|
|
2328
|
+
} catch (error) {
|
|
2329
|
+
spinner.stop();
|
|
2330
|
+
if (error.code === "ENOENT") {
|
|
2331
|
+
logger.error("\u672A\u5728\u7CFB\u7EDF\u4E2D\u627E\u5230 `gemini-cli` \u547D\u4EE4\u3002");
|
|
2332
|
+
logger.info(import_picocolors2.default.yellow("\u8BF7\u786E\u4FDD\u5DF2\u5B89\u88C5 gemini-cli \u5E76\u5C06\u5176\u6DFB\u52A0\u5230\u7CFB\u7EDF PATH \u4E2D\u3002"));
|
|
2333
|
+
} else {
|
|
2334
|
+
logger.error(`AI \u751F\u6210\u8FC7\u7A0B\u4E2D\u51FA\u9519: ${error.message}`);
|
|
2335
|
+
}
|
|
2336
|
+
throw error;
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
// src/commands/doctor.ts
|
|
2342
|
+
init_esm_shims();
|
|
2343
|
+
var import_fs_extra3 = __toESM(require_lib());
|
|
2344
|
+
var import_picocolors3 = __toESM(require_picocolors());
|
|
2345
|
+
import path3 from "path";
|
|
2346
|
+
import glob from "fast-glob";
|
|
2347
|
+
async function doctor(options = {}) {
|
|
2348
|
+
logger.info("\u6B63\u5728\u8BCA\u65AD\u9879\u76EE\u5065\u5EB7\u72B6\u51B5...\n");
|
|
2349
|
+
const cwd = process.cwd();
|
|
2350
|
+
let hasIssues = false;
|
|
2351
|
+
const issues = [];
|
|
2352
|
+
logger.info(import_picocolors3.default.bold("Step 1: \u68C0\u67E5\u57FA\u7840\u73AF\u5883..."));
|
|
2353
|
+
const nodeVersion = process.version;
|
|
2354
|
+
if (parseInt(nodeVersion.slice(1).split(".")[0]) < 18) {
|
|
2355
|
+
logger.error(`Node.js \u7248\u672C\u592A\u4F4E: ${nodeVersion} (\u8981\u6C42 >=18)`);
|
|
2356
|
+
hasIssues = true;
|
|
2357
|
+
issues.push(`Node.js \u7248\u672C\u8FC7\u4F4E (${nodeVersion})`);
|
|
2358
|
+
} else {
|
|
2359
|
+
logger.success(`Node.js \u7248\u672C: ${nodeVersion}`);
|
|
2360
|
+
}
|
|
2361
|
+
try {
|
|
2362
|
+
const { execa: execa2 } = await import("./execa-METROS6Z.mjs");
|
|
2363
|
+
const { stdout: pnpmVer } = await execa2("pnpm", ["-v"]);
|
|
2364
|
+
logger.success(`pnpm \u7248\u672C: ${pnpmVer}`);
|
|
2365
|
+
} catch (e) {
|
|
2366
|
+
logger.warn("\u672A\u68C0\u6D4B\u5230 pnpm\uFF0C\u5EFA\u8BAE\u5B89\u88C5\u4EE5\u83B7\u5F97\u6700\u4F73\u4F53\u9A8C");
|
|
2367
|
+
}
|
|
2368
|
+
logger.info(import_picocolors3.default.bold("\nStep 2: \u68C0\u67E5\u5185\u6838\u6C99\u7BB1\u73AF\u5883..."));
|
|
2369
|
+
const version = await CoreKit.resolveVersion(cwd);
|
|
2370
|
+
const versionPath = Sandbox.getVersionPath(version);
|
|
2371
|
+
if (!import_fs_extra3.default.existsSync(versionPath)) {
|
|
2372
|
+
logger.error(`\u5185\u6838\u6C99\u7BB1\u7248\u672C ${version} \u5C1A\u672A\u5B89\u88C5`);
|
|
2373
|
+
console.log(import_picocolors3.default.gray(` \u5EFA\u8BAE\u8FD0\u884C 'chatbi sync' \u6216 'chatbi use ${version}' \u8FDB\u884C\u5B89\u88C5\u3002`));
|
|
2374
|
+
hasIssues = true;
|
|
2375
|
+
issues.push(`\u5185\u6838\u6C99\u7BB1\u672A\u5B89\u88C5 (${version})`);
|
|
2376
|
+
} else {
|
|
2377
|
+
logger.success(`\u5185\u6838\u6C99\u7BB1\u5C31\u7EEA (\u7248\u672C: ${version})`);
|
|
2378
|
+
const sandboxNm = path3.join(versionPath, "node_modules");
|
|
2379
|
+
if (!import_fs_extra3.default.existsSync(sandboxNm)) {
|
|
2380
|
+
logger.warn("\u6C99\u7BB1\u4F9D\u8D56\u672A\u5B89\u88C5\uFF0C\u5C06\u5BFC\u81F4\u6784\u5EFA\u5931\u8D25");
|
|
2381
|
+
hasIssues = true;
|
|
2382
|
+
issues.push("\u6C99\u7BB1\u4F9D\u8D56\u7F3A\u5931");
|
|
2383
|
+
}
|
|
2384
|
+
const missingDeps = [];
|
|
2385
|
+
for (const dep of Sandbox.CORE_PACKAGES) {
|
|
2386
|
+
if (!import_fs_extra3.default.existsSync(path3.join(sandboxNm, dep))) {
|
|
2387
|
+
missingDeps.push(dep);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
if (missingDeps.length > 0) {
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
logger.info(import_picocolors3.default.bold("\nStep 3: \u68C0\u67E5\u865A\u62DF\u4F9D\u8D56\u6620\u5C04..."));
|
|
2394
|
+
const chatbiDir = path3.join(cwd, ".chatbi");
|
|
2395
|
+
if (!import_fs_extra3.default.existsSync(chatbiDir)) {
|
|
2396
|
+
logger.warn("\u672A\u53D1\u73B0\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E (.chatbi \u76EE\u5F55)");
|
|
2397
|
+
hasIssues = true;
|
|
2398
|
+
issues.push("\u7F3A\u5931 .chatbi \u76EE\u5F55");
|
|
2399
|
+
} else {
|
|
2400
|
+
const pathsJson = path3.join(chatbiDir, "tsconfig.paths.json");
|
|
2401
|
+
const aliasJson = path3.join(chatbiDir, "vite.alias.json");
|
|
2402
|
+
if (!import_fs_extra3.default.existsSync(pathsJson) || !import_fs_extra3.default.existsSync(aliasJson)) {
|
|
2403
|
+
logger.warn("\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B8C\u6574");
|
|
2404
|
+
hasIssues = true;
|
|
2405
|
+
issues.push("\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E\u4E0D\u5B8C\u6574");
|
|
2406
|
+
} else {
|
|
2407
|
+
logger.success("\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E\u5DF2\u751F\u6210");
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
const tsConfigPath = path3.join(cwd, "tsconfig.json");
|
|
2411
|
+
if (import_fs_extra3.default.existsSync(tsConfigPath)) {
|
|
2412
|
+
try {
|
|
2413
|
+
const tsConfig = await import_fs_extra3.default.readJson(tsConfigPath);
|
|
2414
|
+
const extendsPath = tsConfig.extends;
|
|
2415
|
+
const expectedPaths = ["./.chatbi/tsconfig.paths.json", ".chatbi/tsconfig.paths.json"];
|
|
2416
|
+
let hasExtend = false;
|
|
2417
|
+
if (typeof extendsPath === "string") {
|
|
2418
|
+
hasExtend = expectedPaths.includes(extendsPath);
|
|
2419
|
+
} else if (Array.isArray(extendsPath)) {
|
|
2420
|
+
hasExtend = extendsPath.some((p) => expectedPaths.includes(p));
|
|
2421
|
+
}
|
|
2422
|
+
if (!hasExtend) {
|
|
2423
|
+
logger.warn("tsconfig.json \u672A\u7EE7\u627F\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E");
|
|
2424
|
+
hasIssues = true;
|
|
2425
|
+
issues.push("tsconfig.json \u914D\u7F6E\u7F3A\u5931");
|
|
2426
|
+
} else {
|
|
2427
|
+
logger.success("tsconfig.json \u914D\u7F6E\u6B63\u5E38");
|
|
2428
|
+
}
|
|
2429
|
+
} catch (e) {
|
|
2430
|
+
logger.error("\u89E3\u6790 tsconfig.json \u5931\u8D25");
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
const viteConfigPath = path3.join(cwd, "vite.config.ts");
|
|
2434
|
+
if (import_fs_extra3.default.existsSync(viteConfigPath)) {
|
|
2435
|
+
const content = await import_fs_extra3.default.readFile(viteConfigPath, "utf-8");
|
|
2436
|
+
if (!content.includes("vite.alias.json")) {
|
|
2437
|
+
logger.warn("vite.config.ts \u53EF\u80FD\u672A\u52A0\u8F7D\u865A\u62DF\u522B\u540D\u914D\u7F6E");
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
logger.info(import_picocolors3.default.bold("\nStep 4: \u626B\u63CF\u4EE3\u7801\u89C4\u5219..."));
|
|
2441
|
+
const rules = [
|
|
2442
|
+
{
|
|
2443
|
+
id: "plugin-lifecycle-init",
|
|
2444
|
+
description: "\u63D2\u4EF6\u751F\u547D\u5468\u671F init() \u5DF2\u53D8\u66F4\u4E3A onLoad()",
|
|
2445
|
+
pattern: /async\s+init\s*\(\s*context\s*:\s*PluginContext\s*\)/g,
|
|
2446
|
+
fix: (content) => content.replace(/async\s+init\s*\(\s*context\s*:\s*PluginContext\s*\)/g, "async onLoad(context: PluginContext)")
|
|
2447
|
+
},
|
|
2448
|
+
{
|
|
2449
|
+
id: "plugin-lifecycle-destroy",
|
|
2450
|
+
description: "\u63D2\u4EF6\u751F\u547D\u5468\u671F destroy() \u5DF2\u53D8\u66F4\u4E3A onUnload()",
|
|
2451
|
+
pattern: /async\s+destroy\s*\(\s*\)/g,
|
|
2452
|
+
fix: (content) => content.replace(/async\s+destroy\s*\(\s*\)/g, "async onUnload()")
|
|
2453
|
+
}
|
|
2454
|
+
];
|
|
2455
|
+
const files = await glob(["src/**/*.{ts,tsx}"], { cwd, absolute: true });
|
|
2456
|
+
const codeIssues = [];
|
|
2457
|
+
if (files.length > 0) {
|
|
2458
|
+
const scanSpinner = createSpinner(`\u6B63\u5728\u626B\u63CF ${files.length} \u4E2A\u6587\u4EF6...`).start();
|
|
2459
|
+
for (const file of files) {
|
|
2460
|
+
const content = await import_fs_extra3.default.readFile(file, "utf-8");
|
|
2461
|
+
for (const rule of rules) {
|
|
2462
|
+
if (rule.pattern.test(content)) {
|
|
2463
|
+
codeIssues.push({
|
|
2464
|
+
file,
|
|
2465
|
+
ruleId: rule.id,
|
|
2466
|
+
description: rule.description,
|
|
2467
|
+
rule
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
if (codeIssues.length > 0) {
|
|
2473
|
+
scanSpinner.fail(`\u53D1\u73B0 ${codeIssues.length} \u4E2A\u4EE3\u7801\u89C4\u8303\u95EE\u9898`);
|
|
2474
|
+
hasIssues = true;
|
|
2475
|
+
codeIssues.forEach((issue) => {
|
|
2476
|
+
const relativePath = path3.relative(cwd, issue.file);
|
|
2477
|
+
issues.push(`\u4EE3\u7801\u89C4\u8303 [${issue.ruleId}]: ${relativePath}`);
|
|
2478
|
+
});
|
|
2479
|
+
} else {
|
|
2480
|
+
scanSpinner.succeed("\u4EE3\u7801\u89C4\u8303\u68C0\u67E5\u901A\u8FC7");
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
if (!hasIssues) {
|
|
2484
|
+
printBox(
|
|
2485
|
+
import_picocolors3.default.green(import_picocolors3.default.bold("\u2728 \u8BCA\u65AD\u5B8C\u6210\uFF1A\u9879\u76EE\u4E00\u5207\u6B63\u5E38\uFF01")),
|
|
2486
|
+
"Doctor Report"
|
|
2487
|
+
);
|
|
2488
|
+
} else {
|
|
2489
|
+
const issueList = issues.map((i) => import_picocolors3.default.red(`\u2022 ${i}`)).join("\n");
|
|
2490
|
+
printBox(
|
|
2491
|
+
`${import_picocolors3.default.yellow(import_picocolors3.default.bold("\u26A0\uFE0F \u8BCA\u65AD\u5B8C\u6210\uFF1A\u53D1\u73B0\u4EE5\u4E0B\u95EE\u9898"))}
|
|
2492
|
+
|
|
2493
|
+
${issueList}
|
|
2494
|
+
|
|
2495
|
+
${import_picocolors3.default.cyan("\u5EFA\u8BAE\u6839\u636E\u63D0\u793A\u8FDB\u884C\u4FEE\u590D")}`,
|
|
2496
|
+
"Doctor Report"
|
|
2497
|
+
);
|
|
2498
|
+
if (options.fix) {
|
|
2499
|
+
if (codeIssues.length > 0) {
|
|
2500
|
+
const fixSpinner = createSpinner("\u6B63\u5728\u4FEE\u590D\u4EE3\u7801\u89C4\u8303\u95EE\u9898...").start();
|
|
2501
|
+
for (const issue of codeIssues) {
|
|
2502
|
+
const content = await import_fs_extra3.default.readFile(issue.file, "utf-8");
|
|
2503
|
+
const newContent = issue.rule.fix(content);
|
|
2504
|
+
await import_fs_extra3.default.writeFile(issue.file, newContent);
|
|
2505
|
+
}
|
|
2506
|
+
fixSpinner.succeed("\u4EE3\u7801\u4FEE\u590D\u5B8C\u6210");
|
|
2507
|
+
}
|
|
2508
|
+
logger.info("\u6B63\u5728\u4FEE\u590D\u73AF\u5883\u914D\u7F6E...");
|
|
2509
|
+
const { sync: sync2 } = await import("./sync-7HPKGVFY.mjs");
|
|
2510
|
+
await sync2({ force: true });
|
|
2511
|
+
logger.success("\u81EA\u52A8\u4FEE\u590D\u5B8C\u6210\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C\u8BCA\u65AD\u3002");
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
// src/commands/discover.ts
|
|
2517
|
+
init_esm_shims();
|
|
2518
|
+
var import_picocolors4 = __toESM(require_picocolors());
|
|
2519
|
+
async function discover() {
|
|
2520
|
+
const cwd = process.cwd();
|
|
2521
|
+
const spinner = createSpinner("\u6B63\u5728\u626B\u63CF\u9879\u76EE\u4E2D\u7684\u63D2\u4EF6...").start();
|
|
2522
|
+
const plugins = await CoreKit.discoverPlugins(cwd);
|
|
2523
|
+
if (plugins.length === 0) {
|
|
2524
|
+
spinner.warn("\u672A\u53D1\u73B0\u4EFB\u4F55\u63D2\u4EF6");
|
|
2525
|
+
logger.info(import_picocolors4.default.gray("\u8BF7\u786E\u4FDD\u63D2\u4EF6\u4F4D\u4E8E plugins/ \u76EE\u5F55\u4E0B\uFF0C\u4E14\u5305\u542B package.json\u3002"));
|
|
2526
|
+
} else {
|
|
2527
|
+
spinner.succeed(`\u53D1\u73B0\u4E86 ${import_picocolors4.default.cyan(plugins.length)} \u4E2A\u63D2\u4EF6`);
|
|
2528
|
+
const pluginList = plugins.map((p) => `- ${import_picocolors4.default.bold(p.name)} ${import_picocolors4.default.gray(`(${p.id})`)}
|
|
2529
|
+
${import_picocolors4.default.gray(p.path)}`).join("\n\n");
|
|
2530
|
+
printBox(
|
|
2531
|
+
`${import_picocolors4.default.green(import_picocolors4.default.bold("\u2728 \u63D2\u4EF6\u626B\u63CF\u7ED3\u679C"))}
|
|
2532
|
+
|
|
2533
|
+
${pluginList}`,
|
|
2534
|
+
"Plugin Discovery"
|
|
2535
|
+
);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
// src/commands/ls.ts
|
|
2540
|
+
init_esm_shims();
|
|
2541
|
+
var import_picocolors5 = __toESM(require_picocolors());
|
|
2542
|
+
async function ls() {
|
|
2543
|
+
const versions = await CoreKit.listVersions();
|
|
2544
|
+
const currentVersion = await CoreKit.resolveVersion(process.cwd());
|
|
2545
|
+
const globalCurrentVersion = await CoreKit.resolveVersion();
|
|
2546
|
+
logger.info("\u5DF2\u5B89\u88C5\u7684\u5185\u6838\u6C99\u7BB1\u7248\u672C:");
|
|
2547
|
+
if (versions.length === 0) {
|
|
2548
|
+
logger.warn("\u5C1A\u672A\u5B89\u88C5\u4EFB\u4F55\u7248\u672C\uFF0C\u8BF7\u8FD0\u884C chatbi sync \u8FDB\u884C\u5B89\u88C5\u3002");
|
|
2549
|
+
} else {
|
|
2550
|
+
const list = versions.map((v) => {
|
|
2551
|
+
const isGlobalCurrent = v === globalCurrentVersion;
|
|
2552
|
+
const isProjectCurrent = v === currentVersion;
|
|
2553
|
+
let prefix = " ";
|
|
2554
|
+
if (isProjectCurrent) {
|
|
2555
|
+
prefix = import_picocolors5.default.green(" *");
|
|
2556
|
+
} else if (isGlobalCurrent) {
|
|
2557
|
+
prefix = import_picocolors5.default.blue(" >");
|
|
2558
|
+
}
|
|
2559
|
+
let suffix = "";
|
|
2560
|
+
if (isProjectCurrent && isGlobalCurrent) {
|
|
2561
|
+
suffix = import_picocolors5.default.gray(" (\u5F53\u524D\u9879\u76EE & \u5168\u5C40)");
|
|
2562
|
+
} else if (isProjectCurrent) {
|
|
2563
|
+
suffix = import_picocolors5.default.gray(" (\u5F53\u524D\u9879\u76EE)");
|
|
2564
|
+
} else if (isGlobalCurrent) {
|
|
2565
|
+
suffix = import_picocolors5.default.gray(" (\u5168\u5C40)");
|
|
2566
|
+
}
|
|
2567
|
+
return `${prefix} ${import_picocolors5.default.white(v)}${suffix}`;
|
|
2568
|
+
}).join("\n");
|
|
2569
|
+
printBox(
|
|
2570
|
+
list + import_picocolors5.default.gray("\n\n\u63D0\u793A: * \u5F53\u524D\u9879\u76EE\u4F7F\u7528, > \u5168\u5C40\u9ED8\u8BA4\u4F7F\u7528"),
|
|
2571
|
+
"Kernel Versions"
|
|
2572
|
+
);
|
|
2573
|
+
}
|
|
2574
|
+
await Sandbox.visualizeStatus(process.cwd());
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
// src/commands/use.ts
|
|
2578
|
+
init_esm_shims();
|
|
2579
|
+
var import_fs_extra4 = __toESM(require_lib());
|
|
2580
|
+
import path4 from "path";
|
|
2581
|
+
async function use(version, options = {}) {
|
|
2582
|
+
const versions = await CoreKit.listVersions();
|
|
2583
|
+
if (!versions.includes(version)) {
|
|
2584
|
+
logger.warn(`\u7248\u672C ${version} \u5C1A\u672A\u5B89\u88C5\uFF0C\u6B63\u5728\u5C1D\u8BD5\u5B89\u88C5...`);
|
|
2585
|
+
await Sandbox.prepare(version);
|
|
2586
|
+
}
|
|
2587
|
+
if (options.global) {
|
|
2588
|
+
await Sandbox.useVersion(version);
|
|
2589
|
+
logger.success(`\u5DF2\u5207\u6362\u5168\u5C40\u5185\u6838\u7248\u672C\u81F3: ${version}`);
|
|
2590
|
+
} else {
|
|
2591
|
+
const cwd = process.cwd();
|
|
2592
|
+
const versionFilePath = path4.join(cwd, ".chatbi-version");
|
|
2593
|
+
await import_fs_extra4.default.writeFile(versionFilePath, version, "utf-8");
|
|
2594
|
+
logger.success(`\u5DF2\u5207\u6362\u5F53\u524D\u9879\u76EE\u5185\u6838\u7248\u672C\u4E3A: ${version}`);
|
|
2595
|
+
}
|
|
2596
|
+
await sync({ version, force: false });
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
// src/commands/install.ts
|
|
2600
|
+
init_esm_shims();
|
|
2601
|
+
var import_fs_extra5 = __toESM(require_lib());
|
|
2602
|
+
var import_picocolors6 = __toESM(require_picocolors());
|
|
2603
|
+
import path5 from "path";
|
|
2604
|
+
async function install(target) {
|
|
2605
|
+
if (target.endsWith(".tgz") && import_fs_extra5.default.existsSync(target)) {
|
|
2606
|
+
const spinner = createSpinner(`\u6B63\u5728\u5B89\u88C5\u672C\u5730\u79BB\u7EBF\u5305: ${import_picocolors6.default.bold(target)}...`).start();
|
|
2607
|
+
try {
|
|
2608
|
+
const tgzPath = path5.resolve(target);
|
|
2609
|
+
const match = path5.basename(target).match(/chatbi-core-(.+)\.tgz/);
|
|
2610
|
+
let version = "unknown";
|
|
2611
|
+
if (match) {
|
|
2612
|
+
version = match[1];
|
|
2613
|
+
}
|
|
2614
|
+
if (version === "unknown") {
|
|
2615
|
+
spinner.warn("\u65E0\u6CD5\u4ECE\u6587\u4EF6\u540D\u8BC6\u522B\u7248\u672C\uFF0C\u5C06\u4F7F\u7528\u5F53\u524D\u65F6\u95F4\u6233\u4F5C\u4E3A\u7248\u672C\u53F7");
|
|
2616
|
+
version = `local-${Date.now()}`;
|
|
2617
|
+
}
|
|
2618
|
+
const versionRoot = Sandbox.getVersionRoot();
|
|
2619
|
+
await import_fs_extra5.default.ensureDir(versionRoot);
|
|
2620
|
+
spinner.text = "\u6B63\u5728\u89E3\u538B\u6587\u4EF6...";
|
|
2621
|
+
await execa("tar", ["-xzf", tgzPath, "-C", versionRoot]);
|
|
2622
|
+
spinner.succeed(`\u672C\u5730\u5305\u5DF2\u5B89\u88C5\u81F3\u6C99\u7BB1: ${version}`);
|
|
2623
|
+
spinner.text = "\u6B63\u5728\u51C6\u5907\u5185\u6838\u73AF\u5883...";
|
|
2624
|
+
await Sandbox.prepare(version);
|
|
2625
|
+
spinner.succeed("\u5185\u6838\u73AF\u5883\u5C31\u7EEA");
|
|
2626
|
+
printBox(
|
|
2627
|
+
import_picocolors6.default.green(import_picocolors6.default.bold("\u2728 \u672C\u5730\u5185\u6838\u5B89\u88C5\u6210\u529F!")) + "\n\n" + import_picocolors6.default.white("\u7248\u672C: ") + import_picocolors6.default.cyan(version) + "\n" + import_picocolors6.default.white("\u8DEF\u5F84: ") + import_picocolors6.default.gray(Sandbox.getVersionPath(version)),
|
|
2628
|
+
"Install Success"
|
|
2629
|
+
);
|
|
2630
|
+
} catch (e) {
|
|
2631
|
+
spinner.fail("\u5B89\u88C5\u5931\u8D25");
|
|
2632
|
+
throw e;
|
|
2633
|
+
}
|
|
2634
|
+
} else {
|
|
2635
|
+
const { fetch: fetch2 } = await import("./fetch-7X2UFWIV.mjs");
|
|
2636
|
+
await fetch2(target);
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
// package.json
|
|
2641
|
+
var package_default = {
|
|
2642
|
+
name: "@chatbi-v/cli",
|
|
2643
|
+
version: "2.0.2",
|
|
2644
|
+
description: "Standardized CLI tooling for ChatBI Monorepo",
|
|
2645
|
+
main: "dist/index.js",
|
|
2646
|
+
bin: {
|
|
2647
|
+
"chatbi-cli": "./bin/chatbi-cli.js"
|
|
2648
|
+
},
|
|
2649
|
+
files: [
|
|
2650
|
+
"dist",
|
|
2651
|
+
"bin",
|
|
2652
|
+
"templates"
|
|
2653
|
+
],
|
|
2654
|
+
publishConfig: {
|
|
2655
|
+
access: "public"
|
|
2656
|
+
},
|
|
2657
|
+
scripts: {
|
|
2658
|
+
build: "chatbi-cli build",
|
|
2659
|
+
dev: "chatbi-cli build --watch",
|
|
2660
|
+
test: "vitest"
|
|
2661
|
+
},
|
|
2662
|
+
dependencies: {
|
|
2663
|
+
boxen: "^8.0.1",
|
|
2664
|
+
cac: "^6.7.14",
|
|
2665
|
+
execa: "^8.0.1",
|
|
2666
|
+
"fast-glob": "^3.3.3",
|
|
2667
|
+
figlet: "^1.9.4",
|
|
2668
|
+
"fs-extra": "^11.2.0",
|
|
2669
|
+
"gradient-string": "^3.0.0",
|
|
2670
|
+
handlebars: "^4.7.8",
|
|
2671
|
+
jiti: "^2.6.1",
|
|
2672
|
+
ora: "^7.0.1",
|
|
2673
|
+
picocolors: "^1.0.0",
|
|
2674
|
+
prompts: "^2.4.2",
|
|
2675
|
+
tsup: "^8.5.1",
|
|
2676
|
+
typescript: "^5.0.0",
|
|
2677
|
+
vite: "^5.4.21"
|
|
2678
|
+
},
|
|
2679
|
+
devDependencies: {
|
|
2680
|
+
"@types/boxen": "^3.0.5",
|
|
2681
|
+
"@types/figlet": "^1.7.0",
|
|
2682
|
+
"@types/fs-extra": "^11.0.0",
|
|
2683
|
+
"@types/gradient-string": "^1.1.6",
|
|
2684
|
+
"@types/node": "^20.0.0",
|
|
2685
|
+
"@types/prompts": "^2.4.9",
|
|
2686
|
+
"@vitest/coverage-v8": "1.6.1",
|
|
2687
|
+
tsup: "^8.5.1",
|
|
2688
|
+
vitest: "^1.0.0"
|
|
2689
|
+
}
|
|
2690
|
+
};
|
|
2691
|
+
|
|
2692
|
+
// src/index.ts
|
|
2693
|
+
var cli = dist_default("chatbi-cli");
|
|
2694
|
+
var showHeader = () => {
|
|
2695
|
+
const title = figlet.textSync("ChatBI-V CLI", { font: "Standard" });
|
|
2696
|
+
console.log(dist_default2.pastel.multiline(title));
|
|
2697
|
+
console.log(
|
|
2698
|
+
boxen(import_picocolors7.default.cyan(`ChatBI-V \u7EDF\u4E00\u5F00\u53D1\u5DE5\u5177 v${package_default.version}`), {
|
|
2699
|
+
padding: 0,
|
|
2700
|
+
margin: { top: 1, bottom: 1 },
|
|
2701
|
+
borderStyle: "round",
|
|
2702
|
+
borderColor: "cyan",
|
|
2703
|
+
title: "CoreKit Enabled",
|
|
2704
|
+
titleAlignment: "center"
|
|
2705
|
+
})
|
|
2706
|
+
);
|
|
2707
|
+
};
|
|
2708
|
+
var wrapAction = (action, commandName) => {
|
|
2709
|
+
return async (...args) => {
|
|
2710
|
+
showHeader();
|
|
2711
|
+
try {
|
|
2712
|
+
await action(...args);
|
|
2713
|
+
} catch (e) {
|
|
2714
|
+
logger.error(`${commandName} \u6267\u884C\u5931\u8D25`, e);
|
|
2715
|
+
process.exit(1);
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2718
|
+
};
|
|
2719
|
+
cli.command("dev", "\u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668").alias("d").option("--port <port>", "\u7AEF\u53E3\u53F7").action(wrapAction(dev, "dev"));
|
|
2720
|
+
cli.command("build", "\u6784\u5EFA\u5F53\u524D\u9879\u76EE").alias("b").option("--watch", "\u5F00\u542F\u76D1\u542C\u6A21\u5F0F").action(wrapAction(build, "build"));
|
|
2721
|
+
cli.command("fetch <version>", "\u83B7\u53D6\u6307\u5B9A\u7248\u672C\u7684\u5185\u6838 (\u652F\u6301\u6253\u5305)").option("--pack", "\u6253\u5305\u4E3A\u79BB\u7EBF\u5B89\u88C5\u5305 (.tgz)").action(wrapAction(fetch, "fetch"));
|
|
2722
|
+
cli.command("install <target>", "\u5B89\u88C5\u5185\u6838 (\u652F\u6301\u7248\u672C\u53F7\u6216\u79BB\u7EBF\u5305\u8DEF\u5F84)").action(wrapAction(install, "install"));
|
|
2723
|
+
cli.command("init [name]", "\u521D\u59CB\u5316\u4E00\u4E2A\u65B0\u7684\u4E1A\u52A1\u63D2\u4EF6\u9879\u76EE").alias("create").alias("i").option("--project-type <type>", "\u9879\u76EE\u7C7B\u578B (monorepo | app | plugin)").option("--include-app", "Monorepo \u4E2D\u5305\u542B App").option("--no-include-app", "Monorepo \u4E2D\u4E0D\u5305\u542B App").option("--include-plugin", "Monorepo \u4E2D\u5305\u542B Plugin").option("--no-include-plugin", "Monorepo \u4E2D\u4E0D\u5305\u542B Plugin").option("--plugin-type <type>", "\u63D2\u4EF6\u7C7B\u578B (business | system)").option("--theme <theme>", "\u4E3B\u9898 (standard | nebula | glass)").action(wrapAction(async (name, options) => {
|
|
2724
|
+
await init({
|
|
2725
|
+
name,
|
|
2726
|
+
projectType: options.projectType,
|
|
2727
|
+
includeApp: options.includeApp,
|
|
2728
|
+
includePlugin: options.includePlugin,
|
|
2729
|
+
pluginType: options.pluginType,
|
|
2730
|
+
theme: options.theme
|
|
2731
|
+
});
|
|
2732
|
+
}, "init"));
|
|
2733
|
+
cli.command("add [name]", "\u5728\u5F53\u524D\u9879\u76EE\u4E2D\u6DFB\u52A0\u4E00\u4E2A\u65B0\u63D2\u4EF6").option("-t, --type <type>", "\u63D2\u4EF6\u7C7B\u578B (business | system)").option("--display-name <name>", "\u63D2\u4EF6\u663E\u793A\u540D\u79F0").option("--desc <description>", "\u63D2\u4EF6\u63CF\u8FF0").action(wrapAction(async (name, options) => {
|
|
2734
|
+
await add({
|
|
2735
|
+
name,
|
|
2736
|
+
type: options.type,
|
|
2737
|
+
displayName: options.displayName,
|
|
2738
|
+
description: options.desc
|
|
2739
|
+
});
|
|
2740
|
+
}, "add"));
|
|
2741
|
+
cli.command("update [targetVersion]", "\u66F4\u65B0\u5185\u6838\u7248\u672C").alias("up").action(wrapAction(async (targetVersion) => {
|
|
2742
|
+
const { sync: sync2 } = await import("./sync-7HPKGVFY.mjs");
|
|
2743
|
+
await sync2({ version: targetVersion, force: true });
|
|
2744
|
+
logger.success("\u66F4\u65B0\u5B8C\u6210\uFF01");
|
|
2745
|
+
}, "update"));
|
|
2746
|
+
cli.command("sync", "\u540C\u6B65\u5185\u6838\u4F9D\u8D56\u4E0E\u89C4\u8303").alias("s").option("-v, --core-version <version>", "\u6307\u5B9A\u5185\u6838\u7248\u672C").option("-f, --force", "\u5F3A\u5236\u91CD\u65B0\u521D\u59CB\u5316\u5185\u6838\u6C99\u7BB1").option("--clean", "\u6E05\u7406\u5E76\u91CD\u7F6E\u6C99\u7BB1").action(wrapAction(async (options) => {
|
|
2747
|
+
await sync({ ...options, version: options.coreVersion });
|
|
2748
|
+
console.log("");
|
|
2749
|
+
await doctor({ fix: false });
|
|
2750
|
+
}, "sync"));
|
|
2751
|
+
cli.command("doctor", "\u8BCA\u65AD\u9879\u76EE\u5065\u5EB7\u72B6\u51B5\u5E76\u4FEE\u590D").alias("dr").option("--fix", "\u81EA\u52A8\u4FEE\u590D\u53D1\u73B0\u7684\u95EE\u9898").action(wrapAction(doctor, "doctor"));
|
|
2752
|
+
cli.command("list", "\u5217\u51FA\u6240\u6709\u5DF2\u5B89\u88C5\u7684\u5185\u6838\u6C99\u7BB1\u7248\u672C").alias("ls").action(wrapAction(ls, "ls"));
|
|
2753
|
+
cli.command("use <version>", "\u5207\u6362\u5F53\u524D\u9879\u76EE\u4F7F\u7528\u7684\u5185\u6838\u7248\u672C").alias("u").option("--global", "\u5207\u6362\u5168\u5C40\u9ED8\u8BA4\u5185\u6838\u7248\u672C").action(wrapAction(use, "use"));
|
|
2754
|
+
cli.command("gl", "\u4F7F\u7528 AI \u811A\u624B\u67B6\u751F\u6210\u4EE3\u7801\u6216\u6587\u6863").option("-t, --type <type>", "\u751F\u6210\u7C7B\u578B (plugin|util|doc|component)").option("-p, --prompt <prompt>", "AI \u9700\u6C42\u63CF\u8FF0").action(wrapAction(gl, "gl"));
|
|
2755
|
+
cli.command("discover", "\u626B\u63CF\u5E76\u53D1\u73B0\u5F53\u524D\u9879\u76EE\u4E2D\u7684\u63D2\u4EF6").action(wrapAction(discover, "discover"));
|
|
2756
|
+
cli.command("bench", "\u8FD0\u884C CLI \u6027\u80FD\u57FA\u51C6\u6D4B\u8BD5").action(wrapAction(async () => {
|
|
2757
|
+
const { bench } = await import("./bench-ACSHVGHE.mjs");
|
|
2758
|
+
await bench();
|
|
2759
|
+
}, "bench"));
|
|
2760
|
+
cli.help((sections) => {
|
|
2761
|
+
showHeader();
|
|
2762
|
+
sections[0].body = import_picocolors7.default.white("ChatBI-V \u5F00\u53D1\u8005\u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u52A9\u529B\u5FEB\u901F\u5F00\u53D1\u548C\u6784\u5EFA\u63D2\u4EF6\u3002");
|
|
2763
|
+
});
|
|
2764
|
+
cli.version(package_default.version);
|
|
2765
|
+
if (process.argv.length <= 2) {
|
|
2766
|
+
cli.outputHelp();
|
|
2767
|
+
} else {
|
|
2768
|
+
cli.parse();
|
|
2769
|
+
}
|