Add the ability to set the development server IP address from gulp

This commit is contained in:
Christopher C. Wells 2020-01-27 08:52:42 -08:00
parent c51e755c0f
commit 4a81e2c5a9
2 changed files with 32 additions and 3 deletions

View File

@ -160,6 +160,8 @@ in the [`babybuddy/management/commands`](babybuddy/management/commands) folder.
#### `gulp`
Executes the `build` and `watch` commands and runs Django's development server.
This command also accepts the special parameter `--ip` for setting the
development server IP address. See [`gulp runserver`](#runserver) for details.
#### `build`
@ -240,8 +242,12 @@ fake data.
#### `runserver`
Executes Django's `runserver` management task. Gulp also passes along
non-overlapping arguments for this command.
Executes Django's `runserver` management task. Gulp passes non-overlapping
arguments for this command.
A special parameter, `--ip`, is also available to set the IP for the server.
E.g execute `gulp runserver --ip 0.0.0.0:8000` to make the server available to
other devices on your local network.
#### `scripts`

View File

@ -216,7 +216,30 @@ gulp.task('clean', clean);
gulp.task('runserver', function(cb) {
var command = ['run', 'python', 'manage.py', 'runserver'];
command = command.concat(process.argv.splice(3));
/**
* Process any parameters. Any arguments found here will be removed from
* the parameters list so other parameters continue to be passed to the
* command.
**/
var parameters = process.argv.splice(2);
for (var i = 0; i < parameters.length; i++) {
/* May be included because this is the default gulp command. */
if (parameters[i] === 'runserver') {
delete parameters[i];
}
/* "--ip" parameter to set the server IP address. */
else if (parameters[i] === '--ip') {
command.push(parameters[i+1]);
delete parameters[i];
delete parameters[i+1];
i++;
}
}
/* Add parameters to command, removing empty values. */
command = command.concat(parameters.filter(String));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
});