1- import gulp from ' gulp' ;
2- import path from ' path' ;
3- import fs from 'fs' ;
4- import merge from ' merge-stream' ;
5- import { globbySync } from ' globby'
6- import concat from ' gulp-concat' ;
7- import less from ' gulp-less' ;
8- import gulpTerser from ' gulp-terser' ;
9- import { minify } from ' terser'
10- import cleanCss from ' gulp-clean-css' ;
11- import postcss from ' gulp-postcss' ;
12- import url from ' postcss-url' ;
1+ import gulp from " gulp" ;
2+ import path from " path" ;
3+ import fs from "fs" ;
4+ import merge from " merge-stream" ;
5+ import { globbySync } from " globby" ;
6+ import concat from " gulp-concat" ;
7+ import less from " gulp-less" ;
8+ import gulpTerser from " gulp-terser" ;
9+ import { minify } from " terser" ;
10+ import cleanCss from " gulp-clean-css" ;
11+ import postcss from " gulp-postcss" ;
12+ import url from " postcss-url" ;
1313
1414const __dirname = import . meta. dirname ;
1515
16- const bundleConfig = JSON . parse ( fs . readFileSync ( ' ./bundles.json' , ' utf-8' ) ) ;
16+ const bundleConfig = JSON . parse ( fs . readFileSync ( " ./bundles.json" , " utf-8" ) ) ;
1717
1818var production = false ;
1919
2020var styleEntries = { } ;
2121var scriptEntries = { } ;
2222
23- var viewScripts = globbySync ( [ './wwwroot/view-resources/**/*.js' , '!./wwwroot/view-resources/**/*.min.js' ] ) ;
23+ var viewScripts = globbySync ( [
24+ "./wwwroot/view-resources/**/*.js" ,
25+ "!./wwwroot/view-resources/**/*.min.js" ,
26+ ] ) ;
2427
2528var viewStyles = globbySync ( [
26- ' ./wwwroot/view-resources/**/*.css' ,
27- ' ./wwwroot/view-resources/**/*.less' ,
28- ' !./wwwroot/view-resources/**/*.min.css' ,
29+ " ./wwwroot/view-resources/**/*.css" ,
30+ " ./wwwroot/view-resources/**/*.less" ,
31+ " !./wwwroot/view-resources/**/*.min.css" ,
2932] ) ;
3033
3134function processInputDefinition ( input ) {
3235 var result = [ ] ;
3336 for ( var i = 0 ; i < input . length ; i ++ ) {
3437 var url = input [ i ] ;
35- if ( url . startsWith ( '!' ) ) {
36- result . push ( '!' + path . resolve ( __dirname , url . substring ( 1 ) ) ) ;
38+ if ( url . startsWith ( "!" ) ) {
39+ result . push ( "!" + path . resolve ( __dirname , url . substring ( 1 ) ) ) ;
3740 } else {
3841 result . push ( path . resolve ( __dirname , url ) ) ;
3942 }
@@ -53,8 +56,10 @@ function fillScriptBundles() {
5356
5457 // View scripts
5558 for ( var i = 0 ; i < viewScripts . length ; i ++ ) {
56- var viewScriptName = viewScripts [ i ] . replace ( './wwwroot/' , '' ) ;
57- scriptEntries [ viewScriptName . replace ( '.js' , '.min.js' ) ] = [ path . resolve ( __dirname , viewScripts [ i ] ) ] ;
59+ var viewScriptName = viewScripts [ i ] . replace ( "./wwwroot/" , "" ) ;
60+ scriptEntries [ viewScriptName . replace ( ".js" , ".min.js" ) ] = [
61+ path . resolve ( __dirname , viewScripts [ i ] ) ,
62+ ] ;
5863 }
5964}
6065
@@ -68,14 +73,18 @@ function fillStyleBundles() {
6873
6974 // View styles
7075 for ( var j = 0 ; j < viewStyles . length ; j ++ ) {
71- var viewStyleName = viewStyles [ j ] . replace ( ' ./wwwroot/' , '' ) ;
76+ var viewStyleName = viewStyles [ j ] . replace ( " ./wwwroot/" , "" ) ;
7277
73- if ( viewStyleName . indexOf ( '.css' ) >= 0 ) {
74- styleEntries [ viewStyleName . replace ( '.css' , '.min.css' ) ] = [ path . resolve ( __dirname , 'wwwroot/' + viewStyleName ) ] ;
78+ if ( viewStyleName . indexOf ( ".css" ) >= 0 ) {
79+ styleEntries [ viewStyleName . replace ( ".css" , ".min.css" ) ] = [
80+ path . resolve ( __dirname , "wwwroot/" + viewStyleName ) ,
81+ ] ;
7582 }
7683
77- if ( viewStyleName . indexOf ( '.less' ) >= 0 ) {
78- styleEntries [ viewStyleName . replace ( '.less' , '.min.css' ) ] = [ path . resolve ( __dirname , 'wwwroot/' + viewStyleName ) ] ;
84+ if ( viewStyleName . indexOf ( ".less" ) >= 0 ) {
85+ styleEntries [ viewStyleName . replace ( ".less" , ".min.css" ) ] = [
86+ path . resolve ( __dirname , "wwwroot/" + viewStyleName ) ,
87+ ] ;
7988 }
8089 }
8190}
@@ -93,7 +102,10 @@ function fillScriptMappings() {
93102 var scriptBundle = bundleConfig . scriptMappings [ k ] ;
94103 var inputFilesToBeCopied = globbySync ( scriptBundle . input ) ;
95104 for ( var j = 0 ; j < inputFilesToBeCopied . length ; j ++ ) {
96- var outputFileName = path . join ( scriptBundle . outputFolder , getFileNameFromPath ( inputFilesToBeCopied [ j ] ) ) ;
105+ var outputFileName = path . join (
106+ scriptBundle . outputFolder ,
107+ getFileNameFromPath ( inputFilesToBeCopied [ j ] ) ,
108+ ) ;
97109 scriptEntries [ outputFileName ] = [ inputFilesToBeCopied [ j ] ] ;
98110 }
99111 }
@@ -117,7 +129,9 @@ function createScriptBundle(script) {
117129 stream = stream . pipe ( gulpTerser ( { } , minify ) ) ;
118130 }
119131
120- return stream . pipe ( concat ( bundleName ) ) . pipe ( gulp . dest ( 'wwwroot/' + bundlePath ) ) ;
132+ return stream
133+ . pipe ( concat ( bundleName ) )
134+ . pipe ( gulp . dest ( "wwwroot/" + bundlePath ) ) ;
121135}
122136
123137function createStyleBundles ( ) {
@@ -130,48 +144,50 @@ function createStyleBundles() {
130144}
131145
132146function createStyleBundle ( style ) {
133- let basePath = process . argv . length >= 5 ? process . argv [ 4 ] : '' ;
147+ let basePath = process . argv . length >= 5 ? process . argv [ 4 ] : "" ;
134148
135149 var bundleName = getFileNameFromPath ( style ) ;
136150 var bundlePath = getPathWithoutFileNameFromPath ( style ) ;
137151
138152 var options = {
139153 url : function ( asset ) {
140154 // Ignore absolute URLs
141- if ( asset . url . substring ( 0 , 1 ) === '/' ) {
155+ if ( asset . url . substring ( 0 , 1 ) === "/" ) {
142156 return asset . url ;
143157 }
144158
145- var outputFolder = '' ;
159+ var outputFolder = "" ;
146160
147161 if ( asset . url . match ( / \. ( p n g | s v g | j p g | g i f ) $ / ) ) {
148- outputFolder = basePath + ' dist/img' ;
162+ outputFolder = basePath + " dist/img" ;
149163 } else if ( asset . url . match ( / \. ( w o f f | w o f f 2 | e o t | t t f | o t f ) [ ? ] { 0 , 1 } .* $ / ) ) {
150- outputFolder = basePath + ' dist/fonts' ;
164+ outputFolder = basePath + " dist/fonts" ;
151165 } else {
152166 // Ignore not recognized assets like data:image etc...
153167 return asset . url ;
154168 }
155169
156170 var fileName = path . basename ( asset . absolutePath ) ;
157- var outputPath = path . join ( __dirname , ' /wwwroot/' + outputFolder + '/' ) ;
171+ var outputPath = path . join ( __dirname , " /wwwroot/" + outputFolder + "/" ) ;
158172
159173 gulp . src ( asset . absolutePath ) . pipe ( gulp . dest ( outputPath ) ) ;
160174
161- return '/' + outputFolder + '/' + fileName ;
175+ return "/" + outputFolder + "/" + fileName ;
162176 } ,
163177 } ;
164178
165179 var stream = gulp
166180 . src ( styleEntries [ style ] )
167181 . pipe ( postcss ( [ url ( options ) ] ) )
168- . pipe ( less ( { math : ' parens-division' } ) ) ;
182+ . pipe ( less ( { math : " parens-division" } ) ) ;
169183
170184 if ( production ) {
171185 stream = stream . pipe ( cleanCss ( ) ) ;
172186 }
173187
174- return stream . pipe ( concat ( bundleName ) ) . pipe ( gulp . dest ( 'wwwroot/' + bundlePath ) ) ;
188+ return stream
189+ . pipe ( concat ( bundleName ) )
190+ . pipe ( gulp . dest ( "wwwroot/" + bundlePath ) ) ;
175191}
176192
177193function findMatchingElements ( path , array ) {
@@ -189,7 +205,7 @@ function watchScriptEntries() {
189205 for ( var script in scriptEntries ) {
190206 var watcher = gulp . watch ( scriptEntries [ script ] ) ;
191207
192- watcher . on ( ' change' , function ( path , stats ) {
208+ watcher . on ( " change" , function ( path , stats ) {
193209 console . log ( `${ path } updated` ) ;
194210
195211 var changedBundles = findMatchingElements ( path , scriptEntries ) ;
@@ -205,7 +221,7 @@ function watchStyleEntries() {
205221 for ( var style in styleEntries ) {
206222 var watcher = gulp . watch ( styleEntries [ style ] ) ;
207223
208- watcher . on ( ' change' , function ( path , stats ) {
224+ watcher . on ( " change" , function ( path , stats ) {
209225 console . log ( `${ path } updated` ) ;
210226
211227 var changedBundles = findMatchingElements ( path , styleEntries ) ;
@@ -241,7 +257,7 @@ function buildDev() {
241257 watchScriptEntries ( ) ;
242258 watchStyleEntries ( ) ;
243259
244- console . log ( ' Bundles are being created, please wait...' ) ;
260+ console . log ( " Bundles are being created, please wait..." ) ;
245261
246262 return merge ( scriptTasks . concat ( styleTasks ) ) ;
247263}
@@ -252,9 +268,9 @@ function checkBundleItem(bundleItem) {
252268 for ( var i = 0 ; i < definition . length ; i ++ ) {
253269 var url = definition [ i ] ;
254270 if (
255- typeof url == ' undefined' ||
256- url . startsWith ( '!' ) ||
257- url . indexOf ( '*' ) >= 0 ||
271+ typeof url == " undefined" ||
272+ url . startsWith ( "!" ) ||
273+ url . indexOf ( "*" ) >= 0 ||
258274 url . match ( / ^ [ 0 - 9 ] + $ / ) != null //only digit
259275 ) {
260276 continue ;
@@ -269,14 +285,11 @@ function checkFile(path) {
269285 if ( fs . existsSync ( path ) ) {
270286 //file exists
271287 } else {
272- console . error ( ' File not found: ' + path ) ;
288+ console . error ( " File not found: " + path ) ;
273289 }
274290 } catch ( err ) {
275- console . error ( ' File not found: ' + path ) ;
291+ console . error ( " File not found: " + path ) ;
276292 }
277293}
278294
279- export {
280- build as build ,
281- buildDev as buildDev
282- }
295+ export { build as build , buildDev as buildDev } ;
0 commit comments