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 #2094

Closed
wants to merge 19 commits into from
Closed

feat(Grunt) Switch from Rake to Grunt #2094

wants to merge 19 commits into from

Conversation

geddski
Copy link
Contributor

@geddski geddski commented Mar 3, 2013

This is the updated Grunt PR rebased onto the last few months of Angular progress. It also reflects the progress made to the Rake build during that time. See the initial PR #1544 for more details, discussion, improvements, etc. The build/tests/etc verified now works on Windows.

geddski added 17 commits March 1, 2013 23:46
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.
Instructs Travis to remove the local grunt executable placeholder. Should prevent Travis build from breaking.
Runs closure compiler in parallel, which speeds up minification.
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.
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
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.
no longer need to install testacular globally
clear npm cache to avoid issues
Grunt 0.4 is yet to be released and is still evolving.
While waiting for its release use specific, tested commits.
docs now set section and id correctly on Windows
grunt docs task now works correctly in Windows
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.
Executes each build in parallel for greater performance.
Makes the grunt webserver task handle the extras that the old nodeserver used to:

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

ok. I'm taking look at this now. if there are no major issues, I'd like to get this PR in today.

@geddski
Copy link
Contributor Author

geddski commented Mar 4, 2013

cool, let me know if you have any questions.

@IgorMinar
Copy link
Contributor

I found one issue. the i18n files are being copied into a wrong dir:

src/ngLocale/angular-locale_th-th.js -> build/i18n/src/ngLocale/angular-locale_th-th.js

it should be:

src/ngLocale/angular-locale_th-th.js -> build/i18n/angular-locale_th-th.js

btw it would be ideal if the output from the i18n task got silenced.

I found a few other bugs and fixed those. if you could look into the i18n files issue that would be awesome.

Once the issue is resolved I'm happy to merge this in. The rest of the code looks awesome.

Thanks!

@IgorMinar
Copy link
Contributor

I think the correct syntax for copy:i18n is

    copy: {
      i18n: {
        files: {'build/i18n/': 'src/ngLocale/*', flatten: true}
      }
    },

but this results in incorrect paths followed by an error:

...
Copying src/ngLocale/angular-locale_zh-hans.js -> build/i18n/src/ngLocale/angular-locale_zh-hans.js
Copying src/ngLocale/angular-locale_zh-hk.js -> build/i18n/src/ngLocale/angular-locale_zh-hk.js
Copying src/ngLocale/angular-locale_zh-tw.js -> build/i18n/src/ngLocale/angular-locale_zh-tw.js
Copying src/ngLocale/angular-locale_zh.js -> build/i18n/src/ngLocale/angular-locale_zh.js
Warning: Object true has no method 'indexOf' Use --force to continue.

Aborted due to warnings.

I believe that this is a Grunt bug.

@IgorMinar
Copy link
Contributor

ok, this seems to work:

    copy: {
      i18n: {
        files: [
          { src: 'src/ngLocale/**', dest: 'build/i18n/', expand: true, flatten: true }
        ]
      }
    },

there is a buggy/underdocumented behavior in grunt that requires expand to be set in order for flatten to kick in.

additionally files must take an array of a single object otherwise all kinds of weird errors are thrown.

@IgorMinar
Copy link
Contributor

btw I was also wondering about the travis config file. why do you dump the cache and delete local grunt? seems odd to me

@geddski
Copy link
Contributor Author

geddski commented Mar 6, 2013

Travis was having a strange issue where it would execute the local grunt instead of grunt-cli. Might not be necessary anymore, we can try without and see.

@IgorMinar
Copy link
Contributor

What about the npm cache?

@IgorMinar IgorMinar closed this Mar 6, 2013
@IgorMinar IgorMinar reopened this Mar 6, 2013
@IgorMinar
Copy link
Contributor

I removed both npm cache hack and grunt hack from travis.yaml and travis seems to be happy.

last question: how did you settle on the --in=[Chrome,Firefox] argument syntax? can't we just make it --browsers=Chrome,Firefox to mimic Testacular's syntax?

@IgorMinar
Copy link
Contributor

(btw the previous Rake syntax was due to Rake limitations)

@geddski
Copy link
Contributor Author

geddski commented Mar 6, 2013

If I remember right npm cache clean was to prevent travis from installing a dated version of grunt it was hanging onto. Glad it works without it now.

Good call on --browsers. Once this testacular bug is resolved and we're not stuck on 0.5.9 I plan on updating our Grunt build to use my gruntacular plugin. So I'll make sure --browsers still works then.

@IgorMinar
Copy link
Contributor

landed as 79b51d5

many THANKS!

@IgorMinar IgorMinar closed this Mar 6, 2013
@Iristyle
Copy link
Contributor

Iristyle commented Mar 6, 2013

Awesome work @GEDDesign !

@vladikoff
Copy link

Thank you! This is great news :)

@Mischi
Copy link

Mischi commented Mar 6, 2013

Congratulation!

@cowboy
Copy link

cowboy commented Mar 6, 2013

EPIC

@shama
Copy link

shama commented Mar 6, 2013

Woohoo!

@lrlopez
Copy link
Contributor

lrlopez commented Mar 8, 2013

Since the switch, I can no longer run e2e tests:
WARN [proxy]: failed to proxy /build/docs/index-nocache.html (Error: connect ECONNREFUSED)

Then the browser(s) gets idle and nothing else happens.

Am I the only one with this issue?

@geddski
Copy link
Contributor Author

geddski commented Mar 8, 2013

Did you run grunt build first?

@lrlopez
Copy link
Contributor

lrlopez commented Mar 9, 2013

Yep, but it still doesn't work. It started to fail once I pulled the latest changes from the upstream master branch into my local repository. The new grunt build system was one of the pulled changes. How can I help you to pinpoint the problem?

Update: if I wait long enough (4mins approx.) some tests start failing, so everything is not completely frozen.
e2e
e2e-2

@Mischi
Copy link

Mischi commented Mar 9, 2013

same Problem here (Windows 8 + Chrome 25)

@geddski
Copy link
Contributor Author

geddski commented Mar 10, 2013

Ah, you have to run your command line "as Administrator" on Windows for the ‛grunt build‛ task to correctly create the symlinks. I'm going to change that soon. Try running the build as Administrator and let me if that solves it on your box.

@IgorMinar
Copy link
Contributor

You guys are running the webserver already somewhere on the same port. Grunt unlike rake will start webserver for e2e tests.

@geddski
Copy link
Contributor Author

geddski commented Mar 10, 2013

Igor is right. You don't need to start the webserver before running the tests. If you already have the webserver running for something else, then run grunt test:end2end rather than grunt test:e2e.

@Mischi
Copy link

Mischi commented Mar 10, 2013

The Problem only occurs when executing tests with grunt test. When executing only e2e tests with grunt test:e2e all e2e tests pass.

@Mischi
Copy link

Mischi commented Mar 10, 2013

ah grunt test should never be called right?! It would exec grunt end2end which does not start the webserver.....

@lrlopez
Copy link
Contributor

lrlopez commented Mar 10, 2013

Yeah, that was the problem. By default, grunt test doesn't start the test web server, so the test:e2e task fails...

Problem is gone if you use grunt connect:testserver test instead. Thanks for pointing us in the right direction...

@geddski
Copy link
Contributor Author

geddski commented Mar 10, 2013

As soon as the Testacular proxy issue is resolved I'm going to update our build to use gruntacular. At that point I'll make grunt test do what you would have expected.

@Mischi
Copy link

Mischi commented Mar 10, 2013

sounds great 👍

@chicoxyzzy
Copy link

very cool PR

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.

9 participants