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" ;
13
13
14
14
const __dirname = import . meta. dirname ;
15
15
16
- const bundleConfig = JSON . parse ( fs . readFileSync ( ' ./bundles.json' , ' utf-8' ) ) ;
16
+ const bundleConfig = JSON . parse ( fs . readFileSync ( " ./bundles.json" , " utf-8" ) ) ;
17
17
18
18
var production = false ;
19
19
20
20
var styleEntries = { } ;
21
21
var scriptEntries = { } ;
22
22
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
+ ] ) ;
24
27
25
28
var 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" ,
29
32
] ) ;
30
33
31
34
function processInputDefinition ( input ) {
32
35
var result = [ ] ;
33
36
for ( var i = 0 ; i < input . length ; i ++ ) {
34
37
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 ) ) ) ;
37
40
} else {
38
41
result . push ( path . resolve ( __dirname , url ) ) ;
39
42
}
@@ -53,8 +56,10 @@ function fillScriptBundles() {
53
56
54
57
// View scripts
55
58
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
+ ] ;
58
63
}
59
64
}
60
65
@@ -68,14 +73,18 @@ function fillStyleBundles() {
68
73
69
74
// View styles
70
75
for ( var j = 0 ; j < viewStyles . length ; j ++ ) {
71
- var viewStyleName = viewStyles [ j ] . replace ( ' ./wwwroot/' , '' ) ;
76
+ var viewStyleName = viewStyles [ j ] . replace ( " ./wwwroot/" , "" ) ;
72
77
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
+ ] ;
75
82
}
76
83
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
+ ] ;
79
88
}
80
89
}
81
90
}
@@ -93,7 +102,10 @@ function fillScriptMappings() {
93
102
var scriptBundle = bundleConfig . scriptMappings [ k ] ;
94
103
var inputFilesToBeCopied = globbySync ( scriptBundle . input ) ;
95
104
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
+ ) ;
97
109
scriptEntries [ outputFileName ] = [ inputFilesToBeCopied [ j ] ] ;
98
110
}
99
111
}
@@ -117,7 +129,9 @@ function createScriptBundle(script) {
117
129
stream = stream . pipe ( gulpTerser ( { } , minify ) ) ;
118
130
}
119
131
120
- return stream . pipe ( concat ( bundleName ) ) . pipe ( gulp . dest ( 'wwwroot/' + bundlePath ) ) ;
132
+ return stream
133
+ . pipe ( concat ( bundleName ) )
134
+ . pipe ( gulp . dest ( "wwwroot/" + bundlePath ) ) ;
121
135
}
122
136
123
137
function createStyleBundles ( ) {
@@ -130,48 +144,50 @@ function createStyleBundles() {
130
144
}
131
145
132
146
function createStyleBundle ( style ) {
133
- let basePath = process . argv . length >= 5 ? process . argv [ 4 ] : '' ;
147
+ let basePath = process . argv . length >= 5 ? process . argv [ 4 ] : "" ;
134
148
135
149
var bundleName = getFileNameFromPath ( style ) ;
136
150
var bundlePath = getPathWithoutFileNameFromPath ( style ) ;
137
151
138
152
var options = {
139
153
url : function ( asset ) {
140
154
// Ignore absolute URLs
141
- if ( asset . url . substring ( 0 , 1 ) === '/' ) {
155
+ if ( asset . url . substring ( 0 , 1 ) === "/" ) {
142
156
return asset . url ;
143
157
}
144
158
145
- var outputFolder = '' ;
159
+ var outputFolder = "" ;
146
160
147
161
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" ;
149
163
} 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" ;
151
165
} else {
152
166
// Ignore not recognized assets like data:image etc...
153
167
return asset . url ;
154
168
}
155
169
156
170
var fileName = path . basename ( asset . absolutePath ) ;
157
- var outputPath = path . join ( __dirname , ' /wwwroot/' + outputFolder + '/' ) ;
171
+ var outputPath = path . join ( __dirname , " /wwwroot/" + outputFolder + "/" ) ;
158
172
159
173
gulp . src ( asset . absolutePath ) . pipe ( gulp . dest ( outputPath ) ) ;
160
174
161
- return '/' + outputFolder + '/' + fileName ;
175
+ return "/" + outputFolder + "/" + fileName ;
162
176
} ,
163
177
} ;
164
178
165
179
var stream = gulp
166
180
. src ( styleEntries [ style ] )
167
181
. pipe ( postcss ( [ url ( options ) ] ) )
168
- . pipe ( less ( { math : ' parens-division' } ) ) ;
182
+ . pipe ( less ( { math : " parens-division" } ) ) ;
169
183
170
184
if ( production ) {
171
185
stream = stream . pipe ( cleanCss ( ) ) ;
172
186
}
173
187
174
- return stream . pipe ( concat ( bundleName ) ) . pipe ( gulp . dest ( 'wwwroot/' + bundlePath ) ) ;
188
+ return stream
189
+ . pipe ( concat ( bundleName ) )
190
+ . pipe ( gulp . dest ( "wwwroot/" + bundlePath ) ) ;
175
191
}
176
192
177
193
function findMatchingElements ( path , array ) {
@@ -189,7 +205,7 @@ function watchScriptEntries() {
189
205
for ( var script in scriptEntries ) {
190
206
var watcher = gulp . watch ( scriptEntries [ script ] ) ;
191
207
192
- watcher . on ( ' change' , function ( path , stats ) {
208
+ watcher . on ( " change" , function ( path , stats ) {
193
209
console . log ( `${ path } updated` ) ;
194
210
195
211
var changedBundles = findMatchingElements ( path , scriptEntries ) ;
@@ -205,7 +221,7 @@ function watchStyleEntries() {
205
221
for ( var style in styleEntries ) {
206
222
var watcher = gulp . watch ( styleEntries [ style ] ) ;
207
223
208
- watcher . on ( ' change' , function ( path , stats ) {
224
+ watcher . on ( " change" , function ( path , stats ) {
209
225
console . log ( `${ path } updated` ) ;
210
226
211
227
var changedBundles = findMatchingElements ( path , styleEntries ) ;
@@ -241,7 +257,7 @@ function buildDev() {
241
257
watchScriptEntries ( ) ;
242
258
watchStyleEntries ( ) ;
243
259
244
- console . log ( ' Bundles are being created, please wait...' ) ;
260
+ console . log ( " Bundles are being created, please wait..." ) ;
245
261
246
262
return merge ( scriptTasks . concat ( styleTasks ) ) ;
247
263
}
@@ -252,9 +268,9 @@ function checkBundleItem(bundleItem) {
252
268
for ( var i = 0 ; i < definition . length ; i ++ ) {
253
269
var url = definition [ i ] ;
254
270
if (
255
- typeof url == ' undefined' ||
256
- url . startsWith ( '!' ) ||
257
- url . indexOf ( '*' ) >= 0 ||
271
+ typeof url == " undefined" ||
272
+ url . startsWith ( "!" ) ||
273
+ url . indexOf ( "*" ) >= 0 ||
258
274
url . match ( / ^ [ 0 - 9 ] + $ / ) != null //only digit
259
275
) {
260
276
continue ;
@@ -269,14 +285,11 @@ function checkFile(path) {
269
285
if ( fs . existsSync ( path ) ) {
270
286
//file exists
271
287
} else {
272
- console . error ( ' File not found: ' + path ) ;
288
+ console . error ( " File not found: " + path ) ;
273
289
}
274
290
} catch ( err ) {
275
- console . error ( ' File not found: ' + path ) ;
291
+ console . error ( " File not found: " + path ) ;
276
292
}
277
293
}
278
294
279
- export {
280
- build as build ,
281
- buildDev as buildDev
282
- }
295
+ export { build as build , buildDev as buildDev } ;
0 commit comments