mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-03-21 11:35:54 +00:00
Make use of diskpart npm module
This commit is contained in:
parent
e9db8c09e8
commit
fd079b5794
@ -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)
|
@ -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)
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user