-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathwrite.js
More file actions
53 lines (48 loc) · 1.56 KB
/
write.js
File metadata and controls
53 lines (48 loc) · 1.56 KB
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
#!/usr/bin/env node
const fs = require('fs');
const config = require('./config')
const {getThemeKey} = require('./utils');
const writeThemesFile = (themes) => {
// Load existing themes.json and update it
let themesData = themes
// themes.forEach(theme => {
// themesData[theme.theme_key] = theme;
// })
let sortedThemesData = {}
Object.keys(themesData).sort().forEach(key => {
sortedThemesData[key] = themesData[key];
});
console.log(`Writing ${config.themesJsonFile}...`);
fs.writeFileSync(config.themesJsonFile, JSON.stringify(sortedThemesData, null, 2));
}
const writeErrorFile = (errorLog) => {
console.log(`Writing ${config.errorJsonFile}...`);
fs.writeFileSync(config.errorJsonFile, JSON.stringify(errorLog, null, 2));
}
const writeStackbitFile = (stackbit) => {
let stackbitData = config.stackbitJsonData
stackbit.forEach(theme => {
stackbitData[theme.theme_key] = theme;
})
let sortedStackbitData = {}
Object.keys(stackbitData).sort().forEach(key => {
sortedStackbitData[key] = stackbitData[key];
});
console.log(`Writing ${config.stackbitJsonFile}...`);
fs.writeFileSync(config.stackbitJsonFile, JSON.stringify(sortedStackbitData, null, 2));
}
const themeMap = (themes) => {
return themes.reduce((accumulator, theme) => {
const themeKey = getThemeKey(theme.github)
return {
...accumulator,
[themeKey]: theme
};
});
}
module.exports = {
writeThemesFile,
writeErrorFile,
writeStackbitFile,
themeMap
}