Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(Grunt) Switch from Rake to Grunt #1544

Closed
wants to merge 16 commits into from
Closed

feat(Grunt) Switch from Rake to Grunt #1544

wants to merge 16 commits into from

Conversation

geddski
Copy link
Contributor

@geddski geddski commented Nov 9, 2012

Migrates the Angular project from Rake to Grunt.

Benefits:

  • Drops Ruby dependency
  • Lowers barrier to entry for contributions from JavaScript ninjas
  • Simplifies the Angular project setup and build process
  • Adopts industry-standard tools specific to JavaScript projects
  • Windows support for the build and end-to-end tests

BREAKING CHANGE:

Rake is completely replaced by Grunt. Below are the deprecated Rake tasks and their Grunt equivalents:

  • rake --> grunt
  • rake package --> grunt package
  • rake init --> N/A
  • rake clean --> grunt clean
  • rake concat_scenario --> grunt build:scenario
  • rake concat --> grunt build
  • rake concat_scenario --> grunt build:scenario
  • rake minify --> grunt minify
  • rake version --> grunt write:version
  • rake docs --> grunt docs
  • rake webserver --> grunt webserver
  • rake test --> grunt test
  • rake test:unit --> grunt test:unit
  • rake test:<jqlite|jquery|modules|e2e> --> grunt test:<jqlite|jquery|modules|end2end|e2e>
  • rake test[Firefox+Safari] --> grunt test --in=[Firefox,Safari]
  • rake test[Safari] --> grunt test --in=[Safari]
  • rake autotest --> grunt autotest

NOTES:

  • For convenience grunt test:e2e starts a webserver for you, while grunt test:end2end doesn't.
    Use grunt test:end2end if you already have the webserver running.
  • Removes duplicate entry for Describe.js in the angularScenario section of angularFiles.js
  • Updates docs/src/gen-docs.js to use #done intead of the deprecated #end
  • Uses grunt-contrib-connect instead of lib/nodeserver (removed)
  • Removes nodeserver.sh, travis now uses grunt webserver
  • Built and minified files are identical to Rake's output, with the exception of one less
    character for git revisions (using --short) and a couple minor whitespace differences

Closes #199

Migrates the Angular project from Rake to Grunt.
Benefits:
- Drops Ruby dependency
- Lowers barrier to entry for contributions from JavaScript ninjas
- Simplifies the Angular project setup and build process
- Adopts industry-standard tools specific to JavaScript projects

BREAKING CHANGE: Rake is completely replaced by Grunt. Below are the deprecated Rake tasks and their Grunt equivalents:

rake --> grunt
rake package --> grunt package
rake init --> N/A
rake clean --> grunt clean
rake concat_scenario --> grunt build:scenario
rake concat --> grunt build
rake concat_scenario --> grunt build:scenario
rake minify --> grunt minify
rake version --> grunt write:version
rake docs --> grunt docs
rake webserver --> grunt webserver
rake test --> grunt test
rake test:unit --> grunt test:unit
rake test:<jqlite|jquery|modules|e2e> --> grunt test:<jqlite|jquery|modules|end2end|e2e>
rake test[Firefox+Safari] --> grunt test --in=[Firefox,Safari]
rake test[Safari] --> grunt test --in=[Safari]
rake autotest --> grunt autotest

NOTES:
* For convenience grunt test:e2e starts a webserver for you, while grunt test:end2end doesn't.
  Use grunt test:end2end if you already have the webserver running.
* Removes duplicate entry for Describe.js in the angularScenario section of angularFiles.js
* Updates docs/src/gen-docs.js to use #done intead of the deprecated #end
* Uses grunt-contrib-connect instead of lib/nodeserver (removed)
* Removes nodeserver.sh, travis now uses grunt webserver
* Built and minified files are identical to Rake's output, with the exception of one less
  character for git revisions (using --short) and a couple minor whitespace differences

Closes #199
Replaces Rake documentation with Grunt documentation.
@geddski
Copy link
Contributor Author

geddski commented Nov 9, 2012

Not sure why Travis is choking. npm install -g grunt-cli looks like it worked fine, but then when grunt is invoked it errors with: Fatal error: You must install grunt-cli to use the "grunt" command.

Instructs Travis to remove the local grunt executable placeholder. Should prevent Travis build from breaking.
@geddski
Copy link
Contributor Author

geddski commented Nov 10, 2012

@IgorMinar @mhevery let's do this.

@ghost ghost assigned IgorMinar Nov 10, 2012
@Mischi
Copy link

Mischi commented Nov 11, 2012

+1

Runs closure compiler in parallel, which speeds up minification.
@ffesseler
Copy link

Great work!
Another benefit resulting from this is it's now possible to build angular on a windows machine.
Rake build is currently using things like fork() or symlink() that are unavailable on Win

@Mischi
Copy link

Mischi commented Nov 13, 2012

I've tried to test your work on Windows and run into some problems:

  • I've installed only the x64 java version and in min task you pass the -d32 parameter to java. If i rename the parameter to -d64 or remove it, the task works as expected.
  • The zip task fails because the absense of the zip util. I don't know if its available on Windows...
    Maybe you can integrate a nodejs module do do the ziping without the need to install zip

@ffesseler
Copy link

Another thing, build outputs 'Done, without errors' even if there are failing tests

@geddski
Copy link
Contributor Author

geddski commented Nov 13, 2012

thanks @Mischi & @ffesseler, improvements in the works.

@mhevery
Copy link
Contributor

mhevery commented Nov 13, 2012

+1

On Tue, Nov 13, 2012 at 9:40 PM, Dave Geddes [email protected]:

thanks @Mischi https://github.com/Mischi & @ffesselerhttps://github.com/ffesseler,
improvements in the works.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1544#issuecomment-10342593.

Make grunt tasks fail & abort on errors, failing tests, etc.
No longer catch uncaughtException in docs/src/gen-docs.js so Grunt can catch it and abort
Also use spawn instead of exec where appropriate to avoid hitting node's buffer size limit.
@geddski
Copy link
Contributor Author

geddski commented Nov 14, 2012

@ffesseler Grunt now aborts on errors and failing tests, thanks for catching that.

Support for Windows merits more discussion. Currently the gen-docs.js tool also breaks in Windows because of its use of symlinks. Also @IgorMinar added that -d32 flag to speed up closure compiler. I recommend we open a separate issue for Windows build support, as it's beyond the scope of this issue.

In any case, I believe this is now ready to go. Thanks everybody for pointing out the things I had overlooked. @IgorMinar & @mhevery let me know if there's anything else you'd like for this before merging.

@ffesseler
Copy link

Excellent! I'll have a look at it today

The build currently doesn't run in Windows. This creates a problem when a developer using Windows tries to contribute to Angular, but can't run the end-to-end tests.

Fix the few things that prevented the build from working in Windows:

Windows doesn't have "zip", that would be too intuitive.
Solution: Use grunt-contrib-compress instead

This speeds things up, but breaks for Windows 64bit users
Solution: Remove flag

Node can create symlinks in Windows, but you have to pass an extra "dir" option to fs.
gen-docs.js uses q-fs.js to create symlinks, which doesn't pass this needed type argument.
Solution: Add this third type option to qfs#symbolicLink, and pass the option in from gen-docs.js and writer.js
q-fs.js Pull Request #7 pending that adds this feature (kriskowal/q-fs#7)
In the meantime, specify geddesign's fork as the dependency in package.json. Will switch back once merged.

fix(gen-docs) handle symlinks correctly in Windows
@geddski
Copy link
Contributor Author

geddski commented Nov 19, 2012

Chancho, when you are a man, sometimes you support Windows in your code. It's for fun.

It's now possible to run the build and end-to-end tests in Windows. @ffesseler @Mischi give it a spin, let me know if you run into any snags. You may have to run command prompt as administrator (right click > run as Administrator)

@IgorMinar @mhevery I know you guys have been crazy busy speaking at conferences. Looking forward to your review when you get a chance.

@Mischi
Copy link

Mischi commented Nov 19, 2012

@GEDDesign Good Work! Build and tests run now successfully if they where executed as Administrator.

(By the way, I think it has something to do with the read only flag on angular.js folder that prevent from successfull build under normal user but i do not know how to remove that flag xD )

Now builds on WIndows run as smooth as on *unix like systems!

@petebacondarwin
Copy link
Contributor

The grunt build is failing on my Win7 machine. I have installed grunt-cli globally and run npm install locally.
The error message is after running grunt package is:

Running "clean:build" (clean) task
Warning: Cannot read property 'src' of undefined Use --force to continue.

From looking at the source, it seems like the version of grunt-contrib-clean is at fault. There is a line that says:

    var files = grunt.file.expand(this.file.src);

But there is no file field on this. The devel branch on this utils repos has a completely different process for this: gruntjs/grunt-contrib-clean@ea7551c. See tasks/clean.js.

Any thoughts on this? Should I be modifying my npm install in some way?

Pete

@geddski
Copy link
Contributor Author

geddski commented Nov 19, 2012

@petebacondarwin try deleting your node_modules folder, running "npm cache clear" then "npm install". Lemme know.

@ffesseler
Copy link

Same error here, even after clearing the cache

@geddski
Copy link
Contributor Author

geddski commented Nov 19, 2012

@ffesseler @petebacondarwin sounds like npm is still hanging on to an older version of grunt. Try this:

@Mischi
Copy link

Mischi commented Nov 19, 2012

i run into the same problem i think and i solved the problem by executing

npm uninstall grunt -g
npm install grunt@devel -g

maybe that will help

@geddski
Copy link
Contributor Author

geddski commented Nov 19, 2012

ah yeah, you want to uninstall the old global grunt.

@aaronfrost
Copy link
Contributor

I love this idea. Lets merge it.

My pull request to q-fs was merged (kriskowal/q-fs#7)
So q-fs now supports the "type" option for symlinks, neccessary for Windows support.
Switching back to the official repo of q-fs.
When the build runs, it needs to use the global grunt-cli. But since node_modules/.bin is in the path on that server, the grunt command defaults to the local grunt, which is just a placeholder that gives a warning to use the global grunt-cli. So we rm the local one, but the build shouldn't fail if it's already been deleted.
[email protected] introduced a regression with symlink creation.
fixed in [email protected]
@geddski
Copy link
Contributor Author

geddski commented Nov 27, 2012

@ffesseler @petebacondarwin did you get it working on your windows machines? When going from grunt 0.3 to 0.4 you do need to uninstall the global grunt (manually deleting the global node_modules/grunt if npm uninstall grunt -g doesn't do it). Then once you've installed the new grunt-cli globally (`npm install -g grunt-cli) things should work. Lemme know.

Using spawn instead of exec shaves a couple seconds off the grunt docs task.
This speeds up the build again on non-Windows platforms by serveral seconds, while maintaining Windows compat. Win-win.
@geddski
Copy link
Contributor Author

geddski commented Dec 14, 2012

@IgorMinar thanks for the response mate! The grunt docs task was being slowed down by the use of exec instead of spawn, thanks for catching that. Exec is more concise but speed is a priority there I think. Fixed in 3c0989c.

I'm with you, I don't like the speed tradeoff for Windows support. In 51c4a1f I only drop the -d32 flag when the build is running on Windows. That keeps it fast for the majority of us, while maintaining Windows support, which I believe is important. Our issue tracker is littered with instances that could have been prevented if our Windows users could run the build and tests on their platform. This solution is a win-win, thanks for pointing that out.

As for the server, I think it's a bit of a codesmell to depend on a specific custom webserver, but I'll look and see if there are options for those requirements using Connect, if that's the way you'd like to go. Might be a good opportunity to rethink that dependency. Would be trivial to use the old webserver again if we need. I'll do some digging and update soon.

@IgorMinar
Copy link
Contributor

@GEDDesign the perf is much better now. can we paralelize the build task as well? that will shave off another 0.5sec, which would bring is almost to the time it takes to build angular with rake

wrt the webserver - no code smell. any app that uses html5 history api needs to have url rewriting rule on the server. the CSP customization is nothing special either - just extra headers that are sent with http responses.

@arbitrix
Copy link

On Windows 7 I see three problems:

jsdoc won't build for reasons unknown

Running "docs:process" (docs) task
Warning: Error creating docs Use --force to continue.

Aborted due to warnings.

testacular doesn't look for Chrome's SECOND default location

Manually setting of CHROME_BIN gets Chrome fired up on my machine. Testacular really should look in the Chrome .msi-installer default directories when the per-user install is not found:

  • x86: c:\Program Files\Google\Chrome\Application\chrome.exe
  • x64: c:\Program Files (x86)\Google\Chrome\Application\chrome.exe

end2end test fails

Running "test:end2end" (test) task
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser Chrome
info (Chrome 23.0 (Windows)): Connected on socket id fVG4L4Oe1RD2ywahzuzF
warn (proxy): failed to proxy /build/docs/index-nocache.html (Error: connect ECONNREFUSED)

@geddski
Copy link
Contributor Author

geddski commented Dec 16, 2012

@arbitrix thanks for sharing your findings. Windows 7 does support symlinks, but depending on your setup you may run into permissions issues. The solution is to run your command prompt as Administrator (right click, run as Administrator). Not ideal I know, but it works.

You've already found the correct testacular workaround for running the tests in Chrome. That's a testacular bug we should open an issue for. You can also run the tests in IE without any extra setup: grunt test:e2e --in=[IE]

And finally the connection refused error is because the tests depend on the docs building successfully. Running as administrator will take care of that.

Let me know how it goes!

Executes each build in parallel for greater performance.
@geddski
Copy link
Contributor Author

geddski commented Jan 4, 2013

can we paralelize the build task as well?

@IgorMinar done, good suggestion. Looking at the webserver stuff now.

Makes the grunt webserver task handle the extras that the old nodeserver used to:

- optional CSP headers
- rewrite rules for the docs
- favicon
@geddski
Copy link
Contributor Author

geddski commented Jan 5, 2013

@IgorMinar the connect webserver now supports CSP and the rewrites. Thanks for all your excellent feedback on this! Let me know if there's anything else you'd like to see before the merge.

@geddski
Copy link
Contributor Author

geddski commented Jan 16, 2013

@IgorMinar this is ready, let's get it in before too much more work (like #1710) is done on the previous build.

@IgorMinar
Copy link
Contributor

@GEDDesign I love the recent cleanup! this PR is quite awesome now.

we are tracking the grunt development and see that it is still quite unstable. I don't feel confortable about switching over and dealing the grunt undergoing development. I want to wait until it's stable before we hop on.

I'm sorry that this is taking so long, but the build script is a very crucial part of the project, so I want to get it right.

@geddski
Copy link
Contributor Author

geddski commented Jan 16, 2013

@IgorMinar thanks. I hear you. I'll keep a close eye on any progress/updates made on the current build system, and keep this one up to date so that once Grunt 0.4 stable lands we can merge this in seamlessly (current version is 0.4.0rc5). Deal?

@IgorMinar
Copy link
Contributor

@GEDDesign yes!

@taichi
Copy link

taichi commented Jan 19, 2013

+1

@geddski
Copy link
Contributor Author

geddski commented Feb 19, 2013

@IgorMinar Grunt 0.4 stable was released yesterday, I'm working on updating this PR. Here's my plan of attack to make this easy to merge, tell me if there's anything you'd recommend doing differently:

  1. rebase my Grunt changes onto latest angular master, test.
  2. update build to reflect all recent developments in the rake build, test.
  3. verify still working in windows
  4. squash all commits to a single commit for a cleaner history
  5. push

I'm not sure how the Github PR UI is going to handle the squash... let me know if you'd rather do that on your end.

@IgorMinar
Copy link
Contributor

I'll squash on my end in this case. Please ping this PR when you are ready.

@IgorMinar
Copy link
Contributor

I'm planing on making more Rakefile changes within the next week. When do you think that this PR will be ready?

No pressure... I just want to coordinate the conflicting work...

@geddski
Copy link
Contributor Author

geddski commented Mar 2, 2013

@IgorMinar sorry for the delay, I was pretty focused on my Angular workshop. Now that that's done I'll try to get this wrapped up this weekend.

@geddski
Copy link
Contributor Author

geddski commented Mar 3, 2013

Ready. I opened a new pull request #2094 for my updated Grunt branch - pretty sure Github would have choked on the massive rebase onto master. Closing this PR. Thanks everyone for your input! @IgorMinar fire at will, commander.

@geddski geddski closed this Mar 3, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore using Jake instead of Rake