-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (63 loc) · 1.78 KB
/
index.js
File metadata and controls
69 lines (63 loc) · 1.78 KB
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
const {
readdirSync,
statSync,
readFileSync,
existsSync,
mkdirSync,
writeFileSync,
} = require("fs");
const { join, sep } = require("path");
function getFilesFromDirectoryRecursive(staticpath, relativepath) {
const fileNames = readdirSync(staticpath);
let files = [];
fileNames.forEach((file) => {
if (statSync(join(staticpath, file)).isDirectory()) {
files = [
...files,
...getFilesFromDirectoryRecursive(
join(staticpath, file),
join(relativepath, file)
),
];
} else if (statSync(join(staticpath, file)).isFile()) {
files.push({
relative: join(relativepath, file),
static: join(staticpath, file),
data: readFileSync(join(staticpath, file), "utf-8"),
});
}
});
return files;
}
let files = getFilesFromDirectoryRecursive(join(__dirname, "./templates"), "");
files.forEach((file) => {
const folders = file.relative.split(sep).slice(0, -1);
if (folders.length === 0) return;
let path = join(__dirname + "/output");
folders.forEach((filePath) => {
path = join(path, filePath);
if (!existsSync(path)) {
console.log(path);
mkdirSync(path);
}
return path;
});
});
let outputFiles = []
files.forEach((file) => {
const includes = [
...file.data.matchAll(/<include>[a-zA-Z0-9]+.emd<\/include>/g),
];
includes.forEach((include) => {
const path = include[0].replace(/<include>/, "").replace(/<\/include>/, "")
const includedata = readFileSync(join(__dirname ,"/components", path), "utf-8");
file.data = file.data.replace("<include>" + path + "</include>", includedata)
});
outputFiles.push(file)
});
files.forEach((file) => {
writeFileSync(
join(__dirname, "/output", file.relative.replace(".emd", ".md")),
file.data
);
});