forked from vshaxe/vshaxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall.hx
46 lines (42 loc) · 1.35 KB
/
Install.hx
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
import sys.FileSystem;
import sys.io.File;
using StringTools;
function main() {
// this is not hacky at all... but seems there's no way to make `vsce package` skip prepublish
final restorePackageJson = tempModification("package.json", function(content) {
return content.split("\n").map(line -> if (line.contains("vscode:prepublish")) "" else line).join("\n");
});
final restoreVscodeIgnore = tempModification(".vscodeignore", function(content) {
return content + '!node_modules/**/*\n';
});
function restore() {
restorePackageJson();
restoreVscodeIgnore();
}
try {
final out = Sys.command("vsce package");
if (out != 0) {
throw "Error: Failed to generate vsix file";
}
// if it didn't fail, there should be a .vsix now
final vsixFiles = FileSystem.readDirectory(".").filter(file -> file.endsWith(".vsix"));
if (vsixFiles.length > 1) {
Sys.println('Multiple vsix files found: $vsixFiles');
} else {
Sys.command('code --install-extension ${vsixFiles[0]}');
FileSystem.deleteFile(vsixFiles[0]);
}
} catch (e) {
trace(e);
restore();
}
restore();
}
function tempModification(file:String, modify:(content:String) -> String):() -> Void {
final originalContent = File.getContent(file);
final newContent = modify(originalContent);
File.saveContent(file, newContent);
return function() {
File.saveContent(file, originalContent);
};
}