This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 905
/
Gruntfile.js
263 lines (250 loc) · 6.98 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
/**
* google-code-prettify
* https://github.com/google/code-prettify
*
* Copyright (C) 2017 Google Inc.
* Licensed under Apache 2.0 license.
*/
module.exports = function (grunt) {
'use strict';
// project configuration
grunt.initConfig({
// metadata
pkg: grunt.file.readJSON('package.json'),
// grunt-preprocess
preprocess: {
// https://github.com/jsoverson/preprocess#optionstype
options: {
// renders @include directives (similar to SSI server-side includes)
// where JS files are resolved relative to this directory
srcDir: 'js-modules',
type: 'js'
},
prettify: {
src: 'js-modules/prettify.js',
dest: 'src/prettify.js'
},
runprettify: {
options: {
context: {
// to control where defs.js is included (top level)
RUN_PRETTIFY: true
}
},
src: 'js-modules/run_prettify.js',
dest: 'src/run_prettify.js'
},
nodeprettify: {
options: {
context: {
RUN_PRETTIFY: true
}
},
src: 'js-modules/node_prettify.js',
dest: 'src/node_prettify.js'
}
},
// grunt-contrib-copy
copy: {
prettify: {
options: {
process: function (content) {
// trim trailing whitespaces in blank lines added by preprocess
return content.replace(/[ \f\t\v]+$/gm, '');
}
},
files: [
{src: 'src/prettify.js', dest: 'src/prettify.js'},
{src: 'src/run_prettify.js', dest: 'src/run_prettify.js'},
{src: 'src/node_prettify.js', dest: 'src/node_prettify.js'}
]
},
langs: {
options: {
process: function (content) {
// replace PR.PR_* token names with inlined strings
return content
.replace(/\bPR\.PR_ATTRIB_NAME\b/g, '"atn"')
.replace(/\bPR\.PR_ATTRIB_VALUE\b/g, '"atv"')
.replace(/\bPR\.PR_COMMENT\b/g, '"com"')
.replace(/\bPR\.PR_DECLARATION\b/g, '"dec"')
.replace(/\bPR\.PR_KEYWORD\b/g, '"kwd"')
.replace(/\bPR\.PR_LITERAL\b/g, '"lit"')
.replace(/\bPR\.PR_NOCODE\b/g, '"nocode"')
.replace(/\bPR\.PR_PLAIN\b/g, '"pln"')
.replace(/\bPR\.PR_PUNCTUATION\b/g, '"pun"')
.replace(/\bPR\.PR_SOURCE\b/g, '"src"')
.replace(/\bPR\.PR_STRING\b/g, '"str"')
.replace(/\bPR\.PR_TAG\b/g, '"tag"')
.replace(/\bPR\.PR_TYPE\b/g, '"typ"');
}
},
files: [{
expand: true,
cwd: 'loader/',
src: ['lang-*.js'],
dest: 'loader/'
}]
}
},
// ./tasks/aliases.js
aliases: {
langs: {
src: 'loader/lang-*.js',
filter: function (src) {
// skip files that are themselves aliases created in previous runs
return grunt.file.exists(src.replace(/^loader/, 'src'));
}
}
},
// grunt-contrib-uglify
uglify: {
// https://github.com/mishoo/UglifyJS2#usage
options: {
report: 'gzip',
ASCIIOnly: true,
maxLineLen: 500,
screwIE8: false
},
prettify: {
options: {
compress: {
global_defs: {'IN_GLOBAL_SCOPE': true}
},
wrap: true
},
src: 'src/prettify.js',
dest: 'loader/prettify.js'
},
runprettify: {
options: {
compress: {
global_defs: {'IN_GLOBAL_SCOPE': false}
},
wrap: true
},
src: 'src/run_prettify.js',
dest: 'loader/run_prettify.js'
},
langs: {
files: [{
expand: true,
cwd: 'src/',
src: ['lang-*.js'],
dest: 'loader/',
ext: '.js'
}]
}
},
// google-closure-compiler
'closure-compiler': {
// https://github.com/google/closure-compiler/wiki
options: {
// Don't specify --charset=UTF-8. If we do, then non-ascii
// codepoints that do not correspond to line terminators are
// converted to UTF-8 sequences instead of being emitted as
// ASCII. This makes the resulting JavaScript less portable.
warning_level: 'VERBOSE',
language_in: 'ECMASCRIPT5',
compilation_level: 'ADVANCED',
charset: 'US-ASCII'
},
prettify: {
options: {
externs: 'tools/closure-compiler/amd-externs.js',
define: 'IN_GLOBAL_SCOPE=true',
output_wrapper: '!function(){%output%}()'
},
src: '<%= uglify.prettify.src %>',
dest: '<%= uglify.prettify.dest %>'
},
runprettify: {
options: {
externs: 'tools/closure-compiler/amd-externs.js',
define: 'IN_GLOBAL_SCOPE=false',
output_wrapper: '!function(){%output%}()'
},
src: '<%= uglify.runprettify.src %>',
dest: '<%= uglify.runprettify.dest %>'
},
langs: {
options: {
externs: 'js-modules/externs.js'
},
files: '<%= uglify.langs.files %>'
}
},
// ./tasks/gcc.js
gcc: {
// same as 'closure-compiler:langs'
langs: {
options: {
externs: 'js-modules/externs.js'
},
files: '<%= uglify.langs.files %>'
}
},
// grunt-contrib-cssmin
cssmin: {
// https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api
options: {
report: 'gzip'
},
prettify: {
src: 'src/prettify.css',
dest: 'loader/prettify.css'
},
skins: {
files: [{
expand: true,
cwd: 'styles/',
src: ['*.css'],
dest: 'loader/skins/',
ext: '.css'
}]
}
},
// grunt-contrib-compress
compress: {
zip: {
options: {
archive: 'distrib/prettify-small.zip',
mode: 'zip',
level: 9
},
files: [{
expand: true,
cwd: 'loader/',
src: ['*.js', '*.css', 'skins/*.css'],
dest: 'google-code-prettify/'
}]
}
},
// grunt-contrib-clean
clean: {
js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'],
css: ['loader/*.css', 'loader/skins/*.css'],
zip: ['distrib/*.zip']
}
});
// load plugins that provide tasks
require('google-closure-compiler').grunt(grunt);
grunt.loadTasks('./tasks');
grunt.loadNpmTasks('grunt-preprocess');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');
// register task aliases
grunt.registerTask('default', [
//'clean',
'preprocess',
'copy:prettify',
'gcc',
'copy:langs',
'aliases',
'cssmin',
'compress'
]);
};