Skip to content

Commit

Permalink
Fixes tessel erase
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Oct 1, 2015
1 parent 85b1138 commit 3de829c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
3 changes: 3 additions & 0 deletions lib/tessel/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports.scanWiFi = function() {
module.exports.stopRunningScript = function() {
return ['/etc/init.d/tessel-app', 'stop'];
};
module.exports.disablePushedScript = function() {
return ['/etc/init.d/tessel-app', 'disable'];
}
module.exports.deleteFolder = function(filepath) {
return ['rm', '-rf', filepath];
};
Expand Down
8 changes: 3 additions & 5 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ var path = require('path');
var tar = require('tar');
var Ignore = require('fstream-ignore');

var RUN_PATH = '/tmp/remote-script/';
var PUSH_PATH = '/app/';
var PUSH_START_SCRIPT_NAME = 'start';
var NODE_PUSH_SCRIPT = __dirname + '/../../resources/start_node_script.sh';

Expand All @@ -25,7 +23,7 @@ Tessel.prototype.deployScript = function(opts) {
var isPush = opts.push === true;

return new Promise(function(resolve, reject) {
var filepath = isPush ? PUSH_PATH : RUN_PATH;
var filepath = isPush ? Tessel.PUSH_PATH : Tessel.RUN_PATH;

// Stop running any existing scripts
return actions.execRemoteCommand(self, 'stopRunningScript', filepath)
Expand Down Expand Up @@ -65,7 +63,7 @@ Tessel.prototype.deployScript = function(opts) {
Tessel.prototype.restartScript = function(opts) {
var self = this;
var isPush = opts.type === 'flash';
var filepath = isPush ? PUSH_PATH : RUN_PATH;
var filepath = isPush ? Tessel.PUSH_PATH : Tessel.RUN_PATH;

return new Promise(function(resolve, reject) {
return self.simpleExec(commands.readFile(filepath + opts.entryPoint))
Expand Down Expand Up @@ -286,7 +284,7 @@ actions.pushScript = function(t, entryPoint) {
actions.writeToFile = function(t) {
return new Promise(function(resolve, reject) {
// Path of the script to run a Node project
var executablePath = PUSH_PATH + PUSH_START_SCRIPT_NAME;
var executablePath = Tessel.PUSH_PATH + PUSH_START_SCRIPT_NAME;
// Open a stdin pipe tp the file
return t.connection.exec(commands.openStdinToFile(executablePath))
// If it was opened successfully
Expand Down
39 changes: 21 additions & 18 deletions lib/tessel/erase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ var Tessel = require('./tessel'),

Tessel.prototype.eraseScript = function() {
var self = this;
return new Promise(function(resolve, reject) {

logs.info('Erasing files from Flash...');
return self.simpleExec(commands.stopRunningScript())
.then(function stopped() {
logs.info('Files erased.');
return resolve();
})
.catch(function(error) {
// If we get a notice that the command failed
if (error.message.indexOf('Command failed') !== -1) {
// Let the user know what went wrong
return reject('No files have been pushed. Run `tessel push FILE` to push to Flash.');
} else {
// Otherwise this is an unexpected error
return reject('An unexpected error occurred:' + error.message);
}
});
});
logs.info('Erasing files from Flash...');
return self.simpleExec(commands.stopRunningScript())
.then(function stopped() {
return self.simpleExec(commands.disablePushedScript())
})
.then(function disabled() {
return self.simpleExec(commands.deleteFolder(Tessel.PUSH_PATH))
.then(function erased() {
logs.info('Files erased.');
})
})
.catch(function(error) {
// If we get a notice that the command failed
if (error.message.indexOf('Command failed') !== -1) {
// Let the user know what went wrong
return Promise.reject('No files have been pushed. Run `tessel push FILE` to push to Flash.');
} else {
// Otherwise this is an unexpected error
return Promise.reject('An unexpected error occurred:' + error.message);
}
});
};
3 changes: 3 additions & 0 deletions lib/tessel/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ Tessel.prototype.simpleExec = function(command) {
});
};

Tessel.PUSH_PATH = '/app';
Tessel.RUN_PATH = '/tmp/remote-script';

module.exports = Tessel;

require('./provision');
Expand Down

0 comments on commit 3de829c

Please sign in to comment.