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 ?
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.
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.
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.
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 ... ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With