amphtml-validator
Advanced tools
Comparing version 1.0.18 to 1.0.19
83
index.js
@@ -348,5 +348,15 @@ #!/usr/bin/env node | ||
// A note on emitting output to the console and process exit status: | ||
// Node.js prior to 0.11.8 did not support process.exitCode | ||
// (https://nodejs.org/api/process.html#process_process_exitcode), which | ||
// makes it difficult to emit output and errors from multiple callbacks | ||
// and set the appropriate exit code. We use the following workaround: | ||
// process.<<stream>>(<<some output>>, function() { process.exit(<<code>>); }); | ||
// This will flush the appropriate stream (stdout or stderr) and then | ||
// exit with the provided code. For now, this makes the CLI work with | ||
// Node.js versions as old as v0.10.25. | ||
/** | ||
* Logs a validation result to the console using console.log, console.warn, | ||
* and console.error as is appropriate. | ||
* Logs a validation result to the console using process.stdout and | ||
* process.stderr as is appropriate. | ||
* @param {!string} filename | ||
@@ -358,3 +368,4 @@ * @param {!ValidationResult} validationResult | ||
if (validationResult.status === 'PASS') { | ||
console.log(filename + ': ' + (color ? colors.green('PASS') : 'PASS')); | ||
process.stdout.write( | ||
filename + ': ' + (color ? colors.green('PASS') : 'PASS') + '\n'); | ||
} | ||
@@ -373,7 +384,4 @@ for (var ii = 0; ii < validationResult.errors.length; ii++) { | ||
} | ||
if (error.severity === 'ERROR') { | ||
console.error(msg); | ||
} else { | ||
console.warn(msg); | ||
} | ||
// TODO(powdercloud): Should we distinguish error.severity === 'WARNING' ? | ||
process.stderr.write(msg + '\n'); | ||
} | ||
@@ -392,3 +400,4 @@ } | ||
.option( | ||
'--validator_js <fileOrUrl>', 'The Validator Javascript.\n' + | ||
'--validator_js <fileOrUrl>', | ||
'The Validator Javascript.\n' + | ||
' Latest published version by default, or\n' + | ||
@@ -402,3 +411,4 @@ ' dist/validator_minified.js (built with build.py)\n' + | ||
.option( | ||
'--html_format <AMP|AMP4ADS>', 'The input format to be validated.\n' + | ||
'--html_format <AMP|AMP4ADS>', | ||
'The input format to be validated.\n' + | ||
' AMP by default. AMP4ADS is a format for ads creatives that is\n' + | ||
@@ -409,3 +419,4 @@ ' still in draft; this requires specifying \n' + | ||
.option( | ||
'--format <color|text|json>', 'How to format the output.\n' + | ||
'--format <color|text|json>', | ||
'How to format the output.\n' + | ||
' "color" displays errors/warnings/success in\n' + | ||
@@ -424,9 +435,13 @@ ' red/orange/green.\n' + | ||
if (program.html_format !== 'AMP' && program.html_format !== 'AMP4ADS') { | ||
console.error('--html_format must be set to "AMP" or "AMP4ADS".'); | ||
process.exit(1); | ||
process.stderr.write( | ||
'--html_format must be set to "AMP" or "AMP4ADS".\n', function() { | ||
process.exit(1); | ||
}); | ||
} | ||
if (program.format !== 'color' && program.format !== 'text' && | ||
program.format !== 'json') { | ||
console.error('--format must be set to "color", "text", or "json".'); | ||
process.exit(1); | ||
process.stderr.write( | ||
'--format must be set to "color", "text", or "json".\n', function() { | ||
process.exit(1); | ||
}); | ||
} | ||
@@ -449,2 +464,3 @@ var inputs = []; | ||
var jsonOut = {}; | ||
var hasError = false; | ||
for (var ii = 0; ii < resolvedInputs.length; ii++) { | ||
@@ -461,21 +477,38 @@ var validationResult = validator.validateString( | ||
if (validationResult.status !== 'PASS') { | ||
process.exitCode = 1; | ||
hasError = true; | ||
} | ||
} | ||
if (program.format === 'json') { | ||
console.log(JSON.stringify(jsonOut)); | ||
process.stdout.write( | ||
JSON.stringify(jsonOut) + '\n', function() { | ||
process.exit(hasError ? 1 : 0); | ||
}); | ||
} else if (hasError) { | ||
process.stderr.write('', function() { | ||
process.exit(1); | ||
}); | ||
} else { | ||
process.stdout.write('', function() { | ||
process.exit(0); | ||
}); | ||
} | ||
}) | ||
.catch(function(error) { | ||
console.error( | ||
program.format == 'color' ? colors.red(error.message) : | ||
error.message); | ||
process.exitCode = 1; | ||
process.stderr.write( | ||
(program.format == 'color' ? colors.red(error.message) : | ||
error.message) + | ||
'\n', | ||
function() { | ||
process.exit(1); | ||
}); | ||
}); | ||
}) | ||
.catch(function(error) { | ||
console.error( | ||
program.format == 'color' ? colors.red(error.message) : | ||
error.message); | ||
process.exitCode = 1; | ||
process.stderr.write( | ||
(program.format == 'color' ? colors.red(error.message) : | ||
error.message) + | ||
'\n', | ||
function() { | ||
process.exit(1); | ||
}); | ||
}); | ||
@@ -482,0 +515,0 @@ } |
{ | ||
"name": "amphtml-validator", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"description": "Official validator for AMP HTML (www.ampproject.org)", | ||
@@ -5,0 +5,0 @@ "keywords": ["AMP", "validator", "validate", "AMP HTML", "Accelerated Mobile Pages"], |
@@ -79,1 +79,4 @@ # amphtml-validator Node.js Package | ||
* Small tweaks to this file and package.json. | ||
### 1.0.19 | ||
* Set correct process exit status for old versions of Node.js (v0.10.25). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35448
788
82