forked from angular/material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
143 lines (127 loc) · 4.23 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
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 config = {
demoFolder: 'demo-partials'
};
module.exports = function(gulp, IS_RELEASE_BUILD) {
gulp.task('docs', ['docs-js', 'docs-css', 'docs-demo-scripts']);
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', ['docs-app', 'docs-html2js', 'demos', 'build'], function() {
return gulp.src([
'bower_components/angularytics/dist/angularytics.js',
'dist/angular-material.js',
'dist/docs/js/**/*.js'
])
.pipe(concat('docs.js'))
.pipe(gulpif(IS_RELEASE_BUILD, uglify()))
.pipe(gulp.dest('dist/docs'));
});
gulp.task('docs-css', ['docs-app', 'build'], function() {
return gulp.src([
'dist/angular-material.css',
'dist/themes/*.css',
'docs/app/css/highlightjs-codepen.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'));
});
};