Skip to content

Commit 5fdbbdb

Browse files
feat: Colors (#1230)
Co-authored-by: engageintellect <[email protected]>
1 parent cec9c31 commit 5fdbbdb

28 files changed

+2861
-2524
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ vite.config.js.timestamp-*
1010
vite.config.ts.timestamp-*
1111
.turbo
1212

13+
**/.svelte-kit/**/*
14+
1315
# Logs
1416
logs
1517
*.log

package.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"test:unit": "pnpm -F docs test:unit",
2222
"lint": "prettier --check . && eslint .",
2323
"lint:fix": "eslint --fix .",
24-
"format:check": "pnpm -r format:check",
2524
"format": "prettier --write .",
2625
"preinstall": "npx only-allow pnpm",
2726
"postinstall": "pnpm -r sync",
@@ -41,19 +40,18 @@
4140
"license": "MIT",
4241
"type": "module",
4342
"devDependencies": {
44-
"@antfu/eslint-config": "^2.11.6",
4543
"@changesets/cli": "^2.27.1",
46-
"@huntabyte/eslint-config": "^0.0.1",
47-
"eslint": "^8.57.0",
48-
"eslint-plugin-antfu": "^2.1.2",
49-
"eslint-plugin-svelte": "2.36.0-next.13",
44+
"@huntabyte/eslint-config": "^0.3.2",
45+
"@huntabyte/eslint-plugin": "^0.1.0",
46+
"eslint": "^9.0.0",
47+
"eslint-plugin-svelte": "^2.37.0",
5048
"prettier": "^3.2.5",
51-
"prettier-plugin-svelte": "^3.2.3",
52-
"prettier-plugin-tailwindcss": "^0.5.12",
49+
"prettier-plugin-svelte": "^3.2.2",
50+
"prettier-plugin-tailwindcss": "0.5.13",
5351
"pretty-quick": "^4.0.0",
5452
"simple-git-hooks": "^2.10.0",
5553
"svelte": "^4.2.12",
56-
"svelte-eslint-parser": "^0.33.1"
54+
"svelte-eslint-parser": "^0.41.0"
5755
},
5856
"simple-git-hooks": {
5957
"pre-commit": "pnpm -r format:staged --staged"

packages/cli/.prettierrc

-6
This file was deleted.

packages/cli/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
"start": "node dist/index.js",
3737
"start:dev": "cross-env COMPONENTS_REGISTRY_URL=http://localhost:5173 node dist/index.js",
3838
"start:proxy": "pnpm dlx straightforward@latest --port 9000",
39-
"format": "prettier --write .",
40-
"format:check": "prettier --check .",
4139
"release": "changeset version",
4240
"test": "vitest"
4341
},

packages/cli/src/commands/init.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option
151151
if (tailwindBaseColor === undefined) {
152152
const input = await p.select({
153153
message: `Which ${highlight("base color")} would you like to use?`,
154-
initialValue: defaultConfig?.tailwind.baseColor ?? cliConfig.DEFAULT_TAILWIND_BASE_COLOR,
154+
initialValue:
155+
defaultConfig?.tailwind.baseColor ?? cliConfig.DEFAULT_TAILWIND_BASE_COLOR,
155156
options: baseColors.map((color) => ({
156157
label: color.label,
157158
value: color.name,
@@ -172,7 +173,9 @@ async function promptForConfig(cwd: string, defaultConfig: Config | null, option
172173
const input = await p.text({
173174
message: `Where is your ${highlight("global CSS")} file? ${color.gray("(this file will be overwritten)")}`,
174175
initialValue:
175-
defaultConfig?.tailwind.css ?? detectedConfigs.cssPath ?? cliConfig.DEFAULT_TAILWIND_CSS,
176+
defaultConfig?.tailwind.css ??
177+
detectedConfigs.cssPath ??
178+
cliConfig.DEFAULT_TAILWIND_CSS,
176179
placeholder: detectedConfigs.cssPath ?? cliConfig.DEFAULT_TAILWIND_CSS,
177180
validate: (value) => {
178181
if (value && existsSync(path.resolve(cwd, value))) {
@@ -312,7 +315,9 @@ export async function runInit(cwd: string, config: Config, options: InitOptions)
312315
// Ensure all resolved paths directories exist.
313316
for (const [key, resolvedPath] of Object.entries(config.resolvedPaths)) {
314317
// Determine if the path is a file or directory.
315-
let dirname = path.extname(resolvedPath) ? path.dirname(resolvedPath) : resolvedPath;
318+
let dirname = path.extname(resolvedPath)
319+
? path.dirname(resolvedPath)
320+
: resolvedPath;
316321

317322
// If the utils alias is set to something like "@/lib/utils",
318323
// assume this is a file and remove the "utils" file name.
@@ -329,13 +334,19 @@ export async function runInit(cwd: string, config: Config, options: InitOptions)
329334

330335
// Write tailwind config.
331336
const { TS, JS } = templates.TAILWIND_CONFIG_WITH_VARIABLES;
332-
const tailwindConfigContent = config.resolvedPaths.tailwindConfig.endsWith(".ts") ? TS : JS;
337+
const tailwindConfigContent = config.resolvedPaths.tailwindConfig.endsWith(".ts")
338+
? TS
339+
: JS;
333340
await fs.writeFile(config.resolvedPaths.tailwindConfig, tailwindConfigContent, "utf8");
334341

335342
// Write css file.
336343
const baseColor = await getRegistryBaseColor(config.tailwind.baseColor);
337344
if (baseColor) {
338-
await fs.writeFile(config.resolvedPaths.tailwindCss, baseColor.cssVarsTemplate, "utf8");
345+
await fs.writeFile(
346+
config.resolvedPaths.tailwindCss,
347+
baseColor.cssVarsTemplate,
348+
"utf8"
349+
);
339350
}
340351

341352
const utilsPath = config.resolvedPaths.utils + (config.typescript ? ".ts" : ".js");

packages/cli/src/commands/update.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ async function runUpdate(cwd: string, config: Config, options: UpdateOptions) {
215215
componentsToRemove[item.name] = filesToDelete;
216216
}
217217

218-
const componentPath = path.relative(process.cwd(), path.resolve(targetDir, item.name));
218+
const componentPath = path.relative(
219+
process.cwd(),
220+
path.resolve(targetDir, item.name)
221+
);
219222
return `${highlight(item.name)} updated at ${color.gray(componentPath)}`;
220223
},
221224
});

packages/cli/src/utils/get-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export async function getRawConfig(cwd: string): Promise<RawConfig | null> {
120120
const configResult = fs.readFileSync(configPath, { encoding: "utf8" });
121121
const config = JSON.parse(configResult);
122122
return v.parse(rawConfigSchema, config);
123-
} catch (err) {
123+
} catch {
124124
throw new ConfigError(`Invalid configuration found in ${highlight(configPath)}.`);
125125
}
126126
}

packages/cli/src/utils/prompts.ts

+26-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ function limitOptions<TOption>(params: LimitOptionsParams<TOption>): string[] {
7575
let slidingWindowLocation = 0;
7676

7777
if (cursor >= slidingWindowLocation + maxItems - 3) {
78-
slidingWindowLocation = Math.max(Math.min(cursor - maxItems + 3, options.length - maxItems), 0);
78+
slidingWindowLocation = Math.max(
79+
Math.min(cursor - maxItems + 3, options.length - maxItems),
80+
0
81+
);
7982
} else if (cursor < slidingWindowLocation + 2) {
8083
slidingWindowLocation = Math.max(cursor - 2, 0);
8184
}
@@ -219,7 +222,10 @@ export type SelectOptions<Value> = {
219222
};
220223

221224
export function select<Value>(opts: SelectOptions<Value>) {
222-
const opt = (option: Option<Value>, state: "inactive" | "active" | "selected" | "cancelled") => {
225+
const opt = (
226+
option: Option<Value>,
227+
state: "inactive" | "active" | "selected" | "cancelled"
228+
) => {
223229
const label = option.label ?? String(option.value);
224230
switch (state) {
225231
case "selected":
@@ -436,8 +442,10 @@ export function groupMultiselect<Value>(opts: GroupMultiSelectOptions<Value>) {
436442
options: Option<Value>[] = []
437443
) => {
438444
const label = option.label ?? String(option.value);
445+
// eslint-disable-next-line ts/no-explicit-any
439446
const isItem = typeof (option as any).group === "string";
440447
const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true });
448+
// eslint-disable-next-line ts/no-explicit-any
441449
const isLast = isItem && (next as any).group === true;
442450
const prefix = isItem ? `${isLast ? S_BAR_END : S_BAR} ` : "";
443451

@@ -515,7 +523,11 @@ export function groupMultiselect<Value>(opts: GroupMultiSelectOptions<Value>) {
515523
typeof option.group === "string" &&
516524
this.options[this.cursor]!.value === option.group;
517525
if (groupActive) {
518-
return opt(option, selected ? "group-active-selected" : "group-active", options);
526+
return opt(
527+
option,
528+
selected ? "group-active-selected" : "group-active",
529+
options
530+
);
519531
}
520532
if (active && selected) {
521533
return opt(option, "active-selected", options);
@@ -539,7 +551,11 @@ export function groupMultiselect<Value>(opts: GroupMultiSelectOptions<Value>) {
539551
typeof option.group === "string" &&
540552
this.options[this.cursor]!.value === option.group;
541553
if (groupActive) {
542-
return opt(option, selected ? "group-active-selected" : "group-active", options);
554+
return opt(
555+
option,
556+
selected ? "group-active-selected" : "group-active",
557+
options
558+
);
543559
}
544560
if (active && selected) {
545561
return opt(option, "active-selected", options);
@@ -603,7 +619,10 @@ export const log = {
603619
const parts = [`${color.gray(S_BAR)}`];
604620
if (message) {
605621
const [firstLine, ...lines] = message.split("\n");
606-
parts.push(`${symbol} ${firstLine}`, ...lines.map((ln) => `${color.gray(S_BAR)} ${ln}`));
622+
parts.push(
623+
`${symbol} ${firstLine}`,
624+
...lines.map((ln) => `${color.gray(S_BAR)} ${ln}`)
625+
);
607626
}
608627
process.stdout.write(`${parts.join("\n")}\n`);
609628
},
@@ -714,6 +733,7 @@ export function spinner() {
714733
// Adapted from https://github.com/chalk/ansi-regex
715734
// @see LICENSE
716735
function ansiRegex() {
736+
// eslint-disable-next-line regexp/no-useless-non-capturing-group, regexp/no-trivially-nested-quantifier, regexp/no-useless-quantifier, regexp/prefer-w, regexp/no-useless-escape
717737
const pattern = [
718738
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
719739
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
@@ -736,7 +756,6 @@ export type PromptGroupOptions<T> = {
736756

737757
type Prettify<T> = {
738758
[P in keyof T]: T[P];
739-
// eslint-disable-next-line ts/ban-types
740759
} & {};
741760

742761
export type PromptGroup<T> = {
@@ -753,6 +772,7 @@ export async function group<T>(
753772
prompts: PromptGroup<T>,
754773
opts?: PromptGroupOptions<T>
755774
): Promise<Prettify<PromptGroupAwaitedReturn<T>>> {
775+
// eslint-disable-next-line ts/no-explicit-any
756776
const results = {} as any;
757777
const promptNames = Object.keys(prompts);
758778

packages/cli/src/utils/registry/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function getRegistryIndex() {
1717
const [result] = await fetchRegistry(["index.json"]);
1818

1919
return v.parse(schemas.registryIndexSchema, result);
20-
} catch (e) {
20+
} catch {
2121
throw error(`Failed to fetch components from registry.`);
2222
}
2323
}
@@ -65,7 +65,7 @@ export async function getRegistryBaseColor(baseColor: string) {
6565
const [result] = await fetchRegistry([`colors/${baseColor}.json`]);
6666

6767
return v.parse(schemas.registryBaseColorSchema, result);
68-
} catch (e) {
68+
} catch {
6969
throw error(`Failed to fetch base color from registry.`);
7070
}
7171
}
@@ -101,7 +101,7 @@ export async function fetchTree(config: Config, tree: RegistryIndex) {
101101
const result = await fetchRegistry(paths);
102102

103103
return v.parse(schemas.registryWithContentSchema, result);
104-
} catch (e) {
104+
} catch {
105105
throw error(`Failed to fetch tree from registry.`);
106106
}
107107
}
@@ -140,7 +140,7 @@ async function fetchRegistry(paths: string[]) {
140140
);
141141

142142
return results;
143-
} catch (e) {
143+
} catch {
144144
throw error(`Failed to fetch registry from ${baseUrl}.`);
145145
}
146146
}

packages/cli/test/utils/get-config.spec.ts

+40-8
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,21 @@ describe("getConfig", () => {
6969
components: "$lib/components",
7070
},
7171
resolvedPaths: {
72-
components: path.resolve(__dirname, "../fixtures/config-partial", "./src/lib/components"),
72+
components: path.resolve(
73+
__dirname,
74+
"../fixtures/config-partial",
75+
"./src/lib/components"
76+
),
7377
tailwindConfig: path.resolve(
7478
__dirname,
7579
"../fixtures/config-partial",
7680
"./tailwind.config.js"
7781
),
78-
tailwindCss: path.resolve(__dirname, "../fixtures/config-partial", "./src/app.pcss"),
82+
tailwindCss: path.resolve(
83+
__dirname,
84+
"../fixtures/config-partial",
85+
"./src/app.pcss"
86+
),
7987
utils: path.resolve(__dirname, "../fixtures/config-partial", "./src/lib/utils"),
8088
},
8189
typescript: true,
@@ -95,8 +103,16 @@ describe("getConfig", () => {
95103
components: "$lib/components",
96104
},
97105
resolvedPaths: {
98-
components: path.resolve(__dirname, "../fixtures/config-full", "./src/lib/components"),
99-
tailwindConfig: path.resolve(__dirname, "../fixtures/config-full", "./tailwind.config.js"),
106+
components: path.resolve(
107+
__dirname,
108+
"../fixtures/config-full",
109+
"./src/lib/components"
110+
),
111+
tailwindConfig: path.resolve(
112+
__dirname,
113+
"../fixtures/config-full",
114+
"./tailwind.config.js"
115+
),
100116
tailwindCss: path.resolve(__dirname, "../fixtures/config-full", "./src/app.pcss"),
101117
utils: path.resolve(__dirname, "../fixtures/config-full", "./src/lib/utils"),
102118
},
@@ -117,8 +133,16 @@ describe("getConfig", () => {
117133
components: "$lib/components",
118134
},
119135
resolvedPaths: {
120-
components: path.resolve(__dirname, "../fixtures/config-vite", "./src/lib/components"),
121-
tailwindConfig: path.resolve(__dirname, "../fixtures/config-vite", "./tailwind.config.js"),
136+
components: path.resolve(
137+
__dirname,
138+
"../fixtures/config-vite",
139+
"./src/lib/components"
140+
),
141+
tailwindConfig: path.resolve(
142+
__dirname,
143+
"../fixtures/config-vite",
144+
"./tailwind.config.js"
145+
),
122146
tailwindCss: path.resolve(__dirname, "../fixtures/config-vite", "./src/app.pcss"),
123147
utils: path.resolve(__dirname, "../fixtures/config-vite", "./src/lib/utils"),
124148
},
@@ -139,13 +163,21 @@ describe("getConfig", () => {
139163
components: "$lib/components",
140164
},
141165
resolvedPaths: {
142-
components: path.resolve(__dirname, "../fixtures/config-jsconfig", "./src/lib/components"),
166+
components: path.resolve(
167+
__dirname,
168+
"../fixtures/config-jsconfig",
169+
"./src/lib/components"
170+
),
143171
tailwindConfig: path.resolve(
144172
__dirname,
145173
"../fixtures/config-jsconfig",
146174
"./tailwind.config.js"
147175
),
148-
tailwindCss: path.resolve(__dirname, "../fixtures/config-jsconfig", "./src/app.pcss"),
176+
tailwindCss: path.resolve(
177+
__dirname,
178+
"../fixtures/config-jsconfig",
179+
"./src/app.pcss"
180+
),
149181
utils: path.resolve(__dirname, "../fixtures/config-jsconfig", "./src/lib/utils"),
150182
},
151183
typescript: false,

0 commit comments

Comments
 (0)