Using Bower Api in a synchronous way.

164 views
Skip to first unread message

Edmondo Porcu

unread,
Nov 1, 2013, 9:22:06 AM11/1/13
to twitte...@googlegroups.com
Dear all,

Bower API is based on asynchronous callbacks as described in the documentation. I am trying to use it with node the following way:


      var dependenciesTree = {};
      
      var _underscore = require('underscore');  
    
      bower.commands.list({paths:true},bowerConfig).on('end', function(tree){
          dependenciesTree = tree;
      });
    
    
      // Because of _underscore.pick apply signature, this is required
      var prodDependencies = _underscore.pick(dependenciesTree, _underscore.keys(bowerConfig.dependencies));
    
      var devDependencies = _underscore.pick(dependenciesTree, _underscore.keys(bowerConfig.devDependencies));
        

The following code does not yield the correct result because when entering the assignment of **prodDependencies** and **devDependencies**. I need it to be synchronous because it's inside my Gruntfile, so I could push the locking at a later stage, but I will have the same problem sooner or later.

How do I correctly wait for the command to be completed?


Thank you very much

Best Regards

Edmondo

Brian Di Palma

unread,
Nov 1, 2013, 1:44:28 PM11/1/13
to twitte...@googlegroups.com

Grunt supports async tasks, does that not help?

--
You received this message because you are subscribed to the Google Groups "bower" group.
To unsubscribe from this group and stop receiving emails from it, send an email to twitter-bowe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Edmondo Porcu

unread,
Nov 4, 2013, 3:38:30 AM11/4/13
to twitte...@googlegroups.com
The problem here is that I am using bower api in grunt.initConfig, which is not a task I guess.

Best 

Edmondo

Chandu

unread,
Apr 23, 2014, 10:02:56 AM4/23/14
to twitte...@googlegroups.com
Hi,
I am looking for a way to run the bower commands synchronously too (especially list command) :ducks.
I want to require bower components in my js modules just by name and not by paths like './bower_components/jquery/jquery.js'.
The gist @ https://gist.github.com/Chandu/11216253 depicts what I would like to achive.
In brief,
  1. I want to get the list of the modules currently installed and generate a map similar to {module_name => module_path}
  2. Use this map (not the path |||lr to './bower_components.whatever/whatever.js') entries to require the bower components in my js modules


Is there a way to run the list command synchronously?

-
Thanks

Brian Di Palma

unread,
Apr 23, 2014, 12:54:41 PM4/23/14
to twitte...@googlegroups.com
I'd take a look at browserify or webpack ( http://webpack.github.io/ )
> --
> You received this message because you are subscribed to the Google Groups
> "bower" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to twitter-bowe...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages