-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmk-snips-run.js
83 lines (79 loc) · 2.4 KB
/
gmk-snips-run.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
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
(function() {
const child_process = require("child_process");
const Preferences = $gmedit['ui.Preferences'];
const Dialog = $gmedit['electron.Dialog'];
function run() {
if ($gmedit['gml.GmlAPI'].version.name != "gmk-snip") return;
console.log("Starting the runner...");
let runnerPath = Preferences.current.gmkSnipTesterPath;
if (runnerPath == null) {
Dialog.showError("Please set up snippet-tester path in Preferences!");
return;
}
if (!Electron_FS.existsSync(runnerPath)) {
Dialog.showError(`snippet-tester path "${runnerPath}" doesn't exist!`);
return;
}
const project = $gmedit['gml.Project'].current;
let listFilePath = project.path;
listFilePath = listFilePath.split("/").join("\\");
const runnerArgs = [
listFilePath,
];
let runner = child_process.spawn(runnerPath, runnerArgs, {
cwd: project.dir,
});
runner.on("spawn", () => {
console.log("Started up the runner!");
});
runner.stdout.on("data", (e) => {
let text = e.toString();
console.log(text);
});
runner.stderr.on("data", (e) => {
let text = e.toString();
console.error(text);
});
runner.on("close", (exitCode) => {
exitCode ??= 0;
runner = null;
console.log(`Runner closed, exitCode=${exitCode} (0x${exitCode.toString(16)})`);
})
}
function initCommands() {
const commands = [{
name: "gmk-snips-run",
title: "gmk-snips: Run",
bindKey: "F5",
exec: run,
}];
let hashHandler = $gmedit["ui.KeyboardShortcuts"].hashHandler;
let AceCommands = $gmedit["ace.AceCommands"];
for (let cmd of commands) {
hashHandler.addCommand(cmd);
AceCommands.add(cmd);
AceCommands.addToPalette({
name: cmd.title,
exec: cmd.name,
})
}
}
function initPreferences(e) {
let out = e.target.querySelector('.plugin-settings[for="gmk-snips-run"]');
let pathEl = Preferences.addInput(out,
"Path to snippet-tester.exe",
Preferences.current.gmkSnipTesterPath || "",
function(str) {
Preferences.current.gmkSnipTesterPath = str;
Preferences.save();
});
pathEl.querySelector("input").placeholder = "C:\\snippet_tester.exe";
}
//
GMEdit.register("gmk-snips-run", {
init: function(config) {
initCommands();
GMEdit.on("preferencesBuilt", initPreferences);
}
});
})();