-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.js
90 lines (82 loc) · 2.26 KB
/
watch.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
84
85
86
87
88
89
90
const chokidar = require("chokidar"),
fs = require("fs-extra"),
path = require("path"),
deepmerge = require("deepmerge");
var pkg = require("./package.json"),
pkgApiBrowser = require("./Server/ApiBrowser/dnn.json");
if (fs.existsSync("./local.json")) {
var local = require("./local.json");
pkg = deepmerge(pkg, local);
}
var log = console.log.bind(console);
function copy(start, srcRelativePath, destDir) {
if (!fs.existsSync(srcRelativePath)) {
return null;
}
var relPath = path.relative(start, srcRelativePath);
const fullDestPath = path.join(destDir, relPath);
log("Copying: " + srcRelativePath);
return fs
.ensureDir(path.dirname(fullDestPath))
.then(() => fs.copy(srcRelativePath, fullDestPath))
.catch((err) => {
console.error(err);
});
}
var ignore = [
/obj/,
/bin/,
"**/*.{vb,cs,suo,user}",
"**/dnn.json",
"**/*.??proj",
"**/web*.config",
"**/packages.config",
"**/.*",
];
const allDlls = pkgApiBrowser.pathsAndFiles.assemblies
// .concat(pkgApiBrowser.pathsAndFiles.assemblies)
.map((dll) => "bin/" + dll);
const watcher = (src, dest) =>
chokidar
.watch(src, {
ignored: ignore,
persistent: true,
})
.on("add", (path) => copy(src, path, dest))
.on("change", (path) => copy(src, path, dest));
// Todo: delete events?
// Initialize watchers.
const ApiBrowserWatcher = watcher(
"Server/ApiBrowser",
pkg.dnn.pathsAndFiles.devSitePath +
"\\DesktopModules\\MVC\\Connect\\ApiBrowser"
);
const SkinWatcher = watcher(
"Themes/Skins/ApiBrowser",
pkg.dnn.pathsAndFiles.devSitePath + "\\Portals\\_default\\Skins\\ApiBrowser"
);
const ContainerWatcher = watcher(
"Themes/Containers/ApiBrowser",
pkg.dnn.pathsAndFiles.devSitePath +
"\\Portals\\_default\\Containers\\ApiBrowser"
);
const DllWatcher = chokidar
.watch(allDlls, {
persistent: true,
})
.on("add", (path) => {
copy("bin", path, pkg.dnn.pathsAndFiles.devSitePath + "\\bin");
copy(
"bin",
path.replace(".dll", ".pdb"),
pkg.dnn.pathsAndFiles.devSitePath + "\\bin"
);
})
.on("change", (path) => {
copy("bin", path, pkg.dnn.pathsAndFiles.devSitePath + "\\bin");
copy(
"bin",
path.replace(".dll", ".pdb"),
pkg.dnn.pathsAndFiles.devSitePath + "\\bin"
);
});