-
Notifications
You must be signed in to change notification settings - Fork 761
/
build.js
56 lines (45 loc) · 1.36 KB
/
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
51
52
53
54
55
56
const fs = require('fs');
const dirTree = require('directory-tree');
const indexer = require('./search/index-documents');
const flattenPath = require('./tools/flatten-path');
const rootDir = './public/src/';
const examplesJSON = './public/examples.json';
const recentExamplesJSON = './public/recent-examples.json';
let filteredTree = dirTree(rootDir, {
extensions: /\.(js|json)$/,
exclude: /(3\.24)/,
attributes: ["birthtimeMs"]
});
indexer.index(filteredTree);
filteredTree = JSON.stringify(filteredTree, null, 2);
filteredTree = filteredTree.replaceAll(`public/`, ``);
filteredTree = filteredTree.replaceAll(`public\\\\`, ``);
// console.log(filteredTree);
const lastExamplesQuantity = 30;
// Get the 30 more recent examples
const examplesFlatten = flattenPath(JSON.parse(filteredTree))
.filter(x => x.path.endsWith("js"))
.sort((a, b) => b.birthtimeMs - a.birthtimeMs)
.slice(0, lastExamplesQuantity);
// Save the 10 more recent examples
fs.writeFile(recentExamplesJSON, JSON.stringify(examplesFlatten, null, 4), function (error) {
if (error)
{
throw error;
}
else
{
console.log('* recent-examples.json saved');
}
});
// Save the JSON
fs.writeFile(examplesJSON, filteredTree, function (error) {
if (error)
{
throw error;
}
else
{
console.log('* examples.json saved');
}
});