forked from angular/material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
168 lines (150 loc) · 5.98 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
var gulp = require('gulp');
var Dgeni = require('dgeni');
var _ = require('lodash');
var concat = require('gulp-concat');
var fs = require('fs');
var gulpif = require('gulp-if');
var lazypipe = require('lazypipe');
var mkdirp = require('mkdirp');
var ngHtml2js = require('gulp-ng-html2js');
var path = require('path');
var sass = require('gulp-sass');
var through2 = require('through2');
var uglify = require('gulp-uglify');
var utils = require('../scripts/gulp-utils.js');
var karma = require('karma').server;
var argv = require('minimist')(process.argv.slice(2));
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var config = {
demoFolder: 'demo-partials'
};
gulp.task('demos', function() {
var demos = [];
return generateDemos()
.pipe(through2.obj(function(demo, enc, next) {
// Don't include file contents into the docs app,
// it saves space
demo.css.concat(demo.js).concat(demo.html).concat(demo.index)
.forEach(function(file) {
delete file.contents;
});
demos.push(demo);
next();
}, function(done) {
var demoIndex = _(demos)
.groupBy('moduleName')
.map(function(moduleDemos, moduleName) {
return {
name: moduleName,
label: utils.humanizeCamelCase( moduleName.split('.').pop() ),
demos: moduleDemos,
url: '/demo/' + moduleName
};
})
.value();
var dest = path.resolve(__dirname, '../dist/docs/js');
var file = "angular.module('docsApp').constant('DEMOS', " +
JSON.stringify(demoIndex, null, 2) + ");";
mkdirp.sync(dest);
fs.writeFileSync(dest + '/demo-data.js', file);
done();
}));
});
function generateDemos() {
return gulp.src('src/{components,services}/*/')
.pipe(through2.obj(function(folder, enc, next) {
var self = this;
var split = folder.path.split(path.sep);
var name = split.pop();
var moduleName = 'material.' + split.pop() + '.' + name;
utils.copyDemoAssets(name, 'src/components/', 'dist/docs/demo-partials/');
utils.readModuleDemos(moduleName, function(demoId) {
return lazypipe()
.pipe(gulpif, /.css$/, transformCss(demoId))
.pipe(gulp.dest, 'dist/docs/demo-partials/' + name)
();
})
.on('data', function(demo) {
self.push(demo);
})
.on('end', next);
function transformCss(demoId) {
return lazypipe()
.pipe(through2.obj, function(file, enc, next) {
file.contents = new Buffer(
'.' + demoId + ' {\n' + file.contents.toString() + '\n}'
);
next(null, file);
})
.pipe(sass)
();
}
}));
}
gulp.task('docs-generate', ['build'], function() {
var dgeni = new Dgeni([
require('./config')
]);
return dgeni.generate();
});
gulp.task('docs-app', ['docs-generate'], function() {
return gulp.src(['docs/app/**/*', '!docs/app/partials/**/*.html'])
.pipe(gulp.dest('dist/docs'));
});
gulp.task('docs-demo-scripts', ['demos'], function() {
return gulp.src('dist/docs/demo-partials/**/*.js')
.pipe(concat('docs-demo-scripts.js'))
.pipe(gulp.dest('dist/docs'));
});
gulp.task('docs-js-dependencies', ['build'], function() {
return gulp.src(['dist/angular-material.js','dist/angular-material.min.js'])
.pipe(gulp.dest('dist/docs'));
});
gulp.task('docs-js', ['docs-app', 'docs-html2js', 'demos', 'build', 'docs-js-dependencies'], function() {
return gulp.src([
'node_modules/angularytics/dist/angularytics.js',
'dist/docs/js/**/*.js'
])
.pipe(concat('docs.js'))
.pipe(gulpif(!argv.dev, uglify()))
.pipe(gulp.dest('dist/docs'));
});
gulp.task('docs-css-dependencies', ['build'], function() {
return gulp.src(['dist/angular-material.css','dist/angular-material.min.css'])
.pipe(gulp.dest('dist/docs'));
});
gulp.task('docs-css', ['docs-app', 'build', 'docs-css-dependencies'], function() {
return gulp.src([
'dist/themes/*.css',
'docs/app/css/highlightjs-material.css',
'docs/app/css/layout-demo.css',
'docs/app/css/style.css'
])
.pipe(concat('docs.css'))
.pipe(gulp.dest('dist/docs'));
});
gulp.task('docs-html2js', function() {
return gulp.src('docs/app/**/*.tmpl.html')
.pipe(ngHtml2js({
moduleName: 'docsApp',
declareModule: false
}))
.pipe(concat('docs-templates.js'))
.pipe(gulp.dest('dist/docs/js'));
});
gulp.task('docs-karma', ['docs-js'], function(done) {
var karmaConfig = {
singleRun: true,
autoWatch: false,
browsers : argv.browsers ? argv.browsers.trim().split(',') : ['Chrome'],
configFile: __dirname + '/../config/karma-docs.conf.js'
};
karma.start(karmaConfig, function(exitCode){
if (exitCode != 0) {
gutil.log(gutil.colors.red("Karma exited with the following exit code: " + exitCode));
process.exit(exitCode);
}
done();
});
});