Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp - How to write command to runserver from gulpfile

After using Grunt for a couple of projects I decided to give Gulp a try.

Most of the projects we work on are Python based, and the way we usually run them from the command line is: 'python manage.py runserver'

With Grunt, i found the grunt-bg-shell plugin, and was able to run my command like this:

// see: https://npmjs.org/package/grunt-bg-shell
bgShell: {
  _defaults: {
    bg: true
  },
  runDjango: {
    cmd: 'python <%= paths.manageScript %> runserver 0.0.0.0:<%= port %>'
    //cmd: 'python <%= paths.manageScript %> runserver'
  }
}
grunt.registerTask('serve', [
'bgShell:runDjango',
'watch'
]);

Unfortunately, so far i have been unable to find a similar plugin for Gulp. I've tried gulp-shell, gulp-run, gulp-exec, all to no avail. With most im able to print my string on the console, but i havent been able to run the actual command.

Any ideas ?

like image 385
Pablo Rincon Avatar asked Oct 22 '14 17:10

Pablo Rincon


People also ask

How do I run gulp locally?

To install Gulp locally, navigate to your project directory and run npm install gulp . You can save it to your package. json dependencies by running npm install gulp --save-dev . Once you have Gulp installed locally, you can then proceed to create your gulpfile.

How do I run a gulp task?

in the Before launch area and choose Run Gulp task from the list. In the Gulp task dialog that opens, specify the Gulpfile. js where the required task is defined, select the task to execute, and specify the arguments to pass to the Gulp tool. Specify the location of the Node.


2 Answers

You can do this:

var process     = require('child_process');

gulp.task('flask', function(){
  var spawn = process.spawn;
  console.info('Starting flask server');
  var PIPE = {stdio: 'inherit'};
  spawn('python', ['manage.py','runserver'], PIPE);
});

This spawns a new child process running 'python manage.py runserver' and passes the output of flask to gulp output stream.

like image 173
brijeshb42 Avatar answered Sep 28 '22 02:09

brijeshb42


I'm using gulp-shell to run a Flask server. I believe it should work the same way with Django:

var shell = require('gulp-shell');
gulp.task('flask', shell.task(['. env/bin/activate && python my_script.py']));

Did you use another syntax ... ?

like image 39
vcarel Avatar answered Sep 28 '22 03:09

vcarel