Skip to content

Commit 93639e8

Browse files
committed
make stuff faster and simplify more
1 parent d3cbaaf commit 93639e8

2 files changed

Lines changed: 52 additions & 83 deletions

File tree

scripts/build-cli.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
chmodSync,
3-
copyFileSync,
4-
existsSync,
5-
mkdirSync,
6-
mkdtempSync,
7-
rmSync,
8-
writeFileSync,
9-
} from "fs";
1+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs";
102
import { tmpdir } from "os";
113
import { basename, join } from "path";
124
import { CLI_ENTRY, CLI_TARGETS, DIST_DIR, getCliTarget } from "./cli-targets";
@@ -47,7 +39,9 @@ async function buildTarget(target: (typeof CLI_TARGETS)[number]): Promise<void>
4739
console.error(`Build failed for ${target.id}: missing output ${buildOutfile}`);
4840
process.exit(1);
4941
}
50-
copyFileSync(buildOutfile, outfile);
42+
await Bun.write(outfile, Bun.file(buildOutfile));
43+
chmodSync(outfile, 0o755);
44+
writeFileSync(`${outfile}.sha256`, await sha256sumLine(outfile));
5145
} finally {
5246
rmSync(buildDir, { force: true, recursive: true });
5347
}
@@ -71,29 +65,4 @@ for (const target of targets) {
7165
await buildTarget(target);
7266
}
7367

74-
if (targets.length === CLI_TARGETS.length) {
75-
const names = CLI_TARGETS.map((t) => t.outfile);
76-
77-
for (const name of names) {
78-
const path = join(DIST_DIR, name);
79-
chmodSync(path, 0o755);
80-
writeFileSync(`${path}.sha256`, await sha256sumLine(path));
81-
}
82-
83-
const tarName = "chromatic-all.tar.gz";
84-
const tarProc = Bun.spawn(["tar", "-czf", tarName, ...names], {
85-
cwd: DIST_DIR,
86-
stdout: "inherit",
87-
stderr: "inherit",
88-
});
89-
90-
if ((await tarProc.exited) !== 0) {
91-
console.error("Failed to create chromatic-all.tar.gz");
92-
process.exit(1);
93-
}
94-
95-
const tarPath = join(DIST_DIR, tarName);
96-
writeFileSync(`${tarPath}.sha256`, await sha256sumLine(tarPath));
97-
}
98-
9968
console.log(`Built ${targets.length} CLI binary(s) in ${DIST_DIR}/`);

src/cli/cli.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
import { readFileSync, existsSync, statSync } from "fs";
22
import { createInterface } from "readline";
33
import type { ColorScheme } from "../types";
4-
import { configureVim } from "./configs/vim";
5-
import { configureVSCode } from "./configs/vscode";
6-
import { configureCursor } from "./configs/cursor";
7-
import { configureNeovim } from "./configs/neovim";
8-
import { configureFoot } from "./configs/foot";
9-
import { configureAlacritty } from "./configs/alacritty";
10-
import { configureKitty } from "./configs/kitty";
11-
import { configureWezTerm } from "./configs/wezterm";
12-
import { configureXresources } from "./configs/xresources";
13-
import { configureI3 } from "./configs/i3";
14-
import { configureSway } from "./configs/sway";
15-
import { configureRiver } from "./configs/river";
16-
import { configureHyprland } from "./configs/hyprland";
17-
import { configureMango } from "./configs/mango";
18-
import { configureGtk3 } from "./configs/gtk3";
19-
import { configureGtk4 } from "./configs/gtk4";
20-
import { configureRofi } from "./configs/rofi";
21-
import { configureDunst } from "./configs/dunst";
224

235
type AppGroup = "Editors" | "Terminals" | "Window Managers" | "GTK" | "Other";
246
type PathKind = "file" | "dir";
@@ -33,12 +15,12 @@ type AppConfig = {
3315
pathFlag: string;
3416
pathKind: PathKind;
3517
platforms: readonly Platform[];
36-
configure: (scheme: ColorScheme, overridePath?: string) => void;
18+
configure: (scheme: ColorScheme, overridePath?: string) => Promise<void>;
3719
};
3820

3921
const LINUX = ["linux"] as const satisfies readonly Platform[];
4022
const LINUX_MACOS = ["linux", "darwin"] as const satisfies readonly Platform[];
41-
const DESKTOP = ["linux", "darwin", "win32"] as const satisfies readonly Platform[];
23+
const ALL_PLATFORMS = ["linux", "darwin", "win32"] as const satisfies readonly Platform[];
4224

4325
const APPS: AppConfig[] = [
4426
{
@@ -48,8 +30,9 @@ const APPS: AppConfig[] = [
4830
appFlag: "--vim",
4931
pathFlag: "--vim-path",
5032
pathKind: "file",
51-
platforms: DESKTOP,
52-
configure: configureVim,
33+
platforms: ALL_PLATFORMS,
34+
configure: async (scheme, overridePath) =>
35+
(await import("./configs/vim")).configureVim(scheme, overridePath),
5336
},
5437
{
5538
key: "vscode",
@@ -58,8 +41,9 @@ const APPS: AppConfig[] = [
5841
appFlag: "--vscode",
5942
pathFlag: "--vscode-path",
6043
pathKind: "dir",
61-
platforms: DESKTOP,
62-
configure: configureVSCode,
44+
platforms: ALL_PLATFORMS,
45+
configure: async (scheme, overridePath) =>
46+
(await import("./configs/vscode")).configureVSCode(scheme, overridePath),
6347
},
6448
{
6549
key: "cursor",
@@ -68,8 +52,9 @@ const APPS: AppConfig[] = [
6852
appFlag: "--cursor",
6953
pathFlag: "--cursor-path",
7054
pathKind: "dir",
71-
platforms: DESKTOP,
72-
configure: configureCursor,
55+
platforms: ALL_PLATFORMS,
56+
configure: async (scheme, overridePath) =>
57+
(await import("./configs/cursor")).configureCursor(scheme, overridePath),
7358
},
7459
{
7560
key: "neovim",
@@ -78,8 +63,9 @@ const APPS: AppConfig[] = [
7863
appFlag: "--neovim",
7964
pathFlag: "--neovim-path",
8065
pathKind: "file",
81-
platforms: DESKTOP,
82-
configure: configureNeovim,
66+
platforms: ALL_PLATFORMS,
67+
configure: async (scheme, overridePath) =>
68+
(await import("./configs/neovim")).configureNeovim(scheme, overridePath),
8369
},
8470
{
8571
key: "foot",
@@ -89,7 +75,8 @@ const APPS: AppConfig[] = [
8975
pathFlag: "--foot-path",
9076
pathKind: "file",
9177
platforms: LINUX,
92-
configure: configureFoot,
78+
configure: async (scheme, overridePath) =>
79+
(await import("./configs/foot")).configureFoot(scheme, overridePath),
9380
},
9481
{
9582
key: "alacritty",
@@ -98,8 +85,9 @@ const APPS: AppConfig[] = [
9885
appFlag: "--alacritty",
9986
pathFlag: "--alacritty-path",
10087
pathKind: "file",
101-
platforms: DESKTOP,
102-
configure: configureAlacritty,
88+
platforms: ALL_PLATFORMS,
89+
configure: async (scheme, overridePath) =>
90+
(await import("./configs/alacritty")).configureAlacritty(scheme, overridePath),
10391
},
10492
{
10593
key: "kitty",
@@ -109,7 +97,8 @@ const APPS: AppConfig[] = [
10997
pathFlag: "--kitty-path",
11098
pathKind: "file",
11199
platforms: LINUX_MACOS,
112-
configure: configureKitty,
100+
configure: async (scheme, overridePath) =>
101+
(await import("./configs/kitty")).configureKitty(scheme, overridePath),
113102
},
114103
{
115104
key: "wezterm",
@@ -118,8 +107,9 @@ const APPS: AppConfig[] = [
118107
appFlag: "--wezterm",
119108
pathFlag: "--wezterm-path",
120109
pathKind: "dir",
121-
platforms: DESKTOP,
122-
configure: configureWezTerm,
110+
platforms: ALL_PLATFORMS,
111+
configure: async (scheme, overridePath) =>
112+
(await import("./configs/wezterm")).configureWezTerm(scheme, overridePath),
123113
},
124114
{
125115
key: "xresources",
@@ -129,7 +119,8 @@ const APPS: AppConfig[] = [
129119
pathFlag: "--xresources-path",
130120
pathKind: "file",
131121
platforms: LINUX,
132-
configure: configureXresources,
122+
configure: async (scheme, overridePath) =>
123+
(await import("./configs/xresources")).configureXresources(scheme, overridePath),
133124
},
134125
{
135126
key: "i3",
@@ -139,7 +130,8 @@ const APPS: AppConfig[] = [
139130
pathFlag: "--i3-path",
140131
pathKind: "file",
141132
platforms: LINUX,
142-
configure: configureI3,
133+
configure: async (scheme, overridePath) =>
134+
(await import("./configs/i3")).configureI3(scheme, overridePath),
143135
},
144136
{
145137
key: "sway",
@@ -149,7 +141,8 @@ const APPS: AppConfig[] = [
149141
pathFlag: "--sway-path",
150142
pathKind: "file",
151143
platforms: LINUX,
152-
configure: configureSway,
144+
configure: async (scheme, overridePath) =>
145+
(await import("./configs/sway")).configureSway(scheme, overridePath),
153146
},
154147
{
155148
key: "river",
@@ -159,7 +152,8 @@ const APPS: AppConfig[] = [
159152
pathFlag: "--river-path",
160153
pathKind: "file",
161154
platforms: LINUX,
162-
configure: configureRiver,
155+
configure: async (scheme, overridePath) =>
156+
(await import("./configs/river")).configureRiver(scheme, overridePath),
163157
},
164158
{
165159
key: "hyprland",
@@ -169,7 +163,8 @@ const APPS: AppConfig[] = [
169163
pathFlag: "--hyprland-path",
170164
pathKind: "file",
171165
platforms: LINUX,
172-
configure: configureHyprland,
166+
configure: async (scheme, overridePath) =>
167+
(await import("./configs/hyprland")).configureHyprland(scheme, overridePath),
173168
},
174169
{
175170
key: "mango",
@@ -179,7 +174,8 @@ const APPS: AppConfig[] = [
179174
pathFlag: "--mango-path",
180175
pathKind: "file",
181176
platforms: LINUX,
182-
configure: configureMango,
177+
configure: async (scheme, overridePath) =>
178+
(await import("./configs/mango")).configureMango(scheme, overridePath),
183179
},
184180
{
185181
key: "gtk3",
@@ -189,7 +185,8 @@ const APPS: AppConfig[] = [
189185
pathFlag: "--gtk3-path",
190186
pathKind: "file",
191187
platforms: LINUX,
192-
configure: configureGtk3,
188+
configure: async (scheme, overridePath) =>
189+
(await import("./configs/gtk3")).configureGtk3(scheme, overridePath),
193190
},
194191
{
195192
key: "gtk4",
@@ -199,7 +196,8 @@ const APPS: AppConfig[] = [
199196
pathFlag: "--gtk4-path",
200197
pathKind: "file",
201198
platforms: LINUX,
202-
configure: configureGtk4,
199+
configure: async (scheme, overridePath) =>
200+
(await import("./configs/gtk4")).configureGtk4(scheme, overridePath),
203201
},
204202
{
205203
key: "rofi",
@@ -209,7 +207,8 @@ const APPS: AppConfig[] = [
209207
pathFlag: "--rofi-path",
210208
pathKind: "file",
211209
platforms: LINUX,
212-
configure: configureRofi,
210+
configure: async (scheme, overridePath) =>
211+
(await import("./configs/rofi")).configureRofi(scheme, overridePath),
213212
},
214213
{
215214
key: "dunst",
@@ -219,7 +218,8 @@ const APPS: AppConfig[] = [
219218
pathFlag: "--dunst-path",
220219
pathKind: "file",
221220
platforms: LINUX,
222-
configure: configureDunst,
221+
configure: async (scheme, overridePath) =>
222+
(await import("./configs/dunst")).configureDunst(scheme, overridePath),
223223
},
224224
];
225225

@@ -370,7 +370,7 @@ async function main() {
370370

371371
const hasExplicitFlags = args.some((arg) => appFlags.includes(arg));
372372
const configAll = args.includes("--all") || !hasExplicitFlags;
373-
const configs: Array<[boolean, () => void, string]> = APPS.map((app) => [
373+
const configs: Array<[boolean, () => Promise<void>, string]> = APPS.map((app) => [
374374
(configAll && app.platforms.includes(process.platform)) || args.includes(app.appFlag),
375375
() => app.configure(scheme, pathOverrides[app.key]),
376376
app.name,
@@ -396,12 +396,12 @@ async function main() {
396396
}
397397

398398
console.log("Configuring colorscheme...\n");
399-
configs.forEach(([shouldRun, configure, name]) => {
399+
for (const [shouldRun, configure, name] of configs) {
400400
if (shouldRun) {
401-
configure();
401+
await configure();
402402
console.log(`✓ Configured ${name}`);
403403
}
404-
});
404+
}
405405
}
406406

407407
try {

0 commit comments

Comments
 (0)