Skip to content

Commit

Permalink
Added ability to specify a shell used to run script
Browse files Browse the repository at this point in the history
  • Loading branch information
abe545 committed Jun 7, 2015
1 parent d0e0b6e commit e962cc9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
16 changes: 15 additions & 1 deletion config/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ <h2>

<p class="help-text">
The following scripts execute from inside your project directory.
You can use `pwd` or `$PWD` to get the path within your script.
In Bash, Powershell, or the POSIX shell, you can use `pwd` or `$PWD` to get the path within your script.
In the default Windows shell, you can get the current directory by using `cd` with no arguments.
</p>
<h3>Shell</h3>
<div class="row-fluid">
<div class="span12">
<p class="help-text">
Choose which shell to use to execute your scripts.
</p>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<select ng-model="config.shell" ng-options="value for value in ['Default Shell', 'Bash', 'Powershell']"></select>
</div>
</div>
<h3>Environment</h3>
<div class="row-fluid">
<div class="span12">
Expand Down
1 change: 1 addition & 0 deletions webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
config: {
custom: {
shell: { type: String, default: 'Default', enum: ['Default Shell', 'Bash', 'Powershell']},
environment: {type: String, default: '# type shell commands here'},
prepare: {type: String, default: '# type shell commands here'},
test: {type: String, default: '# type shell commands here'},
Expand Down
33 changes: 26 additions & 7 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ module.exports = {
var config = config || {};

done(null, {
environment: shellCommand(config.environment, job),
prepare: shellCommand(config.prepare, job),
test: shellCommand(config.test, job),
deploy: shellCommand(config.deploy, job),
cleanup: shellCommand(config.cleanup, job)
environment: shellCommand(config.environment, config.shell, job),
prepare: shellCommand(config.prepare, config.shell, job),
test: shellCommand(config.test, config.shell, job),
deploy: shellCommand(config.deploy, config.shell, job),
cleanup: shellCommand(config.cleanup, config.shell, job)
});
}
};

function shellCommand(command, job) {
function shellCommand(command, shell, job) {
if (!command) {
return;
}
Expand All @@ -29,8 +29,27 @@ function shellCommand(command, job) {

var commandToExecute = compileScript(job, normalizedCommand);

if ((/bash/i).test(shell)) {
return {
command: 'bash',
args: ['-e', '-x', '-c', commandToExecute]
};
}
else if ((/powershell/i).test(shell)) {
return {
command: 'powershell',
args: ['-NonInteractive', '-Command', commandToExecute]
}
}
else if (process.platform === 'win32') {
return {
command: 'cmd',
args: ['/c', commandToExecute]
}
}

return {
command: 'bash',
command: 'sh',
args: ['-e', '-x', '-c', commandToExecute]
};
}
Expand Down

0 comments on commit e962cc9

Please sign in to comment.