forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-index.js
49 lines (40 loc) · 1.05 KB
/
generate-index.js
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
import fs from "fs";
import glob from "glob";
const normalize = (name) => {
let capitalizeNext = false;
const excluded = "-@";
return name.split("").reduce((out, char) => {
if (excluded.includes(char)) {
capitalizeNext = true;
return out;
}
if (capitalizeNext) {
capitalizeNext = false;
return out + char.toUpperCase();
}
return out + char;
}, "");
};
const files = glob
.sync("**/*.ts", { cwd: `${process.cwd()}/src` })
.map((x) => `"${x.slice(0, -3)}"`);
const commands = glob
.sync("*.ts", { cwd: `${process.cwd()}/src` })
.map((x) => x.slice(0, -3));
const commandExports = commands
.map((x) => `export { default as ${normalize(x)} } from "./${x}";`)
.join("");
fs.writeFileSync(
"build/index.js",
`var e=[${files.join(",")}];export{e as default};`
);
const commandTypeDeclarations = commands
.map((x) => `export declare const ${normalize(x)}: Fig.Spec`)
.join("\n");
fs.writeFileSync(
"build/index.d.ts",
`
declare const completions: string[]
export { completions as default }
`
);