-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathgulpfile.js
125 lines (111 loc) · 3.38 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
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
var babel = require('gulp-babel');
var del = require('del');
var githubPages = require('gulp-gh-pages');
var gulp = require('gulp');
var gulpWebpack = require('gulp-webpack');
var livereload = require('gulp-livereload');
var merge = require('merge-stream');
var rename = require('gulp-rename');
var spawn = require('child_process').spawn;
var webpack = require('webpack');
var uglify = require('gulp-uglify');
var SITE_OUTPUT_DIR = 'build/site/';
var PACKAGE_OUTPUT_DIR = 'build/package/';
gulp.task('default', ['build']);
gulp.task('build', [
'build-htmltojsx', 'build-magic', 'build-site-htmltojsx', 'build-site-misc',
'build-package'
]);
gulp.task('build-htmltojsx', function() {
return gulp.src('src/htmltojsx.js')
.pipe(gulpWebpack({
output: {
library: 'HTMLtoJSX',
libraryTarget: 'umd',
filename: 'htmltojsx.js',
},
plugins: [
new webpack.DefinePlugin({
IN_BROWSER: true,
'process.env.NODE_ENV': '"production"'
}),
],
}))
.pipe(gulp.dest(SITE_OUTPUT_DIR))
.pipe(uglify({ preserveComments: 'some' }))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(SITE_OUTPUT_DIR))
.pipe(livereload({ auto: false }));
});
gulp.task('build-magic', function() {
return gulp.src('src/magic.js')
.pipe(gulpWebpack({
output: {
library: 'ReactMagic',
libraryTarget: 'umd',
filename: 'magic.js',
},
plugins: [
new webpack.DefinePlugin({
IN_BROWSER: true,
'process.env.NODE_ENV': '"production"'
}),
],
}))
.pipe(gulp.dest(SITE_OUTPUT_DIR))
.pipe(uglify({ preserveComments: 'some' }))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(SITE_OUTPUT_DIR))
.pipe(livereload({ auto: false }));
});
gulp.task('build-site-htmltojsx', function() {
return gulp.src('src/htmltojsx-component.js')
.pipe(babel())
.pipe(gulp.dest(SITE_OUTPUT_DIR));
});
gulp.task('build-site-misc', function() {
return gulp.src(['site/*', 'test/*'])
.pipe(gulp.dest(SITE_OUTPUT_DIR))
.pipe(livereload({ auto: false }));
});
gulp.task('build-package', function() {
var main = gulp
.src([
'**/*', '!README*.md', '!node_modules{,/**}', '!build{,/**}',
'!site{,/**}', '!temp{,/**}',
])
.pipe(gulp.dest(PACKAGE_OUTPUT_DIR));
var readme = gulp.src('README-htmltojsx.md')
.pipe(rename('README.md'))
.pipe(gulp.dest(PACKAGE_OUTPUT_DIR));
return merge(main, readme);
});
gulp.task('publish-site', ['build'], function() {
return gulp.src('build/site/**/*')
.pipe(githubPages({}));
});
gulp.task('publish-package', ['build'], function(callback) {
spawn(
'npm',
['publish', PACKAGE_OUTPUT_DIR],
{ stdio: 'inherit' }
).on('close', callback);
});
gulp.task('clean', function(callback) {
del(['build'], callback);
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch(['site/*', 'test/*'], ['build-site-misc']);
gulp.watch('src/htmltojsx.js', ['build-htmltojsx', 'build-site-htmltojsx']);
gulp.watch('src/htmltojsx-component.js', ['build-site-htmltojsx']);
});