Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added better handling for validate responses

  • Loading branch information...
commit 04d1dd9e9df056d097cc936a2b277cb86526a53b 1 parent 509ae1e
Chris Jones chrisfjones authored
Showing with 36 additions and 14 deletions.
  1. +21 −8 lib/command.js
  2. +1 −1  package.json
  3. +14 −5 src/command.coffee
29 lib/command.js
View
@@ -123,14 +123,29 @@
buildCfnPath = function() {
var cfnHome;
cfnHome = commander['cfn-home'] || process.env.AWS_CLOUDFORMATION_HOME;
- return path.normalize("" + cfnHome + "/bin");
+ return path.normalize(path.join(cfnHome, 'bin'));
};
validateTemplate = function(templatePath, callback) {
- var validateExec;
- validateExec = "cfn-validate-template --template-file " + templatePath;
- return exec("" + (buildCfnPath()) + "/" + validateExec, function(err) {
- return typeof callback === "function" ? callback(err ? 1 : 0) : void 0;
+ var errorText, resultText, validateExec;
+ validateExec = spawn(path.join(buildCfnPath(), 'cfn-validate-template'), ['--template-file', templatePath]);
+ errorText = '';
+ resultText = '';
+ validateExec.stderr.on('data', function(data) {
+ return errorText += data.toString();
+ });
+ validateExec.stdout.on('data', function(data) {
+ return resultText += data.toString();
+ });
+ return validateExec.on('exit', function(code) {
+ if (code === 0) {
+ process.stdout.write("" + checkChar + "\n");
+ process.stdout.write(resultText);
+ } else {
+ process.stdout.write("" + crossChar + "\n");
+ process.stderr.write(errorText);
+ }
+ return typeof callback === "function" ? callback(code) : void 0;
});
};
@@ -232,9 +247,7 @@
process.stdout.write("" + coffinChar + " " + template + " ");
tempFileName = generateTempFileName();
return writeJsonTemplate(compiled, tempFileName, function() {
- return validateTemplate(tempFileName, function(resultCode) {
- return process.stdout.write(resultCode === 0 ? "" + checkChar + "\n" : "" + crossChar + "\n");
- });
+ return validateTemplate(tempFileName, function(resultCode) {});
});
});
});
2  package.json
View
@@ -1,6 +1,6 @@
{
"name": "coffin",
- "version": "0.0.4",
+ "version": "0.0.5",
"description": "Coffee dsl for aws cloudformation",
"keywords": ["coffeescript", "coffee-script", "aws", "cloudformation"],
"author": "Chris Jones",
19 src/command.coffee
View
@@ -71,12 +71,22 @@ generateOutputFileName = (source) ->
buildCfnPath = ->
cfnHome = commander['cfn-home'] || process.env.AWS_CLOUDFORMATION_HOME
- return path.normalize "#{cfnHome}/bin"
+ return path.normalize path.join cfnHome, 'bin'
validateTemplate = (templatePath, callback) =>
- validateExec = "cfn-validate-template --template-file #{templatePath}"
- exec "#{buildCfnPath()}/#{validateExec}", (err) ->
- callback?(if err then 1 else 0)
+ validateExec = spawn path.join(buildCfnPath(), 'cfn-validate-template'), ['--template-file', templatePath]
+ errorText = ''
+ resultText = ''
+ validateExec.stderr.on 'data', (data) -> errorText += data.toString()
+ validateExec.stdout.on 'data', (data) -> resultText += data.toString()
+ validateExec.on 'exit', (code) ->
+ if code is 0
+ process.stdout.write "#{checkChar}\n"
+ process.stdout.write resultText
+ else
+ process.stdout.write "#{crossChar}\n"
+ process.stderr.write errorText
+ callback?(code)
updateOrCreateStack = (name, templatePath, callback) =>
updateExec = spawn "#{buildCfnPath()}/cfn-update-stack", ['--template-file', templatePath, '--stack-name', name]
@@ -147,7 +157,6 @@ validateCommand.action (template) ->
tempFileName = generateTempFileName()
writeJsonTemplate compiled, tempFileName, ->
validateTemplate tempFileName, (resultCode) ->
- process.stdout.write if resultCode is 0 then "#{checkChar}\n" else "#{crossChar}\n"
stackCommand = commander.command 'stack [name] [template]'
stackCommand.description 'Create or update the named stack using the compiled template. Either an AWS_CLOUDFORMATION_HOME environment variable or a --cfn-home switch is required.'
Please sign in to comment.
Something went wrong with that request. Please try again.