-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
47 lines (39 loc) · 1.43 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
//
// 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});
// 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;
}