shadcn-svelte 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +976 -469
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,22 +1,106 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// ../../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
29
|
+
var require_src = __commonJS({
|
|
30
|
+
"../../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module) {
|
|
31
|
+
"use strict";
|
|
32
|
+
var ESC2 = "\x1B";
|
|
33
|
+
var CSI2 = `${ESC2}[`;
|
|
34
|
+
var beep2 = "\x07";
|
|
35
|
+
var cursor3 = {
|
|
36
|
+
to(x, y) {
|
|
37
|
+
if (!y)
|
|
38
|
+
return `${CSI2}${x + 1}G`;
|
|
39
|
+
return `${CSI2}${y + 1};${x + 1}H`;
|
|
40
|
+
},
|
|
41
|
+
move(x, y) {
|
|
42
|
+
let ret = "";
|
|
43
|
+
if (x < 0)
|
|
44
|
+
ret += `${CSI2}${-x}D`;
|
|
45
|
+
else if (x > 0)
|
|
46
|
+
ret += `${CSI2}${x}C`;
|
|
47
|
+
if (y < 0)
|
|
48
|
+
ret += `${CSI2}${-y}A`;
|
|
49
|
+
else if (y > 0)
|
|
50
|
+
ret += `${CSI2}${y}B`;
|
|
51
|
+
return ret;
|
|
52
|
+
},
|
|
53
|
+
up: (count = 1) => `${CSI2}${count}A`,
|
|
54
|
+
down: (count = 1) => `${CSI2}${count}B`,
|
|
55
|
+
forward: (count = 1) => `${CSI2}${count}C`,
|
|
56
|
+
backward: (count = 1) => `${CSI2}${count}D`,
|
|
57
|
+
nextLine: (count = 1) => `${CSI2}E`.repeat(count),
|
|
58
|
+
prevLine: (count = 1) => `${CSI2}F`.repeat(count),
|
|
59
|
+
left: `${CSI2}G`,
|
|
60
|
+
hide: `${CSI2}?25l`,
|
|
61
|
+
show: `${CSI2}?25h`,
|
|
62
|
+
save: `${ESC2}7`,
|
|
63
|
+
restore: `${ESC2}8`
|
|
64
|
+
};
|
|
65
|
+
var scroll2 = {
|
|
66
|
+
up: (count = 1) => `${CSI2}S`.repeat(count),
|
|
67
|
+
down: (count = 1) => `${CSI2}T`.repeat(count)
|
|
68
|
+
};
|
|
69
|
+
var erase3 = {
|
|
70
|
+
screen: `${CSI2}2J`,
|
|
71
|
+
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
72
|
+
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
73
|
+
line: `${CSI2}2K`,
|
|
74
|
+
lineEnd: `${CSI2}K`,
|
|
75
|
+
lineStart: `${CSI2}1K`,
|
|
76
|
+
lines(count) {
|
|
77
|
+
let clear2 = "";
|
|
78
|
+
for (let i = 0; i < count; i++)
|
|
79
|
+
clear2 += this.line + (i < count - 1 ? cursor3.up() : "");
|
|
80
|
+
if (count)
|
|
81
|
+
clear2 += cursor3.left;
|
|
82
|
+
return clear2;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
module.exports = { cursor: cursor3, scroll: scroll2, erase: erase3, beep: beep2 };
|
|
86
|
+
}
|
|
87
|
+
});
|
|
2
88
|
|
|
3
89
|
// src/index.ts
|
|
4
90
|
import { Command as Command4 } from "commander";
|
|
5
91
|
|
|
6
92
|
// src/commands/add.ts
|
|
7
|
-
import { existsSync as existsSync2, promises as fs6 } from "fs";
|
|
8
|
-
import path10 from "path";
|
|
9
|
-
import
|
|
93
|
+
import { existsSync as existsSync2, promises as fs6 } from "node:fs";
|
|
94
|
+
import path10 from "node:path";
|
|
95
|
+
import color5 from "chalk";
|
|
10
96
|
import { Command } from "commander";
|
|
11
97
|
import { execa as execa3 } from "execa";
|
|
12
|
-
import
|
|
13
|
-
import prompts2 from "prompts";
|
|
14
|
-
import { z as z3 } from "zod";
|
|
98
|
+
import * as z3 from "zod";
|
|
15
99
|
|
|
16
100
|
// src/utils/get-config.ts
|
|
17
|
-
import { promises as fs5 } from "fs";
|
|
18
|
-
import path8 from "path";
|
|
19
|
-
import
|
|
101
|
+
import { promises as fs5 } from "node:fs";
|
|
102
|
+
import path8 from "node:path";
|
|
103
|
+
import color2 from "chalk";
|
|
20
104
|
import { execa as execa2 } from "execa";
|
|
21
105
|
|
|
22
106
|
// ../../node_modules/.pnpm/tsconfck@2.1.2_typescript@5.3.3/node_modules/tsconfck/dist/index.js
|
|
@@ -382,8 +466,8 @@ var TSConfckParseNativeError = class _TSConfckParseNativeError extends Error {
|
|
|
382
466
|
import * as z from "zod";
|
|
383
467
|
|
|
384
468
|
// src/utils/find-tsconfig.ts
|
|
385
|
-
import { promises as fs } from "fs";
|
|
386
|
-
import path from "path";
|
|
469
|
+
import { promises as fs } from "node:fs";
|
|
470
|
+
import path from "node:path";
|
|
387
471
|
async function find(filename, options2) {
|
|
388
472
|
let dir = path.dirname(path.resolve(filename));
|
|
389
473
|
const root = options2?.root ? path.resolve(options2.root) : null;
|
|
@@ -434,8 +518,8 @@ async function tsconfigInDir(dir, options2) {
|
|
|
434
518
|
}
|
|
435
519
|
|
|
436
520
|
// src/utils/get-package-info.ts
|
|
437
|
-
import path4 from "path";
|
|
438
|
-
import { fileURLToPath } from "url";
|
|
521
|
+
import path4 from "node:path";
|
|
522
|
+
import { fileURLToPath } from "node:url";
|
|
439
523
|
import fs3 from "fs-extra";
|
|
440
524
|
function getPackageInfo() {
|
|
441
525
|
const packageJsonPath = getPackageFilePath("../package.json");
|
|
@@ -859,8 +943,8 @@ _escape.command = escapeCommand;
|
|
|
859
943
|
_escape.argument = escapeArgument;
|
|
860
944
|
var shebangRegex$1 = /^#!(.*)/;
|
|
861
945
|
var shebangRegex = shebangRegex$1;
|
|
862
|
-
var shebangCommand$1 = (
|
|
863
|
-
const match =
|
|
946
|
+
var shebangCommand$1 = (string5 = "") => {
|
|
947
|
+
const match = string5.match(shebangRegex);
|
|
864
948
|
if (!match) {
|
|
865
949
|
return null;
|
|
866
950
|
}
|
|
@@ -1697,9 +1781,9 @@ var SignalExit = class extends SignalExitBase {
|
|
|
1697
1781
|
if (listeners.length === count) {
|
|
1698
1782
|
this.unload();
|
|
1699
1783
|
const ret = this.#emitter.emit("exit", null, sig);
|
|
1700
|
-
const
|
|
1784
|
+
const s2 = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
1701
1785
|
if (!ret)
|
|
1702
|
-
process2.kill(process2.pid,
|
|
1786
|
+
process2.kill(process2.pid, s2);
|
|
1703
1787
|
}
|
|
1704
1788
|
};
|
|
1705
1789
|
}
|
|
@@ -2666,7 +2750,7 @@ ansiEscapes.clearTerminal = process.platform === "win32" ? `${ansiEscapes.eraseS
|
|
|
2666
2750
|
`${ansiEscapes.eraseScreen}${ESC$1}3J${ESC$1}H`
|
|
2667
2751
|
);
|
|
2668
2752
|
ansiEscapes.beep = BEL;
|
|
2669
|
-
ansiEscapes.link = (
|
|
2753
|
+
ansiEscapes.link = (text3, url2) => {
|
|
2670
2754
|
return [
|
|
2671
2755
|
OSC,
|
|
2672
2756
|
"8",
|
|
@@ -2674,7 +2758,7 @@ ansiEscapes.link = (text2, url2) => {
|
|
|
2674
2758
|
SEP,
|
|
2675
2759
|
url2,
|
|
2676
2760
|
BEL,
|
|
2677
|
-
|
|
2761
|
+
text3,
|
|
2678
2762
|
OSC,
|
|
2679
2763
|
"8",
|
|
2680
2764
|
SEP,
|
|
@@ -2887,17 +2971,17 @@ var supportsHyperlinks = {
|
|
|
2887
2971
|
stderr: supportsHyperlink(process.stderr)
|
|
2888
2972
|
};
|
|
2889
2973
|
var supportsHyperlinks$1 = /* @__PURE__ */ getDefaultExportFromCjs(supportsHyperlinks);
|
|
2890
|
-
function terminalLink(
|
|
2974
|
+
function terminalLink(text3, url2, { target = "stdout", ...options2 } = {}) {
|
|
2891
2975
|
if (!supportsHyperlinks$1[target]) {
|
|
2892
2976
|
if (options2.fallback === false) {
|
|
2893
|
-
return
|
|
2977
|
+
return text3;
|
|
2894
2978
|
}
|
|
2895
|
-
return typeof options2.fallback === "function" ? options2.fallback(
|
|
2979
|
+
return typeof options2.fallback === "function" ? options2.fallback(text3, url2) : `${text3} (\u200B${url2}\u200B)`;
|
|
2896
2980
|
}
|
|
2897
|
-
return ansiEscapes.link(
|
|
2981
|
+
return ansiEscapes.link(text3, url2);
|
|
2898
2982
|
}
|
|
2899
2983
|
terminalLink.isSupported = supportsHyperlinks$1.stdout;
|
|
2900
|
-
terminalLink.stderr = (
|
|
2984
|
+
terminalLink.stderr = (text3, url2, options2 = {}) => terminalLink(text3, url2, { target: "stderr", ...options2 });
|
|
2901
2985
|
terminalLink.stderr.isSupported = supportsHyperlinks$1.stderr;
|
|
2902
2986
|
var prompts$3 = {};
|
|
2903
2987
|
var FORCE_COLOR$1;
|
|
@@ -3205,9 +3289,9 @@ var wrap$3 = (msg, opts = {}) => {
|
|
|
3205
3289
|
return arr;
|
|
3206
3290
|
}, [tab]).join("\n")).join("\n");
|
|
3207
3291
|
};
|
|
3208
|
-
var entriesToDisplay$3 = (
|
|
3292
|
+
var entriesToDisplay$3 = (cursor3, total, maxVisible) => {
|
|
3209
3293
|
maxVisible = maxVisible || total;
|
|
3210
|
-
let startIndex = Math.min(total - maxVisible,
|
|
3294
|
+
let startIndex = Math.min(total - maxVisible, cursor3 - Math.floor(maxVisible / 2));
|
|
3211
3295
|
if (startIndex < 0)
|
|
3212
3296
|
startIndex = 0;
|
|
3213
3297
|
let endIndex = Math.min(startIndex + maxVisible, total);
|
|
@@ -3866,8 +3950,8 @@ var Seconds$1 = class Seconds extends DatePart$2 {
|
|
|
3866
3950
|
this.date.setSeconds(parseInt(val.substr(-2)));
|
|
3867
3951
|
}
|
|
3868
3952
|
toString() {
|
|
3869
|
-
let
|
|
3870
|
-
return this.token.length > 1 ? String(
|
|
3953
|
+
let s2 = this.date.getSeconds();
|
|
3954
|
+
return this.token.length > 1 ? String(s2).padStart(2, "0") : s2;
|
|
3871
3955
|
}
|
|
3872
3956
|
};
|
|
3873
3957
|
var seconds = Seconds$1;
|
|
@@ -4410,14 +4494,14 @@ Instructions:
|
|
|
4410
4494
|
}
|
|
4411
4495
|
return "";
|
|
4412
4496
|
}
|
|
4413
|
-
renderOption(
|
|
4497
|
+
renderOption(cursor3, v, i, arrowIndicator) {
|
|
4414
4498
|
const prefix = (v.selected ? color$3.green(figures$2.radioOn) : figures$2.radioOff) + " " + arrowIndicator + " ";
|
|
4415
4499
|
let title, desc;
|
|
4416
4500
|
if (v.disabled) {
|
|
4417
|
-
title =
|
|
4501
|
+
title = cursor3 === i ? color$3.gray().underline(v.title) : color$3.strikethrough().gray(v.title);
|
|
4418
4502
|
} else {
|
|
4419
|
-
title =
|
|
4420
|
-
if (
|
|
4503
|
+
title = cursor3 === i ? color$3.cyan().underline(v.title) : v.title;
|
|
4504
|
+
if (cursor3 === i && v.description) {
|
|
4421
4505
|
desc = ` - ${v.description}`;
|
|
4422
4506
|
if (prefix.length + title.length + desc.length >= this.out.columns || v.description.split(/\r?\n/).length > 1) {
|
|
4423
4507
|
desc = "\n" + wrap$1(v.description, { margin: prefix.length, width: this.out.columns });
|
|
@@ -4541,7 +4625,7 @@ var AutocompletePrompt = class extends Prompt$1 {
|
|
|
4541
4625
|
const suggestions = await p;
|
|
4542
4626
|
if (this.completing !== p)
|
|
4543
4627
|
return;
|
|
4544
|
-
this.suggestions = suggestions.map((
|
|
4628
|
+
this.suggestions = suggestions.map((s2, i, arr) => ({ title: getTitle(arr, i), value: getVal(arr, i), description: s2.description }));
|
|
4545
4629
|
this.completing = false;
|
|
4546
4630
|
const l = Math.max(suggestions.length - 1, 0);
|
|
4547
4631
|
this.moveSelect(Math.min(l, this.select));
|
|
@@ -4821,13 +4905,13 @@ Instructions:
|
|
|
4821
4905
|
Filtered results for: ${this.inputValue ? this.inputValue : color$1.gray("Enter something to filter")}
|
|
4822
4906
|
`;
|
|
4823
4907
|
}
|
|
4824
|
-
renderOption(
|
|
4908
|
+
renderOption(cursor3, v, i, arrowIndicator) {
|
|
4825
4909
|
const prefix = (v.selected ? color$1.green(figures.radioOn) : figures.radioOff) + " " + arrowIndicator + " ";
|
|
4826
4910
|
let title;
|
|
4827
4911
|
if (v.disabled)
|
|
4828
|
-
title =
|
|
4912
|
+
title = cursor3 === i ? color$1.gray().underline(v.title) : color$1.strikethrough().gray(v.title);
|
|
4829
4913
|
else
|
|
4830
|
-
title =
|
|
4914
|
+
title = cursor3 === i ? color$1.cyan().underline(v.title) : v.title;
|
|
4831
4915
|
return prefix + title;
|
|
4832
4916
|
}
|
|
4833
4917
|
renderDoneOrInstructions() {
|
|
@@ -4973,7 +5057,7 @@ var elements = {
|
|
|
4973
5057
|
$2.list = (args) => {
|
|
4974
5058
|
const sep3 = args.separator || ",";
|
|
4975
5059
|
return toPrompt("TextPrompt", args, {
|
|
4976
|
-
onSubmit: (str) => str.split(sep3).map((
|
|
5060
|
+
onSubmit: (str) => str.split(sep3).map((s2) => s2.trim())
|
|
4977
5061
|
});
|
|
4978
5062
|
};
|
|
4979
5063
|
$2.toggle = (args) => toPrompt("TogglePrompt", args);
|
|
@@ -5477,26 +5561,6 @@ async function getPackageManager(targetDir) {
|
|
|
5477
5561
|
return packageManager ?? "npm";
|
|
5478
5562
|
}
|
|
5479
5563
|
|
|
5480
|
-
// src/utils/logger.ts
|
|
5481
|
-
import chalk from "chalk";
|
|
5482
|
-
var logger = {
|
|
5483
|
-
error(...args) {
|
|
5484
|
-
console.log(chalk.red(...args));
|
|
5485
|
-
},
|
|
5486
|
-
warn(...args) {
|
|
5487
|
-
console.log(chalk.yellow(...args));
|
|
5488
|
-
},
|
|
5489
|
-
info(...args) {
|
|
5490
|
-
console.log(chalk.cyan(...args));
|
|
5491
|
-
},
|
|
5492
|
-
success(...args) {
|
|
5493
|
-
console.log(chalk.green(...args));
|
|
5494
|
-
},
|
|
5495
|
-
highlight(...args) {
|
|
5496
|
-
return chalk.bold(chalk.cyan(...args));
|
|
5497
|
-
}
|
|
5498
|
-
};
|
|
5499
|
-
|
|
5500
5564
|
// src/utils/resolve-imports.ts
|
|
5501
5565
|
import { createMatchPath } from "tsconfig-paths";
|
|
5502
5566
|
async function resolveImport(importPath, config) {
|
|
@@ -5510,6 +5574,7 @@ var DEFAULT_UTILS = "$lib/utils";
|
|
|
5510
5574
|
var DEFAULT_TAILWIND_CSS = "src/app.pcss";
|
|
5511
5575
|
var DEFAULT_TAILWIND_CONFIG = "tailwind.config.cjs";
|
|
5512
5576
|
var DEFAULT_TYPESCRIPT = true;
|
|
5577
|
+
var highlight = (...args) => color2.bold.cyan(...args);
|
|
5513
5578
|
var rawConfigSchema = z.object({
|
|
5514
5579
|
$schema: z.string().optional(),
|
|
5515
5580
|
style: z.string(),
|
|
@@ -5551,18 +5616,18 @@ async function resolveConfigPaths(cwd, config) {
|
|
|
5551
5616
|
const tsconfigPath = await find(path8.resolve(cwd, "package.json"), { root: cwd });
|
|
5552
5617
|
if (tsconfigPath === null) {
|
|
5553
5618
|
const configToFind = config.typescript ? "tsconfig.json" : "jsconfig.json";
|
|
5554
|
-
throw new Error(`Failed to find ${
|
|
5619
|
+
throw new Error(`Failed to find ${highlight(configToFind)}.`);
|
|
5555
5620
|
}
|
|
5556
5621
|
const parsedConfig = await parseNative(tsconfigPath);
|
|
5557
5622
|
const absoluteBaseUrl = parsedConfig.result.options.pathsBasePath;
|
|
5558
5623
|
let paths = parsedConfig.result.options.paths;
|
|
5559
5624
|
if (absoluteBaseUrl === void 0 || paths === void 0) {
|
|
5560
5625
|
throw new Error(
|
|
5561
|
-
`Specify a ${
|
|
5626
|
+
`Specify a ${highlight("paths")} field in your ${highlight(
|
|
5562
5627
|
"tsconfig.json"
|
|
5563
5628
|
)} and define your path aliases.
|
|
5564
5629
|
|
|
5565
|
-
See: ${
|
|
5630
|
+
See: ${color2.green(
|
|
5566
5631
|
"https://www.shadcn-svelte.com/docs/installation#setup-path-aliases"
|
|
5567
5632
|
)}`
|
|
5568
5633
|
);
|
|
@@ -5595,7 +5660,7 @@ async function getRawConfig(cwd) {
|
|
|
5595
5660
|
const config = JSON.parse(configResult);
|
|
5596
5661
|
return rawConfigSchema.parse(config);
|
|
5597
5662
|
} catch (error) {
|
|
5598
|
-
throw new Error(`Invalid configuration found in ${
|
|
5663
|
+
throw new Error(`Invalid configuration found in ${highlight(configPath)}.`);
|
|
5599
5664
|
}
|
|
5600
5665
|
}
|
|
5601
5666
|
|
|
@@ -5605,24 +5670,447 @@ function getEnvProxy() {
|
|
|
5605
5670
|
return HTTP_PROXY || http_proxy;
|
|
5606
5671
|
}
|
|
5607
5672
|
|
|
5673
|
+
// src/utils/prompts.ts
|
|
5674
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
5675
|
+
import {
|
|
5676
|
+
block,
|
|
5677
|
+
ConfirmPrompt as ConfirmPrompt2,
|
|
5678
|
+
GroupMultiSelectPrompt,
|
|
5679
|
+
isCancel,
|
|
5680
|
+
MultiSelectPrompt,
|
|
5681
|
+
PasswordPrompt,
|
|
5682
|
+
SelectKeyPrompt,
|
|
5683
|
+
SelectPrompt as SelectPrompt2,
|
|
5684
|
+
TextPrompt as TextPrompt2
|
|
5685
|
+
} from "@clack/core";
|
|
5686
|
+
import isUnicodeSupported from "is-unicode-supported";
|
|
5687
|
+
import color3 from "chalk";
|
|
5688
|
+
import { isCancel as isCancel2 } from "@clack/core";
|
|
5689
|
+
var unicode = isUnicodeSupported();
|
|
5690
|
+
var s = (c2, fallback) => unicode ? c2 : fallback;
|
|
5691
|
+
var S_STEP_ACTIVE = s("\u25C6", "*");
|
|
5692
|
+
var S_STEP_CANCEL = s("\u25A0", "x");
|
|
5693
|
+
var S_STEP_ERROR = s("\u25B2", "x");
|
|
5694
|
+
var S_STEP_SUBMIT = s("\u25C7", "o");
|
|
5695
|
+
var S_BAR_START = s("\u250C", "T");
|
|
5696
|
+
var S_BAR = s("\u2502", "|");
|
|
5697
|
+
var S_BAR_END = s("\u2514", "\u2014");
|
|
5698
|
+
var S_RADIO_ACTIVE = s("\u25CF", ">");
|
|
5699
|
+
var S_RADIO_INACTIVE = s("\u25CB", " ");
|
|
5700
|
+
var S_CHECKBOX_ACTIVE = s("\u25FB", "[\u2022]");
|
|
5701
|
+
var S_CHECKBOX_SELECTED = s("\u25FC", "[+]");
|
|
5702
|
+
var S_CHECKBOX_INACTIVE = s("\u25FB", "[ ]");
|
|
5703
|
+
var S_PASSWORD_MASK = s("\u25AA", "\u2022");
|
|
5704
|
+
var S_BAR_H = s("\u2500", "-");
|
|
5705
|
+
var S_CORNER_TOP_RIGHT = s("\u256E", "+");
|
|
5706
|
+
var S_CONNECT_LEFT = s("\u251C", "+");
|
|
5707
|
+
var S_CORNER_BOTTOM_RIGHT = s("\u256F", "+");
|
|
5708
|
+
var S_INFO = s("\u25CF", "\u2022");
|
|
5709
|
+
var S_SUCCESS = s("\u25C6", "*");
|
|
5710
|
+
var S_WARN = s("\u25B2", "!");
|
|
5711
|
+
var S_ERROR = s("\u25A0", "x");
|
|
5712
|
+
var symbol2 = (state) => {
|
|
5713
|
+
switch (state) {
|
|
5714
|
+
case "initial":
|
|
5715
|
+
case "active":
|
|
5716
|
+
return color3.cyan(S_STEP_ACTIVE);
|
|
5717
|
+
case "cancel":
|
|
5718
|
+
return color3.red(S_STEP_CANCEL);
|
|
5719
|
+
case "error":
|
|
5720
|
+
return color3.yellow(S_STEP_ERROR);
|
|
5721
|
+
case "submit":
|
|
5722
|
+
return color3.green(S_STEP_SUBMIT);
|
|
5723
|
+
}
|
|
5724
|
+
};
|
|
5725
|
+
var limitOptions = (params) => {
|
|
5726
|
+
const { cursor: cursor3, options: options2, style: style2 } = params;
|
|
5727
|
+
const maxItems = params.maxItems === void 0 ? Infinity : Math.max(params.maxItems, 5);
|
|
5728
|
+
let slidingWindowLocation = 0;
|
|
5729
|
+
if (cursor3 >= slidingWindowLocation + maxItems - 3) {
|
|
5730
|
+
slidingWindowLocation = Math.max(Math.min(cursor3 - maxItems + 3, options2.length - maxItems), 0);
|
|
5731
|
+
} else if (cursor3 < slidingWindowLocation + 2) {
|
|
5732
|
+
slidingWindowLocation = Math.max(cursor3 - 2, 0);
|
|
5733
|
+
}
|
|
5734
|
+
const shouldRenderTopEllipsis = maxItems < options2.length && slidingWindowLocation > 0;
|
|
5735
|
+
const shouldRenderBottomEllipsis = maxItems < options2.length && slidingWindowLocation + maxItems < options2.length;
|
|
5736
|
+
return options2.slice(slidingWindowLocation, slidingWindowLocation + maxItems).map((option, i, arr) => {
|
|
5737
|
+
const isTopLimit = i === 0 && shouldRenderTopEllipsis;
|
|
5738
|
+
const isBottomLimit = i === arr.length - 1 && shouldRenderBottomEllipsis;
|
|
5739
|
+
return isTopLimit || isBottomLimit ? color3.dim("...") : style2(option, i + slidingWindowLocation === cursor3);
|
|
5740
|
+
});
|
|
5741
|
+
};
|
|
5742
|
+
var text2 = (opts) => {
|
|
5743
|
+
return new TextPrompt2({
|
|
5744
|
+
validate: opts.validate,
|
|
5745
|
+
placeholder: opts.placeholder,
|
|
5746
|
+
defaultValue: opts.defaultValue,
|
|
5747
|
+
initialValue: opts.initialValue,
|
|
5748
|
+
render() {
|
|
5749
|
+
const title = `${color3.gray(S_BAR)}
|
|
5750
|
+
${symbol2(this.state)} ${opts.message}
|
|
5751
|
+
`;
|
|
5752
|
+
const placeholder = opts.placeholder ? color3.inverse(opts.placeholder[0]) + color3.dim(opts.placeholder.slice(1)) : color3.inverse(color3.hidden("_"));
|
|
5753
|
+
const value = !this.value ? placeholder : this.valueWithCursor;
|
|
5754
|
+
switch (this.state) {
|
|
5755
|
+
case "error":
|
|
5756
|
+
return `${title.trim()}
|
|
5757
|
+
${color3.yellow(S_BAR)} ${value}
|
|
5758
|
+
${color3.yellow(
|
|
5759
|
+
S_BAR_END
|
|
5760
|
+
)} ${color3.yellow(this.error)}
|
|
5761
|
+
`;
|
|
5762
|
+
case "submit":
|
|
5763
|
+
return `${title}${color3.gray(S_BAR)} ${color3.dim(this.value || opts.placeholder)}`;
|
|
5764
|
+
case "cancel":
|
|
5765
|
+
return `${title}${color3.gray(S_BAR)} ${color3.strikethrough(
|
|
5766
|
+
color3.dim(this.value ?? "")
|
|
5767
|
+
)}${this.value?.trim() ? "\n" + color3.gray(S_BAR) : ""}`;
|
|
5768
|
+
default:
|
|
5769
|
+
return `${title}${color3.cyan(S_BAR)} ${value}
|
|
5770
|
+
${color3.cyan(S_BAR_END)}
|
|
5771
|
+
`;
|
|
5772
|
+
}
|
|
5773
|
+
}
|
|
5774
|
+
}).prompt();
|
|
5775
|
+
};
|
|
5776
|
+
var confirm2 = (opts) => {
|
|
5777
|
+
const active = opts.active ?? "Yes";
|
|
5778
|
+
const inactive = opts.inactive ?? "No";
|
|
5779
|
+
return new ConfirmPrompt2({
|
|
5780
|
+
active,
|
|
5781
|
+
inactive,
|
|
5782
|
+
initialValue: opts.initialValue ?? true,
|
|
5783
|
+
render() {
|
|
5784
|
+
const title = `${color3.gray(S_BAR)}
|
|
5785
|
+
${symbol2(this.state)} ${opts.message}
|
|
5786
|
+
`;
|
|
5787
|
+
const value = this.value ? active : inactive;
|
|
5788
|
+
switch (this.state) {
|
|
5789
|
+
case "submit":
|
|
5790
|
+
return `${title}${color3.gray(S_BAR)} ${color3.dim(value)}`;
|
|
5791
|
+
case "cancel":
|
|
5792
|
+
return `${title}${color3.gray(S_BAR)} ${color3.strikethrough(
|
|
5793
|
+
color3.dim(value)
|
|
5794
|
+
)}
|
|
5795
|
+
${color3.gray(S_BAR)}`;
|
|
5796
|
+
default: {
|
|
5797
|
+
return `${title}${color3.cyan(S_BAR)} ${this.value ? `${color3.green(S_RADIO_ACTIVE)} ${active}` : `${color3.dim(S_RADIO_INACTIVE)} ${color3.dim(active)}`} ${color3.dim("/")} ${!this.value ? `${color3.green(S_RADIO_ACTIVE)} ${inactive}` : `${color3.dim(S_RADIO_INACTIVE)} ${color3.dim(inactive)}`}
|
|
5798
|
+
${color3.cyan(S_BAR_END)}
|
|
5799
|
+
`;
|
|
5800
|
+
}
|
|
5801
|
+
}
|
|
5802
|
+
}
|
|
5803
|
+
}).prompt();
|
|
5804
|
+
};
|
|
5805
|
+
var select2 = (opts) => {
|
|
5806
|
+
const opt = (option, state) => {
|
|
5807
|
+
const label = option.label ?? String(option.value);
|
|
5808
|
+
switch (state) {
|
|
5809
|
+
case "selected":
|
|
5810
|
+
return `${color3.dim(label)}`;
|
|
5811
|
+
case "active":
|
|
5812
|
+
return `${color3.green(S_RADIO_ACTIVE)} ${label} ${option.hint ? color3.dim(`(${option.hint})`) : ""}`;
|
|
5813
|
+
case "cancelled":
|
|
5814
|
+
return `${color3.strikethrough(color3.dim(label))}`;
|
|
5815
|
+
default:
|
|
5816
|
+
return `${color3.dim(S_RADIO_INACTIVE)} ${color3.dim(label)}`;
|
|
5817
|
+
}
|
|
5818
|
+
};
|
|
5819
|
+
return new SelectPrompt2({
|
|
5820
|
+
options: opts.options,
|
|
5821
|
+
initialValue: opts.initialValue,
|
|
5822
|
+
render() {
|
|
5823
|
+
const title = `${color3.gray(S_BAR)}
|
|
5824
|
+
${symbol2(this.state)} ${opts.message}
|
|
5825
|
+
`;
|
|
5826
|
+
switch (this.state) {
|
|
5827
|
+
case "submit":
|
|
5828
|
+
return `${title}${color3.gray(S_BAR)} ${opt(this.options[this.cursor], "selected")}`;
|
|
5829
|
+
case "cancel":
|
|
5830
|
+
return `${title}${color3.gray(S_BAR)} ${opt(
|
|
5831
|
+
this.options[this.cursor],
|
|
5832
|
+
"cancelled"
|
|
5833
|
+
)}
|
|
5834
|
+
${color3.gray(S_BAR)}`;
|
|
5835
|
+
default: {
|
|
5836
|
+
return `${title}${color3.cyan(S_BAR)} ${limitOptions({
|
|
5837
|
+
cursor: this.cursor,
|
|
5838
|
+
options: this.options,
|
|
5839
|
+
maxItems: opts.maxItems,
|
|
5840
|
+
style: (item2, active) => opt(item2, active ? "active" : "inactive")
|
|
5841
|
+
}).join(`
|
|
5842
|
+
${color3.cyan(S_BAR)} `)}
|
|
5843
|
+
${color3.cyan(S_BAR_END)}
|
|
5844
|
+
`;
|
|
5845
|
+
}
|
|
5846
|
+
}
|
|
5847
|
+
}
|
|
5848
|
+
}).prompt();
|
|
5849
|
+
};
|
|
5850
|
+
var multiselect2 = (opts) => {
|
|
5851
|
+
const opt = (option, state) => {
|
|
5852
|
+
const label = option.label ?? String(option.value);
|
|
5853
|
+
if (state === "active") {
|
|
5854
|
+
return `${color3.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color3.dim(`(${option.hint})`) : ""}`;
|
|
5855
|
+
} else if (state === "selected") {
|
|
5856
|
+
return `${color3.green(S_CHECKBOX_SELECTED)} ${color3.dim(label)}`;
|
|
5857
|
+
} else if (state === "cancelled") {
|
|
5858
|
+
return `${color3.strikethrough(color3.dim(label))}`;
|
|
5859
|
+
} else if (state === "active-selected") {
|
|
5860
|
+
return `${color3.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color3.dim(`(${option.hint})`) : ""}`;
|
|
5861
|
+
} else if (state === "submitted") {
|
|
5862
|
+
return `${color3.dim(label)}`;
|
|
5863
|
+
}
|
|
5864
|
+
return `${color3.dim(S_CHECKBOX_INACTIVE)} ${color3.dim(label)}`;
|
|
5865
|
+
};
|
|
5866
|
+
return new MultiSelectPrompt({
|
|
5867
|
+
options: opts.options,
|
|
5868
|
+
initialValues: opts.initialValues,
|
|
5869
|
+
required: opts.required ?? true,
|
|
5870
|
+
cursorAt: opts.cursorAt,
|
|
5871
|
+
validate(selected) {
|
|
5872
|
+
if (this.required && selected.length === 0)
|
|
5873
|
+
return `Please select at least one option.
|
|
5874
|
+
${color3.reset(
|
|
5875
|
+
color3.dim(
|
|
5876
|
+
`Press ${color3.gray(color3.bgWhite(color3.inverse(" space ")))} to select, ${color3.gray(
|
|
5877
|
+
color3.bgWhite(color3.inverse(" enter "))
|
|
5878
|
+
)} to submit`
|
|
5879
|
+
)
|
|
5880
|
+
)}`;
|
|
5881
|
+
},
|
|
5882
|
+
render() {
|
|
5883
|
+
let title = `${color3.gray(S_BAR)}
|
|
5884
|
+
${symbol2(this.state)} ${opts.message}
|
|
5885
|
+
`;
|
|
5886
|
+
const styleOption = (option, active) => {
|
|
5887
|
+
const selected = this.value.includes(option.value);
|
|
5888
|
+
if (active && selected) {
|
|
5889
|
+
return opt(option, "active-selected");
|
|
5890
|
+
}
|
|
5891
|
+
if (selected) {
|
|
5892
|
+
return opt(option, "selected");
|
|
5893
|
+
}
|
|
5894
|
+
return opt(option, active ? "active" : "inactive");
|
|
5895
|
+
};
|
|
5896
|
+
switch (this.state) {
|
|
5897
|
+
case "submit": {
|
|
5898
|
+
return `${title}${color3.gray(S_BAR)} ${this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(color3.dim(", ")) || color3.dim("none")}`;
|
|
5899
|
+
}
|
|
5900
|
+
case "cancel": {
|
|
5901
|
+
const label = this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "cancelled")).join(color3.dim(", "));
|
|
5902
|
+
return `${title}${color3.gray(S_BAR)} ${label.trim() ? `${label}
|
|
5903
|
+
${color3.gray(S_BAR)}` : ""}`;
|
|
5904
|
+
}
|
|
5905
|
+
case "error": {
|
|
5906
|
+
const footer = this.error.split("\n").map(
|
|
5907
|
+
(ln, i) => i === 0 ? `${color3.yellow(S_BAR_END)} ${color3.yellow(ln)}` : ` ${ln}`
|
|
5908
|
+
).join("\n");
|
|
5909
|
+
return title + color3.yellow(S_BAR) + " " + limitOptions({
|
|
5910
|
+
options: this.options,
|
|
5911
|
+
cursor: this.cursor,
|
|
5912
|
+
maxItems: opts.maxItems,
|
|
5913
|
+
style: styleOption
|
|
5914
|
+
}).join(`
|
|
5915
|
+
${color3.yellow(S_BAR)} `) + "\n" + footer + "\n";
|
|
5916
|
+
}
|
|
5917
|
+
default: {
|
|
5918
|
+
return `${title}${color3.cyan(S_BAR)} ${limitOptions({
|
|
5919
|
+
options: this.options,
|
|
5920
|
+
cursor: this.cursor,
|
|
5921
|
+
maxItems: opts.maxItems,
|
|
5922
|
+
style: styleOption
|
|
5923
|
+
}).join(`
|
|
5924
|
+
${color3.cyan(S_BAR)} `)}
|
|
5925
|
+
${color3.cyan(S_BAR_END)}
|
|
5926
|
+
`;
|
|
5927
|
+
}
|
|
5928
|
+
}
|
|
5929
|
+
}
|
|
5930
|
+
}).prompt();
|
|
5931
|
+
};
|
|
5932
|
+
var strip2 = (str) => str.replace(ansiRegex(), "");
|
|
5933
|
+
var note = (message = "", title = "") => {
|
|
5934
|
+
const lines2 = `
|
|
5935
|
+
${message}
|
|
5936
|
+
`.split("\n");
|
|
5937
|
+
const titleLen = strip2(title).length;
|
|
5938
|
+
const len = Math.max(
|
|
5939
|
+
lines2.reduce((sum, ln) => {
|
|
5940
|
+
ln = strip2(ln);
|
|
5941
|
+
return ln.length > sum ? ln.length : sum;
|
|
5942
|
+
}, 0),
|
|
5943
|
+
titleLen
|
|
5944
|
+
) + 2;
|
|
5945
|
+
const msg = lines2.map(
|
|
5946
|
+
(ln) => `${color3.gray(S_BAR)} ${color3.dim(ln)}${" ".repeat(len - strip2(ln).length)}${color3.gray(
|
|
5947
|
+
S_BAR
|
|
5948
|
+
)}`
|
|
5949
|
+
).join("\n");
|
|
5950
|
+
process.stdout.write(
|
|
5951
|
+
`${color3.gray(S_BAR)}
|
|
5952
|
+
${color3.green(S_STEP_SUBMIT)} ${color3.reset(title)} ${color3.gray(
|
|
5953
|
+
S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT
|
|
5954
|
+
)}
|
|
5955
|
+
${msg}
|
|
5956
|
+
${color3.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
5957
|
+
`
|
|
5958
|
+
);
|
|
5959
|
+
};
|
|
5960
|
+
var cancel = (message = "") => {
|
|
5961
|
+
process.stdout.write(`${color3.gray(S_BAR_END)} ${color3.red(message)}
|
|
5962
|
+
|
|
5963
|
+
`);
|
|
5964
|
+
};
|
|
5965
|
+
var intro = (title = "") => {
|
|
5966
|
+
process.stdout.write(`${color3.gray(S_BAR_START)} ${title}
|
|
5967
|
+
`);
|
|
5968
|
+
};
|
|
5969
|
+
var outro = (message = "") => {
|
|
5970
|
+
process.stdout.write(`${color3.gray(S_BAR)}
|
|
5971
|
+
${color3.gray(S_BAR_END)} ${message}
|
|
5972
|
+
|
|
5973
|
+
`);
|
|
5974
|
+
};
|
|
5975
|
+
var log = {
|
|
5976
|
+
message: (message = "", { symbol: symbol3 = color3.gray(S_BAR) } = {}) => {
|
|
5977
|
+
const parts = [`${color3.gray(S_BAR)}`];
|
|
5978
|
+
if (message) {
|
|
5979
|
+
const [firstLine, ...lines2] = message.split("\n");
|
|
5980
|
+
parts.push(`${symbol3} ${firstLine}`, ...lines2.map((ln) => `${color3.gray(S_BAR)} ${ln}`));
|
|
5981
|
+
}
|
|
5982
|
+
process.stdout.write(`${parts.join("\n")}
|
|
5983
|
+
`);
|
|
5984
|
+
},
|
|
5985
|
+
info: (message) => {
|
|
5986
|
+
log.message(message, { symbol: color3.blue(S_INFO) });
|
|
5987
|
+
},
|
|
5988
|
+
success: (message) => {
|
|
5989
|
+
log.message(message, { symbol: color3.green(S_SUCCESS) });
|
|
5990
|
+
},
|
|
5991
|
+
step: (message) => {
|
|
5992
|
+
log.message(message, { symbol: color3.green(S_STEP_SUBMIT) });
|
|
5993
|
+
},
|
|
5994
|
+
warn: (message) => {
|
|
5995
|
+
log.message(message, { symbol: color3.yellow(S_WARN) });
|
|
5996
|
+
},
|
|
5997
|
+
/** alias for `log.warn()`. */
|
|
5998
|
+
warning: (message) => {
|
|
5999
|
+
log.warn(message);
|
|
6000
|
+
},
|
|
6001
|
+
error: (message) => {
|
|
6002
|
+
log.message(message, { symbol: color3.red(S_ERROR) });
|
|
6003
|
+
}
|
|
6004
|
+
};
|
|
6005
|
+
var spinner = () => {
|
|
6006
|
+
const frames = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"];
|
|
6007
|
+
const delay = unicode ? 80 : 120;
|
|
6008
|
+
let unblock;
|
|
6009
|
+
let loop;
|
|
6010
|
+
let isSpinnerActive = false;
|
|
6011
|
+
let _message = "";
|
|
6012
|
+
const handleExit = (code) => {
|
|
6013
|
+
const msg = code > 1 ? "Something went wrong" : "Canceled";
|
|
6014
|
+
if (isSpinnerActive)
|
|
6015
|
+
stop(msg, code);
|
|
6016
|
+
};
|
|
6017
|
+
const errorEventHandler = () => handleExit(2);
|
|
6018
|
+
const signalEventHandler = () => handleExit(1);
|
|
6019
|
+
const registerHooks = () => {
|
|
6020
|
+
process.on("uncaughtExceptionMonitor", errorEventHandler);
|
|
6021
|
+
process.on("unhandledRejection", errorEventHandler);
|
|
6022
|
+
process.on("SIGINT", signalEventHandler);
|
|
6023
|
+
process.on("SIGTERM", signalEventHandler);
|
|
6024
|
+
process.on("exit", handleExit);
|
|
6025
|
+
};
|
|
6026
|
+
const clearHooks = () => {
|
|
6027
|
+
process.removeListener("uncaughtExceptionMonitor", errorEventHandler);
|
|
6028
|
+
process.removeListener("unhandledRejection", errorEventHandler);
|
|
6029
|
+
process.removeListener("SIGINT", signalEventHandler);
|
|
6030
|
+
process.removeListener("SIGTERM", signalEventHandler);
|
|
6031
|
+
process.removeListener("exit", handleExit);
|
|
6032
|
+
};
|
|
6033
|
+
const start = (msg = "") => {
|
|
6034
|
+
isSpinnerActive = true;
|
|
6035
|
+
unblock = block();
|
|
6036
|
+
_message = msg.replace(/\.+$/, "");
|
|
6037
|
+
process.stdout.write(`${color3.gray(S_BAR)}
|
|
6038
|
+
`);
|
|
6039
|
+
let frameIndex = 0;
|
|
6040
|
+
let dotsTimer = 0;
|
|
6041
|
+
registerHooks();
|
|
6042
|
+
loop = setInterval(() => {
|
|
6043
|
+
const frame = color3.magenta(frames[frameIndex]);
|
|
6044
|
+
const loadingDots = ".".repeat(Math.floor(dotsTimer)).slice(0, 3);
|
|
6045
|
+
process.stdout.write(import_sisteransi.cursor.move(-999, 0));
|
|
6046
|
+
process.stdout.write(import_sisteransi.erase.down(1));
|
|
6047
|
+
process.stdout.write(`${frame} ${_message}${loadingDots}`);
|
|
6048
|
+
frameIndex = frameIndex + 1 < frames.length ? frameIndex + 1 : 0;
|
|
6049
|
+
dotsTimer = dotsTimer < frames.length ? dotsTimer + 0.125 : 0;
|
|
6050
|
+
}, delay);
|
|
6051
|
+
};
|
|
6052
|
+
const stop = (msg = "", code = 0) => {
|
|
6053
|
+
_message = msg ?? _message;
|
|
6054
|
+
isSpinnerActive = false;
|
|
6055
|
+
clearInterval(loop);
|
|
6056
|
+
const step = code === 0 ? color3.green(S_STEP_SUBMIT) : code === 1 ? color3.red(S_STEP_CANCEL) : color3.red(S_STEP_ERROR);
|
|
6057
|
+
process.stdout.write(import_sisteransi.cursor.move(-999, 0));
|
|
6058
|
+
process.stdout.write(import_sisteransi.erase.down(1));
|
|
6059
|
+
process.stdout.write(`${step} ${_message}
|
|
6060
|
+
`);
|
|
6061
|
+
clearHooks();
|
|
6062
|
+
unblock();
|
|
6063
|
+
};
|
|
6064
|
+
const message = (msg = "") => {
|
|
6065
|
+
_message = msg ?? _message;
|
|
6066
|
+
};
|
|
6067
|
+
return {
|
|
6068
|
+
start,
|
|
6069
|
+
stop,
|
|
6070
|
+
message
|
|
6071
|
+
};
|
|
6072
|
+
};
|
|
6073
|
+
function ansiRegex() {
|
|
6074
|
+
const pattern = [
|
|
6075
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
6076
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
|
|
6077
|
+
].join("|");
|
|
6078
|
+
return new RegExp(pattern, "g");
|
|
6079
|
+
}
|
|
6080
|
+
var group = async (prompts2, opts) => {
|
|
6081
|
+
const results = {};
|
|
6082
|
+
const promptNames = Object.keys(prompts2);
|
|
6083
|
+
for (const name of promptNames) {
|
|
6084
|
+
const prompt2 = prompts2[name];
|
|
6085
|
+
const result = await prompt2({ results })?.catch((e) => {
|
|
6086
|
+
throw e;
|
|
6087
|
+
});
|
|
6088
|
+
if (typeof opts?.onCancel === "function" && isCancel(result)) {
|
|
6089
|
+
results[name] = "canceled";
|
|
6090
|
+
opts.onCancel({ results });
|
|
6091
|
+
continue;
|
|
6092
|
+
}
|
|
6093
|
+
results[name] = result;
|
|
6094
|
+
}
|
|
6095
|
+
return results;
|
|
6096
|
+
};
|
|
6097
|
+
|
|
5608
6098
|
// src/utils/handle-error.ts
|
|
5609
6099
|
function handleError(error) {
|
|
5610
|
-
const PREFIX = "ERROR: ";
|
|
5611
|
-
logger.error();
|
|
5612
6100
|
if (typeof error === "string") {
|
|
5613
|
-
|
|
6101
|
+
cancel(error);
|
|
5614
6102
|
process.exit(1);
|
|
5615
6103
|
}
|
|
5616
6104
|
if (error instanceof Error) {
|
|
5617
|
-
|
|
6105
|
+
cancel(error.message);
|
|
5618
6106
|
process.exit(1);
|
|
5619
6107
|
}
|
|
5620
|
-
|
|
6108
|
+
cancel("Something went wrong. Please try again.");
|
|
5621
6109
|
process.exit(1);
|
|
5622
6110
|
}
|
|
5623
6111
|
|
|
5624
6112
|
// src/utils/registry/index.ts
|
|
5625
|
-
import path9 from "path";
|
|
6113
|
+
import path9 from "node:path";
|
|
5626
6114
|
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
5627
6115
|
import fetch from "node-fetch";
|
|
5628
6116
|
|
|
@@ -5630,8 +6118,8 @@ import fetch from "node-fetch";
|
|
|
5630
6118
|
import * as z2 from "zod";
|
|
5631
6119
|
var registryItemSchema = z2.object({
|
|
5632
6120
|
name: z2.string(),
|
|
5633
|
-
dependencies: z2.array(z2.string())
|
|
5634
|
-
registryDependencies: z2.array(z2.string())
|
|
6121
|
+
dependencies: z2.array(z2.string()),
|
|
6122
|
+
registryDependencies: z2.array(z2.string()),
|
|
5635
6123
|
files: z2.array(z2.string()),
|
|
5636
6124
|
type: z2.enum(["components:ui", "components:component", "components:example"])
|
|
5637
6125
|
});
|
|
@@ -5742,7 +6230,7 @@ async function fetchTree(config, tree) {
|
|
|
5742
6230
|
throw new Error(`Failed to fetch tree from registry.`);
|
|
5743
6231
|
}
|
|
5744
6232
|
}
|
|
5745
|
-
|
|
6233
|
+
function getItemTargetPath(config, item2, override2) {
|
|
5746
6234
|
if (override2 && item2.type !== "components:ui") {
|
|
5747
6235
|
return override2;
|
|
5748
6236
|
}
|
|
@@ -6190,10 +6678,10 @@ var warned = {
|
|
|
6190
6678
|
storeName: false
|
|
6191
6679
|
};
|
|
6192
6680
|
var MagicString = class {
|
|
6193
|
-
constructor(
|
|
6194
|
-
const chunk = new Chunk(0,
|
|
6681
|
+
constructor(string5, options2 = {}) {
|
|
6682
|
+
const chunk = new Chunk(0, string5.length, string5);
|
|
6195
6683
|
Object.defineProperties(this, {
|
|
6196
|
-
original: { writable: true, value:
|
|
6684
|
+
original: { writable: true, value: string5 },
|
|
6197
6685
|
outro: { writable: true, value: "" },
|
|
6198
6686
|
intro: { writable: true, value: "" },
|
|
6199
6687
|
firstChunk: { writable: true, value: chunk },
|
|
@@ -6209,7 +6697,7 @@ var MagicString = class {
|
|
|
6209
6697
|
ignoreList: { writable: true, value: options2.ignoreList }
|
|
6210
6698
|
});
|
|
6211
6699
|
this.byStart[0] = chunk;
|
|
6212
|
-
this.byEnd[
|
|
6700
|
+
this.byEnd[string5.length] = chunk;
|
|
6213
6701
|
}
|
|
6214
6702
|
addSourcemapLocation(char) {
|
|
6215
6703
|
this.sourcemapLocations.add(char);
|
|
@@ -6828,11 +7316,11 @@ var MagicString = class {
|
|
|
6828
7316
|
}
|
|
6829
7317
|
return this;
|
|
6830
7318
|
}
|
|
6831
|
-
_replaceString(
|
|
7319
|
+
_replaceString(string5, replacement) {
|
|
6832
7320
|
const { original } = this;
|
|
6833
|
-
const index = original.indexOf(
|
|
7321
|
+
const index = original.indexOf(string5);
|
|
6834
7322
|
if (index !== -1) {
|
|
6835
|
-
this.overwrite(index, index +
|
|
7323
|
+
this.overwrite(index, index + string5.length, replacement);
|
|
6836
7324
|
}
|
|
6837
7325
|
return this;
|
|
6838
7326
|
}
|
|
@@ -6842,10 +7330,10 @@ var MagicString = class {
|
|
|
6842
7330
|
}
|
|
6843
7331
|
return this._replaceRegexp(searchValue, replacement);
|
|
6844
7332
|
}
|
|
6845
|
-
_replaceAllString(
|
|
7333
|
+
_replaceAllString(string5, replacement) {
|
|
6846
7334
|
const { original } = this;
|
|
6847
|
-
const stringLength =
|
|
6848
|
-
for (let index = original.indexOf(
|
|
7335
|
+
const stringLength = string5.length;
|
|
7336
|
+
for (let index = original.indexOf(string5); index !== -1; index = original.indexOf(string5, index + stringLength)) {
|
|
6849
7337
|
this.overwrite(index, index + stringLength, replacement);
|
|
6850
7338
|
}
|
|
6851
7339
|
return this;
|
|
@@ -6865,13 +7353,31 @@ var MagicString = class {
|
|
|
6865
7353
|
|
|
6866
7354
|
// src/utils/transformers.ts
|
|
6867
7355
|
function transformImports(content, config) {
|
|
6868
|
-
const
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
return
|
|
7356
|
+
const s2 = new MagicString(content);
|
|
7357
|
+
s2.replaceAll(/\$lib\/registry\/[^/]+/g, config.aliases.components);
|
|
7358
|
+
s2.replaceAll(/\$lib\/utils/g, config.aliases.utils);
|
|
7359
|
+
return s2.toString();
|
|
7360
|
+
}
|
|
7361
|
+
|
|
7362
|
+
// src/utils/prompt-helpers.ts
|
|
7363
|
+
import color4 from "chalk";
|
|
7364
|
+
function intro2() {
|
|
7365
|
+
const packageInfo = getPackageInfo();
|
|
7366
|
+
const title = color4.bgHex("#FF5500").black(" shadcn-svelte ");
|
|
7367
|
+
const version = color4.gray(` v${packageInfo.version} `);
|
|
7368
|
+
intro(title + version);
|
|
7369
|
+
}
|
|
7370
|
+
function prettifyList(arr, max = 9) {
|
|
7371
|
+
return arr.reduce((pre, curr, i) => {
|
|
7372
|
+
if (i % max === 0)
|
|
7373
|
+
return `${pre},
|
|
7374
|
+
${curr}`;
|
|
7375
|
+
return `${pre}, ${curr}`;
|
|
7376
|
+
});
|
|
6872
7377
|
}
|
|
6873
7378
|
|
|
6874
7379
|
// src/commands/add.ts
|
|
7380
|
+
var highlight2 = (...args) => color5.bold.cyan(...args);
|
|
6875
7381
|
var addOptionsSchema = z3.object({
|
|
6876
7382
|
components: z3.array(z3.string()).optional(),
|
|
6877
7383
|
yes: z3.boolean(),
|
|
@@ -6882,170 +7388,187 @@ var addOptionsSchema = z3.object({
|
|
|
6882
7388
|
nodep: z3.boolean(),
|
|
6883
7389
|
proxy: z3.string().optional()
|
|
6884
7390
|
});
|
|
6885
|
-
var add = new Command().command("add").description("add components to your project").argument("[components...]", "name of components").option("--nodep", "
|
|
7391
|
+
var add = new Command().command("add").description("add components to your project").argument("[components...]", "name of components").option("--nodep", "skips adding & installing package dependencies.", false).option("-a, --all", "install all components to your project.", false).option("-y, --yes", "skip confirmation prompt.", false).option("-o, --overwrite", "overwrite existing files.", false).option("--proxy <proxy>", "fetch components from registry using a proxy.").option(
|
|
6886
7392
|
"-c, --cwd <cwd>",
|
|
6887
7393
|
"the working directory. defaults to the current directory.",
|
|
6888
7394
|
process.cwd()
|
|
6889
7395
|
).option("-p, --path <path>", "the path to add the component to.").action(async (components, opts) => {
|
|
6890
7396
|
try {
|
|
7397
|
+
intro2();
|
|
6891
7398
|
const options2 = addOptionsSchema.parse({
|
|
6892
7399
|
components,
|
|
6893
7400
|
...opts
|
|
6894
7401
|
});
|
|
6895
7402
|
const cwd = path10.resolve(options2.cwd);
|
|
6896
7403
|
if (!existsSync2(cwd)) {
|
|
6897
|
-
|
|
6898
|
-
process.
|
|
6899
|
-
return;
|
|
7404
|
+
cancel(`The path ${color5.cyan(cwd)} does not exist. Please try again.`);
|
|
7405
|
+
process.exit(1);
|
|
6900
7406
|
}
|
|
6901
7407
|
const config = await getConfig2(cwd);
|
|
6902
7408
|
if (!config) {
|
|
6903
|
-
|
|
6904
|
-
`Configuration is missing. Please run ${
|
|
6905
|
-
`init`
|
|
6906
|
-
)} to create a components.json file.`
|
|
6907
|
-
);
|
|
6908
|
-
process.exitCode = 1;
|
|
6909
|
-
return;
|
|
6910
|
-
}
|
|
6911
|
-
const chosenProxy = options2.proxy ?? getEnvProxy();
|
|
6912
|
-
if (chosenProxy) {
|
|
6913
|
-
const isCustom = !!options2.proxy;
|
|
6914
|
-
if (isCustom)
|
|
6915
|
-
process.env.HTTP_PROXY = options2.proxy;
|
|
6916
|
-
logger.warn(
|
|
6917
|
-
`You are using a ${isCustom ? "provided" : "system environment"} proxy: ${chalk3.green(chosenProxy)}`
|
|
7409
|
+
cancel(
|
|
7410
|
+
`Configuration file is missing. Please run ${color5.green("init")} to create a ${highlight2("components.json")} file.`
|
|
6918
7411
|
);
|
|
7412
|
+
process.exit(1);
|
|
6919
7413
|
}
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
})
|
|
6934
|
-
|
|
7414
|
+
await runAdd(cwd, config, options2);
|
|
7415
|
+
outro(`${color5.green("Success!")} Component installation completed.`);
|
|
7416
|
+
} catch (error) {
|
|
7417
|
+
handleError(error);
|
|
7418
|
+
}
|
|
7419
|
+
});
|
|
7420
|
+
async function runAdd(cwd, config, options2) {
|
|
7421
|
+
const proxy = options2.proxy ?? getEnvProxy();
|
|
7422
|
+
if (proxy) {
|
|
7423
|
+
const isCustom = !!options2.proxy;
|
|
7424
|
+
if (isCustom)
|
|
7425
|
+
process.env.HTTP_PROXY = options2.proxy;
|
|
7426
|
+
log.warn(
|
|
7427
|
+
`You are using a ${isCustom ? "provided" : "system environment"} proxy: ${color5.green(proxy)}`
|
|
7428
|
+
);
|
|
7429
|
+
}
|
|
7430
|
+
const registryIndex = await getRegistryIndex();
|
|
7431
|
+
let selectedComponents = options2.all ? registryIndex.map(({ name }) => name) : options2.components;
|
|
7432
|
+
if (selectedComponents === void 0 || selectedComponents.length === 0) {
|
|
7433
|
+
const components = await multiselect2({
|
|
7434
|
+
message: `Which ${highlight2("components")} would you like to install?`,
|
|
7435
|
+
maxItems: 10,
|
|
7436
|
+
options: registryIndex.map(({ name, dependencies: dependencies2, registryDependencies }) => {
|
|
7437
|
+
const deps = [...options2.nodep ? [] : dependencies2, ...registryDependencies];
|
|
7438
|
+
return {
|
|
7439
|
+
label: name,
|
|
7440
|
+
value: name,
|
|
7441
|
+
hint: deps.length ? `also installs: ${deps.join(", ")}` : void 0
|
|
7442
|
+
};
|
|
7443
|
+
})
|
|
7444
|
+
});
|
|
7445
|
+
if (isCancel2(components)) {
|
|
7446
|
+
cancel("Operation cancelled.");
|
|
7447
|
+
process.exit(0);
|
|
6935
7448
|
}
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
7449
|
+
selectedComponents = components;
|
|
7450
|
+
} else {
|
|
7451
|
+
const prettyList = prettifyList(selectedComponents);
|
|
7452
|
+
log.step(`Components to install:
|
|
7453
|
+
${color5.gray(prettyList)}`);
|
|
7454
|
+
}
|
|
7455
|
+
const tree = await resolveTree(registryIndex, selectedComponents);
|
|
7456
|
+
const payload = await fetchTree(config, tree);
|
|
7457
|
+
if (payload.length === 0) {
|
|
7458
|
+
cancel("Selected components not found.");
|
|
7459
|
+
process.exit(0);
|
|
7460
|
+
}
|
|
7461
|
+
const existingComponents = [];
|
|
7462
|
+
const targetPath = options2.path ? path10.resolve(cwd, options2.path) : void 0;
|
|
7463
|
+
for (const item2 of payload) {
|
|
7464
|
+
if (selectedComponents.includes(item2.name) === false)
|
|
7465
|
+
continue;
|
|
7466
|
+
const targetDir = getItemTargetPath(config, item2, targetPath);
|
|
7467
|
+
if (targetDir === null)
|
|
7468
|
+
continue;
|
|
7469
|
+
const componentExists = item2.files.some((file) => {
|
|
7470
|
+
return existsSync2(path10.resolve(targetDir, item2.name, file.name));
|
|
7471
|
+
});
|
|
7472
|
+
if (componentExists) {
|
|
7473
|
+
existingComponents.push(item2.name);
|
|
6940
7474
|
}
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
const
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
7475
|
+
}
|
|
7476
|
+
if (options2.overwrite === false && existingComponents.length > 0) {
|
|
7477
|
+
const prettyList = prettifyList(existingComponents);
|
|
7478
|
+
log.warn(
|
|
7479
|
+
`The following components ${color5.bold.yellow("already exists")}:
|
|
7480
|
+
${color5.gray(prettyList)}`
|
|
7481
|
+
);
|
|
7482
|
+
const overwrite = await confirm2({
|
|
7483
|
+
message: `Would you like to ${color5.bold.red("overwrite")} all existing components?`,
|
|
7484
|
+
active: "Yes, overwrite everything",
|
|
7485
|
+
inactive: "No, let me decide individually",
|
|
7486
|
+
initialValue: false
|
|
7487
|
+
});
|
|
7488
|
+
if (isCancel2(overwrite)) {
|
|
7489
|
+
cancel("Operation cancelled.");
|
|
7490
|
+
process.exit(0);
|
|
6948
7491
|
}
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
process.exitCode = 0;
|
|
6960
|
-
return;
|
|
6961
|
-
}
|
|
7492
|
+
options2.overwrite = overwrite;
|
|
7493
|
+
}
|
|
7494
|
+
if (options2.yes === false) {
|
|
7495
|
+
const proceed = await confirm2({
|
|
7496
|
+
message: `Ready to install ${highlight2("components")}${options2.nodep ? "?" : ` and ${highlight2("dependencies")}?`}`,
|
|
7497
|
+
initialValue: true
|
|
7498
|
+
});
|
|
7499
|
+
if (isCancel2(proceed) || proceed === false) {
|
|
7500
|
+
cancel("Operation cancelled.");
|
|
7501
|
+
process.exit(0);
|
|
6962
7502
|
}
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
});
|
|
6986
|
-
if (existingComponent.length && !options2.overwrite) {
|
|
6987
|
-
if (selectedComponents.includes(item2.name)) {
|
|
6988
|
-
logger.warn(
|
|
6989
|
-
`
|
|
6990
|
-
Component ${logger.highlight(
|
|
6991
|
-
item2.name
|
|
6992
|
-
)} already exists at ${logger.highlight(
|
|
6993
|
-
componentPath
|
|
6994
|
-
)}. Use ${chalk3.green("--overwrite")} to overwrite.`
|
|
6995
|
-
);
|
|
6996
|
-
spinner.stop();
|
|
6997
|
-
process.exitCode = 1;
|
|
6998
|
-
return;
|
|
6999
|
-
}
|
|
7000
|
-
continue;
|
|
7001
|
-
}
|
|
7002
|
-
for (const file of item2.files) {
|
|
7003
|
-
const componentDir = path10.resolve(targetDir, item2.name);
|
|
7004
|
-
let filePath = path10.resolve(targetDir, item2.name, file.name);
|
|
7005
|
-
const content = transformImports(file.content, config);
|
|
7006
|
-
if (!existsSync2(componentDir)) {
|
|
7007
|
-
await fs6.mkdir(componentDir, { recursive: true });
|
|
7503
|
+
}
|
|
7504
|
+
const skippedDeps = /* @__PURE__ */ new Set();
|
|
7505
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
7506
|
+
for (const item2 of payload) {
|
|
7507
|
+
const targetDir = getItemTargetPath(config, item2, targetPath);
|
|
7508
|
+
if (targetDir === null)
|
|
7509
|
+
continue;
|
|
7510
|
+
if (!existsSync2(targetDir)) {
|
|
7511
|
+
await fs6.mkdir(targetDir, { recursive: true });
|
|
7512
|
+
}
|
|
7513
|
+
const componentPath = path10.relative(process.cwd(), path10.resolve(targetDir, item2.name));
|
|
7514
|
+
if (!options2.overwrite && existingComponents.includes(item2.name)) {
|
|
7515
|
+
if (selectedComponents.includes(item2.name)) {
|
|
7516
|
+
log.warn(
|
|
7517
|
+
`Component ${highlight2(item2.name)} already exists at ${color5.gray(componentPath)}`
|
|
7518
|
+
);
|
|
7519
|
+
const overwrite = await confirm2({
|
|
7520
|
+
message: `Would you like to ${color5.bold.red("overwrite")} your existing ${highlight2(item2.name)} component?`
|
|
7521
|
+
});
|
|
7522
|
+
if (isCancel2(overwrite)) {
|
|
7523
|
+
cancel("Operation cancelled.");
|
|
7524
|
+
process.exit(0);
|
|
7008
7525
|
}
|
|
7009
|
-
|
|
7010
|
-
}
|
|
7011
|
-
if (item2.dependencies?.length) {
|
|
7012
|
-
if (options2.nodep) {
|
|
7013
|
-
item2.dependencies.forEach((dep) => skippedDeps.add(dep));
|
|
7526
|
+
if (overwrite === false)
|
|
7014
7527
|
continue;
|
|
7015
|
-
}
|
|
7016
|
-
const packageManager = await getPackageManager(cwd);
|
|
7017
|
-
await execa3(packageManager, ["add", ...item2.dependencies], {
|
|
7018
|
-
cwd
|
|
7019
|
-
});
|
|
7020
7528
|
}
|
|
7021
|
-
componentPaths.push(componentPath);
|
|
7022
7529
|
}
|
|
7023
|
-
|
|
7024
|
-
|
|
7530
|
+
const installSpinner = spinner();
|
|
7531
|
+
installSpinner.start(`Installing ${highlight2(item2.name)}`);
|
|
7532
|
+
for (const file of item2.files) {
|
|
7533
|
+
const componentDir = path10.resolve(targetDir, item2.name);
|
|
7534
|
+
let filePath = path10.resolve(targetDir, item2.name, file.name);
|
|
7535
|
+
const content = transformImports(file.content, config);
|
|
7536
|
+
if (!existsSync2(componentDir)) {
|
|
7537
|
+
await fs6.mkdir(componentDir, { recursive: true });
|
|
7538
|
+
}
|
|
7539
|
+
await fs6.writeFile(filePath, content);
|
|
7540
|
+
}
|
|
7025
7541
|
if (options2.nodep) {
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
...skippedDeps
|
|
7030
|
-
].join("\n- ")}`
|
|
7031
|
-
);
|
|
7542
|
+
item2.dependencies.forEach((dep) => skippedDeps.add(dep));
|
|
7543
|
+
} else {
|
|
7544
|
+
item2.dependencies.forEach((dep) => dependencies.add(dep));
|
|
7032
7545
|
}
|
|
7033
|
-
|
|
7034
|
-
logger.info("Components installed at:");
|
|
7035
|
-
logger.info(logger.highlight(componentPaths.map((path13) => `- ${path13}`).join("\n")));
|
|
7036
|
-
} catch (error) {
|
|
7037
|
-
handleError(error);
|
|
7546
|
+
installSpinner.stop(`${highlight2(item2.name)} installed at ${color5.gray(componentPath)}`);
|
|
7038
7547
|
}
|
|
7039
|
-
|
|
7548
|
+
if (dependencies.size > 0) {
|
|
7549
|
+
const spinner2 = spinner();
|
|
7550
|
+
spinner2.start("Installing package dependencies");
|
|
7551
|
+
const packageManager = await getPackageManager(cwd);
|
|
7552
|
+
await execa3(packageManager, ["add", ...dependencies], {
|
|
7553
|
+
cwd
|
|
7554
|
+
});
|
|
7555
|
+
spinner2.stop("Dependencies installed");
|
|
7556
|
+
}
|
|
7557
|
+
if (options2.nodep) {
|
|
7558
|
+
const prettyList = prettifyList([...skippedDeps], 7);
|
|
7559
|
+
log.warn(
|
|
7560
|
+
`Components have been installed ${color5.bold.red("without")} the following ${highlight2("dependencies")}:
|
|
7561
|
+
${color5.gray(prettyList)}`
|
|
7562
|
+
);
|
|
7563
|
+
}
|
|
7564
|
+
}
|
|
7040
7565
|
|
|
7041
7566
|
// src/commands/init.ts
|
|
7042
|
-
import { existsSync as existsSync3, promises as fs7 } from "fs";
|
|
7043
|
-
import path11 from "path";
|
|
7044
|
-
import
|
|
7567
|
+
import { existsSync as existsSync3, promises as fs7 } from "node:fs";
|
|
7568
|
+
import path11 from "node:path";
|
|
7569
|
+
import color6 from "chalk";
|
|
7045
7570
|
import { Command as Command2 } from "commander";
|
|
7046
7571
|
import { execa as execa4 } from "execa";
|
|
7047
|
-
import ora2 from "ora";
|
|
7048
|
-
import prompts3 from "prompts";
|
|
7049
7572
|
|
|
7050
7573
|
// src/utils/templates.ts
|
|
7051
7574
|
var UTILS = `import { type ClassValue, clsx } from "clsx";
|
|
@@ -7226,121 +7749,95 @@ export default config;
|
|
|
7226
7749
|
|
|
7227
7750
|
// src/commands/init.ts
|
|
7228
7751
|
var PROJECT_DEPENDENCIES = ["tailwind-variants", "clsx", "tailwind-merge"];
|
|
7229
|
-
var
|
|
7752
|
+
var highlight3 = (...args) => color6.bold.cyan(...args);
|
|
7753
|
+
var init2 = new Command2().command("init").description("initialize your project and install dependencies").option(
|
|
7230
7754
|
"-c, --cwd <cwd>",
|
|
7231
7755
|
"the working directory. defaults to the current directory.",
|
|
7232
7756
|
process.cwd()
|
|
7233
7757
|
).action(async (options2) => {
|
|
7758
|
+
intro2();
|
|
7234
7759
|
const cwd = path11.resolve(options2.cwd);
|
|
7235
|
-
logger.warn("This command assumes a SvelteKit project with Tailwind CSS.");
|
|
7236
|
-
logger.warn(
|
|
7237
|
-
"If you don't have these, follow the manual steps at https://shadcn-svelte.com/docs/installation."
|
|
7238
|
-
);
|
|
7239
|
-
logger.warn("");
|
|
7240
|
-
if (!options2.yes) {
|
|
7241
|
-
const { proceed } = await prompts3([
|
|
7242
|
-
{
|
|
7243
|
-
type: "confirm",
|
|
7244
|
-
name: "proceed",
|
|
7245
|
-
message: "Running this command will install dependencies and overwrite your existing tailwind.config.[cjs|js|ts] & app.pcss file. Proceed?",
|
|
7246
|
-
initial: true
|
|
7247
|
-
}
|
|
7248
|
-
]);
|
|
7249
|
-
if (!proceed) {
|
|
7250
|
-
process.exitCode = 0;
|
|
7251
|
-
return;
|
|
7252
|
-
}
|
|
7253
|
-
}
|
|
7254
7760
|
try {
|
|
7255
7761
|
if (!existsSync3(cwd)) {
|
|
7256
|
-
|
|
7257
|
-
process.
|
|
7258
|
-
return;
|
|
7762
|
+
cancel(`The path ${color6.cyan(cwd)} does not exist. Please try again.`);
|
|
7763
|
+
process.exit(1);
|
|
7259
7764
|
}
|
|
7260
7765
|
const existingConfig = await getConfig2(cwd);
|
|
7261
|
-
const config = await promptForConfig(cwd, existingConfig
|
|
7766
|
+
const config = await promptForConfig(cwd, existingConfig);
|
|
7262
7767
|
await runInit(cwd, config);
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
logger.info("");
|
|
7768
|
+
if (!config.aliases.components.startsWith("$lib") || !config.aliases.utils.startsWith("$lib")) {
|
|
7769
|
+
note("Don't forget to add the import aliases you configured to your svelte.config.js!");
|
|
7770
|
+
}
|
|
7771
|
+
outro(`${color6.green("Success!")} Project initialization completed.`);
|
|
7268
7772
|
} catch (e) {
|
|
7269
7773
|
handleError(e);
|
|
7270
7774
|
}
|
|
7271
7775
|
});
|
|
7272
|
-
async function promptForConfig(cwd, defaultConfig = null
|
|
7273
|
-
const highlight = logger.highlight;
|
|
7776
|
+
async function promptForConfig(cwd, defaultConfig = null) {
|
|
7274
7777
|
const styles2 = await getRegistryStyles();
|
|
7275
7778
|
const baseColors = await getRegistryBaseColors();
|
|
7276
|
-
const options2 = await
|
|
7277
|
-
{
|
|
7278
|
-
type: "toggle",
|
|
7279
|
-
name: "typescript",
|
|
7280
|
-
message: `Would you like to use ${highlight("TypeScript")} (recommended)?`,
|
|
7281
|
-
initial: defaultConfig?.typescript ?? DEFAULT_TYPESCRIPT,
|
|
7282
|
-
active: "yes",
|
|
7283
|
-
inactive: "no"
|
|
7284
|
-
},
|
|
7285
|
-
{
|
|
7286
|
-
type: "select",
|
|
7287
|
-
name: "style",
|
|
7288
|
-
message: `Which ${highlight("style")} would you like to use?`,
|
|
7289
|
-
choices: styles2.map((style2) => ({
|
|
7290
|
-
title: style2.label,
|
|
7291
|
-
value: style2.name
|
|
7292
|
-
}))
|
|
7293
|
-
},
|
|
7294
|
-
{
|
|
7295
|
-
type: "select",
|
|
7296
|
-
name: "tailwindBaseColor",
|
|
7297
|
-
message: `Which color would you like to use as ${highlight("base color")}?`,
|
|
7298
|
-
choices: baseColors.map((color2) => ({
|
|
7299
|
-
title: color2.label,
|
|
7300
|
-
value: color2.name
|
|
7301
|
-
}))
|
|
7302
|
-
},
|
|
7779
|
+
const options2 = await group(
|
|
7303
7780
|
{
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7781
|
+
typescript: () => confirm2({
|
|
7782
|
+
message: `Would you like to use ${highlight3("TypeScript")} (recommended)?`,
|
|
7783
|
+
initialValue: defaultConfig?.typescript ?? DEFAULT_TYPESCRIPT
|
|
7784
|
+
}),
|
|
7785
|
+
style: ({}) => select2({
|
|
7786
|
+
message: `Which ${highlight3("style")} would you like to use?`,
|
|
7787
|
+
initialValue: defaultConfig?.style,
|
|
7788
|
+
options: styles2.map((style2) => ({
|
|
7789
|
+
label: style2.label,
|
|
7790
|
+
value: style2.name
|
|
7791
|
+
}))
|
|
7792
|
+
}),
|
|
7793
|
+
tailwindBaseColor: ({}) => select2({
|
|
7794
|
+
message: `Which ${highlight3("base color")} would you like to use?`,
|
|
7795
|
+
initialValue: defaultConfig?.tailwind.baseColor,
|
|
7796
|
+
options: baseColors.map((color8) => ({
|
|
7797
|
+
label: color8.label,
|
|
7798
|
+
value: color8.name
|
|
7799
|
+
}))
|
|
7800
|
+
}),
|
|
7801
|
+
tailwindCss: () => text2({
|
|
7802
|
+
message: `Where is your ${highlight3("global CSS")} file?`,
|
|
7803
|
+
initialValue: defaultConfig?.tailwind.css ?? DEFAULT_TAILWIND_CSS,
|
|
7804
|
+
placeholder: DEFAULT_TAILWIND_CSS,
|
|
7805
|
+
validate: (value) => {
|
|
7806
|
+
if (existsSync3(path11.resolve(cwd, value))) {
|
|
7807
|
+
return;
|
|
7808
|
+
}
|
|
7809
|
+
return `${color6.bold(value)} does not exist. Please enter a valid path.`;
|
|
7311
7810
|
}
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
if (existsSync3(value)) {
|
|
7323
|
-
return true;
|
|
7811
|
+
}),
|
|
7812
|
+
tailwindConfig: () => text2({
|
|
7813
|
+
message: `Where is your ${highlight3("Tailwind config")} located?`,
|
|
7814
|
+
initialValue: defaultConfig?.tailwind.config ?? DEFAULT_TAILWIND_CONFIG,
|
|
7815
|
+
placeholder: DEFAULT_TAILWIND_CONFIG,
|
|
7816
|
+
validate: (value) => {
|
|
7817
|
+
if (existsSync3(path11.resolve(cwd, value))) {
|
|
7818
|
+
return;
|
|
7819
|
+
}
|
|
7820
|
+
return `${color6.bold(value)} does not exist. Please enter a valid path.`;
|
|
7324
7821
|
}
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7822
|
+
}),
|
|
7823
|
+
components: () => text2({
|
|
7824
|
+
message: `Configure the import alias for ${highlight3("components")}:`,
|
|
7825
|
+
initialValue: defaultConfig?.aliases["components"] ?? DEFAULT_COMPONENTS,
|
|
7826
|
+
placeholder: DEFAULT_COMPONENTS
|
|
7827
|
+
}),
|
|
7828
|
+
utils: () => text2({
|
|
7829
|
+
message: `Configure the import alias for ${highlight3("utils")}:`,
|
|
7830
|
+
initialValue: defaultConfig?.aliases["utils"] ?? DEFAULT_UTILS,
|
|
7831
|
+
placeholder: DEFAULT_UTILS
|
|
7832
|
+
})
|
|
7336
7833
|
},
|
|
7337
7834
|
{
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7835
|
+
onCancel: () => {
|
|
7836
|
+
cancel("Operation cancelled.");
|
|
7837
|
+
process.exit(0);
|
|
7838
|
+
}
|
|
7342
7839
|
}
|
|
7343
|
-
|
|
7840
|
+
);
|
|
7344
7841
|
const config = rawConfigSchema.parse({
|
|
7345
7842
|
$schema: "https://shadcn-svelte.com/schema.json",
|
|
7346
7843
|
style: options2.style,
|
|
@@ -7355,32 +7852,22 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
|
|
|
7355
7852
|
components: options2.components
|
|
7356
7853
|
}
|
|
7357
7854
|
});
|
|
7358
|
-
if (!skip) {
|
|
7359
|
-
const { proceed } = await prompts3({
|
|
7360
|
-
type: "confirm",
|
|
7361
|
-
name: "proceed",
|
|
7362
|
-
message: `Write configuration to ${highlight("components.json")}. Proceed?`,
|
|
7363
|
-
initial: true
|
|
7364
|
-
});
|
|
7365
|
-
if (!proceed) {
|
|
7366
|
-
process.exitCode = 0;
|
|
7367
|
-
}
|
|
7368
|
-
}
|
|
7369
7855
|
if (config.tailwind.config.endsWith(".cjs")) {
|
|
7370
|
-
|
|
7856
|
+
log.info(`Your tailwind config has been renamed to ${highlight3("tailwind.config.js")}.`);
|
|
7371
7857
|
const renamedTailwindConfigPath = config.tailwind.config.replace(".cjs", ".js");
|
|
7372
7858
|
config.tailwind.config = renamedTailwindConfigPath;
|
|
7373
7859
|
}
|
|
7374
7860
|
const configPaths = await resolveConfigPaths(cwd, config);
|
|
7375
|
-
|
|
7376
|
-
|
|
7861
|
+
const spinner2 = spinner();
|
|
7862
|
+
spinner2.start(`Creating config file ${highlight3("components.json")}`);
|
|
7377
7863
|
const targetPath = path11.resolve(cwd, "components.json");
|
|
7378
7864
|
await fs7.writeFile(targetPath, JSON.stringify(config, null, 2), "utf8");
|
|
7379
|
-
|
|
7865
|
+
spinner2.stop(`Config file ${highlight3("components.json")} created`);
|
|
7380
7866
|
return configPaths;
|
|
7381
7867
|
}
|
|
7382
7868
|
async function runInit(cwd, config) {
|
|
7383
|
-
const
|
|
7869
|
+
const spinner2 = spinner();
|
|
7870
|
+
spinner2.start(`Initializing project`);
|
|
7384
7871
|
for (const [key, resolvedPath] of Object.entries(config.resolvedPaths)) {
|
|
7385
7872
|
let dirname2 = path11.extname(resolvedPath) ? path11.dirname(resolvedPath) : resolvedPath;
|
|
7386
7873
|
if (key === "utils" && resolvedPath.endsWith("/utils")) {
|
|
@@ -7405,8 +7892,9 @@ async function runInit(cwd, config) {
|
|
|
7405
7892
|
const utilsPath = config.resolvedPaths.utils + (config.typescript ? ".ts" : ".js");
|
|
7406
7893
|
const utilsTemplate = config.typescript ? UTILS : UTILS_JS;
|
|
7407
7894
|
await fs7.writeFile(utilsPath, utilsTemplate, "utf8");
|
|
7408
|
-
|
|
7409
|
-
const dependenciesSpinner =
|
|
7895
|
+
spinner2.stop("Project initialized");
|
|
7896
|
+
const dependenciesSpinner = spinner();
|
|
7897
|
+
dependenciesSpinner.start(`Installing dependencies`);
|
|
7410
7898
|
const packageManager = await getPackageManager(cwd);
|
|
7411
7899
|
const deps = [
|
|
7412
7900
|
...PROJECT_DEPENDENCIES,
|
|
@@ -7415,191 +7903,210 @@ async function runInit(cwd, config) {
|
|
|
7415
7903
|
await execa4(packageManager, ["add", ...deps], {
|
|
7416
7904
|
cwd
|
|
7417
7905
|
});
|
|
7418
|
-
dependenciesSpinner
|
|
7906
|
+
dependenciesSpinner.stop("Dependencies installed");
|
|
7419
7907
|
}
|
|
7420
7908
|
|
|
7421
7909
|
// src/commands/update.ts
|
|
7422
7910
|
import { existsSync as existsSync4, promises as fs8 } from "fs";
|
|
7423
7911
|
import path12 from "path";
|
|
7424
|
-
import
|
|
7912
|
+
import color7 from "chalk";
|
|
7425
7913
|
import { Command as Command3 } from "commander";
|
|
7426
7914
|
import { execa as execa5 } from "execa";
|
|
7427
|
-
import
|
|
7428
|
-
import prompts4 from "prompts";
|
|
7429
|
-
import { z as z4 } from "zod";
|
|
7915
|
+
import * as z4 from "zod";
|
|
7430
7916
|
var updateOptionsSchema = z4.object({
|
|
7431
7917
|
all: z4.boolean(),
|
|
7432
7918
|
components: z4.array(z4.string()).optional(),
|
|
7433
|
-
cwd: z4.string()
|
|
7919
|
+
cwd: z4.string(),
|
|
7920
|
+
proxy: z4.string().optional(),
|
|
7921
|
+
yes: z4.boolean()
|
|
7434
7922
|
});
|
|
7435
|
-
var
|
|
7923
|
+
var highlight4 = (msg) => color7.bold.cyan(msg);
|
|
7924
|
+
var update = new Command3().command("update").description("update components in your project").argument("[components...]", "name of components").option("-a, --all", "update all existing components.", false).option("-y, --yes", "skip confirmation prompt.", false).option("--proxy <proxy>", "fetch components from registry using a proxy.").option(
|
|
7436
7925
|
"-c, --cwd <cwd>",
|
|
7437
7926
|
"the working directory. defaults to the current directory.",
|
|
7438
7927
|
process.cwd()
|
|
7439
|
-
).action(async (
|
|
7440
|
-
|
|
7441
|
-
logger.warn("Make sure you have committed your changes before proceeding.");
|
|
7442
|
-
logger.warn("");
|
|
7928
|
+
).action(async (components, opts) => {
|
|
7929
|
+
intro2();
|
|
7443
7930
|
try {
|
|
7444
7931
|
const options2 = updateOptionsSchema.parse({
|
|
7445
|
-
components
|
|
7932
|
+
components,
|
|
7446
7933
|
...opts
|
|
7447
7934
|
});
|
|
7448
|
-
const components = options2.components;
|
|
7449
7935
|
const cwd = path12.resolve(options2.cwd);
|
|
7450
7936
|
if (!existsSync4(cwd)) {
|
|
7451
|
-
|
|
7452
|
-
process.
|
|
7453
|
-
return;
|
|
7937
|
+
cancel(`The path ${color7.cyan(cwd)} does not exist. Please try again.`);
|
|
7938
|
+
process.exit(1);
|
|
7454
7939
|
}
|
|
7455
7940
|
const config = await getConfig2(cwd);
|
|
7456
7941
|
if (!config) {
|
|
7457
|
-
|
|
7458
|
-
`Configuration is missing. Please run ${
|
|
7459
|
-
`init`
|
|
7460
|
-
)} to create a components.json file.`
|
|
7942
|
+
cancel(
|
|
7943
|
+
`Configuration file is missing. Please run ${color7.green("init")} to create a ${highlight4("components.json")} file.`
|
|
7461
7944
|
);
|
|
7462
|
-
process.
|
|
7463
|
-
return;
|
|
7464
|
-
}
|
|
7465
|
-
const registryIndex = await getRegistryIndex();
|
|
7466
|
-
const componentDir = path12.resolve(config.resolvedPaths.components, "ui");
|
|
7467
|
-
if (!existsSync4(componentDir)) {
|
|
7468
|
-
logger.error(`Component dir '${componentDir}' does not exist.`);
|
|
7469
|
-
process.exitCode = 1;
|
|
7470
|
-
return;
|
|
7945
|
+
process.exit(1);
|
|
7471
7946
|
}
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7947
|
+
await runUpdate(cwd, config, options2);
|
|
7948
|
+
note(
|
|
7949
|
+
`This action ${color7.underline("does not")} update your ${highlight4("dependencies")} to their ${color7.bold("latest")} versions.
|
|
7950
|
+
|
|
7951
|
+
Consider updating them as well.`
|
|
7952
|
+
);
|
|
7953
|
+
outro(`${color7.green("Success!")} Component update completed.`);
|
|
7954
|
+
} catch (e) {
|
|
7955
|
+
handleError(e);
|
|
7956
|
+
}
|
|
7957
|
+
});
|
|
7958
|
+
async function runUpdate(cwd, config, options2) {
|
|
7959
|
+
const components = options2.components;
|
|
7960
|
+
const proxy = options2.proxy ?? getEnvProxy();
|
|
7961
|
+
if (proxy) {
|
|
7962
|
+
const isCustom = !!options2.proxy;
|
|
7963
|
+
if (isCustom)
|
|
7964
|
+
process.env.HTTP_PROXY = options2.proxy;
|
|
7965
|
+
log.warn(
|
|
7966
|
+
`You are using a ${isCustom ? "provided" : "system environment"} proxy: ${color7.green(proxy)}`
|
|
7967
|
+
);
|
|
7968
|
+
}
|
|
7969
|
+
const registryIndex = await getRegistryIndex();
|
|
7970
|
+
const componentDir = path12.resolve(config.resolvedPaths.components, "ui");
|
|
7971
|
+
if (!existsSync4(componentDir)) {
|
|
7972
|
+
cancel(`Component directory ${color7.cyan(componentDir)} does not exist.`);
|
|
7973
|
+
process.exit(1);
|
|
7974
|
+
}
|
|
7975
|
+
const existingComponents = [];
|
|
7976
|
+
const files = await fs8.readdir(componentDir, {
|
|
7977
|
+
withFileTypes: true
|
|
7978
|
+
});
|
|
7979
|
+
for (const file of files) {
|
|
7980
|
+
if (file.isDirectory()) {
|
|
7981
|
+
const component = registryIndex.find((comp) => comp.name === file.name);
|
|
7982
|
+
if (component) {
|
|
7983
|
+
existingComponents.push(component);
|
|
7482
7984
|
}
|
|
7483
7985
|
}
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7986
|
+
}
|
|
7987
|
+
existingComponents.push({
|
|
7988
|
+
name: "utils",
|
|
7989
|
+
type: "components:ui",
|
|
7990
|
+
files: [],
|
|
7991
|
+
dependencies: [],
|
|
7992
|
+
registryDependencies: []
|
|
7993
|
+
});
|
|
7994
|
+
let selectedComponents = options2.all ? existingComponents : [];
|
|
7995
|
+
if (selectedComponents.length === 0 && components !== void 0) {
|
|
7996
|
+
selectedComponents = existingComponents.filter(
|
|
7997
|
+
(component) => components.includes(component.name)
|
|
7998
|
+
);
|
|
7999
|
+
}
|
|
8000
|
+
if (selectedComponents.length === 0) {
|
|
8001
|
+
const selected = await multiselect2({
|
|
8002
|
+
message: "Which components would you like to update?",
|
|
8003
|
+
maxItems: 10,
|
|
8004
|
+
options: existingComponents.map((component) => ({
|
|
8005
|
+
label: component.name,
|
|
8006
|
+
value: component,
|
|
8007
|
+
hint: component.registryDependencies.length ? `also updates: ${component.registryDependencies.join(", ")}` : void 0
|
|
8008
|
+
}))
|
|
7488
8009
|
});
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
(component) => components.includes(component.name)
|
|
7493
|
-
);
|
|
8010
|
+
if (isCancel2(selected)) {
|
|
8011
|
+
cancel("Operation cancelled.");
|
|
8012
|
+
process.exit(0);
|
|
7494
8013
|
}
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
8014
|
+
selectedComponents = selected;
|
|
8015
|
+
} else {
|
|
8016
|
+
const prettyList = prettifyList(selectedComponents.map(({ name }) => name));
|
|
8017
|
+
log.step(`Components to update:
|
|
8018
|
+
${color7.gray(prettyList)}`);
|
|
8019
|
+
}
|
|
8020
|
+
if (options2.yes === false) {
|
|
8021
|
+
const proceed = await confirm2({
|
|
8022
|
+
message: `Ready to update ${highlight4("components")}? ${color7.gray("(Make sure you have committed your changes before proceeding!)")}`,
|
|
8023
|
+
initialValue: true
|
|
8024
|
+
});
|
|
8025
|
+
if (isCancel2(proceed) || proceed === false) {
|
|
8026
|
+
cancel("Operation cancelled.");
|
|
8027
|
+
process.exit(0);
|
|
7499
8028
|
}
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
8029
|
+
}
|
|
8030
|
+
if (selectedComponents.find((item2) => item2.name === "utils")) {
|
|
8031
|
+
const extension = config.typescript ? ".ts" : ".js";
|
|
8032
|
+
const utilsPath = config.resolvedPaths.utils + extension;
|
|
8033
|
+
if (!existsSync4(utilsPath)) {
|
|
8034
|
+
cancel(`Failed to find ${highlight4("utils")} at ${color7.cyan(utilsPath)}`);
|
|
8035
|
+
process.exit(1);
|
|
7505
8036
|
}
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
8037
|
+
await fs8.writeFile(utilsPath, UTILS);
|
|
8038
|
+
}
|
|
8039
|
+
const tree = await resolveTree(
|
|
8040
|
+
registryIndex,
|
|
8041
|
+
selectedComponents.map((com) => com.name)
|
|
8042
|
+
);
|
|
8043
|
+
const payload = (await fetchTree(config, tree)).sort((a, b) => a.name.localeCompare(b.name));
|
|
8044
|
+
const componentsToRemove = {};
|
|
8045
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
8046
|
+
for (const item2 of payload) {
|
|
8047
|
+
const updateSpinner = spinner();
|
|
8048
|
+
updateSpinner.start(`Updating ${highlight4(item2.name)}`);
|
|
8049
|
+
const targetDir = getItemTargetPath(config, item2);
|
|
8050
|
+
if (!targetDir) {
|
|
8051
|
+
continue;
|
|
7513
8052
|
}
|
|
7514
|
-
if (
|
|
7515
|
-
|
|
7516
|
-
const utilsPath = config.resolvedPaths.utils + extension;
|
|
7517
|
-
if (!existsSync4(utilsPath)) {
|
|
7518
|
-
spinner.fail(`utils at ${logger.highlight(utilsPath)} does not exist.`);
|
|
7519
|
-
process.exitCode = 1;
|
|
7520
|
-
return;
|
|
7521
|
-
}
|
|
7522
|
-
await fs8.writeFile(utilsPath, UTILS);
|
|
8053
|
+
if (!existsSync4(targetDir)) {
|
|
8054
|
+
await fs8.mkdir(targetDir, { recursive: true });
|
|
7523
8055
|
}
|
|
7524
|
-
const
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
);
|
|
7528
|
-
const payload = (await fetchTree(config, tree)).sort(
|
|
7529
|
-
(a, b) => a.name.localeCompare(b.name)
|
|
7530
|
-
);
|
|
7531
|
-
const componentsToRemove = {};
|
|
7532
|
-
for (const [index, item2] of payload.entries()) {
|
|
7533
|
-
spinner.text = `Updating ${logger.highlight(item2.name)} (${index + 1}/${payload.length})...`;
|
|
7534
|
-
const targetDir = await getItemTargetPath(config, item2);
|
|
7535
|
-
if (!targetDir) {
|
|
7536
|
-
continue;
|
|
7537
|
-
}
|
|
7538
|
-
if (!existsSync4(targetDir)) {
|
|
7539
|
-
await fs8.mkdir(targetDir, { recursive: true });
|
|
7540
|
-
}
|
|
7541
|
-
const componentDir2 = path12.resolve(targetDir, item2.name);
|
|
7542
|
-
if (!existsSync4(componentDir2)) {
|
|
7543
|
-
await fs8.mkdir(componentDir2, { recursive: true });
|
|
7544
|
-
}
|
|
7545
|
-
for (const file of item2.files) {
|
|
7546
|
-
const filePath = path12.resolve(targetDir, item2.name, file.name);
|
|
7547
|
-
const content = transformImports(file.content, config);
|
|
7548
|
-
await fs8.writeFile(filePath, content);
|
|
7549
|
-
}
|
|
7550
|
-
const installedFiles = await fs8.readdir(componentDir2);
|
|
7551
|
-
const remoteFiles = item2.files.map((file) => file.name);
|
|
7552
|
-
const filesToDelete = installedFiles.filter((file) => !remoteFiles.includes(file)).map((file) => path12.resolve(targetDir, item2.name, file));
|
|
7553
|
-
if (filesToDelete.length > 0) {
|
|
7554
|
-
componentsToRemove[item2.name] = filesToDelete;
|
|
7555
|
-
}
|
|
7556
|
-
if (item2.dependencies?.length) {
|
|
7557
|
-
const packageManager = await getPackageManager(cwd);
|
|
7558
|
-
await execa5(packageManager, ["add", ...item2.dependencies], {
|
|
7559
|
-
cwd
|
|
7560
|
-
});
|
|
7561
|
-
}
|
|
8056
|
+
const componentDir2 = path12.resolve(targetDir, item2.name);
|
|
8057
|
+
if (!existsSync4(componentDir2)) {
|
|
8058
|
+
await fs8.mkdir(componentDir2, { recursive: true });
|
|
7562
8059
|
}
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
The ${logger.highlight(
|
|
7568
|
-
component
|
|
7569
|
-
)} component does not use the following files:`
|
|
7570
|
-
);
|
|
7571
|
-
logger.warn(
|
|
7572
|
-
files2.map((file) => chalk5.white(`- ${path12.relative(cwd, file)}`)).join("\n")
|
|
7573
|
-
);
|
|
8060
|
+
for (const file of item2.files) {
|
|
8061
|
+
const filePath = path12.resolve(targetDir, item2.name, file.name);
|
|
8062
|
+
const content = transformImports(file.content, config);
|
|
8063
|
+
await fs8.writeFile(filePath, content);
|
|
7574
8064
|
}
|
|
7575
|
-
|
|
7576
|
-
|
|
8065
|
+
const installedFiles = await fs8.readdir(componentDir2);
|
|
8066
|
+
const remoteFiles = item2.files.map((file) => file.name);
|
|
8067
|
+
const filesToDelete = installedFiles.filter((file) => !remoteFiles.includes(file)).map((file) => path12.resolve(targetDir, item2.name, file));
|
|
8068
|
+
if (filesToDelete.length > 0) {
|
|
8069
|
+
componentsToRemove[item2.name] = filesToDelete;
|
|
7577
8070
|
}
|
|
7578
|
-
|
|
7579
|
-
|
|
8071
|
+
item2.dependencies.forEach((dep) => dependencies.add(dep));
|
|
8072
|
+
const componentPath = path12.relative(process.cwd(), path12.resolve(targetDir, item2.name));
|
|
8073
|
+
updateSpinner.stop(`${highlight4(item2.name)} updated at ${color7.gray(componentPath)}`);
|
|
8074
|
+
}
|
|
8075
|
+
if (dependencies.size > 0) {
|
|
8076
|
+
const spinner2 = spinner();
|
|
8077
|
+
spinner2.start("Installing new package dependencies");
|
|
8078
|
+
const packageManager = await getPackageManager(cwd);
|
|
8079
|
+
await execa5(packageManager, ["add", ...dependencies], {
|
|
8080
|
+
cwd
|
|
8081
|
+
});
|
|
8082
|
+
spinner2.stop("Dependencies installed");
|
|
8083
|
+
}
|
|
8084
|
+
for (const [component, files2] of Object.entries(componentsToRemove)) {
|
|
8085
|
+
log.warn(
|
|
8086
|
+
`The ${highlight4(component)} component does not use the following files:
|
|
8087
|
+
${files2.map((file) => color7.white(`- ${color7.gray(path12.relative(cwd, file))}`)).join("\n")}`
|
|
8088
|
+
);
|
|
8089
|
+
}
|
|
8090
|
+
if (Object.keys(componentsToRemove).length > 0) {
|
|
8091
|
+
log.message(color7.bold("You may want to delete them."));
|
|
7580
8092
|
}
|
|
7581
|
-
});
|
|
7582
|
-
async function promptForComponents(components, message) {
|
|
7583
|
-
const { components: selectedComponents } = await prompts4({
|
|
7584
|
-
type: "multiselect",
|
|
7585
|
-
name: "components",
|
|
7586
|
-
message,
|
|
7587
|
-
hint: "<SPACE> to select. <A> to select all.",
|
|
7588
|
-
instructions: false,
|
|
7589
|
-
choices: components.map((component) => ({
|
|
7590
|
-
title: component.name,
|
|
7591
|
-
value: component
|
|
7592
|
-
}))
|
|
7593
|
-
});
|
|
7594
|
-
return selectedComponents;
|
|
7595
8093
|
}
|
|
7596
8094
|
|
|
7597
8095
|
// src/index.ts
|
|
7598
8096
|
process.on("SIGINT", () => process.exit(0));
|
|
7599
8097
|
process.on("SIGTERM", () => process.exit(0));
|
|
8098
|
+
var currentVersion = process.versions.node;
|
|
8099
|
+
var currentMajorVersion = parseInt(currentVersion.split(".")[0], 10);
|
|
8100
|
+
var minimumMajorVersion = 18;
|
|
8101
|
+
if (currentMajorVersion < minimumMajorVersion) {
|
|
8102
|
+
console.error(`Node.js v${currentVersion} is out of date and unsupported!`);
|
|
8103
|
+
console.error(`Please use Node.js v${minimumMajorVersion} or higher.`);
|
|
8104
|
+
process.exit(1);
|
|
8105
|
+
}
|
|
7600
8106
|
async function main2() {
|
|
8107
|
+
console.clear();
|
|
7601
8108
|
const packageInfo = getPackageInfo();
|
|
7602
|
-
const program = new Command4().name("shadcn-svelte").description("Add shadcn-svelte components to your project").version(packageInfo.version || "
|
|
8109
|
+
const program = new Command4().name("shadcn-svelte").description("Add shadcn-svelte components to your project").version(packageInfo.version || "0.0.0", "-v, --version", "display the version number");
|
|
7603
8110
|
program.addCommand(init2).addCommand(add).addCommand(update);
|
|
7604
8111
|
program.parse();
|
|
7605
8112
|
}
|