-
Notifications
You must be signed in to change notification settings - Fork 15
/
generate-skins.js
47 lines (36 loc) · 1.14 KB
/
generate-skins.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
const { statSync, readdirSync, readFileSync, writeFileSync } = require('fs');
const { join } = require('path')
const SKINS_PATH = './src/skins';
const template = `
import {ISkin} from './models';
export const SKINS: ISkin[] = ## SKINS ##;
`
function getDirectories(path) {
return readdirSync(path).filter(function (file) {
return statSync(path+'/'+file).isDirectory();
});
}
function getManifest(skin) {
let jsonData = {};
try {
jsonData = JSON.parse(readFileSync(join(SKINS_PATH, skin, 'manifest.json'), 'utf-8'))
} catch {
console.log('missing manifest file for skin ' + skin);
}
return jsonData;
}
const skins = getDirectories(SKINS_PATH)
.map(skin => {
console.log(`found skin: ${skin}`);
const manifest = getManifest(skin);
return {
name: skin,
displayName: manifest.displayName || skin,
component: skin,
createdBy: manifest.createdBy || []
}
});
const skinsStr = JSON.stringify(skins, null, 2);
const skinFileContent = template.replace('## SKINS ##', skinsStr);
writeFileSync(join(SKINS_PATH, 'skins.ts'), skinFileContent);
console.log(`Skins file was created successfully`);