-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb16
executable file
·192 lines (162 loc) · 5.09 KB
/
db16
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env node
var pkg = require('./package.json');
var fs = require('fs');
var chalk = require('chalk');
var indent = require('indent-string');
var program = require('commander');
var download = require('download-github-repo');
var less = require('less');
var parseCss = require('css').parse;
var find = require('lodash.find');
var result = require('lodash.result');
var assign = require('lodash.assign');
var yamljs = require('yamljs');
var drepo;
program
.version(pkg.version)
.arguments('<duotone-repo>')
.description(pkg.description);
program.on('--help', function(){
console.log(' Examples:');
console.log('');
console.log(' $ ./db16 simurai/duotone-dark-syntax');
console.log('');
});
program
.action(function (drepoarg) {
drepo = drepoarg;
})
.parse(process.argv);
if (!drepo) {
if (!process.argv.slice(2).length) {
program.help();
}
}
var repoParts = drepo.split('/');
if (repoParts.length < 2) {
console.error(chalk.red('Invalid repo name. Should be regular github repo like `simurai/duotone-dark-syntax`'));
process.exit(1);
}
var userName = repoParts[0];
var themeName = repoParts[1];
var themePath = 'atom-themes/' + themeName;
var lessFile = themePath + '/index.less';
console.log(chalk.magenta('Derived theme name: ' + themeName));
console.log(chalk.magenta('Derived theme author: ' + userName));
console.log(chalk.green('Fetching ' + drepo + ' into ' + themePath));
download(drepo, themePath, readIndexLess);
/**
* readIndexLess
*
*/
function readIndexLess() {
console.log(chalk.green('Reading ' + lessFile));
fs.readFile(lessFile, compileLess);
}
/**
* compileLess
*
* @param err
* @param data
*/
function compileLess(err, data) {
console.log(chalk.green('Compiling ' + lessFile));
if (err) {
throw err;
process.exit(1);
}
less
.render(String(data), {
paths: [ './' + themePath ], // Specify search paths for @import directives
filename: 'style.less', // Specify a filename, for better error messages
})
.then(convertToBase16);
}
/**
* convertToBase16
*
* @param output
*/
function convertToBase16(output) {
var css = output.css;
var parsedCss = parseCss(css);
var rules = parsedCss.stylesheet.rules;
var scheme = {};
scheme['base00'] = /* background - terminal */
getColor(rules, ':host', 'background-color'); /* #2a2734 */
scheme['base01'] = /* gutter,current line background - terminal */
getColor(rules, ':host .gutter .line-number.cursor-line', 'background-color'); /* #312e3d */
scheme['base02'] = /* function names, variable names */
getColor(rules, '.uno-3', 'color'); /* #a391fd */
scheme['base03'] =
getColor(rules, ':host .selection .region', 'background-color'); /* #454257 */
scheme['base04'] = /* gutter,current line text */
getColor(rules, ':host .wrap-guide', 'background-color'); /* #413d51 */
scheme['base05'] = /* pum,visual select background */
getColor(rules, '.uno-4', 'color'); /* #6c6783 */
scheme['base06'] = /* gutter,current line background */
getColor(rules, ':host .gutter .line-number.cursor-line', 'background-color'); /* #312e3d */
scheme['base07'] = /* background */
getColor(rules, ':host', 'background-color'); /* #2a2734 */
scheme['base08'] =
getColor(rules, '.uno-4', 'color'); /* #6c6783 */
scheme['base09'] = /* number values in css properties */
getColor(rules, '.duo-1', 'color'); /* #ffcc99 */
scheme['base0A'] =
getColor(rules, '.uno-1', 'color'); /* #eeebff */
scheme['base0B'] = /* strings */
getColor(rules, '.duo-1', 'color'); /* #ffcc99 */
scheme['base0C'] =
getColor(rules, '.duo-3', 'color'); /* #7c756e */
scheme['base0D'] = /* keyword function */
getColor(rules, '.duo-2', 'color'); /* #e49e58 */
scheme['base0E'] =
getColor(rules, '.uno-2', 'color'); /* #c4b8fe */
scheme['base0F'] =
getColor(rules, ':host .cursor', 'border-color'); /* #ffa852 */
outputSchemeYml(scheme);
}
function getColor(rules, selector, property) {
return getProperty(getRule(rules, selector), property).replace('#', '');
}
/**
* getRule
*
* @param rules
* @param selector
*/
function getRule(rules, selector) {
return find(rules, function (rule, key) {
if (rule.type !== 'rule') {
return false;
}
return rule.selectors.indexOf(selector) !== -1;
});
}
/**
* getProperty
*
* @param selector
* @param property
*/
function getProperty(selector, property) {
return result(find(selector.declarations, function (dec, key) {
return (dec.property === property);
}), 'value');
}
function outputSchemeYml(colors) {
console.log(chalk.green('Adding metadata'));
var scheme = assign({
scheme: themeName,
author: userName + ' (converted via duotone-base16)',
}, colors);
var schemeYaml = yamljs.stringify(scheme, 4);
console.log(chalk.magenta('Generated YAML:'));
console.log(indent(schemeYaml, ' ', 4));
var ymlPath = 'base16-schemes/' + themeName + '.yml';
console.log(chalk.green('Writing ' + ymlPath));
fs.writeFile(ymlPath, schemeYaml, function (err) {
if (err) throw err;
console.log(chalk.green('Saved ' + ymlPath));
});
}