Skip to content

Commit

Permalink
Merge pull request #349 from Swiip/new-other-task
Browse files Browse the repository at this point in the history
Replace misc task by a new "other" task
  • Loading branch information
Mehdy Dara committed Feb 20, 2015
2 parents 2a53c8a + 212a071 commit 60d7c24
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 37 deletions.
1 change: 0 additions & 1 deletion app/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"src/favicon.ico",
"src/404.html",
"src/assets/images/yeoman.png",
"src/assets/fonts/README",
"karma.conf.js",
"protractor.conf.js",
"e2e/main.spec.js"
Expand Down
3 changes: 0 additions & 3 deletions app/src/mock-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,5 @@ module.exports = {
cssPreprocessor: model.cssPreprocessor.values['node-sass'],
jsPreprocessor: model.jsPreprocessor.values.none,
htmlPreprocessor: model.htmlPreprocessor.values.none
},
libRegexp: function(name, version) {
return new RegExp('"' + name + '": "' + version + '"');
}
};
22 changes: 22 additions & 0 deletions app/src/preprocessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ function rejectWithRegexp(regexp) {

module.exports = function(GulpAngularGenerator) {

/**
* List files extension processed by the generator
*/
GulpAngularGenerator.prototype.computeProcessedFileExtension = function computeProcessedFileExtension() {
this.processedFileExtension = [
'html',
'css',
'js',
this.props.cssPreprocessor.extension,
this.props.jsPreprocessor.extension,
this.props.htmlPreprocessor.extension
];
if (this.imageMin) {
this.processedFileExtension = this.processedFileExtension.concat(['jpg', 'png', 'gif', 'svg']);
}
this.processedFileExtension = _.chain(this.processedFileExtension)
.uniq()
.filter(_.isString)
.value()
.join(',');
};

/**
* Compute gulp inject task dependencies depending on js and css preprocessors
*/
Expand Down
35 changes: 20 additions & 15 deletions app/templates/gulp/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,46 @@ module.exports = function(options) {
.pipe(gulp.dest(options.dist + '/'))
.pipe($.size({ title: options.dist + '/', showFiles: true }));
});

<% if (imageMin) { %>
gulp.task('images', function () {
return gulp.src(options.src + '/assets/images/**/*')
<% if (imageMin) { %>
.pipe($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
<% } %>
.pipe(gulp.dest(options.dist + '/assets/images/'));
});
<% } %>

// Only applies for fonts from bower dependencies
// Custom fonts are handled by the "other" task
gulp.task('fonts', function () {
var customFonts = gulp.src(options.src + '/assets/fonts/**/*')
.pipe(gulp.dest(options.dist + '/assets/fonts/'));

var bowerFonts = gulp.src($.mainBowerFiles())
return gulp.src($.mainBowerFiles())
.pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}'))
.pipe($.flatten())
.pipe(gulp.dest(options.dist + '/fonts/'));

return merge(customFonts, bowerFonts);
});

gulp.task('misc', function () {
return gulp.src(options.src + '/**/*.ico')
gulp.task('other', function () {
return gulp.src([
options.src + '/**/*',
'!' + options.src + '/**/*.{<%= processedFileExtension %>}'
])
.pipe(gulp.dest(options.dist + '/'));
});

gulp.task('clean'
<% if (props.jsPreprocessor.key === 'typescript') { %>, ['tsd:purge']
<% } %>, function (done) {
<% if (props.jsPreprocessor.key === 'typescript') { %>
gulp.task('clean', ['tsd:purge'], function (done) {
<% } else { %>
gulp.task('clean', function (done) {
<% } %>
$.del([options.dist + '/', options.tmp + '/'], done);
});

gulp.task('build', ['html', 'images', 'fonts', 'misc']);
<% if (imageMin) { %>
gulp.task('build', ['html', 'images', 'fonts', 'other']);
<% } else { %>
gulp.task('build', ['html', 'fonts', 'other']);
<% } %>
};
1 change: 0 additions & 1 deletion app/templates/src/assets/fonts/README

This file was deleted.

17 changes: 0 additions & 17 deletions test/node/test-mock-prompts.js

This file was deleted.

17 changes: 17 additions & 0 deletions test/node/test-preprocessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ describe('gulp-angular generator preprocessors script', function () {
];
});

describe('compute file extension processed by the generator', function() {
it('should clean up the list and join with ,', function() {
generator.props = {
cssPreprocessor: { extension: null },
jsPreprocessor: { extension: 'js' },
htmlPreprocessor: { extension: 'jade' }
};
generator.imageMin = true;
generator.computeProcessedFileExtension();
generator.processedFileExtension.should.be.equal('html,css,js,jade,jpg,png,gif,svg');

generator.imageMin = false;
generator.computeProcessedFileExtension();
generator.processedFileExtension.should.be.equal('html,css,js,jade');
});
});

describe('compute dependencies for the gulp inject task', function() {
it('should be empty if no preprocessors', function() {
generator.props = {
Expand Down
1 change: 1 addition & 0 deletions test/template/mock-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = function() {
isVendorStylesPreprocessed: false,
injectTaskDeps: null,
wiredepExclusions: [],
processedFileExtension: null,
includeModernizr: false,
imageMin: false,
qrCode: false
Expand Down

0 comments on commit 60d7c24

Please sign in to comment.