-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
executable file
·172 lines (153 loc) · 4.57 KB
/
gulpfile.babel.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
import babelify from 'babelify';
import browserify from 'browserify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import concat from 'gulp-concat';
import gulp from 'gulp';
import notify from 'gulp-notify';
import plugins from 'gulp-load-plugins';
import plumber from 'gulp-plumber';
import rename from 'gulp-rename';
import sourcemaps from 'gulp-sourcemaps';
import uglify from 'gulp-uglify';
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
import mode from 'gulp-mode';
import cleanCSS from 'gulp-clean-css';
const sass = gulpSass(dartSass);
const $ = plugins();
// Configure gulp mode. See package.json for flags used to trigger different builds
const gulpMode = mode({
modes: ['production', 'development'],
default: 'development',
verbose: false,
});
// Error handler
var onError = function (error) {
notify.onError({
title: 'Gulp Error',
message: '<%= error %>',
})(error);
this.emit('end');
};
// Standalone paths
const assetDirs = {
src: './src/',
dest: './assets/',
};
const sassPaths = [
'node_modules/', // Include specific sass files from folders in this directory
];
////////////////////
// App Processors //
////////////////////
// Compile dem styles
const Styles = (function () {
const paths = {
src: `${assetDirs.src}scss/`,
watch: `${assetDirs.src}scss/**/*.scss`,
dest: `${assetDirs.dest}styles/`,
};
const _compile = (fileIn, fileOut) => {
return gulp
.src(paths.src + fileIn)
.pipe(plumber({ errorHanlder: onError }))
.pipe(sourcemaps.init())
.pipe(
sass({
includePaths: sassPaths,
}).on('error', sass.logError),
)
.pipe($.autoprefixer())
.pipe(cleanCSS())
.pipe(rename(fileOut))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest(paths.dest));
};
return {
paths,
compileFluency: () => _compile('fluency_core.scss', 'fluency_core.min.css'),
compileStandaloneTranslator: () =>
_compile('fluency_standalone_translator.scss', 'fluency_standalone_translator.min.css'),
compileModuleConfig: () =>
_compile('fluency_module_config.scss', 'fluency_module_config.min.css'),
compileApiUsage: () => _compile('fluency_api_usage.scss', 'fluency_api_usage.min.css'),
};
})();
// Build dem scripts
const Scripts = (function () {
const paths = {
source: `${assetDirs.src}scripts/`,
watch: `${assetDirs.src}scripts/**/*.js`,
dest: `${assetDirs.dest}scripts/`,
};
const _compile = (fileIn, fileOut) => {
return browserify({
entries: `${paths.source}${fileIn}`,
extensions: ['.js'],
debug: false,
})
.transform(babelify)
.bundle()
.pipe(plumber({ errorHandler: onError }))
.pipe(source(fileOut))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(sourcemaps.init({ largeFile: true }))
.pipe(uglify())
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest(paths.dest));
};
return {
paths,
compileFluency: () => _compile('fluency.js', 'fluency.bundle.js'),
compileLanguageTranslator: () =>
_compile('fluency.language_translator.js', 'fluency_language_translator.bundle.js'),
compileModuleConfig: () =>
_compile('fluency.module_config.js', 'fluency_module_config.bundle.js'),
compileStandaloneTranslator: () =>
_compile('fluency.standalone_translator.js', 'fluency_standalone_translator.bundle.js'),
compileApiUsage: () => _compile('fluency.api_usage.js', 'fluency_api_usage.bundle.js'),
};
})();
// Start watch tasks. Command defined in package.json, called with --development flag
const watch = async function () {
// Styles
gulp.watch(
Styles.paths.watch,
gulp.series(
Styles.compileFluency,
Styles.compileStandaloneTranslator,
Styles.compileApiUsage,
Styles.compileModuleConfig,
),
);
// Scripts
gulp.watch(
Scripts.paths.watch,
gulp.series(
Scripts.compileFluency,
Scripts.compileStandaloneTranslator,
Scripts.compileApiUsage,
Scripts.compileLanguageTranslator,
Scripts.compileModuleConfig,
),
);
};
// Compile it all. Command defined in package.json, called with --production flag
const build = function (done) {
gulp.series(
Styles.compileFluency,
Styles.compileStandaloneTranslator,
Styles.compileLanguageTranslator,
Styles.compileModuleConfig,
Styles.compileApiUsage,
Scripts.compileFluency,
Scripts.compileLanguageTranslator,
Scripts.compileModuleConfig,
Scripts.compileStandaloneTranslator,
Scripts.compileApiUsage,
);
done();
};
export { watch, build };