From 9069b07d4ab1b0b0e968811d4404ecc877e4b62f Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 29 Jan 2015 12:04:48 -0400 Subject: [PATCH] Integrate windosu --- bin/resin | 4 ++-- bin/resin-write | 16 ++++++++++++++++ lib/actions/device.coffee | 11 +++++++++-- package.json | 3 +++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 bin/resin-write diff --git a/bin/resin b/bin/resin index e738d5fa..2453c981 100755 --- a/bin/resin +++ b/bin/resin @@ -1,5 +1,5 @@ #!/usr/bin/env node // http://coffeescript.org/documentation/docs/register.html -require('coffee-script/register') -require('../lib/app.coffee') +require('coffee-script/register'); +require('../lib/app.coffee'); diff --git a/bin/resin-write b/bin/resin-write new file mode 100644 index 00000000..c26dac48 --- /dev/null +++ b/bin/resin-write @@ -0,0 +1,16 @@ +#!/usr/bin/env node + +// http://coffeescript.org/documentation/docs/register.html +require('coffee-script/register'); + +var device = require('../lib/actions/device.coffee'); +var errors = require('../lib/errors/errors'); + +device.init.action({ + image: process.argv[2], + device: process.argv[3] +}, { + yes: true +}, function(error) { + return errors.handle(error); +}); diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 2d43a063..4155f925 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -1,4 +1,5 @@ _ = require('lodash-contrib') +path = require('path') async = require('async') resin = require('resin-sdk') os = require('os') @@ -165,7 +166,7 @@ exports.init = options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> - async.waterfall([ + async.waterfall [ (callback) -> if options.yes @@ -186,5 +187,11 @@ exports.init = progressBar.tick(status.delta) , callback - ], done) + ], (error) -> + return done(error) if os.platform() isnt 'win32' + windosu = require('windosu') + # Need to escape everypath to avoid errors + resinWritePath = "\"#{path.join(__dirname, '..', '..', 'bin', 'resin-write')}\"" + windosu.exec("node #{resinWritePath} \"#{params.image}\" \"#{params.device}\"").then -> + console.log 'Done' diff --git a/package.json b/package.json index b801d2fb..ebc4e1ba 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,9 @@ ], "author": "Juan Cruz Viotti ", "license": "MIT", + "optionalDependencies": { + "windosu": "^0.1.3" + }, "devDependencies": { "chai": "~1.9.2", "gulp": "~3.8.9",