Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit f6c4ce7

Browse files
amroamroamromikesamuel
authored andcommitted
Patch 2: grunt (#469)
* initialize NPM package ran 'npm init' and 'bower init' and filled some fields * run perl script and commit the output JS file * add grunt as dependency and create initial Gruntfile * replace js_include.pl with a grunt task we're a using package which processes @include directives (similar to server-side-includes) We also use @ifdef/@ifndef to customize prettify and run_prettify * add grunt task to trim tailing spaces in processed files * add grunt task to minify using UglifyJS * add grunt task to minify using clean-css * add task to inline token strings in minifed lang files replace PR.PR_PLAIN with "pln", etc. * add grunt task to create distrbution zip file * add grunt clean task * add task to minify using Closure Compiler * new custom task to override closure-compiler This is needed because closure-compiler:langs will attempt to compile all 30+ lang files in parallel, each being a separate target. The concurrent Java processes will struggle for memory and crash. This task will split the multi-file target into separate targets, each with one file. This way the lang files are compiled one by one. * new custom task to create lang aliases * remove old makefile and related build tools functionality replaced with grunt * update git ignore patterns * add an npm script to call the local grunt this way we dont need to have grunt-cli globally installed, we can just use: "npm install && npm run grunt" (Note: npm sets the PATH correctly to find ./node_modules/.bin/grunt)
1 parent 04e95f6 commit f6c4ce7

21 files changed

+639
-1198
lines changed

.gitignore

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
*.tstamp
1+
# temporary files
22
*~
3-
/google-code-prettify/
3+
*.swp
4+
.DS_Store
5+
6+
# package managers
7+
/node_modules/
8+
/bower_components/
9+
npm-debug.log
10+
.bower.json
11+
12+
# generated files
13+
#/src/prettify.js
14+
#/src/run_prettify.js
15+
#/loader/*.js
16+
#/loader/*.css
17+
#/loader/skins/*.css
18+
#/distrib/*.zip

Gruntfile.js

+253
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
/**
2+
* google-code-prettify
3+
* https://github.com/google/code-prettify
4+
*
5+
* Copyright (C) 2017 Google Inc.
6+
* Licensed under Apache 2.0 license.
7+
*/
8+
9+
module.exports = function (grunt) {
10+
'use strict';
11+
12+
// project configuration
13+
grunt.initConfig({
14+
// metadata
15+
pkg: grunt.file.readJSON('package.json'),
16+
17+
// grunt-preprocess
18+
preprocess: {
19+
// https://github.com/jsoverson/preprocess#optionstype
20+
options: {
21+
// renders @include directives (similar to SSI server-side includes)
22+
// where JS files are resolved relative to this directory
23+
srcDir: 'js-modules',
24+
type: 'js'
25+
},
26+
prettify: {
27+
src: 'js-modules/prettify.js',
28+
dest: 'src/prettify.js'
29+
},
30+
runprettify: {
31+
options: {
32+
context: {
33+
// to control where defs.js is included (top level)
34+
RUN_PRETTIFY: true
35+
}
36+
},
37+
src: 'js-modules/run_prettify.js',
38+
dest: 'src/run_prettify.js'
39+
}
40+
},
41+
42+
// grunt-contrib-copy
43+
copy: {
44+
prettify: {
45+
options: {
46+
process: function (content) {
47+
// trim trailing whitespaces in blank lines added by preprocess
48+
return content.replace(/[ \f\t\v]+$/gm, '');
49+
}
50+
},
51+
files: [
52+
{src: 'src/prettify.js', dest: 'src/prettify.js'},
53+
{src: 'src/run_prettify.js', dest: 'src/run_prettify.js'}
54+
]
55+
},
56+
langs: {
57+
options: {
58+
process: function (content) {
59+
// replace PR.PR_* token names with inlined strings
60+
return content
61+
.replace(/\bPR\.PR_ATTRIB_NAME\b/g, '"atn"')
62+
.replace(/\bPR\.PR_ATTRIB_VALUE\b/g, '"atv"')
63+
.replace(/\bPR\.PR_COMMENT\b/g, '"com"')
64+
.replace(/\bPR\.PR_DECLARATION\b/g, '"dec"')
65+
.replace(/\bPR\.PR_KEYWORD\b/g, '"kwd"')
66+
.replace(/\bPR\.PR_LITERAL\b/g, '"lit"')
67+
.replace(/\bPR\.PR_NOCODE\b/g, '"nocode"')
68+
.replace(/\bPR\.PR_PLAIN\b/g, '"pln"')
69+
.replace(/\bPR\.PR_PUNCTUATION\b/g, '"pun"')
70+
.replace(/\bPR\.PR_SOURCE\b/g, '"src"')
71+
.replace(/\bPR\.PR_STRING\b/g, '"str"')
72+
.replace(/\bPR\.PR_TAG\b/g, '"tag"')
73+
.replace(/\bPR\.PR_TYPE\b/g, '"typ"');
74+
}
75+
},
76+
files: [{
77+
expand: true,
78+
cwd: 'loader/',
79+
src: ['lang-*.js'],
80+
dest: 'loader/'
81+
}]
82+
}
83+
},
84+
85+
// ./tasks/aliases.js
86+
aliases: {
87+
langs: {
88+
src: 'loader/lang-*.js',
89+
filter: function (src) {
90+
// skip files that are themselves aliases created in previous runs
91+
return grunt.file.exists(src.replace(/^loader/, 'src'));
92+
}
93+
}
94+
},
95+
96+
// grunt-contrib-uglify
97+
uglify: {
98+
// https://github.com/mishoo/UglifyJS2#usage
99+
options: {
100+
report: 'gzip',
101+
ASCIIOnly: true,
102+
maxLineLen: 500,
103+
screwIE8: false
104+
},
105+
prettify: {
106+
options: {
107+
compress: {
108+
global_defs: {'IN_GLOBAL_SCOPE': true}
109+
},
110+
wrap: true
111+
},
112+
src: 'src/prettify.js',
113+
dest: 'loader/prettify.js'
114+
},
115+
runprettify: {
116+
options: {
117+
compress: {
118+
global_defs: {'IN_GLOBAL_SCOPE': false}
119+
},
120+
wrap: true
121+
},
122+
src: 'src/run_prettify.js',
123+
dest: 'loader/run_prettify.js'
124+
},
125+
langs: {
126+
files: [{
127+
expand: true,
128+
cwd: 'src/',
129+
src: ['lang-*.js'],
130+
dest: 'loader/',
131+
ext: '.js'
132+
}]
133+
}
134+
},
135+
136+
// google-closure-compiler
137+
'closure-compiler': {
138+
// https://github.com/google/closure-compiler/wiki
139+
options: {
140+
// Don't specify --charset=UTF-8. If we do, then non-ascii
141+
// codepoints that do not correspond to line terminators are
142+
// converted to UTF-8 sequences instead of being emitted as
143+
// ASCII. This makes the resulting JavaScript less portable.
144+
warning_level: 'VERBOSE',
145+
language_in: 'ECMASCRIPT5',
146+
compilation_level: 'ADVANCED',
147+
charset: 'US-ASCII',
148+
},
149+
prettify: {
150+
options: {
151+
externs: 'tools/closure-compiler/amd-externs.js',
152+
define: 'IN_GLOBAL_SCOPE=true',
153+
output_wrapper: '!function(){%output%}()'
154+
},
155+
src: '<%= uglify.prettify.src %>',
156+
dest: '<%= uglify.prettify.dest %>'
157+
},
158+
runprettify: {
159+
options: {
160+
externs: 'tools/closure-compiler/amd-externs.js',
161+
define: 'IN_GLOBAL_SCOPE=false',
162+
output_wrapper: '!function(){%output%}()'
163+
},
164+
src: '<%= uglify.runprettify.src %>',
165+
dest: '<%= uglify.runprettify.dest %>'
166+
},
167+
langs: {
168+
options: {
169+
externs: 'js-modules/externs.js'
170+
},
171+
files: '<%= uglify.langs.files %>'
172+
}
173+
},
174+
175+
// ./tasks/gcc.js
176+
gcc: {
177+
// same as 'closure-compiler:langs'
178+
langs: {
179+
options: {
180+
externs: 'js-modules/externs.js'
181+
},
182+
files: '<%= uglify.langs.files %>'
183+
}
184+
},
185+
186+
// grunt-contrib-cssmin
187+
cssmin: {
188+
// https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api
189+
options: {
190+
report: 'gzip'
191+
},
192+
prettify: {
193+
src: 'src/prettify.css',
194+
dest: 'loader/prettify.css'
195+
},
196+
skins: {
197+
files: [{
198+
expand: true,
199+
cwd: 'styles/',
200+
src: ['*.css'],
201+
dest: 'loader/skins/',
202+
ext: '.css'
203+
}]
204+
}
205+
},
206+
207+
// grunt-contrib-compress
208+
compress: {
209+
zip: {
210+
options: {
211+
archive: 'distrib/prettify-small.zip',
212+
mode: 'zip',
213+
level: 9
214+
},
215+
files: [{
216+
expand: true,
217+
cwd: 'loader/',
218+
src: ['*.js', '*.css', 'skins/*.css'],
219+
dest: 'google-code-prettify/'
220+
}]
221+
}
222+
},
223+
224+
// grunt-contrib-clean
225+
clean: {
226+
js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'],
227+
css: ['loader/*.css', 'loader/skins/*.css'],
228+
zip: ['distrib/*.zip']
229+
}
230+
});
231+
232+
// load plugins that provide tasks
233+
require('google-closure-compiler').grunt(grunt);
234+
grunt.loadTasks('./tasks');
235+
grunt.loadNpmTasks('grunt-preprocess');
236+
grunt.loadNpmTasks('grunt-contrib-copy');
237+
grunt.loadNpmTasks('grunt-contrib-uglify');
238+
grunt.loadNpmTasks('grunt-contrib-cssmin');
239+
grunt.loadNpmTasks('grunt-contrib-compress');
240+
grunt.loadNpmTasks('grunt-contrib-clean');
241+
242+
// register task aliases
243+
grunt.registerTask('default', [
244+
//'clean',
245+
'preprocess',
246+
'copy:prettify',
247+
'gcc',
248+
'copy:langs',
249+
'aliases',
250+
'cssmin',
251+
'compress'
252+
]);
253+
};

Makefile

-116
This file was deleted.

0 commit comments

Comments
 (0)