-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
61 lines (51 loc) · 1.92 KB
/
index.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
//
// index.js creates a database of all the
// soundfiles, tutorials, examples and stores
// in separate json files under src/data
//
// Configure variables for custom filepaths and settings through .ini file
// const { parse } = require('ini');
// Read all the audio-files and serve the data sheet
const fs = require('fs-extra');
const fg = require('fast-glob');
const path = require('path');
// make sure the data folder exists, otherwise create it
fs.ensureDirSync('src/data');
// load custom paths through ini file
// fs.ensureFileSync('./mercury.ini');
// let ini = fs.readFileSync('./mercury.ini', 'utf-8');
// const config = parse(ini);
// get soundfile paths from default location
// let samples = {};
let samples = getFiles('public/assets/samples/**/*.wav');
// if custom paths are provided load those samples
// config.samples?.paths.forEach((p) => {
// samples = {...samples, ...getFiles(`${p}/**/*.wav`)}
// });
fs.writeJSONSync('src/data/samples.json', samples, {spaces : 2});
// load example
let examples = getFiles('public/assets/examples/**/*.txt');
Object.keys(examples).forEach((f) => {
examples[f] = fs.readFileSync(`./public/${examples[f]}`, 'utf8');
});
fs.writeJSONSync('src/data/examples.json', examples, {spaces : 2});
// load tutorials
let tuts = getFiles('public/assets/tutorial/**/*.txt');
Object.keys(tuts).forEach((f) => {
tuts[f] = fs.readFileSync(`./public/${tuts[f]}`, 'utf8');
});
fs.writeJSONSync('src/data/tutorials.json', tuts, {spaces : 2});
// return a list of files in json format
// with key: filename value: path
// Using FastGlob, that does not give windows path separators on windows.
function getFiles(glob){
const fold = fg.sync(glob);
let files = {};
for (let f in fold){
let relative_path = fold[f];
let separator = (relative_path.includes("/")) ? '/' : '\\';
let file = path.parse(relative_path);
files[file.name] = fold[f].split(separator).slice(1).join(separator);
}
return files;
}