Skip to content

Commit

Permalink
Add convenience function in Gulp for simple pipenv tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubz committed Dec 22, 2021
1 parent 5811755 commit c01dbee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
2 changes: 1 addition & 1 deletion gulpfile.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
files: 'babybuddy/static_src/root/*'
}
},
glyphFontCOnfig: {
glyphFontConfig: {
configFile: 'babybuddy/static_src/fontello/config.json',
dest: 'babybuddy/static_src/fontello'
},
Expand Down
58 changes: 19 additions & 39 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ var config = require('./gulpfile.config.js');
* Support functions for Gulp tasks.
*/

function _runInPipenv(command, cb) {
command.unshift('run');
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', function (code) {
if (code) process.exit(code);
cb();
});
}

/**
* Deletes local static files.
*
Expand Down Expand Up @@ -115,12 +124,7 @@ function extras(cb) {
* @param cb
*/
function lint(cb) {
var command = ['run', 'flake8', '--exclude=.venv,etc,migrations,manage.py,node_modules,settings'];
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', function (code) {
if (code) process.exit(code);
cb();
});
_runInPipenv(['flake8', '--exclude=.venv,etc,migrations,manage.py,node_modules,settings'], cb);

pump([
gulp.src(config.watchConfig.stylesGlob),
Expand Down Expand Up @@ -212,9 +216,9 @@ function test(cb) {
*/
function updateglyphs(cb) {
pump([
gulp.src(config.glyphFontCOnfig.configFile),
gulp.src(config.glyphFontConfig.configFile),
fontello({ assetsOnly: false }),
gulp.dest(config.glyphFontCOnfig.dest)
gulp.dest(config.glyphFontConfig.dest)
], cb);
}

Expand Down Expand Up @@ -251,58 +255,34 @@ gulp.task('collectstatic', function(cb) {
});

gulp.task('compilemessages', function(cb) {
var command = ['run', 'python', 'manage.py', 'compilemessages'];
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
_runInPipenv(['python', 'manage.py', 'compilemessages'], cb);
});

gulp.task('createcachetable', function(cb) {
var command = ['run', 'python', 'manage.py', 'createcachetable'];
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
_runInPipenv(['python', 'manage.py', 'createcachetable'], cb);
});

gulp.task('fake', function(cb) {
var command = ['run', 'python', 'manage.py', 'fake'];
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
_runInPipenv(['python', 'manage.py', 'fake'], cb);
});

gulp.task('migrate', function(cb) {
var command = ['run', 'python', 'manage.py', 'migrate'];
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
_runInPipenv(['python', 'manage.py', 'migrate'], cb);
});

gulp.task('makemessages', function(cb) {
var command = ['run', 'python', 'manage.py', 'makemessages'];
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
_runInPipenv(['python', 'manage.py', 'makemessages'], cb);
});

gulp.task('makemigrations', function(cb) {
var command = ['run', 'python', 'manage.py', 'makemigrations'];
command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
_runInPipenv(['python', 'manage.py', 'makemigrations'], cb);
});

/**
* Runs the custom "reset" command to start a fresh database with fake data.
*/
gulp.task('reset', function(cb) {
spawn(
'pipenv',
[
'run',
'python',
'manage.py',
'reset',
'--no-input'
],
{
stdio: 'inherit'
}
).on('exit', cb);
_runInPipenv(['python', 'manage.py', 'reset', '--no-input'], cb);
});

gulp.task('runserver', function(cb) {
Expand Down

0 comments on commit c01dbee

Please sign in to comment.