This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
forked from SpongePowered/SpongeAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
95 lines (78 loc) · 2.68 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
import fs from 'fs';
import path from 'path';
import minimist from 'minimist'
import gulp from 'gulp'
import sourcemaps from 'gulp-sourcemaps';
import sass from 'gulp-sass';
import cleanCSS from 'gulp-clean-css';
import moduleImporter from 'sass-module-importer';
import compilerPackage from 'google-closure-compiler';
import babel from 'gulp-babel'
const closureCompiler = compilerPackage.gulp();
const paths = {
inBase: './spongeauth/static',
outBase: './spongeauth/static-build',
styles: '/styles',
appStyle: '/styles/app.scss',
fonts: '/fonts',
scripts: '/scripts',
appScript: '/scripts/app.js',
images: '/images',
};
const production = minimist(process.argv).production || false;
function styles() {
let pipe = gulp.src(paths.inBase + paths.styles + '/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({ importer: moduleImporter() }));
if (production) {
pipe = pipe.pipe(cleanCSS());
}
return pipe
.pipe(sourcemaps.write('../maps/'))
.pipe(gulp.dest(paths.outBase + paths.styles));
}
function fonts() {
return gulp.src([
'./node_modules/font-awesome/fonts/fontawesome-webfont.*',
'./node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.*',
]).pipe(gulp.dest(paths.outBase + paths.fonts));
}
function images() {
return gulp.src(paths.inBase + paths.images + '/**')
.pipe(gulp.dest(paths.outBase + paths.images));
}
const buildExterns = () => {
const externsDir = './closureexterns';
const externsFiles = fs.readdirSync(externsDir);
return externsFiles
.filter((fn) => fn.endsWith('.js'))
.map((fn) => path.join(externsDir, fn));
};
function scripts() {
const compiler = production ? closureCompiler({
compilationLevel: 'ADVANCED',
languageIn: 'STABLE',
languageOut: 'ECMASCRIPT5_STRICT',
jsOutputFile: 'app.js',
assumeFunctionWrapper: true,
outputWrapper: '(function(){%output%}).call(this)',
externs: buildExterns(),
warningLevel: 'VERBOSE',
}) : babel({
presets: ['@babel/env'],
});
return gulp.src(paths.inBase + paths.appScript, {base: './'})
.pipe(sourcemaps.init())
.pipe(compiler)
.pipe(sourcemaps.write('../maps/'))
.pipe(gulp.dest(paths.outBase + paths.scripts));
}
function watch() {
gulp.watch(paths.inBase + paths.styles + '/**', styles);
gulp.watch(paths.inBase + paths.scripts + '/**', scripts);
gulp.watch(paths.inBase + paths.images + '/**', images);
}
const build = gulp.parallel(styles, fonts, scripts, images);
exports.build = build;
exports.watch = watch;
exports.default = gulp.series(build, watch);