Skip to content

Commit

Permalink
Fix static checking support (jshint, coffeelint, tslint)
Browse files Browse the repository at this point in the history
Close #277
  • Loading branch information
Toilal committed Feb 4, 2015
1 parent d28665b commit 1018e12
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 29 deletions.
15 changes: 4 additions & 11 deletions app/src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ module.exports = function () {
if (this.props.cssPreprocessor.key !== 'none') {
this.injectTaskDeps.push('\'styles\'');
}
if (this.props.jsPreprocessor.key !== 'none') {
if (this.props.jsPreprocessor.key === 'traceur') {
this.injectTaskDeps.push('\'browserify\'');
} else {
this.injectTaskDeps.push('\'scripts\'');
}
if (this.props.jsPreprocessor.key === 'traceur') {
this.injectTaskDeps.push('\'browserify\'');
} else {
this.injectTaskDeps.push('\'scripts\'');
}

// Wiredep exclusions
Expand Down Expand Up @@ -199,11 +197,6 @@ module.exports = function () {
return /styles\.js/.test(path);
});
}
if(this.props.jsPreprocessor.key === 'none') {
templateFiles = _.reject(templateFiles, function(path) {
return /scripts\.js/.test(path);
});
}
if(this.props.jsPreprocessor.key !== 'typescript') {
staticFiles = _.reject(staticFiles, function(path) {
return /tsd\.js/.test(path);
Expand Down
13 changes: 11 additions & 2 deletions app/templates/_gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ gulp.paths = {
e2e: '<%= props.paths.e2e %>'
};

gulp.errorHandler = function(title) {
gulp.context = {
failOnLintErrors: true,
failOnCompileErrors: true
};

gulp.errorHandler = function(title, throw_) {
return function(err) {
gutil.log(gutil.colors.red('[' + title + ']'), err.toString());
this.emit('end');
if (throw_) {
throw err;
} else {
this.emit('end');
}
};
};

Expand Down
1 change: 1 addition & 0 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"<%= props.htmlPreprocessor.module %>": "<%= props.htmlPreprocessor.version %>",
<% } %>
"main-bower-files": "~2.4.0",
"merge-stream": "~0.1.7",
"jshint-stylish": "~1.0.0",
"wiredep": "~2.2.0",
"karma-jasmine": "~0.3.1",
Expand Down
46 changes: 31 additions & 15 deletions app/templates/gulp/_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
<% } if (props.jsPreprocessor.key === '6to5') { %>
var to5ify = require('6to5ify');
var merge = require('merge-stream');
<% } %>

var paths = gulp.paths;
Expand All @@ -23,26 +24,37 @@ gulp.task('scripts', ['tsd:install'], function () {
<% } else { %>
gulp.task('scripts', function () {
<% } %>
<% if (props.jsPreprocessor.key !== '6to5') { %>
return gulp.src(paths.src + '/{app,components}/**/*.<%= props.jsPreprocessor.extension %>')
<% if (props.jsPreprocessor.extension === 'js') { %>
var scripts = gulp.src(paths.src + '/{app,components}/**/*.<%= props.jsPreprocessor.extension %>')
<% if (props.jsPreprocessor.extension === 'js') { %>
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
<% } if (props.jsPreprocessor.key !== 'none') { %>
.pipe($.jshint.reporter('jshint-stylish'));
if (gulp.context.failOnLintErrors) {
scripts = scripts.pipe($.jshint.reporter('fail'));
}
<% } else if (props.jsPreprocessor.extension === 'coffee') { %>
.pipe($.coffeelint())
.pipe($.coffeelint.reporter());
if (gulp.context.failOnLintErrors) {
scripts = scripts.pipe($.coffeelint.reporter('fail'));
}
<% } else if (props.jsPreprocessor.extension === 'ts') { %>
.pipe($.tslint())
.pipe($.tslint.report('prose', {emitError: gulp.context.failOnLintErrors}));
<% } %>

<% if (props.jsPreprocessor.key !== '6to5') { %>
scripts = scripts
<% if (props.jsPreprocessor.key !== 'none') { %>
.pipe($.sourcemaps.init())
<% } if (props.jsPreprocessor.key === 'traceur') { %>
.pipe($.traceur())
.on('error', gulp.errorHandler('Traceur'))
.on('error', gulp.errorHandler('Traceur', gulp.context.failOnCompileErrors))
<% } if (props.jsPreprocessor.key === 'coffee') { %>
.pipe($.coffeelint())
.pipe($.coffeelint.reporter())
.pipe($.coffee())
.on('error', gulp.errorHandler('CoffeeScript'))
.on('error', gulp.errorHandler('CoffeeScript', gulp.context.failOnCompileErrors))
<% } if (props.jsPreprocessor.key === 'typescript') { %>
.pipe($.tslint())
.pipe($.tslint.report('prose', { emitError: false }))
.pipe($.typescript({sortOutput: true}))
.on('error', gulp.errorHandler('TypeScript'))
.on('error', gulp.errorHandler('TypeScript', gulp.context.failOnCompileErrors))
<% } %>
<% if (props.jsPreprocessor.key !== 'none') { %>
.pipe($.sourcemaps.write())
Expand All @@ -56,17 +68,21 @@ gulp.task('scripts', function () {
.pipe(gulp.dest(paths.tmp + '/serve/'))
<% } %>
.pipe($.size());

return scripts;
<% } else { %>
return browserify({ debug: true })
var browserifyStream = browserify({ debug: true })
.add('./' + paths.src + '/app/index.js')
.transform(to5ify)
.bundle()
.on('error', gulp.errorHandler('Browserify'))
.on('error', gulp.errorHandler('Browserify', gulp.context.failOnCompileErrors))
.pipe(source('index.js'))
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.sourcemaps.write())
.pipe(gulp.dest(paths.tmp + '/serve/app'));

return merge(browserifyStream, scripts)
<% } %>
});

Expand All @@ -75,7 +91,7 @@ gulp.task('browserify', ['scripts'], function () {
return browserify({ debug: true })
.add('./' + paths.tmp + '/<%= props.jsPreprocessor.key %>/app/index.js')
.bundle()
.on('error', gulp.errorHandler('Browserify'))
.on('error', gulp.errorHandler('Browserify', gulp.context.failOnCompileErrors))
.pipe(source('index.js'))
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
Expand Down
2 changes: 2 additions & 0 deletions app/templates/gulp/_watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ gulp.task('watch', ['inject'], function () {
<% } else { %>
gulp.task('watch', ['markups', 'inject'], function () {
<% } %>
gulp.context.failOnLintErrors = false;
gulp.context.failOnCompileErrors = false;
gulp.watch([
paths.src + '/*.html',
paths.src + '/{app,components}/**/*.<%= props.cssPreprocessor.extension %>',
Expand Down
1 change: 1 addition & 0 deletions test/deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"gulp-protractor": "~0.0.11",
"gulp-karma": "~0.0.4",
"main-bower-files": "~2.4.0",
"merge-stream": "~0.1.7",
"jshint-stylish": "~1.0.0",
"wiredep": "~2.2.0",
"karma-jasmine": "~0.3.1",
Expand Down
2 changes: 1 addition & 1 deletion test/test-files-generate.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ describe('gulp-angular generator', function () {
]);

assert.fileContent([].concat(expectedGulpContent, [
['gulp/inject.js', /gulp\.task\(\'inject\', \[\'styles\'\]/],
['gulp/inject.js', /gulp\.task\(\'inject\', \[\'styles\', \'scripts\'\]/],
['gulp/inject.js', /paths\.src \+ '\/{app,components}\/\*\*\/\*\.js'/]
]));

Expand Down

0 comments on commit 1018e12

Please sign in to comment.