1

How to call a Yeoman command from a NodeJS server?

I want to make a simple client webpage which allows me to execute Yeoman commands, on the NodeJS server, such as

yeoman install angular
yeoman server
Phil
  • 46,436
  • 33
  • 110
  • 175

2 Answers2

2

Add a path or a websocket command which executes this sample code:

var spawn = require('child_process').spawn;
var yeoman = spawn('yeoman', ['install', 'angular']);
yeoman.stdout.on('data', function (data) {
    console.log('yeoman: ' + data);
});

Later edit: You have several options + examples here, including exec suggested in the comments: http://nodejs.org/api/child_process.html

randunel
  • 8,917
  • 1
  • 26
  • 24
  • using exec would be simpler `var exec = require('child_process').exec; exec('yeoman install angular', function(err, stdout) { console.log('yeoman', stdout); });` – Sindre Sorhus Jan 11 '13 at 15:10
1

var env = require('yeoman-generator')();

var workingDirectory = //Path where generator should be executed. generator = env.create('iosapp:app'); generator.destinationRoot(workingDirectory);
generator.run();

Generator ID for create call you will be able to find by calling yo without arguments.

Nikita Leonov
  • 5,684
  • 31
  • 37