forked from skratchdot/react-bootstrap-multiselect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
107 lines (95 loc) · 2.6 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
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var cssmin = require('gulp-cssmin');
var exec = require('child_process').exec;
var less = require('gulp-less');
var rename = require("gulp-rename");
var uglify = require('gulp-uglify');
var connect = require('gulp-connect');
var react = require('gulp-react');
var fs = require('fs');
var wrap = require("gulp-wrap");
var port = 8080;
gulp.task('bootstrap-dropdown', function () {
gulp.src('./node_modules/bootstrap/js/dropdown.js')
.pipe(wrap('var jQuery = require("jquery");\nexports.init = function () {\n<%= contents %>};'))
.pipe(rename('bootstrap-dropdown.js'))
.pipe(gulp.dest('./src'))
.pipe(gulp.dest('./lib'));
});
gulp.task('lint', function () {
exec([
'node',
'./node_modules/jsxhint/cli.js',
//'--show-non-errors',
'--config',
'./.jshint',
'./index.js ./demo/src/*.js'
].join(' '),
function (err, stdout, stderr) {
if (stdout) {
console.log(stdout);
}
});
});
gulp.task('prepublish', ['bootstrap-dropdown'], function () {
gulp.src('./src/index.js')
.pipe(react())
.pipe(gulp.dest('./lib'));
});
gulp.task('fonts', function () {
gulp.src('./node_modules/bootstrap/dist/fonts/*')
.pipe(gulp.dest('./demo/www/fonts/'));
});
gulp.task('app-content', function () {
var content = fs.readFileSync('./demo/src/App.js', 'utf-8');
fs.writeFileSync(
'./demo/src/AppContent.js',
[
'/* autogenerated by gulpfile.js */',
'exports.content = ' + JSON.stringify(content) + ';'
].join('\n'),
'utf-8'
);
});
gulp.task('demo', function () {
var buildStyles = function (name) {
gulp.src('./demo/src/less/' + name + '.less')
.pipe(less())
.pipe(rename(name + '.debug.css'))
.pipe(gulp.dest('./demo/www/css/'))
.pipe(cssmin())
.pipe(rename(name + '.min.css'))
.pipe(gulp.dest('./demo/www/css/'));
};
// styles
buildStyles('demo');
buildStyles('bootstrap-multiselect');
// scripts
gulp.src('./demo/src/App.js')
.pipe(browserify({
debug: true,
transform: ['reactify']
}))
.pipe(rename('demo.debug.js'))
.pipe(gulp.dest('./demo/www/js/'))
.pipe(uglify())
.pipe(rename('demo.min.js'))
.pipe(gulp.dest('./demo/www/js/'));
});
gulp.task('server', function() {
connect.server({
root: './demo/www',
livereload: true,
port: 8080
});
});
gulp.task('watch', function () {
gulp.watch(['./src/index.js','./demo/src/**/*.js'], ['build']);
});
gulp.task('build', ['lint', 'fonts', 'app-content', 'demo', 'prepublish']);
gulp.task('default', ['bootstrap-dropdown', 'build', 'server', 'watch']);
//handle errors
process.on('uncaughtException', function (e) {
console.error(e);
});