Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Feaure(grunt): Wiredep task for grunt #1402

Merged
merged 8 commits into from
Jul 23, 2016

Conversation

shanavas786
Copy link
Contributor

Update dependencies and remove trailing comma from asset files.

Fixes #1360

Shanavas M added 4 commits July 16, 2016 15:55
remove explicit grunt task loading for `grunt-protactor-coverage` as
`load-grunt-tasks` handles it
Automatically update bower dependencies.
Remove trailing comma from assets configuration generated by wiredep
Remove trailing comma from asset configurations generated by wiredep
@@ -51,6 +51,9 @@
"glob": "~7.0.0",
"grunt": "~1.0.1",
"grunt-cli": "~1.2.0",
"grunt-rtc": "^0.1.1",
Copy link
Member

@ilanbiala ilanbiala Jul 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ please

@shanavas786
Copy link
Contributor Author

No.

@ilanbiala
Copy link
Member

@lirantal I think you were working on something with grunt-wiredep, can you take a look at this too?

@lirantal
Copy link
Member

@ilanbiala indeed, thanks for the heads up.
@shanavas786 can you please take a look at my open issue related to this one? #1398. The fix should be simpler, and address gulp more specifically.

@shanavas786
Copy link
Contributor Author

@lirantal Well, this PR doesn't do much with gulp-wiredep. It just removes the trailing commas created by wiredep from asset config files which causes lint errors (#1360).

This PR primarily addresses grunt-wiredep. Since that also adds trailing commas, grunt-rtc is used to remove them.

@lirantal
Copy link
Member

@shanavas786 first of all I sincerely appreciate the effort in your PRs.
I don't want to add more dependencies to the project than what is really needed which is why I don't want to continue the route this PR is taking.

Both gulp-wiredep, and grunt-wiredep aren't really doing a lot, just take a look here: https://github.com/stephenplusplus/grunt-wiredep/blob/master/tasks/wiredep.js, we can easily just add wiredep itself and use it in either gulp or grunt.

As to the trailing commas, it sounds like we have some bug there that needs to get resolved. It doesn't make sense that we need a package to remove trailing commas.

So getting back to the point - can you update this PR to take my comments above into consideration and this way to solve both #1360 as well as #1398

@shanavas786
Copy link
Contributor Author

shanavas786 commented Jul 18, 2016

@lirantal sounds cool.
Had a look at gulp-wiredep too. it has only two lines of code in it. So both gulp-wiredep and grunt-wiredep dependencies can be removed easily.

For handling trailing commas, it needs a little parsing using esprima. Where it would be appropriate to place that piece of code ?, in {gulp,grunt}file.js or in a dedicated file?

@lirantal
Copy link
Member

You totally understood my points, great :)

As for the commas, why does it even happen? do other projects need to forcely remove the trailing commas in their build process? This sounds like something we aren't doing right in the build process.

@shanavas786
Copy link
Contributor Author

@lirantal ok, let me explain, basically wiredep is for updating bower dependencies in html source.
It just replaces

<body>
  <!-- bower:js -->
  <!-- endbower -->
</body>

with something like

<body>
  <!-- bower:js -->
  <script src="bower_components/jquery/dist/jquery.js"></script>
  <script src="bower_components/angular/angular.js"></script>
  <!-- endbower -->
</body>

The replacement template, though it is customizable, is uniform for all dependencies (in this case <script src="path-to-bower-dep"></script>). Since we are not directly wiring to html source, but to a javascript array object for later use, we use a replacement template which may look like path-to-bower-dep, with a trailing comma see gulpfile.

The trailing comma is necessary in replacement as it ends up as an array element, and since the replacement template is uniform, wiredep can't handle the trailing comma of last element specifically.

There comes need for a remove-comma task.

@shanavas786
Copy link
Contributor Author

@lirantal Just one more thought.
I think its better to wire https://github.com/meanjs/mean/blob/master/modules/core/server/views/layout.server.view.html directly. It also removes the dependency on server for a task that could be performed statically.

@lirantal
Copy link
Member

So to be honest I think that the trailing comma here is still just a symptom of the project not managing correctly the assets to wire. I suggest we do the following in this order too:

  1. First let's get rid of the security issues with the gulp/grunt wiredep modules and work only with the wiredep library
  2. I'm not sure the config/assets/production.js assets file is actually set up correctly because changing it means that we need to commit things to the repository. Let's leave this issue aside for a sec.
  3. Since this is really just a linting issue how about we add a lint ignore statement on that file?

If we're still not in agreement on this then let's start with a PR on (1) to resolve the security issue and figure out how to solve (3) in a later PR.

@shanavas786
Copy link
Contributor Author

👍 for 1.

3 would only be a temporary fix. The proper solution would be to wire the template file directly and remove the bower dependencies from asset files. That will fix 2 too.

@lirantal
Copy link
Member

Great. So let's proceed with a PR for (1) and I'll be happy to review your proposed solution for (3) in another PR.

@ilanbiala
Copy link
Member

SGTM too.

@@ -228,7 +257,6 @@ module.exports = function (grunt) {

// Load NPM tasks
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('grunt-protractor-coverage');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shanavas786 why are we removing this?

@lirantal
Copy link
Member

@shanavas786 looks like we're done there? just see my comment on the protractor task removal.
can you also build it for production and test it is working well?

@shanavas786
Copy link
Contributor Author

@lirantal load-grunt-tasks package in require('load-grunt-tasks')(grunt); loads all the grunt tasks. So need not load grunt-protractor-coverage task explicitly.
All the development, test and production builds were successful with each of grunt and gulp :).

@lirantal
Copy link
Member

You're right. That's great.
Super job making this pokemon happy! :)

pokemon

@lirantal lirantal merged commit 0934f87 into meanjs:master Jul 23, 2016
@shanavas786 shanavas786 deleted the grunt-wiredep branch July 23, 2016 19:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants