-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
generatePage.js
38 lines (34 loc) · 1.15 KB
/
generatePage.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
var fs = require('fs');
var path = require('path');
var { htmlStart, htmlEnd, jsStart, jsEnd } = require('./pageElements')
// In newer Node.js versions where process is already global this isn't necessary.
var process = require("process");
// Loop through all the files in the temp directory
fs.readdir("tracks", function (err, files) {
if (err) {
console.error("Could not list the directory.", err);
process.exit(1);
}
var htmlText = htmlStart;
var jsText = jsStart;
files.forEach(function (file, index) {
// Make one pass and make the file complete
var fileId = file.slice(0, -4);
htmlText += `<input type="checkbox" id="`+ fileId + `" name="` + fileId + `">
<label for="unknown1">` + fileId + `</label>
<audio id="audio` + fileId + `" src="tracks/` + file + `" preload="auto"></audio>`;
jsText += `playIfChecked('` + fileId + `', 'audio` + fileId + `');`;
});
htmlText += htmlEnd;
jsText += jsEnd;
fs.writeFile('index.html', htmlText, err => {
if (err) {
console.error(err);
}
});
fs.writeFile('script.js', jsText, err => {
if (err) {
console.error(err);
}
});
});