forked from huangzhipeng/amazeui-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
179 lines (158 loc) · 4.35 KB
/
gulpfile.babel.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
169
170
171
172
173
174
175
176
177
178
179
import path from 'path';
import pkg from './package.json';
import del from 'del';
import runSequence from 'run-sequence';
import browserSync from 'browser-sync';
import webpack from 'webpack';
import webpackStream from 'webpack-stream';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import gulp from 'gulp';
import loadPlugins from 'gulp-load-plugins';
import buildConfig from './webpack.build';
import docsConfig from './webpack.docs';
const $ = loadPlugins();
const paths = {
src: {
docs: {
js: 'docs/app.js',
i: 'docs/assets/i/*',
less: 'docs/docs.less'
},
build: 'src/AMUIReact.js'
},
dist: {
docs: './www',
build: './dist',
lib: './lib'
}
};
const buildDate = $.util.date(Date.now(), 'isoDateTime');
const banner = [
'/*! <%= pkg.title %> v<%= pkg.version %>',
'by Amaze UI Team',
'(c) ' + $.util.date(Date.now(), 'UTC:yyyy') + ' AllMobilize, Inc.',
'Licensed under <%= pkg.license %>',
buildDate + ' */\n'
].join(' | ');
gulp.task('build:pack', () => {
return gulp.src(paths.src.build)
.pipe(webpackStream(buildConfig))
.pipe($.replace('__VERSION__', pkg.version))
.pipe($.header(banner, {pkg: pkg}))
.pipe(gulp.dest(paths.dist.build))
.pipe($.uglify())
.pipe($.rename({suffix: '.min'}))
.pipe($.header(banner, {pkg: pkg}))
.pipe(gulp.dest(paths.dist.build))
.pipe($.size({showFiles: true, title: 'minified'}))
.pipe($.size({showFiles: true, gzip: true, title: 'gzipped'}));
});
gulp.task('build:docs', () => {
return gulp.src('docs/app.js')
.pipe(webpackStream(docsConfig))
.pipe($.replace('__VERSION__', pkg.version, {skipBinary: true}))
.pipe(gulp.dest(paths.dist.docs))
.pipe($.size({
showFiles: true,
title: 'Docs bundle'
}))
.pipe($.size({
showFiles: true,
gzip: true,
title: 'Docs bundle gzipped'
}));
});
gulp.task('build:jsx', () => {
return gulp.src(['src/**/*.js', '!src/__tests__/*.js'])
.pipe($.if((file) => {
return file.path.indexOf('AMUIReact.js') > -1;
}, $.replace('__VERSION__', pkg.version)))
.pipe($.babel())
.pipe(gulp.dest(paths.dist.lib));
});
gulp.task('clean', () => {
return del([
paths.dist.lib,
paths.dist.build,
paths.dist.docs,
]);
});
gulp.task('build', (cb) => {
runSequence(
'clean',
['build:pack', 'build:docs', 'build:jsx'],
cb);
});
// upload docs assets to Qiniu
gulp.task('publish:cdn', () => {
gulp.src(['www/**/*', '!www/**/*.html'])
.pipe($.qndn.upload({
prefix: 'assets/react',
qn: {
accessKey: process.env.qnAK,
secretKey: process.env.qnSK,
bucket: process.env.qnBucketUIS,
domain: process.env.qnDomainUIS
}
}));
});
gulp.task('publish:npm', (done) => {
require('child_process')
.spawn('npm', ['publish'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('publish:tag', (done) => {
var v = 'v' + pkg.version;
var message = 'Release ' + v;
$.git.tag(v, message, (err) => {
if (err) {
throw err;
}
$.git.push('origin', 'master', (error) => {
if (error) {
throw error;
}
done();
});
});
});
// TODO: complete publish tasks.
gulp.task('publish', (cb) => {
runSequence(
'build',
[
// to be
],cb
);
});
gulp.task('dev', () => {
const bundler = webpack(docsConfig);
const bs = browserSync.create();
bs.init({
logPrefix: 'AMR',
server: {
baseDir: ['www', 'node_modules/amazeui/dist'],
middleware: [
// @see https://github.com/BrowserSync/browser-sync/issues/204
/*function(req, res, next) {
var match = req.url.match(/\/[css|fonts|i].+\..+|\/app\.js|\/app\.min\.js/g);
req.url = match ? match[0] : '/index.html';
return next();
},*/
webpackDevMiddleware(bundler, {
// IMPORTANT: dev middleware can't access config, so we should
// provide publicPath by ourselves
publicPath: docsConfig.output.publicPath,
// pretty colored output
stats: {colors: true}
// for other settings see
// http://webpack.github.io/docs/webpack-dev-middleware.html
}),
// bundler should be the same as above
webpackHotMiddleware(bundler)
]
},
});
});
gulp.task('default', ['dev']);