Skip to content

Commit

Permalink
style injection of both deps and sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiip committed Apr 2, 2015
1 parent 75de994 commit f08778d
Show file tree
Hide file tree
Showing 33 changed files with 131 additions and 82 deletions.
2 changes: 1 addition & 1 deletion app/src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = function(GulpAngularGenerator) {
if (this.props.ui.key === 'bootstrap') {
if(this.props.bootstrapComponents.key !== 'official') {
if(this.props.cssPreprocessor.extension === 'scss') {
this.wiredepExclusions.push('/bootstrap-sass-official/');
this.wiredepExclusions.push('/bootstrap-sass-official\\/.*\\.js/');
} else {
this.wiredepExclusions.push('/bootstrap\\.js/');
}
Expand Down
7 changes: 6 additions & 1 deletion app/templates/_gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var gulp = require('gulp');
var gutil = require('gulp-util');
var _ = require('lodash');
var wrench = require('wrench');

var options = {
Expand All @@ -15,6 +14,12 @@ var options = {
gutil.log(gutil.colors.red('[' + title + ']'), err.toString());
this.emit('end');
};
},
wiredep: {
directory: 'bower_components'
<% if(wiredepExclusions.length > 0) { %>,
exclude: [<%= wiredepExclusions.join(', ') %>]
<% } %>
}
};

Expand Down
11 changes: 2 additions & 9 deletions app/templates/gulp/_inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = function(options) {
options.src + '/app/**/*.css'
], { read: false });
<% } %>

<% if (props.jsPreprocessor.key === 'typescript') { %>

var sortOutput = require('../' + options.tmp + '/sortOutput.json');
<% } %>

Expand Down Expand Up @@ -49,17 +49,10 @@ module.exports = function(options) {
addRootSlash: false
};
var wiredepOptions = {
directory: 'bower_components'
<% if(wiredepExclusions.length > 0) { %>,
exclude: [<%= wiredepExclusions.join(', ') %>]
<% } %>
};
return gulp.src(options.src + '/*.html')
.pipe($.inject(injectStyles, injectOptions))
.pipe($.inject(injectScripts, injectOptions))
.pipe(wiredep(wiredepOptions))
.pipe(wiredep(options.wiredep))
.pipe(gulp.dest(options.tmp + '/serve'));

});
Expand Down
36 changes: 21 additions & 15 deletions app/templates/gulp/_styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var browserSync = require('browser-sync');

var $ = require('gulp-load-plugins')();

var wiredep = require('wiredep').stream;

module.exports = function(options) {
gulp.task('styles', function () {
<% if (props.cssPreprocessor.key === 'less') { %>
Expand Down Expand Up @@ -37,6 +39,7 @@ module.exports = function(options) {
};

var indexFilter = $.filter('index.<%= props.cssPreprocessor.extension %>');
var vendorFilter = $.filter('vendor.<%= props.cssPreprocessor.extension %>');
<% if (props.cssPreprocessor.key === 'ruby-sass') { %>
var cssFilter = $.filter('**/*.css');
<% } %>
Expand All @@ -45,28 +48,31 @@ module.exports = function(options) {
options.src + '/app/index.<%= props.cssPreprocessor.extension %>',
options.src + '/app/vendor.<%= props.cssPreprocessor.extension %>'
])
.pipe(indexFilter)
.pipe($.inject(injectFiles, injectOptions))
.pipe(indexFilter.restore())
.pipe(indexFilter)
.pipe($.inject(injectFiles, injectOptions))
.pipe(indexFilter.restore())
.pipe(vendorFilter)
.pipe(wiredep(options.wiredep))
.pipe(vendorFilter.restore())
<% if (props.cssPreprocessor.key === 'ruby-sass') { %>
.pipe($.rubySass(sassOptions)).on('error', options.errorHandler('RubySass'))
.pipe(cssFilter)
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.rubySass(sassOptions)).on('error', options.errorHandler('RubySass'))
.pipe(cssFilter)
.pipe($.sourcemaps.init({ loadMaps: true }))
<% } else { %>
.pipe($.sourcemaps.init())
.pipe($.sourcemaps.init())
<% } if (props.cssPreprocessor.key === 'less') { %>
.pipe($.less(lessOptions)).on('error', options.errorHandler('Less'))
.pipe($.less(lessOptions)).on('error', options.errorHandler('Less'))
<% } else if (props.cssPreprocessor.key === 'node-sass') { %>
.pipe($.sass(sassOptions)).on('error', options.errorHandler('Sass'))
.pipe($.sass(sassOptions)).on('error', options.errorHandler('Sass'))
<% } else if (props.cssPreprocessor.key === 'stylus') { %>
.pipe($.stylus()).on('error', options.errorHandler('Stylus'))
.pipe($.stylus()).on('error', options.errorHandler('Stylus'))
<% } %>
.pipe($.autoprefixer()).on('error', options.errorHandler('Autoprefixer'))
.pipe($.sourcemaps.write())
.pipe($.autoprefixer()).on('error', options.errorHandler('Autoprefixer'))
.pipe($.sourcemaps.write())
<% if (props.cssPreprocessor.key === 'ruby-sass') { %>
.pipe(cssFilter.restore())
.pipe(cssFilter.restore())
<% } %>
.pipe(gulp.dest(options.tmp + '/serve/app/'))
.pipe(browserSync.reload({ stream: true }));
.pipe(gulp.dest(options.tmp + '/serve/app/'))
.pipe(browserSync.reload({ stream: true }));
});
};
7 changes: 2 additions & 5 deletions app/templates/gulp/_unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ var _ = require('lodash');

module.exports = function(options) {
function listFiles(callback) {
var bowerDeps = wiredep({
directory: 'bower_components',
<% if(wiredepExclusions.length > 0) { %>
exclude: [<%= wiredepExclusions.join(', ') %>],
<% } %>
var wiredepOptions = _.extend({}, options.wiredep, {
dependencies: true,
devDependencies: true
});
var bowerDeps = wiredep(wiredepOptions);

var specFiles = [
options.src + '/**/*.spec.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ section.jumbotron {
}
}
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your less files automatically */
// injector
// endinjector
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ section.jumbotron {
}
}
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your sass files automatically */
// injector
// endinjector
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ section
&.pull-right
float right
width 50px

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your stylus files automatically */
// injector
// endinjector
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
less dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:less
// endbower
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
sass dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:scss
// endbower
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
stylus dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:styl
// endbower
5 changes: 5 additions & 0 deletions app/templates/src/app/_bootstrap/__bootstrap-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
width: 50px;
}
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your less files automatically */
// injector
// endinjector
5 changes: 5 additions & 0 deletions app/templates/src/app/_bootstrap/__bootstrap-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
width: 50px;
}
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your sass files automatically */
// injector
// endinjector
5 changes: 5 additions & 0 deletions app/templates/src/app/_bootstrap/__bootstrap-index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@

img.pull-right
width 50px

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your stylus files automatically */
// injector
// endinjector
10 changes: 4 additions & 6 deletions app/templates/src/app/_bootstrap/__bootstrap-vendor.less
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@import '../<%= computedPaths.appToBower %>/bower_components/bootstrap/less/bootstrap.less';

@icon-font-path: '../<%= computedPaths.appToBower %>/bower_components/bootstrap/fonts/';

/* Do not remove this comments bellow. It's the markers used by wiredep to inject
less dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:less
// endbower

@icon-font-path: '../<%= computedPaths.appToBower %>/bower_components/bootstrap/fonts/';
6 changes: 2 additions & 4 deletions app/templates/src/app/_bootstrap/__bootstrap-vendor.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
$icon-font-path: "../<%= computedPaths.appToBower %>/bower_components/bootstrap-sass-official/assets/fonts/bootstrap/";

@import '../<%= computedPaths.appToBower %>/bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap';

/* Do not remove this comments bellow. It's the markers used by wiredep to inject
sass dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:scss
// endbower
4 changes: 2 additions & 2 deletions app/templates/src/app/_bootstrap/__bootstrap-vendor.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
stylus dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:styl
// endbower
5 changes: 5 additions & 0 deletions app/templates/src/app/_foundation/__foundation-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
width: 50px;
}
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your less files automatically */
// injector
// endinjector
5 changes: 5 additions & 0 deletions app/templates/src/app/_foundation/__foundation-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@
width: 50px;
}
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your sass files automatically */
// injector
// endinjector
5 changes: 5 additions & 0 deletions app/templates/src/app/_foundation/__foundation-index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@

img.right
width 50px

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your stylus files automatically */
// injector
// endinjector
4 changes: 2 additions & 2 deletions app/templates/src/app/_foundation/__foundation-vendor.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
less dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:less
// endbower
6 changes: 4 additions & 2 deletions app/templates/src/app/_foundation/__foundation-vendor.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* The import of foundation is made manually because there is still no links of the
sass version in theit bower.json... */
@import '../<%= computedPaths.appToBower %>/bower_components/foundation/scss/foundation';

/* Do not remove this comments bellow. It's the markers used by wiredep to inject
sass dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:scss
// endbower
4 changes: 2 additions & 2 deletions app/templates/src/app/_foundation/__foundation-vendor.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
stylus dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:styl
// endbower
5 changes: 5 additions & 0 deletions app/templates/src/app/_none/__none-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@ a {
hr {
clear: both;
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your less files automatically */
// injector
// endinjector
5 changes: 5 additions & 0 deletions app/templates/src/app/_none/__none-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@ a {
hr {
clear: both;
}

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your sass files automatically */
// injector
// endinjector
5 changes: 5 additions & 0 deletions app/templates/src/app/_none/__none-index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ a

hr
clear both

/* Do not remove this comments bellow. It's the markers used by gulp-inject to inject
all your stylus files automatically */
// injector
// endinjector
4 changes: 2 additions & 2 deletions app/templates/src/app/_none/__none-vendor.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
less dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:less
// endbower
4 changes: 2 additions & 2 deletions app/templates/src/app/_none/__none-vendor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
sass dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:scss
// endbower
4 changes: 2 additions & 2 deletions app/templates/src/app/_none/__none-vendor.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Do not remove this comments bellow. It's the markers used by wiredep to inject
stylus dependencies when defined in the bower.json of your dependencies */
// injector
// endinjector
// bower:styl
// endbower
2 changes: 1 addition & 1 deletion test/node/test-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('gulp-angular generator ui script', function () {
cssPreprocessor: { extension: 'scss' }
};
generator.computeWiredepExclusions();
generator.wiredepExclusions[0].should.be.equal('/bootstrap-sass-official/');
generator.wiredepExclusions[0].should.be.equal('/bootstrap-sass-official\\/.*\\.js/');
generator.wiredepExclusions[1].should.be.equal('/bootstrap\\.css/');
});

Expand Down
10 changes: 10 additions & 0 deletions test/template/test-gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ describe('gulp-angular gulpfile template', function () {
result.should.match(/e2e: 'test\/e2e\/dir'/);
});

it('should configure wiredep with wiredep exclusions', function() {
model.wiredepExclusions = [];
var result = gulpfile(model);
result.should.not.match(/exclude:/);

model.wiredepExclusions = ['\'a\'', '\'b\''];
result = gulpfile(model);
result.should.match(/exclude: \['a', 'b'\]/);
});

});
10 changes: 0 additions & 10 deletions test/template/test-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,4 @@ describe('gulp-angular inject template', function () {
result.should.not.match(/order/);
});

it('should configure wiredep with wiredep exclusions', function() {
model.wiredepExclusions = [];
var result = inject(model);
result.should.not.match(/exclude:/);

model.wiredepExclusions = ['\'a\'', '\'b\''];
result = inject(model);
result.should.match(/exclude: \['a', 'b'\]/);
});

});
Loading

0 comments on commit f08778d

Please sign in to comment.