33 */
44const { src, dest, series, parallel } = require ( "gulp" ) ;
55const del = require ( "delete" ) ;
6- // const gulpEsbuild = require("gulp-esbuild");
6+ const rename = require ( 'gulp-rename' )
7+ const header = require ( 'gulp-header' )
8+
9+ // Styles
10+ const sass = require ( 'gulp-sass' ) ( require ( 'sass' ) )
11+ const prefix = require ( 'gulp-autoprefixer' )
12+ const minify = require ( 'gulp-cssnano' )
13+ const sourcemaps = require ( 'gulp-sourcemaps' )
14+
15+ // SVGs
16+ const svgmin = require ( 'gulp-svgmin' )
17+
18+ const pkg = require ( './package.json' )
19+
20+
21+ const settings = {
22+ clean : true ,
23+ scripts : true ,
24+ hjs : false ,
25+ polyfills : false ,
26+ styles : true ,
27+ svgs : true ,
28+ vendor : true
29+ }
30+
31+ /**
32+ * Template for banner to add to file headers
33+ */
34+
35+ const banner = {
36+ full : '/*!\n' +
37+ ' * <%= package.name %> v<%= package.version %>\n' +
38+ ' * <%= package.description %>\n' +
39+ ' * (c) ' + new Date ( ) . getFullYear ( ) + ' <%= package.author.name %>\n' +
40+ ' * <%= package.license %> License\n' +
41+ ' * <%= package.repository.url %>\n' +
42+ ' */\n\n' ,
43+ min : '/*!' +
44+ ' <%= package.name %> v<%= package.version %>' +
45+ ' | (c) ' + new Date ( ) . getFullYear ( ) + ' <%= package.author.name %>' +
46+ ' | <%= package.license %> License' +
47+ ' | <%= package.repository.url %>' +
48+ ' */\n'
49+ }
750
851const paths = {
952 input : "src/main/xar-resources/resources" ,
@@ -18,7 +61,7 @@ const paths = {
1861 "target/generated-resources/frontend/xar-resources/resources/scripts/" ,
1962 } ,
2063 styles : {
21- input : "src/main/xar-resources/resources/css /*" ,
64+ input : "src/main/frontend/sass /*" ,
2265 output : "target/generated-resources/frontend/xar-resources/resources/css/" ,
2366 } ,
2467 fonts : {
@@ -36,12 +79,16 @@ const paths = {
3679 "node_modules/zero-md/dist/index.min.js"
3780 ] ,
3881 styles : [
39- "src/main/xar-resources/resources/css/*" ,
4082 "node_modules/bootstrap/dist/css/bootstrap.min.*" ,
41- "node_modules/@highlightjs/cdn-assets/styles/atom-one-dark.min.css"
83+ "node_modules/@highlightjs/cdn-assets/styles/atom-one-dark.min.css" ,
84+ "node_modules/@neos21/bootstrap3-glyphicons/dist/css/*"
4285 ] ,
4386 fonts : [ "node_modules/@neos21/bootstrap3-glyphicons/dist/fonts/*" ] ,
4487 } ,
88+ svgs : {
89+ input : 'src/main/frontend/svg/*.svg' ,
90+ output : 'target/generated-resources/frontend/xar-resources/resources/images/'
91+ } ,
4592} ;
4693
4794/**
@@ -52,10 +99,61 @@ function clean(cb) {
5299}
53100exports . clean = clean ;
54101
55- function styles ( ) {
56- return src ( paths . styles . input ) . pipe ( dest ( paths . styles . output ) ) ;
102+ // Process, lint, and minify Sass files
103+ function buildStyles ( done ) {
104+ // Make sure this feature is activated before running
105+ if ( ! settings . styles ) return done ( )
106+
107+ // Run tasks on all Sass files
108+ src ( paths . styles . input )
109+ . pipe ( sourcemaps . init ( ) )
110+ . pipe ( sass ( {
111+ outputStyle : 'expanded' ,
112+ sourceComments : true
113+ } ) )
114+ . pipe ( prefix ( {
115+ cascade : true ,
116+ remove : true
117+ } ) )
118+ // Uncomment if you want the non minified files
119+ // .pipe(header(banner.full, {
120+ // package: pkg
121+ // }))
122+ // .pipe(dest(paths.styles.output))
123+ . pipe ( rename ( {
124+ suffix : '.min'
125+ } ) )
126+ . pipe ( minify ( {
127+ discardComments : {
128+ removeAll : true
129+ }
130+ } ) )
131+ . pipe ( header ( banner . min , {
132+ package : pkg
133+ } ) )
134+ . pipe ( sourcemaps . write ( '.' ) )
135+ . pipe ( dest ( paths . styles . output ) )
136+
137+ // Signal completion
138+ done ( )
139+ }
140+ exports . styles = buildStyles ;
141+
142+ // Optimize SVG files
143+ function minifySvg ( done ) {
144+ // Make sure this feature is activated before running
145+ if ( ! settings . svgs ) return done ( )
146+
147+ // Optimize SVG files
148+ src ( paths . svgs . input )
149+ . pipe ( svgmin ( ) )
150+ . pipe ( dest ( paths . svgs . output ) )
151+
152+ // Signal completion
153+ done ( )
57154}
58- exports . styles = styles ;
155+
156+ exports . minifySvg = minifySvg ;
59157
60158/**
61159 * minify EcmaSript files and put them into 'build/app/js'
@@ -93,6 +191,8 @@ function copyVendorFonts() {
93191 ) ;
94192}
95193
194+
195+
96196/**
97197 * copy vendor scripts, styles and fonts
98198 */
@@ -103,7 +203,7 @@ const copyStatic = parallel(copyFonts, copyVendorFonts, copyVendorScripts, copyV
103203// composed tasks //
104204// ///////////////// //
105205
106- const build = series ( clean , styles , minifyEs , copyStatic ) ;
206+ const build = series ( clean , buildStyles , minifySvg , minifyEs , copyStatic ) ;
107207
108208exports . build = build ;
109209
0 commit comments