-
Notifications
You must be signed in to change notification settings - Fork 3
/
generator.js
executable file
·104 lines (77 loc) · 2.5 KB
/
generator.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env node
var fs = require('fs');
var capitalize = function (s) {
return s && s[0].toUpperCase() + s.slice(1);
};
var getPaletteName = function (filename) {
var name = filename
.split('guake-').join('')
.split('.sh').join('')
.split('-').map(function (partialStr) {
return capitalize(partialStr);
}).join(' ');
return name;
};
var getForegroundColor = function (file) {
var color = file[0]
.split('gconftool-2 -s -t string /apps/guake/style/font/color "').join('')
.split('"').join('');
return color;
};
var getBackgroundColor = function (file) {
var color = file[1]
.split('gconftool-2 -s -t string /apps/guake/style/background/color "').join('')
.split('"').join('');
return color;
};
var getPaletteColors = function (file) {
var temp = file[2]
.split('gconftool-2 -s -t string /apps/guake/style/font/palette "').join('')
.split('"').join('');
var colors = [[], [], [], []];
var counter = -1;
temp.split(':').forEach(function (color, i) {
if (i % 5 === 0) {
counter ++;
}
colors[counter].push(color);
});
return colors;
};
var mergeColors = function (foreground, background, palette) {
palette[palette.length - 1].push(background);
palette[palette.length - 1].push(foreground);
var result = [];
for (var i = 0; i < palette.length; i++) {
result.push(palette[i].join(':'));
}
return result;
};
var makePaletteString = function (palette) {
var result = '\t\'' + palette.name + '\'\:\n';
palette.colors.forEach(function (row) {
result += '\t\t\'' + row + '\:\'\n';
});
paletteStr += result.slice(0,-3) + '\',\n';
};
var makeGuakePalette = function (filename, index) {
var file = fs.readFileSync(filespath + '/' + filename).toString().split("\n");
var foregroundColor = getForegroundColor(file);
var backgroundColor = getBackgroundColor(file);
var paletteColors = getPaletteColors(file);
var guakePalette = {
name: getPaletteName(filename),
colors: mergeColors(foregroundColor, backgroundColor, paletteColors)
};
makePaletteString(guakePalette);
};
var filespath = 'palettes/';
var paletteStr;
var logPaletteStr = function () {
var files = fs.readdirSync(filespath);
paletteStr = 'PALETTES = {\n';
files.forEach(makeGuakePalette);
paletteStr = paletteStr.slice(0,-2) + '\n}';
console.log(paletteStr);
};
logPaletteStr();