-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
177 lines (154 loc) · 4.39 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
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
var gulp = require('gulp');
var concat = require('gulp-concat');
var react = require('gulp-react');
var browserSync = require('browser-sync');
var browserReload = browserSync.reload;
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var reactify = require('reactify');
var streamify = require('gulp-streamify');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var copy = require('gulp-copy');
var del = require('del');
var _ = require('lodash');
var runSequence = require('run-sequence');
var uglify = require('gulp-uglify');
var cssmin = require('gulp-cssmin');
var buffer = require('vinyl-buffer');
var gutil = require('gulp-util');
var path = {
ALL: ['src/**/*.*'],
ENTRY_POINT: './src/app/main.js',
HTML: 'src/index.html',
GEOM: 'src/Geometry.js',
IMG: 'src/img/**/*.*',
STATIC: 'src/static/**/*.*',
JS: ['src/app/**/*.js'],
SCSS: ['src/style/**/*.scss'],
DEST_PROD: 'production',
DEST_DEV: 'development',
OUT: 'build.js'
};
function compileStyle(dest) {
var files = gulp.src([
'./src/style/app.scss'
])
.pipe(sass({
includePaths: [ './node_modules/foundation-apps/scss' ]
}))
.pipe(sass())
.pipe(cssmin())
.pipe(rename('contextual.css'))
.pipe(gulp.dest(dest))
.on('error', sass.logError);
return files;
}
function copyFiles(dest) {
var files = gulp.src([path.IMG, path.STATIC, path.HTML, path.GEOM])
.pipe(copy(dest, { prefix: 1 }));
return files;
}
function copyLib(dest) {
var files = gulp.src([path.GEOM])
.pipe(copy(dest, { prefix: 1 }));
return files;
}
gulp.task('sass:dev', function(cb) {
compileStyle(path.DEST_DEV).on('end', cb);
});
gulp.task('sass:prod', function(cb) {
compileStyle(path.DEST_PROD).on('end', cb);
});
gulp.task('copyFiles:dev', function(cb) {
copyFiles(path.DEST_DEV).on('end', cb);
});
gulp.task('copyFiles:prod', function(cb) {
copyFiles(path.DEST_PROD).on('end', cb);
});
gulp.task('copyLib:dev', function(cb) {
copyLib(path.DEST_DEV).on('end', cb);
});
gulp.task('copyLib:prod', function(cb) {
copyLib(path.DEST_PROD).on('end', cb);
});
gulp.task('cleanFiles:dev', function(cb){
del(['development'], cb);
});
gulp.task('cleanFiles:prod', function(cb){
del(['production'], cb);
});
gulp.task('buildJS:dev', function() {
return browserify('./src/app/Main.js')
.transform('reactify')
.bundle()
.on('error', function(e) {
console.log("ERROR");
console.log(e.message);
})
.pipe(source('contextual.js'))
.pipe(gulp.dest(path.DEST_DEV));
});
gulp.task('buildJS:prod', function() {
return browserify('./src/app/Main.js')
.transform('reactify')
.bundle()
.on('error', function(e) {
console.log("ERROR");
console.log(e.message);
})
.pipe(source('contextual.js'))
.pipe(buffer())
.pipe(uglify({output: {ascii_only:true}}).on('error', gutil.log))
.pipe(gulp.dest(path.DEST_PROD));
});
gulp.task('serve:dev', function() {
browserSync({
ui: false,
ghostMode: false,
logLevel: 'silent',
server: {
baseDir: path.DEST_DEV
},
open: false,
notify: false,
injectChanges: false,
minify: false,
scrollProportionally: false,
online: false,
reloadOnRestart: true,
browser: [ 'google chrome' ]
});
});
gulp.task('reload:dev', function() {
browserReload();
});
gulp.task('watch:html', function() {
gulp.watch([ path.HTML ], function() {
runSequence('copyFiles:dev');
});
});
gulp.task('watch:scss', function() {
gulp.watch(path.SCSS, function() {
runSequence('sass:dev');
});
});
gulp.task('watch:JS', function() {
gulp.watch(path.JS, function() {
runSequence('buildJS:dev', 'reload:dev');
});
});
gulp.task('watch:lib', function() {
gulp.watch([path.GEOM], function() {
runSequence('copyLib:dev', 'reload:dev');
});
});
gulp.task('watch', function() {
runSequence('cleanFiles:dev');
runSequence('buildJS:dev', 'sass:dev', 'copyFiles:dev', 'watch:html', 'watch:scss', 'watch:JS', 'watch:lib');
runSequence('serve:dev');
});
gulp.task('production', function() {
runSequence('cleanFiles:prod');
runSequence('buildJS:prod', 'sass:prod', 'copyFiles:prod', 'copyLib:prod');
});