forked from Kimilhee/literallycanvas
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
119 lines (98 loc) · 3.37 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
var browserify = require('browserify');
var gulp = require('gulp');
var connect = require('gulp-connect');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify')
var uglify = require('gulp-uglify');
var coffee = require('gulp-coffee');
var babel = require('gulp-babel');
var preprocess = require('gulp-preprocess');
var preprocessify = require('preprocessify');
var merge = require('merge-stream');
gulp.task('commonjs', function() {
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md
var babelTrans = gulp.src(['./src/**/*.js', './src/**/*.jsx'])
.pipe(preprocess({context: { INCLUDE_GUI: true }}))
.pipe(babel())
.pipe(gulp.dest('./lib/js/'));
var coffeeTrans = gulp.src('./src/**/*.coffee')
.pipe(preprocess({context: { INCLUDE_GUI: true }}))
.pipe(coffee({ bare: true }))
.pipe(gulp.dest('./lib/js/'));
return merge(babelTrans, coffeeTrans);
});
gulp.task('sass', function() {
return gulp.src('./scss/**/*.scss')
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(gulp.dest('./lib/css/'))
.pipe(connect.reload())
});
gulp.task('browserify-lc-main', function() {
var bundleStream = browserify({
basedir: 'src', extensions: ['.js', '.jsx', '.coffee'], debug: true, standalone: 'LC',
debug: false
}).add('./index.coffee')
.external('react')
.external('react-dom')
.transform(preprocessify({ INCLUDE_GUI: true }, {includeExtensions: ['.coffee'], type: 'coffee'}))
.transform('coffeeify')
.transform('babelify')
.bundle()
.on('error', function (err) {
if (err) {
console.error(err.toString());
}
});
return bundleStream
.pipe(source('./src/index.coffee'))
.pipe(rename('literallycanvas.js'))
.pipe(gulp.dest('./lib/js/'))
.pipe(connect.reload());
});
gulp.task('browserify-lc-core', function() {
var bundleStream = browserify({
basedir: 'src', extensions: ['.js', '.jsx', '.coffee'], debug: true, standalone: 'LC',
debug: false
}).add('./index.coffee')
.transform(preprocessify({}, {includeExtensions: ['.coffee'], type: 'coffee'}))
.transform('coffeeify')
.transform('babelify')
.bundle()
.on('error', function (err) {
if (err) {
console.error(err.toString());
}
});
return bundleStream
.pipe(source('./src/index.coffee'))
.pipe(rename('literallycanvas-core.js'))
.pipe(gulp.dest('./lib/js/'))
.pipe(connect.reload());
});
gulp.task('uglify', ['browserify-lc-main', 'browserify-lc-core'], function() {
return gulp.src(['./lib/js/literallycanvas?(-core).js'])
.pipe(uglify())
.pipe(rename({
suffix: ".min"
}))
.pipe(gulp.dest('./lib/js'));
});
gulp.task('default', ['uglify', 'sass'], function() {
});
gulp.task('demo-reload', function () {
return gulp.src('demo/*').pipe(connect.reload());
});
gulp.task('watch', function() {
gulp.watch(['src/*.coffee', 'src/*/*.coffee', 'src/*.js', 'src/*/*.js', 'src/*/*.jsx'], ['browserify-lc-main', 'browserify-lc-core']);
gulp.watch('scss/*.scss', ['sass']);
gulp.watch('demo/*', ['demo-reload']);
});
gulp.task('serve', function() {
connect.server({
livereload: {port: 35728}
});
});
gulp.task('dev', ['browserify-lc-main', 'browserify-lc-core', 'sass', 'watch', 'serve'], function() {
});