forked from torch2424/made-with-webassembly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowcase-build.js
50 lines (40 loc) · 1.44 KB
/
showcase-build.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
// Require our file navigation
const fs = require("fs");
const path = require("path");
const mkdirp = require("mkdirp");
const recursiveReadDir = require("recursive-readdir");
const recursiveCopy = require("recursive-copy");
// Require our Markdown parsing
const showdown = require("showdown");
const showdownConverter = new showdown.Converter({ metadata: true });
// Start our building task
const buildTask = async () => {
console.log(" ");
console.log("Building showcase...");
console.log(" ");
// Create our build output folder
mkdirp.sync("./src/assets");
mkdirp.sync("./src/assets/showcase");
// Recursively get all showcase markdown files
const showcaseFiles = await recursiveReadDir("showcase");
// Start our metadata JSON
const metadataJson = {};
showcaseFiles.forEach(file => {
// Get the contents of the file
const text = fs.readFileSync(file, "utf8");
// Get the name, html, and metadata of the file
const name = path.basename(file, ".md");
const html = showdownConverter.makeHtml(text);
const metadata = showdownConverter.getMetadata();
// Add the metadata
metadata["key"] = name;
metadataJson[name] = metadata;
// Create the HTML output
fs.writeFileSync(`./src/assets/showcase/${name}.html`, html);
});
// Create our showcase json (minified)
fs.writeFileSync(`./src/assets/showcase.json`, JSON.stringify(metadataJson));
console.log("Done!");
console.log(" ");
};
buildTask();