-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
171 lines (145 loc) · 5.22 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
'use strict';
const config = {
presentation: {
js: {
src: `./src/presentation/js`,
dst: `./dist/presentation/js`
},
scss: {
src: `./src/presentation/scss`,
dst: `./dist/presentation/css`
}
},
server: {
js: {
src: `./src/server`,
dst: `./dist/server`
}
},
mobile: {
js: {
src: `./src/mobile/js`,
dst: `./dist/mobile/js`
},
scss: {
src: `./src/mobile/scss`,
dst: `./dist/mobile/css`
}
}
};
const autoprefixer = require(`autoprefixer`);
const babelify = require(`babelify`);
const babel = require(`gulp-babel`);
const browserify = require(`browserify`);
const buffer = require(`vinyl-buffer`);
const cssnano = require(`gulp-cssnano`);
const gulp = require(`gulp`);
const gutil = require(`gulp-util`);
const postcss = require(`gulp-postcss`);
const sass = require(`gulp-sass`);
const combineMq = require(`gulp-combine-mq`);
const sourcemaps = require(`gulp-sourcemaps`);
const source = require(`vinyl-source-stream`);
const uglify = require(`gulp-uglify`);
const watchify = require(`watchify`);
const stylesTask = function(src, dst) {
const processors = [
autoprefixer({browsers: [`IE >= 10`, `last 2 version`], cascade: false}),
];
return gulp.src(`${src }/**/*.scss`)
.pipe(sass().on(`error`, sass.logError))
.pipe(postcss(processors))
.pipe(combineMq({
beautify: true
}))
.pipe(gutil.env.type === `production` ? cssnano() : gutil.noop())
.pipe(gulp.dest(dst));
};
const scriptsTask = function(b, watch, name, dst) {
const bundler = (watch) ? watchify(b) : b;
function rebundle() {
console.log(`-> bundling ${ dst }/${ name}`);
return bundler.bundle()
.on(`error`, function(err) { console.error(err); this.emit(`end`); })
.pipe(source(name))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(gutil.env.type === `production` ? uglify() : gutil.noop())
.pipe(sourcemaps.write(`./`))
.pipe(gulp.dest(dst));
}
if (watch) {
bundler.on(`update`, function() {
rebundle();
});
}
return rebundle();
};
const presentationStylesTask = function() {
return stylesTask(config.presentation.scss.src, config.presentation.scss.dst);
};
const presentationScriptsTask = function(watch) {
const b = browserify(`${config.presentation.js.src }/script.js`, { debug: gutil.env.type !== `production` })
.require(`${__dirname }/${ config.presentation.js.src }/classes/live-code-slide/index.js`, { expose: `LiveCodeSlide`})
.require(`${__dirname }/${ config.presentation.js.src }/classes/video-slide/index.js`, { expose: `VideoSlide`})
.require(`${__dirname }/${ config.presentation.js.src }/classes/webview-slide/index.js`, { expose: `WebviewSlide`})
.transform(babelify);
return scriptsTask(b, watch, `script.js`, config.presentation.js.dst);
};
const presentationVendorsTask = function(watch) {
const b = browserify(`${config.presentation.js.src }/vendors.js`, { debug: gutil.env.type !== `production` })
.transform(babelify);
return scriptsTask(b, watch, `vendors.js`, config.presentation.js.dst);
};
const liveCodeWebPreviewTask = function(watch) {
const b = browserify(`${config.presentation.js.src }/livecode-webpreview.js`, { debug: gutil.env.type !== `production` })
.transform(babelify);
return scriptsTask(b, watch, `livecode-webpreview.js`, config.presentation.js.dst);
};
const mobileStylesTask = function() {
return stylesTask(config.mobile.scss.src, config.mobile.scss.dst);
};
const mobileScriptsTask = function(watch) {
const b = browserify(`${config.mobile.js.src }/script.js`, { debug: gutil.env.type !== `production` })
.transform(babelify);
return scriptsTask(b, watch, `script.js`, config.mobile.js.dst);
};
const mobileVendorsTask = function(watch) {
const b = browserify(`${config.mobile.js.src }/vendors.js`, { debug: gutil.env.type !== `production` })
.transform(babelify);
return scriptsTask(b, watch, `vendors.js`, config.mobile.js.dst);
};
const serverScriptsTask = function() {
return gulp.src(`${config.server.js.src }/**/*.js`)
.pipe(babel())
.pipe(gulp.dest(config.server.js.dst));
};
gulp.task(`presentation-styles`, presentationStylesTask);
gulp.task(`presentation-scripts`, function() {
return presentationScriptsTask(false);
});
gulp.task(`presentation-vendors`, function() {
return presentationVendorsTask(false);
});
gulp.task(`mobile-styles`, mobileStylesTask);
gulp.task(`mobile-scripts`, function() {
return mobileScriptsTask(false);
});
gulp.task(`mobile-vendors`, function() {
return mobileVendorsTask(false);
});
gulp.task(`livecode-webpreview`, function() {
return liveCodeWebPreviewTask(false);
});
gulp.task(`server-scripts`, serverScriptsTask);
gulp.task(`watch`, [`presentation-styles`, `mobile-styles`, `server-scripts`], function() {
gulp.watch(`${config.presentation.scss.src }/**/*.scss`, [`presentation-styles`]);
gulp.watch(`${config.mobile.scss.src }/**/*.scss`, [`mobile-styles`]);
gulp.watch(`${config.server.js.src }/**/*.js`, [`server-scripts`]);
presentationScriptsTask(true);
presentationVendorsTask(true);
mobileScriptsTask(true);
mobileVendorsTask(true);
liveCodeWebPreviewTask(true);
});
gulp.task(`default`, [`watch`]);