Skip to content

Commit 0b0f0a9

Browse files
committed
feat(validate): output file being validated
This update to the gulpfile modifies the default gulp task to only validate the build output. It also outputs the filename so a person running the task can know where to look for errors. A `build` task calls purifycss and inlines the CSS in one step.
1 parent b348c9b commit 0b0f0a9

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

gulpfile.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var amphtmlValidator = require('amphtml-validator');
66
var fs = require('fs');
77

88
const BUILD_PATH = './build';
9+
const BUILD_HTML = BUILD_PATH + '/index.html';
910
const SOURCE = {
1011
'BOOTSTRAP_CSS': './html/css/bootstrap.min.css',
1112
'AMPHTML': './amphtml/index.html',
@@ -20,7 +21,7 @@ gulp.task('purify', function() {
2021
});
2122

2223
// inline-css inserts the cleaned + minified CSS into HTML
23-
gulp.task('inline-css', function() {
24+
gulp.task('inline-css', ['purify'], function() {
2425
return gulp.src(SOURCE.AMPHTML)
2526
.pipe(htmlreplace({
2627
'cssInline': {
@@ -34,9 +35,9 @@ gulp.task('inline-css', function() {
3435
// validate ensures the AMP HTML is valid
3536
gulp.task('validate', function() {
3637
amphtmlValidator.getInstance().then(function (validator) {
37-
var input = fs.readFileSync(BUILD_PATH + '/index.html', 'utf8');
38+
var input = fs.readFileSync(BUILD_HTML, 'utf8');
3839
var result = validator.validateString(input);
39-
((result.status === 'PASS') ? console.log : console.error)(result.status);
40+
((result.status === 'PASS') ? console.log : console.error)(BUILD_HTML + ": " + result.status);
4041
for (var ii = 0; ii < result.errors.length; ii++) {
4142
var error = result.errors[ii];
4243
var msg = 'line ' + error.line + ', col ' + error.col + ': ' + error.message;
@@ -48,4 +49,7 @@ gulp.task('validate', function() {
4849
});
4950
});
5051

51-
gulp.task('default', ['purify']);
52+
// Build task cleans the CSS and inlines it
53+
gulp.task('build', ['inline-css']);
54+
// Default task will only validate the build output
55+
gulp.task('default', ['validate']);

0 commit comments

Comments
 (0)