forked from StylishThemes/GitHub-Dark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
265 lines (246 loc) · 8.42 KB
/
Gruntfile.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
module.exports = function(grunt) {
'use strict';
var config, getTheme, file;
try {
config = grunt.file.readJSON('build.json');
} catch (err) {
console.info('build.json not found - using defaults');
config = {
'theme' : 'Twilight',
'color' : '#4183C4',
'font' : 'Menlo',
'image' : 'url(https://raw.githubusercontent.com/StylishThemes/GitHub-Dark/master/images/backgrounds/bg-tile1.png)',
'tiled' : true,
'codeWrap' : false,
'attach' : 'scroll',
'tab' : 4,
'webkit' : false
};
}
getTheme = function() {
return (config.theme || '').toLowerCase().replace(/\s+/g, '-');
};
// ** set up build options **
config.sourceFile = 'github-dark.css';
file = getTheme();
// setting "ace" to an empty string, or "default" will leave the default GitHub-base16 theme in place, with a dark background
// using theme src files until we can figure out why cssmin is removing 2/3 of the definitions - see #240
config.themeFile = file === '' || file === 'default' ? '' : 'themes/' + file + '.min.css';
// build file name
config.buildFile = 'github-dark-' + (file || 'default') + '-' + config.color.replace(/[^\d\w]/g, '') + '.build.min.css';
// background options
config.bgOptions = config.tiled ?
'background-repeat: repeat !important; background-size: auto !important; background-position: left top !important;' :
'background-repeat: no-repeat !important; background-size: cover !important; background-position: center top !important;';
config.bgAttachment = config.attach.toLowerCase() === 'scroll' ? 'scroll' : 'fixed';
config.codeWrapCss = config.codeWrap ? [
'/* GitHub: Enable wrapping of long code lines */',
' body:not(.nowrap) .blob-code-inner,',
' body:not(.nowrap) .markdown-body pre > code,',
' body:not(.nowrap) .markdown-body .highlight > pre {',
' white-space: pre-wrap !important;',
' word-break: break-all !important;',
' display: block !important;',
' }',
' body:not(.nowrap) td.blob-code-inner {',
' display: table-cell !important;',
' }'
].join('\n') : '';
// Don't include closing bracket for a chrome build
config.newTheme = config.themeFile ? '<%= grunt.file.read("' + config.themeFile + '") %>' : '';
// get @-moz prefix
file = grunt.file.read('github-dark.css').match(/(@-moz-document regexp\((.*)+\) \{(\n|\r)+)/);
config.prefix = file && file.length ? file[1].replace(/^\s+|\s+$/g, '') : '';
// custom build
config.replacements = [{
pattern: /@-moz-document regexp\((.*)\) \{(\n|\r)+/,
replacement: ''
}, {
pattern: /\/\*\[\[bg-choice\]\]\*\/ url\(.*\)/,
replacement: config.image
}, {
pattern: '/*[[bg-options]]*/',
replacement: config.bgOptions
}, {
pattern: '/*[[bg-attachment]]*/ fixed',
replacement: config.bgAttachment
}, {
pattern: /\/\*\[\[base-color\]\]\*\/ #\w{3,6}/g,
replacement: config.color
}, {
pattern: '/*[[font-choice]]*/',
replacement: config.font
}, {
pattern: '/*[[code-wrap]]*/',
replacement: config.codeWrapCss
}, {
pattern: /\/\*\[\[tab-size\]\]\*\/ \d+/g,
replacement: config.tab
}, {
// remove default syntax themes AND closing bracket
pattern: /\s+\/\* grunt build - remove to end of file(.*(\n|\r))+\}$/m,
replacement: ''
}, {
// add selected theme
pattern: '/*[[syntax-theme]]*/',
replacement: config.newTheme
}];
// userstyles.org - remove defaults & leave placeholders
config.replacements_user = [{
pattern: /@-moz-document regexp\((.*)\) \{(\n|\r)+/,
replacement: ''
}, {
pattern: /\/\*\[\[bg-choice\]\]\*\/ url\(.*\)/,
replacement: '/*[[bg-choice]]*/'
}, {
pattern: '/*[[bg-attachment]]*/ fixed',
replacement: '/*[[bg-attachment]]*/'
}, {
pattern: /\/\*\[\[base-color\]\]\*\/ #\w{3,6}/g,
replacement: '/*[[base-color]]*/'
}, {
pattern: /\/\*\[\[tab-size\]\]\*\/ \d+/g,
replacement: '/*[[tab-size]]*/'
}, {
// remove default syntax theme AND closing bracket
pattern: /\s+\/\* grunt build - remove to end of file(.*(\n|\r))+\}$/m,
replacement: ''
}];
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: config,
'string-replace': {
inline: {
files: {'<%= config.buildFile %>' : '<%= config.sourceFile %>'},
options: {replacements: '<%= config.replacements %>'}
},
mark: {
files: {'<%= config.buildFile %>' : '<%= config.buildFile %>'},
options: {
replacements: [
{pattern: /\/\*\[\[/gm, replacement: '/*![['},
{pattern: '/* AGENT_SHEET */', replacement: '/*! AGENT_SHEET */'}
]
}
},
unmark: {
files: {'<%= config.buildFile %>' : '<%= config.buildFile %>'},
options: {
replacements: [
{pattern: /\/\*\!\[\[/gm, replacement: '/*[['},
{pattern: '/*! AGENT_SHEET */', replacement: '/* AGENT_SHEET */'}
]
}
},
fix: {
files: {'<%= config.buildFile %>' : '<%= config.buildFile %>'},
options: {replacements: [{pattern: /\;\:\/\*\[\[/gm, replacement: ';/*[['}]}
},
afterCleanCss: {
files: {'<%= config.buildFile %>' : '<%= config.buildFile %>'},
options: {replacements: [{pattern: /__ESCAPED_SOURCE_END_CLEAN_CSS__/g, replacement: ''}]}
}
},
clean: {
themes: {
src: ['themes/*.min.css']
}
},
exec: {
stylelint: 'npm run stylelint --silent -- github-dark.css themes/src/twilight.css',
authors: 'bash tools/authors'
},
cssmin: {
minify: {
files: {'<%= config.buildFile %>' : '<%= config.buildFile %>'},
options: {
keepSpecialComments: '*',
advanced: false
}
},
themes: {
files: [{
expand : true,
cwd : 'themes/src/',
src : '*.css',
dest : 'themes/',
ext : '.min.css'
}],
options: {
keepSpecialComments: '*',
advanced: false
}
}
},
wrap: {
mozrule: {
files: {'<%= config.buildFile %>' : '<%= config.buildFile %>'},
options: {
wrapper: ['<%= config.prefix %>', '}']
}
}
},
watch: {
css: {files: ['github-dark.css']}
}
});
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-wrap');
grunt.loadNpmTasks('grunt-exec');
// build custom GitHub-Dark style using build.json settings
grunt.registerTask('default', 'Building custom style', function() {
config.buildFile = config.buildFile.replace('.min.css', '.css');
grunt.task.run(['string-replace:inline']);
if (!(config.chrome || config.webkit)) {
grunt.task.run(['wrap']);
}
});
// build custom minified GitHub-Dark style
grunt.registerTask('minify', 'Building custom minified style', function() {
grunt.task.run(['string-replace:inline', 'cssmin:minify']);
if (!(config.chrome || config.webkit)) {
grunt.task.run(['wrap']);
}
});
// build userstyle for pasting into https://userstyles.org/styles/37035/github-dark
grunt.registerTask('user', 'building userstyles.org file', function() {
config.buildFile = 'github-dark-userstyle.build.css';
config.replacements = config.replacements_user;
grunt.task.run([
'string-replace:inline',
'wrap'
]);
});
grunt.registerTask('usermin', 'building userstyles.org file', function() {
config.buildFile = 'github-dark-userstyle.build.css';
config.replacements = config.replacements_user;
grunt.task.run([
'string-replace:inline',
'string-replace:mark',
'cssmin:minify',
'string-replace:afterCleanCss',
'string-replace:unmark',
'string-replace:fix',
'wrap'
]);
});
// build custom minified GitHub-Dark style
grunt.registerTask('themes', 'Rebuild minified theme files', function() {
grunt.task.run([
'cssmin:themes'
]);
});
// lint github-dark.css and themes for errors
grunt.registerTask('lint', 'Lint CSS for style errors', function() {
grunt.task.run(['exec:stylelint']);
});
// regenerate AUTHORS based on commits
grunt.registerTask('authors', 'Regenerate AUTHORS', function() {
grunt.task.run(['exec:authors']);
});
// watch thingy
grunt.registerTask('dev', ['watch']);
};