-
Notifications
You must be signed in to change notification settings - Fork 759
/
build355.js
54 lines (44 loc) · 1.35 KB
/
build355.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
const fs = require('fs');
const dirTree = require('directory-tree');
const indexer = require('./search/index-documents');
const flattenPath = require('./tools/flatten-path');
const rootDir = './public/3.55/src/';
const examplesJSON = './public/3.55/examples.json';
const recentExamplesJSON = './public/3.55/recent-examples.json';
var filteredTree = dirTree(rootDir, {
extensions: /\.(js|json)$/,
exclude: /(3\.24)/,
attributes: ["birthtimeMs"]
});
indexer.index(filteredTree);
filteredTree = JSON.stringify(filteredTree, null, 2);
filteredTree = filteredTree.replaceAll(`public/3.55/`, ``);
filteredTree = filteredTree.replaceAll(`public\\3.55\\`, ``);
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');
}
});