-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
50 lines (38 loc) · 1.47 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
const yaml = require('js-yaml');
const fs = require('fs');
const glob = require('glob');
const { execSync } = require('child_process');
function convertToFlac(source, destination) {
execSync(`ffmpeg -i "${source}" -c:a flac "${destination}"`);
}
if (fs.existsSync('samples'))
fs.rmSync('samples', { recursive: true });
fs.mkdirSync('samples');
const packs = [];
for (const pack of fs.readdirSync('packs')) {
if (pack === '.DS_Store')
continue;
const yamlPath = glob(`./packs/${pack}/*.yaml`, { sync: true })[0];
const meta = yaml.load(fs.readFileSync(yamlPath));
if (meta.draft)
continue;
fs.mkdirSync(`./samples/${pack}`);
const imagePath = glob(`./packs/${pack}/*.jpg`, { sync: true })[0];
if (imagePath) {
fs.cpSync(imagePath, `./samples/${pack}/image.jpg`);
meta.image = `${pack}/image.jpg`;
}
meta.samples = [];
if (fs.existsSync(`./packs/${pack}/samples`)) {
const samples = fs.readdirSync(`./packs/${pack}/samples`);
for (const sample of samples) {
const destinationPath = `./samples/${pack}/${sample}`;
if (sample === '.DS_Store')
continue;
convertToFlac(`./packs/${pack}/samples/${sample}`, destinationPath.replace('.wav', '.flac'));
meta.samples.push({ name: sample, path: `${pack}/${sample.replace('.wav', '.flac')}` });
}
}
packs.push(meta);
}
fs.writeFileSync('./samples/samples.json', JSON.stringify(packs));