-
Notifications
You must be signed in to change notification settings - Fork 889
Patch 2: grunt #469
Patch 2: grunt #469
Conversation
ran 'npm init' and 'bower init' and filled some fields
replace PR.PR_PLAIN with "pln", etc.
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.
functionality replaced with 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)
var IN_GLOBAL_SCOPE = true; | ||
/* @endif */ | ||
/* @ifdef RUN_PRETTIFY */ | ||
var IN_GLOBAL_SCOPE = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this cause duplicate definition warnings under closure compiler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it won't because the file is never fed directly to closure compiler, it only sees src/prettify.js
and src/run_prettify.js
by which time those directives are already "processed" and only one of the two alternatives survives (either true or false depending on wheather RUN_PRETTIFY
was set in the context (see the grunt preprocess task options)).
In fact the value used here doesn't really matter (I set it here only as a form of documentation), because we later pass the closure-compiler option --define='IN_GLOBAL_SCOPE=??'
which overrides the const anyway: https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#define-type-description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. LGTM
print "$pattern;\n"; | ||
|
||
print " | ||
// CAVEAT: this does not properly handle the case where a regular |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self. Caveat moved to top file comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that way it shows up above the regex it's talking about when included in the final bundle.
include("defs.js"); | ||
|
||
var HACK_TO_FIX_JS_INCLUDE_PL; | ||
/* @ifndef RUN_PRETTIFY */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: run_prettify includes defs.js above its envelope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand this is a limitation of closure compiler: https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#typedef-type, so I tried to keep things the same as what js_include.pl
was doing, so that defs.js
typedefs are always included top-level in both prettify.js
and run_prettify.js
"Mike Samuel <[email protected]>" | ||
], | ||
"contributors": [ | ||
"Amro <[email protected]>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more accurate to put you down as a maintainer these days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
* separate targets (one file per target) so that lang files are compiled | ||
* sequentially (sync) instead of in parallel (async). | ||
*/ | ||
grunt.registerMultiTask('gcc', 'Override closure-compiler', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It blows my mind that someone would use "gcc" as an abbreviation for Google Closure Compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe, what other GNU compiler thing :)
@mikesamuel you forgot to publish this to npm. Now the package name has been stolen. |
I didn't realize this was the wild west! |
@mikesamuel @amroamroamro is this going to be fixed? |
@graingert I noticed you published the package under the code-prettify name. Was that to protect the name before others grab it? |
@amroamroamro it was to steal it! But yeah I'll hand it over if you promise to be more careful next time, and one of the members gives me their preferred npm ID. |
Can we get some details on how to use code-prettify with npm? |
@amroamroamro you've not been forthcoming with any npm IDs... |
@tamj0rd2 I would not recommend using the npm edition of this tool until the official team have some ownership over the module name. |
@graingert I ran |
@tamj0rd2 If I'm not mistaken, you can always install directly from GitHub repo:
or specify the full URL: |
Yeah but that breaks npm shrinkwrap |
Summary:
package.json
andbower.json
for integrating with npm and Bower package managers. Note: I set the version to "1.0.0", feel free to change it to something else if needed.grunt preprocess
to processjs-modules/*.js
files and producesrc/prettify.js
andsrc/run_prettify.js
bundlesgrunt gcc
to compile/minify JS using Closure Compiler (also added agrunt uglify
task as alternative, but it's not used by default)grunt cssmin
to minify CSS filesgrunt aliases
to create lang aliasesgrunt compress
to produce a ZIP file for distributiongrunt clean
to clean generated filesTo rebuild the project from scratch, first you need to install Node, then you simply run :
(note: Closure Compiler requires Java JRE to run).