-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
74 lines (57 loc) · 1.86 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// https://www.sitepoint.com/beginners-guide-node-package-manager/
// npm install && node build.js
const fs = require('fs');
const cheerio = require('cheerio');
const root = "docs";
const homeUrl = "https://igorrosenberg.github.io/js_playground";
const readme = "README.md";
const exclusions = [
'index.html',
'extra.js',
'jquery-rewire-fragment.html',
'js_playground.js',
'oracle.js',
'node-server.js'
];
let stream = ''; // fs.createWriteStream("output.txt");
function write(s) {
stream += s + "\n"; // stream.write(s + "\n");
}
write(`## Igor Rosenberg's JS demos
This repo saves *experiments* in JS. The code below should be seen as sandbox futilities.
#### node server
\`node-server.js\`, a quick HTTP file server, from <a href="https://stackoverflow.com/questions/16333790">stackoverflow-16333790</a>.
\`\`\`
npm install finalhandler serve-static
cat > node-server.js
node node-server.js
firefox http://localhost:8000/
\`\`\`
<a href="https://igorrosenberg.github.io/js_playground/node-server.js">Javascript source</a>.
`);
fs.readdirSync(root).forEach(file => {
for (let i=0; i<exclusions.length; i++)
if (file == exclusions[i]) {
return
}
let title, description ;
if (file.match(/\.html$/)) {
const $ = cheerio.load(fs.readFileSync(root + '/' + file));
title = $('head title').text();
description = $('#description').text().trim();
} else if (file.match(/\.js$/)) {
title = file;
description = fs.readFileSync(root + '/' + file).toString().split(/\n/)[0].substr(3);
} else {
return;
}
let liveLink = `<a href="${homeUrl}/${file}">Live Version</a>`;
write(`#### ${title}`);
write("");
write(description);
write(liveLink);
write("");
});
// stream.end();
// stream.close();
console.log(fs.readFileSync(readme).toString() == stream.toString());