Created
October 15, 2015 15:32
-
-
Save josser/0b7f6cbec21364ebf9fd to your computer and use it in GitHub Desktop.
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
var fs = require('fs'); | |
var gulp = require('gulp'); | |
var env = process.env.NODE_ENV || 'development'; | |
var child_process = require('child_process'); | |
var config = require('../../config/config.json')[env]; | |
var path = require('path'); | |
var minimist = require('minimist'); | |
var knownOptions = { | |
string: ['from'], | |
default: { | |
from: 'pg_dump.sql' | |
} | |
}; | |
var options = minimist(process.argv.slice(2), knownOptions); | |
gulp.task('metastock:import', function (cb) { | |
var importFile = fs.createReadStream(path.resolve(options.from)); | |
var psql = child_process.spawn('/usr/local/bin/psql', ['-h', config.host, '-U', config.username, config.database], { | |
env: { | |
PGPASSWORD: config.password | |
} | |
}); | |
importFile.pipe(psql.stdin); | |
psql.stdout.on('close', function (code) { | |
cb(null, code); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment