-
Notifications
You must be signed in to change notification settings - Fork 0
/
link-to-plugin.js
63 lines (55 loc) · 1.44 KB
/
link-to-plugin.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
/* eslint-disable no-console */
const fs = require("fs");
const path = require("path");
const neodoc = require("neodoc");
const args = neodoc.run(`Link the dist folder to Notepad++ plugin folder. You should execute this script under Admin privilege.
Usage: link-to-plugin [--clear]
Options:
-c, --clear Clear the link.`);
// find notepad++
const nppDir = (() => {
const dirs = [
"C:\\Program Files\\Notepad++",
"C:\\Program Files (x86)\\Notepad++"
];
for (const dir of dirs) {
try {
fs.accessSync(dir + "/notepad++.exe");
return dir;
} catch (err) {
// pass
}
}
throw new Error("Can't find notepad++.exe");
})();
const includesDir = `${nppDir}/plugins/jN/includes`;
const appName = require("./package.json").name.replace(/^jn-npp-/, "");
const files = [
[`demo/${appName}.js`, `${includesDir}/${appName}.js`, "file"],
[`demo/${appName}`, `${includesDir}/${appName}`, "dir"],
[`${appName}.js`, `demo/${appName}/${appName}.js`, "file"]
];
function unlink(file) {
try {
fs.unlinkSync(file);
console.log(`Unlink "${file}"`);
} catch (err) {
if (err.code != "ENOENT") {
throw err;
}
}
}
function link(from, to, type) {
from = path.resolve(from);
to = path.resolve(to);
fs.symlinkSync(from, to, type);
console.log(`Link from "${from}" to "${to}"`);
}
for (const [, to] of files) {
unlink(to);
}
if (!args["--clear"]) {
for (const args of files) {
link(...args);
}
}