@usalyt/cli 0.0.1 → 0.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/CHANGELOG.md +8 -0
- package/LICENSE +21 -674
- package/NOTICE +7 -8
- package/README.md +22 -8
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/index.mjs +1514 -99
- package/package.json +4 -4
- package/src/commands/add.ts +42 -12
- package/src/commands/diff.ts +130 -0
- package/src/commands/init.ts +177 -9
- package/src/commands/theme.ts +194 -0
- package/src/index.ts +6 -1
- package/src/lib/config.ts +30 -0
- package/src/lib/imports.ts +31 -5
- package/src/lib/install.ts +85 -13
- package/src/lib/paths.ts +31 -5
- package/src/lib/project.ts +218 -0
- package/src/lib/theme.ts +161 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usalyt/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Usalyt component distribution CLI",
|
|
5
5
|
"bin": {
|
|
6
6
|
"usalyt": "./dist/index.mjs"
|
|
@@ -9,18 +9,18 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"citty": "^0.2.2",
|
|
11
11
|
"picocolors": "^1.1.1",
|
|
12
|
-
"@usalyt/registry": "^0.0.
|
|
12
|
+
"@usalyt/registry": "^0.0.2"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@types/node": "^26.1.1",
|
|
16
16
|
"tsdown": "^0.22.14",
|
|
17
17
|
"typescript": "^6.0.0"
|
|
18
18
|
},
|
|
19
|
-
"license": "
|
|
19
|
+
"license": "MIT",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
22
|
"url": "git+https://github.com/Usalyt/ui.git",
|
|
23
|
-
"directory": "
|
|
23
|
+
"directory": "packages/cli"
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/Usalyt/ui",
|
|
26
26
|
"bugs": {
|
package/src/commands/add.ts
CHANGED
|
@@ -12,6 +12,13 @@ import {
|
|
|
12
12
|
} from "../lib/install";
|
|
13
13
|
import { printError } from "../lib/output";
|
|
14
14
|
import { UnsafePathError } from "../lib/paths";
|
|
15
|
+
import {
|
|
16
|
+
detectPackageManager,
|
|
17
|
+
formatInstallArgs,
|
|
18
|
+
formatInstallCommand,
|
|
19
|
+
readInstalledDependencies,
|
|
20
|
+
type PackageManager,
|
|
21
|
+
} from "../lib/project";
|
|
15
22
|
import { loadRegistry, RegistryLoadError, type Registry } from "../lib/registry";
|
|
16
23
|
|
|
17
24
|
function normalizePositionals(values: unknown[]): string[] {
|
|
@@ -33,17 +40,21 @@ async function confirmInstall(command: string): Promise<boolean> {
|
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
function
|
|
37
|
-
|
|
43
|
+
function runPackageInstall(
|
|
44
|
+
root: string,
|
|
45
|
+
pm: PackageManager,
|
|
46
|
+
dependencies: string[]
|
|
47
|
+
): void {
|
|
48
|
+
const result = spawnSync(pm, formatInstallArgs(pm, dependencies), {
|
|
38
49
|
cwd: root,
|
|
39
50
|
stdio: "inherit",
|
|
40
51
|
});
|
|
41
52
|
if (result.error) {
|
|
42
|
-
printError(`could not run
|
|
53
|
+
printError(`could not run ${pm}: ${result.error.message}`);
|
|
43
54
|
return;
|
|
44
55
|
}
|
|
45
56
|
if (result.status !== 0) {
|
|
46
|
-
printError(
|
|
57
|
+
printError(`${pm} exited with status ${String(result.status)}.`);
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
|
|
@@ -75,7 +86,7 @@ export const addCommand = defineCommand({
|
|
|
75
86
|
},
|
|
76
87
|
install: {
|
|
77
88
|
type: "boolean",
|
|
78
|
-
description: "
|
|
89
|
+
description: "Install missing npm dependencies using the detected package manager",
|
|
79
90
|
},
|
|
80
91
|
},
|
|
81
92
|
async run({ args }) {
|
|
@@ -155,21 +166,40 @@ export const addCommand = defineCommand({
|
|
|
155
166
|
}
|
|
156
167
|
|
|
157
168
|
const installedItems = new Set(plan.writes.map((write) => write.item)).size;
|
|
158
|
-
const
|
|
169
|
+
const requestedInstalled = targets.filter((t) =>
|
|
170
|
+
plan.writes.some((write) => write.item === t)
|
|
171
|
+
).length;
|
|
172
|
+
const dependencyCount = Math.max(0, installedItems - requestedInstalled);
|
|
159
173
|
|
|
160
174
|
console.log(
|
|
161
|
-
`Installed ${installedItems} item(s) (${
|
|
175
|
+
`Installed ${installedItems} item(s) (${requestedInstalled} requested, ${dependencyCount} registry dependencies):`
|
|
162
176
|
);
|
|
163
177
|
for (const write of plan.writes) {
|
|
164
178
|
console.log(` + ${write.relativeDestination}`);
|
|
165
179
|
}
|
|
180
|
+
if (plan.skipped.length > 0) {
|
|
181
|
+
console.log(`Skipped ${plan.skipped.length} existing dependency file(s):`);
|
|
182
|
+
for (const skipped of plan.skipped) {
|
|
183
|
+
console.log(` = ${skipped.relativeDestination}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
166
186
|
|
|
167
|
-
|
|
168
|
-
|
|
187
|
+
const installedPackages = readInstalledDependencies(root);
|
|
188
|
+
const missingDependencies = plan.dependencies.filter(
|
|
189
|
+
(dep) => !installedPackages.has(dep)
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (missingDependencies.length === 0) {
|
|
193
|
+
console.log(
|
|
194
|
+
plan.dependencies.length === 0
|
|
195
|
+
? "No npm dependencies required."
|
|
196
|
+
: "All required npm dependencies are already installed."
|
|
197
|
+
);
|
|
169
198
|
return;
|
|
170
199
|
}
|
|
171
200
|
|
|
172
|
-
const
|
|
201
|
+
const pm = detectPackageManager(root);
|
|
202
|
+
const installCommand = formatInstallCommand(pm, missingDependencies);
|
|
173
203
|
console.log(`Dependencies: ${installCommand}`);
|
|
174
204
|
|
|
175
205
|
if (!args.install) {
|
|
@@ -182,7 +212,7 @@ export const addCommand = defineCommand({
|
|
|
182
212
|
if (!args.yes) {
|
|
183
213
|
if (process.stdin.isTTY && process.stdout.isTTY) {
|
|
184
214
|
if (await confirmInstall(installCommand)) {
|
|
185
|
-
|
|
215
|
+
runPackageInstall(root, pm, missingDependencies);
|
|
186
216
|
} else {
|
|
187
217
|
console.log("Dependencies were not installed.");
|
|
188
218
|
}
|
|
@@ -194,6 +224,6 @@ export const addCommand = defineCommand({
|
|
|
194
224
|
return;
|
|
195
225
|
}
|
|
196
226
|
|
|
197
|
-
|
|
227
|
+
runPackageInstall(root, pm, missingDependencies);
|
|
198
228
|
},
|
|
199
229
|
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import { defaultConfig, readConfig, type UsalytConfig } from "../lib/config";
|
|
5
|
+
import { buildInstallPlan, UnknownItemsError } from "../lib/install";
|
|
6
|
+
import { printError } from "../lib/output";
|
|
7
|
+
import { loadRegistry, RegistryLoadError, type Registry } from "../lib/registry";
|
|
8
|
+
|
|
9
|
+
function renderLineDiff(localText: string, registryText: string): string[] {
|
|
10
|
+
const localLines = localText.split(/\r?\n/);
|
|
11
|
+
const registryLines = registryText.split(/\r?\n/);
|
|
12
|
+
const max = Math.max(localLines.length, registryLines.length);
|
|
13
|
+
const diff: string[] = [];
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < max; i += 1) {
|
|
16
|
+
const localLine = localLines[i];
|
|
17
|
+
const registryLine = registryLines[i];
|
|
18
|
+
if (localLine === registryLine) continue;
|
|
19
|
+
if (localLine !== undefined) {
|
|
20
|
+
diff.push(pc.red(`- L${i + 1}: ${localLine}`));
|
|
21
|
+
}
|
|
22
|
+
if (registryLine !== undefined) {
|
|
23
|
+
diff.push(pc.green(`+ L${i + 1}: ${registryLine}`));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return diff;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const diffCommand = defineCommand({
|
|
30
|
+
meta: {
|
|
31
|
+
name: "diff",
|
|
32
|
+
description: "Compare local installed components against the packaged registry",
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
components: {
|
|
36
|
+
type: "positional",
|
|
37
|
+
description: "Component name(s) to compare (defaults to all installed items)",
|
|
38
|
+
required: false,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
run({ args }) {
|
|
42
|
+
const root = process.cwd();
|
|
43
|
+
|
|
44
|
+
let registry: Registry;
|
|
45
|
+
try {
|
|
46
|
+
({ registry } = loadRegistry());
|
|
47
|
+
} catch (error) {
|
|
48
|
+
printError(error instanceof RegistryLoadError ? error.message : String(error));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let config: UsalytConfig;
|
|
53
|
+
try {
|
|
54
|
+
config = readConfig(root) ?? defaultConfig();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
printError((error as Error).message);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const positionals = Array.isArray(args._)
|
|
61
|
+
? (args._ as unknown[]).map((v) => String(v).trim()).filter(Boolean)
|
|
62
|
+
: [];
|
|
63
|
+
const targets =
|
|
64
|
+
positionals.length > 0
|
|
65
|
+
? [...new Set(positionals)]
|
|
66
|
+
: registry.items.map((item) => item.name);
|
|
67
|
+
|
|
68
|
+
let plan;
|
|
69
|
+
try {
|
|
70
|
+
plan = buildInstallPlan({
|
|
71
|
+
registry,
|
|
72
|
+
config,
|
|
73
|
+
root,
|
|
74
|
+
targets,
|
|
75
|
+
overwrite: true,
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof UnknownItemsError) {
|
|
79
|
+
printError(`${error.message}.`);
|
|
80
|
+
} else {
|
|
81
|
+
printError((error as Error).message);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const targetSet = new Set(targets);
|
|
87
|
+
const inspected = plan.writes.filter((entry) => targetSet.has(entry.item));
|
|
88
|
+
|
|
89
|
+
let checked = 0;
|
|
90
|
+
let changed = 0;
|
|
91
|
+
|
|
92
|
+
for (const file of inspected) {
|
|
93
|
+
if (!existsSync(file.destination)) {
|
|
94
|
+
if (positionals.length > 0) {
|
|
95
|
+
console.log(`${pc.yellow("missing")} ${file.relativeDestination}`);
|
|
96
|
+
changed += 1;
|
|
97
|
+
}
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
checked += 1;
|
|
102
|
+
const localContent = readFileSync(file.destination, "utf8");
|
|
103
|
+
if (localContent === file.content) {
|
|
104
|
+
if (positionals.length > 0) {
|
|
105
|
+
console.log(`${pc.green("up to date")} ${file.relativeDestination}`);
|
|
106
|
+
}
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
changed += 1;
|
|
111
|
+
console.log(`${pc.yellow("modified")} ${file.relativeDestination}`);
|
|
112
|
+
const lines = renderLineDiff(localContent, file.content);
|
|
113
|
+
for (const line of lines.slice(0, 40)) {
|
|
114
|
+
console.log(` ${line}`);
|
|
115
|
+
}
|
|
116
|
+
if (lines.length > 40) {
|
|
117
|
+
console.log(` ... (${lines.length - 40} more diff lines)`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (checked === 0 && positionals.length === 0) {
|
|
122
|
+
console.log("No installed Usalyt registry files found.");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (changed === 0) {
|
|
127
|
+
console.log(`All ${checked} checked file(s) are up to date.`);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
});
|
package/src/commands/init.ts
CHANGED
|
@@ -9,16 +9,48 @@ import {
|
|
|
9
9
|
type UsalytConfig,
|
|
10
10
|
} from "../lib/config";
|
|
11
11
|
import { printError } from "../lib/output";
|
|
12
|
+
import { UnsafePathError } from "../lib/paths";
|
|
13
|
+
import {
|
|
14
|
+
detectCssEntry,
|
|
15
|
+
detectTsconfigPathMapping,
|
|
16
|
+
injectThemeStylesheet,
|
|
17
|
+
type TsconfigPathMapping,
|
|
18
|
+
} from "../lib/project";
|
|
19
|
+
import { loadRegistry } from "../lib/registry";
|
|
20
|
+
import {
|
|
21
|
+
applyThemePresetToCss,
|
|
22
|
+
encodeThemePreset,
|
|
23
|
+
hasThemeFlags,
|
|
24
|
+
isDefaultThemeConfig,
|
|
25
|
+
resolveThemeFromFlags,
|
|
26
|
+
ThemeOptionError,
|
|
27
|
+
toUsalytThemeConfig,
|
|
28
|
+
type ThemePresetConfig,
|
|
29
|
+
} from "../lib/theme";
|
|
12
30
|
|
|
13
|
-
function aliasFromPath(
|
|
31
|
+
function aliasFromPath(
|
|
32
|
+
value: string,
|
|
33
|
+
stripExtension = false,
|
|
34
|
+
tsconfigPaths?: TsconfigPathMapping | null
|
|
35
|
+
): string {
|
|
14
36
|
const normalized = value.trim().replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
15
37
|
const withoutExtension = stripExtension
|
|
16
38
|
? normalized.replace(/\.(tsx?|jsx?)$/, "")
|
|
17
39
|
: normalized;
|
|
18
|
-
|
|
40
|
+
if (tsconfigPaths && tsconfigPaths.targetDir !== "") {
|
|
41
|
+
if (withoutExtension.startsWith(`${tsconfigPaths.targetDir}/`)) {
|
|
42
|
+
return `${tsconfigPaths.prefix}${withoutExtension.slice(tsconfigPaths.targetDir.length + 1)}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const prefix = tsconfigPaths?.prefix ?? "@/";
|
|
46
|
+
return `${prefix}${withoutExtension}`;
|
|
19
47
|
}
|
|
20
48
|
|
|
21
|
-
async function promptForConfig(
|
|
49
|
+
async function promptForConfig(
|
|
50
|
+
defaults: UsalytConfig,
|
|
51
|
+
detectedCss: string,
|
|
52
|
+
tsconfigPaths: TsconfigPathMapping | null
|
|
53
|
+
): Promise<UsalytConfig> {
|
|
22
54
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
23
55
|
try {
|
|
24
56
|
const defaultComponents = defaults.aliases.components.replace(/^@\//, "");
|
|
@@ -30,15 +62,23 @@ async function promptForConfig(defaults: UsalytConfig): Promise<UsalytConfig> {
|
|
|
30
62
|
const utilsAnswer = await rl.question(
|
|
31
63
|
`Utils file (relative to the project root) [${defaultUtils}]: `
|
|
32
64
|
);
|
|
65
|
+
const cssAnswer = await rl.question(
|
|
66
|
+
`Global Tailwind CSS file (relative to the project root) [${detectedCss}]: `
|
|
67
|
+
);
|
|
33
68
|
|
|
34
69
|
const componentsPath = componentsAnswer.trim() || defaultComponents;
|
|
35
70
|
const utilsPath = utilsAnswer.trim() || defaultUtils;
|
|
71
|
+
const cssPath = cssAnswer.trim() || detectedCss;
|
|
36
72
|
|
|
37
73
|
return {
|
|
38
74
|
...defaults,
|
|
75
|
+
tailwind: {
|
|
76
|
+
...defaults.tailwind,
|
|
77
|
+
css: cssPath,
|
|
78
|
+
},
|
|
39
79
|
aliases: {
|
|
40
|
-
components: aliasFromPath(componentsPath),
|
|
41
|
-
utils: aliasFromPath(utilsPath, true),
|
|
80
|
+
components: aliasFromPath(componentsPath, false, tsconfigPaths),
|
|
81
|
+
utils: aliasFromPath(utilsPath, true, tsconfigPaths),
|
|
42
82
|
},
|
|
43
83
|
};
|
|
44
84
|
} finally {
|
|
@@ -49,24 +89,75 @@ async function promptForConfig(defaults: UsalytConfig): Promise<UsalytConfig> {
|
|
|
49
89
|
export const initCommand = defineCommand({
|
|
50
90
|
meta: {
|
|
51
91
|
name: "init",
|
|
52
|
-
description: "Create usalyt.json
|
|
92
|
+
description: "Create usalyt.json and set up the Usalyt Tailwind v4 theme tokens",
|
|
53
93
|
},
|
|
54
94
|
args: {
|
|
55
95
|
yes: {
|
|
56
96
|
type: "boolean",
|
|
57
|
-
description: "Use
|
|
97
|
+
description: "Use detected defaults without prompting",
|
|
58
98
|
alias: "y",
|
|
59
99
|
},
|
|
60
100
|
overwrite: {
|
|
61
101
|
type: "boolean",
|
|
62
|
-
description: "Replace an existing usalyt.json",
|
|
102
|
+
description: "Replace an existing usalyt.json and theme stylesheet",
|
|
63
103
|
alias: "o",
|
|
64
104
|
},
|
|
105
|
+
"no-theme": {
|
|
106
|
+
type: "boolean",
|
|
107
|
+
description: "Skip writing usalyt-theme.css and updating the Tailwind CSS entry",
|
|
108
|
+
},
|
|
109
|
+
preset: {
|
|
110
|
+
type: "string",
|
|
111
|
+
description: "Named theme preset (e.g. linear, console-dense, minimal-light) or Theme Studio URL/query",
|
|
112
|
+
},
|
|
113
|
+
base: {
|
|
114
|
+
type: "string",
|
|
115
|
+
description: "Surface base palette (linear, zinc, slate, stone)",
|
|
116
|
+
},
|
|
117
|
+
accent: {
|
|
118
|
+
type: "string",
|
|
119
|
+
description: "Primary accent (lavender, cobalt, emerald, amber, crimson, monochrome, or #RRGGBB)",
|
|
120
|
+
},
|
|
121
|
+
radius: {
|
|
122
|
+
type: "string",
|
|
123
|
+
description: "Border radius scale (none, sm, md, lg, xl)",
|
|
124
|
+
},
|
|
125
|
+
density: {
|
|
126
|
+
type: "string",
|
|
127
|
+
description: "Spacing density scale (compact, default, comfortable)",
|
|
128
|
+
},
|
|
129
|
+
font: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "Sans font stack (inter, system, geist, jakarta)",
|
|
132
|
+
},
|
|
133
|
+
mode: {
|
|
134
|
+
type: "string",
|
|
135
|
+
description: "Default theme polarity (dark, light)",
|
|
136
|
+
},
|
|
65
137
|
},
|
|
66
138
|
async run({ args }) {
|
|
67
139
|
const root = process.cwd();
|
|
68
140
|
const configPath = configPathFor(root);
|
|
69
141
|
|
|
142
|
+
let resolvedTheme: ThemePresetConfig;
|
|
143
|
+
try {
|
|
144
|
+
resolvedTheme = resolveThemeFromFlags({
|
|
145
|
+
preset: args.preset,
|
|
146
|
+
base: args.base,
|
|
147
|
+
accent: args.accent,
|
|
148
|
+
radius: args.radius,
|
|
149
|
+
density: args.density,
|
|
150
|
+
font: args.font,
|
|
151
|
+
mode: args.mode,
|
|
152
|
+
});
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (error instanceof ThemeOptionError) {
|
|
155
|
+
printError(error.message);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
|
|
70
161
|
if (existsSync(configPath) && !args.overwrite) {
|
|
71
162
|
printError(
|
|
72
163
|
`${CONFIG_FILE} already exists at ${configPath}. Pass --overwrite to replace it.`
|
|
@@ -86,9 +177,51 @@ export const initCommand = defineCommand({
|
|
|
86
177
|
}
|
|
87
178
|
|
|
88
179
|
const defaults = defaultConfig();
|
|
180
|
+
const detectedCss = detectCssEntry(root);
|
|
181
|
+
const tsconfigPaths = detectTsconfigPathMapping(root);
|
|
89
182
|
const interactive =
|
|
90
183
|
!args.yes && Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
91
|
-
|
|
184
|
+
|
|
185
|
+
const themeCustomized =
|
|
186
|
+
hasThemeFlags({
|
|
187
|
+
preset: args.preset,
|
|
188
|
+
base: args.base,
|
|
189
|
+
accent: args.accent,
|
|
190
|
+
radius: args.radius,
|
|
191
|
+
density: args.density,
|
|
192
|
+
font: args.font,
|
|
193
|
+
mode: args.mode,
|
|
194
|
+
}) || !isDefaultThemeConfig(resolvedTheme);
|
|
195
|
+
|
|
196
|
+
const baseConfig: UsalytConfig = {
|
|
197
|
+
...defaults,
|
|
198
|
+
tailwind: {
|
|
199
|
+
...defaults.tailwind,
|
|
200
|
+
css: detectedCss,
|
|
201
|
+
baseColor: themeCustomized ? resolvedTheme.base : defaults.tailwind?.baseColor,
|
|
202
|
+
},
|
|
203
|
+
...(themeCustomized ? { theme: toUsalytThemeConfig(resolvedTheme) } : {}),
|
|
204
|
+
aliases: tsconfigPaths
|
|
205
|
+
? {
|
|
206
|
+
components: aliasFromPath("src/components/ui", false, tsconfigPaths),
|
|
207
|
+
utils: aliasFromPath("src/lib/utils", true, tsconfigPaths),
|
|
208
|
+
}
|
|
209
|
+
: defaults.aliases,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const promptedConfig = interactive
|
|
213
|
+
? await promptForConfig(defaults, detectedCss, tsconfigPaths)
|
|
214
|
+
: baseConfig;
|
|
215
|
+
const config: UsalytConfig = themeCustomized
|
|
216
|
+
? {
|
|
217
|
+
...promptedConfig,
|
|
218
|
+
tailwind: {
|
|
219
|
+
...promptedConfig.tailwind,
|
|
220
|
+
baseColor: resolvedTheme.base,
|
|
221
|
+
},
|
|
222
|
+
theme: toUsalytThemeConfig(resolvedTheme),
|
|
223
|
+
}
|
|
224
|
+
: promptedConfig;
|
|
92
225
|
|
|
93
226
|
try {
|
|
94
227
|
writeFileSync(configPath, serializeConfig(config), "utf8");
|
|
@@ -99,5 +232,40 @@ export const initCommand = defineCommand({
|
|
|
99
232
|
console.log(`Created ${CONFIG_FILE} at ${configPath}`);
|
|
100
233
|
console.log(` components: ${config.aliases.components}`);
|
|
101
234
|
console.log(` utils: ${config.aliases.utils}`);
|
|
235
|
+
if (config.tailwind?.css) {
|
|
236
|
+
console.log(` css: ${config.tailwind.css}`);
|
|
237
|
+
}
|
|
238
|
+
if (themeCustomized) {
|
|
239
|
+
console.log(` preset: ${encodeThemePreset(resolvedTheme)}`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (args["no-theme"]) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
const { registry } = loadRegistry();
|
|
248
|
+
const themeItem = registry.items.find((item) => item.name === "theme");
|
|
249
|
+
const themeContent = themeItem?.files[0]?.content;
|
|
250
|
+
if (themeContent && config.tailwind?.css) {
|
|
251
|
+
const finalThemeCss = applyThemePresetToCss(themeContent, resolvedTheme);
|
|
252
|
+
const result = injectThemeStylesheet({
|
|
253
|
+
root,
|
|
254
|
+
cssEntryRelative: config.tailwind.css,
|
|
255
|
+
themeCss: finalThemeCss,
|
|
256
|
+
overwriteTheme: Boolean(args.overwrite),
|
|
257
|
+
});
|
|
258
|
+
console.log(` theme: ${result.themeFile}`);
|
|
259
|
+
if (result.cssUpdated) {
|
|
260
|
+
console.log(` updated: ${result.cssEntry}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
} catch (error) {
|
|
264
|
+
if (error instanceof UnsafePathError) {
|
|
265
|
+
printError(error.message);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
printError(`could not set up theme stylesheet: ${(error as Error).message}`);
|
|
269
|
+
}
|
|
102
270
|
},
|
|
103
271
|
});
|