-
Notifications
You must be signed in to change notification settings - Fork 754
/
addToFilesOption.ts
54 lines (48 loc) · 1.52 KB
/
addToFilesOption.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
import {List, Map} from "immutable";
import {BsTempOptions, TransformResult} from "../cli-options";
export function addToFilesOption(incoming: BsTempOptions): TransformResult {
if (!incoming.get("watch")) {
return [incoming, []];
}
let serverPaths = [];
const fromServeStatic = incoming
.get("serveStatic", List([]))
.toArray();
const ssPaths = fromServeStatic
.reduce((acc, ss) => {
if (typeof ss === "string") {
return acc.concat(ss);
}
if (ss.dir && typeof ss.dir === "string") {
return acc.concat(ss);
}
return acc;
}, []);
ssPaths.forEach(p => serverPaths.push(p));
const server = incoming.get("server");
if (server) {
if (server === true) {
serverPaths.push(".");
}
if (typeof server === "string") {
serverPaths.push(server);
}
if (
List.isList(server) &&
server.every(x => typeof x === "string")
) {
server.forEach(s => serverPaths.push(s));
}
if (Map.isMap(server)) {
const baseDirProp = server.get("baseDir");
const baseDirs = List([]).concat(baseDirProp).filter(Boolean);
baseDirs.forEach(s => serverPaths.push(s));
}
}
const output = incoming.update("files", files => {
return List([])
.concat(files, serverPaths)
.filter(Boolean);
});
return [output, []];
}