forked from angular/material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
137 lines (120 loc) · 4.37 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var _ = require('lodash');
var changelog = require('conventional-changelog');
var dgeni = require('dgeni');
var gulp = require('gulp');
var karma = require('karma').server;
var pkg = require('./package.json');
var argv = require('minimist')(process.argv.slice(2));
var concat = require('gulp-concat');
var footer = require('gulp-footer');
var gulpif = require('gulp-if');
var header = require('gulp-header');
var jshint = require('gulp-jshint');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var stripDebug = require('gulp-strip-debug');
var template = require('gulp-template');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var replace = require('gulp-replace');
var buildConfig = require('./config/build.config');
var karmaConf = require('./config/karma.conf.js');
var IS_RELEASE_BUILD = !!argv.release;
if (IS_RELEASE_BUILD) {
gutil.log(
gutil.colors.red('--release:'),
'Building release version (minified, debugs stripped)...'
);
}
gulp.task('default', ['build']);
gulp.task('build', ['scripts', 'sass']);
gulp.task('validate', ['jshint', 'karma']);
gulp.task('watch', ['build'], function() {
gulp.watch(['src/**/*.{scss,js,html}'], ['build']);
});
gulp.task('docs-assets', ['build'], function() {
return gulp.src([
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/angular.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angularytics/dist/angularytics.js',
'config/lib/angular-animate-sequence/angular-animate-sequence.js',
'config/lib/angular-animate-sequence/angular-animate-stylers.js',
buildConfig.dist + '/material-design.js',
buildConfig.dist + '/material-design.css'
])
.pipe(gulp.dest(buildConfig.docsDist + '/lib'));
});
gulp.task('docs-html', function() {
return gulp.src('docs/app/**/*.html', { base: 'docs/app' })
.pipe(gulpif(IS_RELEASE_BUILD,
replace(/material-design\.(js|css)/g, 'material-design.min.$1')))
.pipe(gulp.dest(buildConfig.docsDist));
});
gulp.task('docs-app', function() {
return gulp.src(['docs/app/**/*', '!docs/app/**/*.html'], { base: 'docs/app' })
.pipe(gulp.dest(buildConfig.docsDist));
});
gulp.task('docs', ['docs-assets', 'docs-app', 'docs-html'], function() {
return dgeni.generator(__dirname + '/docs/index.js')();
});
gulp.task('jshint', function() {
return gulp.src(
buildConfig.paths.js.concat(buildConfig.paths.test)
)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(require('jshint-summary')({
fileColCol: ',bold',
positionCol: ',bold',
codeCol: 'green,bold',
reasonCol: 'cyan'
})))
.pipe(jshint.reporter('fail'));
});
argv.browsers && (karmaConf.browsers = argv.browsers.trim().split(','));
gulp.task('karma', function(done) {
karma.start(_.assign({}, karmaConf, {singleRun: true}), done);
});
gulp.task('karma-watch', function(done) {
karma.start(_.assign({}, karmaConf, {singleRun: false}), done);
});
//TODO build components individually
//Factor scripts and scss out into a task that works on either
//an individual component or the whole bundle
gulp.task('scripts', function() {
return gulp.src(buildConfig.paths.js)
.pipe(concat('material-design.js'))
.pipe(header(_.template(buildConfig.componentsModule, {
components: buildConfig.components.map(enquote)
})))
.pipe(header(buildConfig.closureStart))
.pipe(footer(buildConfig.closureEnd))
.pipe(header(buildConfig.banner))
.pipe(gulp.dest(buildConfig.dist))
.pipe(gulpif(IS_RELEASE_BUILD, uglify({
preserveComments: 'some' //preverse banner
})))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest(buildConfig.docsDist + '/lib'));
});
gulp.task('sass', function() {
return gulp.src(buildConfig.paths.scss)
.pipe(header(buildConfig.banner))
.pipe(sass({
// Normally, gulp-sass exits on error. This is good during normal builds.
// During watch builds, we only want to log the error.
errLogToConsole: argv._.indexOf('watch') > -1
}))
.pipe(concat('material-design.css'))
.pipe(gulp.dest(buildConfig.dist))
.pipe(gulpif(IS_RELEASE_BUILD, minifyCss()))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(buildConfig.docsDist + '/lib'));
});
function enquote(str) {
return '"' + str + '"';
}