-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.ts
57 lines (47 loc) · 1.44 KB
/
update.ts
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
import editInPlace from "json-in-place";
import { copySync } from "fs-extra";
import * as fs from "fs";
import { join } from "path";
import { homedir } from "os";
const themes = fs.readdirSync("./themes").map((theme) => {
const themePath = "./" + join("themes", theme);
const label = theme
.replace(/\.[^.]+$/, "")
.replace(/-/g, " ")
.replace(/\b\w/g, (l) => l.toUpperCase());
console.log("+", label);
return {
label,
uiTheme: fs.readFileSync(themePath, "utf8").includes('"type": "dark"')
? "vs-dark"
: "vs",
path: themePath,
};
});
function setThemesField(pkgJson: string) {
const pkg = editInPlace(pkgJson);
pkg.set("contributes", { themes });
fs.writeFileSync("./package.json", pkg.toString());
}
const pkgJson = fs.readFileSync("./package.json", "utf-8");
const pkg = JSON.parse(pkgJson);
setThemesField(pkgJson);
const installId = pkg.publisher + "." + pkg.name + "-" + pkg.version;
const installPath = join(homedir(), ".vscode", "extensions", installId);
const insidersPath = join(
homedir(),
".vscode-insiders",
"extensions",
installId
);
if (fs.existsSync(installPath)) {
overwriteSync("package.json", installPath);
overwriteSync("themes", installPath);
}
if (fs.existsSync(insidersPath)) {
overwriteSync("package.json", insidersPath);
overwriteSync("themes", insidersPath);
}
function overwriteSync(src: string, dest: string) {
copySync(src, join(dest, src), { overwrite: true });
}