Make use of diskpart npm module

This commit is contained in:
Juan Cruz Viotti 2015-01-30 15:41:14 -04:00
parent e9db8c09e8
commit fd079b5794
3 changed files with 3 additions and 47 deletions

View File

@ -1,45 +0,0 @@
_ = require('lodash')
childProcess = require('child_process')
fs = require('fs')
path = require('path')
async = require('async')
exports.runScript = (scriptPath, callback) ->
async.waterfall([
(callback) ->
fs.exists scriptPath, (exists) ->
if not exists
error = new Error("Diskpart script does not exist: #{scriptPath}")
return callback()
(callback) ->
command = "diskpart /s \"#{scriptPath}\""
childProcess.exec command, {}, (error, stdout, stderr) ->
return callback(new Error(stderr)) if not _.isEmpty(stderr)
return callback(null, stdout)
], callback)
exports.getTempScriptPath = ->
currentTime = new Date().getTime()
return path.join(process.env.TEMP, "_diskpart-#{currentTime}")
exports.evaluate = (input, callback) ->
scriptFilePath = exports.getTempScriptPath()
async.waterfall([
(callback) ->
fs.writeFile(scriptFilePath, input.join('\n'), callback)
(callback) ->
exports.runScript(scriptFilePath, callback)
(output, callback) ->
fs.unlink scriptFilePath, (error) ->
return callback(error) if error?
return callback(null, output)
], callback)

View File

@ -3,7 +3,7 @@ path = require('path')
_ = require('lodash-contrib')
async = require('async')
fs = require('fs')
diskpart = require('./diskpart')
diskpart = require('diskpart')
exports.rescanDrives = (callback) ->
diskpart.evaluate([ 'rescan' ], callback)

View File

@ -27,7 +27,8 @@
"author": "Juan Cruz Viotti <juanchiviotti@gmail.com>",
"license": "MIT",
"optionalDependencies": {
"windosu": "^0.1.3"
"windosu": "^0.1.3",
"diskpart": "^1.0.0"
},
"devDependencies": {
"chai": "~1.9.2",