-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.build.ts
More file actions
207 lines (185 loc) · 6.19 KB
/
Copy pathpackage.build.ts
File metadata and controls
207 lines (185 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { writeFile } from "node:fs/promises";
import path from "node:path";
import { pathToFileURL } from "node:url";
type KeybindingConfig = {
groups: Record<string, unknown[]>;
};
type ResolvedKeybinding = {
key: string;
command: string;
args?: unknown;
when?: string;
};
type DefaultConfigModule = {
default: KeybindingConfig;
};
type ResolveModule = {
resolveKeybindings: (config: KeybindingConfig) => ResolvedKeybinding[];
};
type GermanModule = {
toGermanLayoutBindings: (bindings: readonly ResolvedKeybinding[]) => ResolvedKeybinding[];
};
type PackageJson = {
contributes?: {
commands?: Record<string, unknown>[];
keybindings?: Record<string, unknown>[];
configuration?: Record<string, unknown>;
};
} & Record<string, unknown>;
type KeyboardLayout = "default" | "german";
const BASE_PACKAGE_JSON: PackageJson = {
name: "flowquill",
displayName: "Flowquill",
description: "Better modal editing",
version: "1.0.1",
publisher: "reddev",
license: "0BSD",
icon: "icon.png",
engines: {
vscode: "^1.115.0",
},
categories: ["Keymaps"],
"repository": {
"type": "git",
"url": "https://github.com/TheRedDeveloper/flowquill.git"
},
activationEvents: ["onStartupFinished"],
main: "./dist/extension.js",
contributes: {
commands: [
{
command: "flowquill.makeNormal",
title: "Disable Zen UI Layout",
category: "Flowquill",
},
{
command: "flowquill.startTutor",
title: "Start Interactive Tutor",
category: "Flowquill",
},
],
configuration: {
title: "Flowquill",
properties: {
"flowquill.cursorDecorationColor": {
type: "string",
default: "editorCursor.foreground",
description: "Theme color token used by the fake block cursor decoration.",
},
},
},
keybindings: [],
},
scripts: {
build: "pnpm run build:keybindings && pnpm run build:code",
"build:code": "pnpm run build:code:bundle && pnpm run build:code:optimize",
"build:code:bundle": "tsup",
"build:code:optimize": "node optimize.mjs",
"build:german": "pnpm run build:keybindings:german && FLOWQUILL_LAYOUT=german pnpm run build:code",
"build:keybindings": "node --no-warnings=MODULE_TYPELESS_PACKAGE_JSON package.build.ts",
"build:keybindings:german": "node --no-warnings=MODULE_TYPELESS_PACKAGE_JSON package.build.ts --layout=german",
clean: "rimraf dist out .vscode-test",
lint: "eslint .",
test: "pnpm run test:unit && pnpm run test:integration",
"test:compile": "tsc -p test/tsconfig.json",
"test:integration": "pnpm run build && pnpm run test:compile && node ./test/runTest.js",
"test:unit": "vitest run",
typecheck: "tsc --noEmit",
watch: "tsup --watch",
"package": "pnpm build && vsce package --no-dependencies",
"package:german": "pnpm build:german && vsce package --no-dependencies",
},
dependencies: {
"vscode-languageclient": "^9.0.1",
},
devDependencies: {
"@types/mocha": "^10.0.10",
"@types/node": "^25.6.0",
"@types/vscode": "^1.115.0",
"@typescript-eslint/eslint-plugin": "^8.58.1",
"@typescript-eslint/parser": "^8.58.1",
"@vscode/test-electron": "^2.5.2",
eslint: "^10.2.0",
"eslint-config-prettier": "^10.1.8",
glob: "^13.0.6",
"google-closure-compiler": "^20260407.0.0",
mocha: "^11.7.5",
prettier: "^3.8.2",
rimraf: "^6.1.3",
tsup: "^8.5.1",
tsx: "^4.21.0",
typescript: "^6.0.2",
vitest: "^4.1.4",
},
packageManager: "pnpm@9.15.1",
};
const parseLayout = (): KeyboardLayout => {
const fromArg = process.argv.find((arg) => arg.startsWith("--layout="))?.split("=")[1];
const fromEnv = process.env.FLOWQUILL_KEYBOARD_LAYOUT;
const candidate = (fromArg ?? fromEnv ?? "default").toLowerCase();
return candidate === "german" ? "german" : "default";
};
const loadKeybindingModules = async (): Promise<{
defaultConfig: KeybindingConfig;
resolveKeybindings: (config: KeybindingConfig) => ResolvedKeybinding[];
toGermanLayoutBindings: (bindings: readonly ResolvedKeybinding[]) => ResolvedKeybinding[];
}> => {
const root = process.cwd();
const defaultConfigModulePath = pathToFileURL(path.resolve(root, "src/keybinds/default.ts")).href;
const resolveModulePath = pathToFileURL(path.resolve(root, "src/keybinds/resolve.ts")).href;
const germanModulePath = pathToFileURL(path.resolve(root, "src/keybinds/german.ts")).href;
const [defaultConfigModule, resolveModule, germanModule] = await Promise.all([
import(defaultConfigModulePath) as Promise<DefaultConfigModule>,
import(resolveModulePath) as Promise<ResolveModule>,
import(germanModulePath) as Promise<GermanModule>,
]);
return {
defaultConfig: defaultConfigModule.default,
resolveKeybindings: resolveModule.resolveKeybindings,
toGermanLayoutBindings: germanModule.toGermanLayoutBindings,
};
};
const build = async (): Promise<void> => {
const layout = parseLayout();
const packagePath = path.resolve(process.cwd(), "package.json");
const {
defaultConfig,
resolveKeybindings,
toGermanLayoutBindings,
} = await loadKeybindingModules();
const packageJson: PackageJson = {
...BASE_PACKAGE_JSON,
contributes: {
...BASE_PACKAGE_JSON.contributes,
},
};
const resolved = resolveKeybindings(defaultConfig);
const layoutAwareBindings = layout === "german"
? toGermanLayoutBindings(resolved)
: resolved;
const keybindings = layoutAwareBindings.map((keybinding) => ({
key: keybinding.key,
command: keybinding.command,
...(keybinding.args === undefined ? {} : { args: keybinding.args }),
...(keybinding.when === undefined ? {} : { when: keybinding.when }),
}));
packageJson.contributes = {
...packageJson.contributes,
keybindings,
};
if (layout === "german") {
packageJson.name = "flowquill-german";
packageJson.displayName = "Flowquill (German Layout)";
packageJson.icon = "icon-german.png";
}
await writeFile(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf8");
};
void (async () => {
try {
await build();
} catch (error: unknown) {
console.error("Flowquill keybinding build failed");
console.error(error);
process.exitCode = 1;
}
})();