Last active
April 12, 2017 04:34
-
-
Save Kreshnik/4bd164572e11df7f96e4 to your computer and use it in GitHub Desktop.
Gulp task to create a MySQL database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Required npm packages: gulp, gulp-shell, gulp-prompt | |
// Usage: gulp db:create | |
var util = require('util'); | |
var gulp = require('gulp'); | |
var shell = require('gulp-shell'); | |
var prompt = require('gulp-prompt'); | |
gulp.task('db:create', function() { | |
gulp.src('').pipe( | |
prompt.prompt([{ | |
type: 'input', | |
name: 'username', | |
message: 'Please enter your mysql username' | |
}, { | |
type: 'password', | |
name: 'password', | |
message: 'Please enter your mysql password' | |
}, { | |
type: 'input', | |
name: 'databaseName', | |
message: 'Enter the name of the database to create' | |
}], function(response) { | |
var shellCommand; | |
if (response.password == '') { | |
shellCommand = util.format('mysql -u %s -e "CREATE DATABASE %s"', response.username, response.databaseName) | |
} else { | |
shellCommand = util.format('mysql -u %s -p %s -e "CREATE DATABASE %s"', response.username, response.password, response.databaseName); | |
} | |
gulp.src('').pipe(shell([shellCommand])); | |
console.log('\n\x1b[32m%s\x1b[0m', 'Database created!'); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think he wants a WAMP/AMMPS sort of setup whereby Gulp and BrowserSync etc manage MySQL and PHP