1
+ const { src, dest, series, parallel } = require ( 'gulp' ) ;
2
+ const fs = require ( 'fs' ) ;
3
+ const concat = require ( 'gulp-concat' ) ;
4
+ const uglify = require ( 'gulp-uglify-es' ) . default ;
5
+ const wrapUmd = require ( 'gulp-wrap-umd' ) ;
6
+ const babel = require ( 'gulp-babel' ) ;
7
+ const notify = require ( 'gulp-notify' ) ;
8
+ const paths = require ( '../utils/paths' ) ;
9
+ const config = require ( '../config' ) ;
10
+
11
+ // Read UMD wrapper template
12
+ const getUmdWrapper = ( ) => fs . readFileSync ( config . umdWrapperPath , 'utf-8' ) ;
13
+
14
+ // UMD configurations for different builds
15
+ const umdConfigs = {
16
+ web : {
17
+ deps : [ {
18
+ "name" : "jquery" ,
19
+ "globalName" : "jQuery" ,
20
+ "paramName" : "$"
21
+ } , {
22
+ "name" : "handlebars" ,
23
+ "globalName" : "Handlebars" ,
24
+ "paramName" : "Handlebars"
25
+ } ] ,
26
+ namespace : "Alpaca" ,
27
+ exports : "Alpaca" ,
28
+ template : getUmdWrapper ( )
29
+ } ,
30
+ bootstrap : {
31
+ deps : [ {
32
+ "name" : "jquery" ,
33
+ "globalName" : "jQuery" ,
34
+ "paramName" : "$"
35
+ } , {
36
+ "name" : "handlebars" ,
37
+ "globalName" : "Handlebars" ,
38
+ "paramName" : "Handlebars"
39
+ } , {
40
+ "name" : "bootstrap" ,
41
+ "globalName" : "Bootstrap" ,
42
+ "paramName" : "Bootstrap"
43
+ } ] ,
44
+ namespace : "Alpaca" ,
45
+ exports : "Alpaca" ,
46
+ template : getUmdWrapper ( ) ,
47
+ defaultView : 'bootstrap'
48
+ } ,
49
+ jqueryui : {
50
+ deps : [ {
51
+ "name" : "jquery" ,
52
+ "globalName" : "jQuery" ,
53
+ "paramName" : "$"
54
+ } , {
55
+ "name" : "handlebars" ,
56
+ "globalName" : "Handlebars" ,
57
+ "paramName" : "Handlebars"
58
+ } , {
59
+ "name" : "jquery-ui" ,
60
+ "globalName" : "jQueryUI" ,
61
+ "paramName" : "jQueryUI"
62
+ } ] ,
63
+ namespace : "Alpaca" ,
64
+ exports : "Alpaca" ,
65
+ template : getUmdWrapper ( ) ,
66
+ defaultView : 'jqueryui'
67
+ } ,
68
+ jquerymobile : {
69
+ deps : [ {
70
+ "name" : "jquery" ,
71
+ "globalName" : "jQuery" ,
72
+ "paramName" : "$"
73
+ } , {
74
+ "name" : "handlebars" ,
75
+ "globalName" : "Handlebars" ,
76
+ "paramName" : "Handlebars"
77
+ } , {
78
+ "name" : "jquery-mobile" ,
79
+ "globalName" : "jQM" ,
80
+ "paramName" : "jQM"
81
+ } ] ,
82
+ namespace : "Alpaca" ,
83
+ exports : "Alpaca" ,
84
+ template : getUmdWrapper ( ) ,
85
+ defaultView : 'jquerymobile'
86
+ }
87
+ } ;
88
+
89
+ // Transpile files that need babel
90
+ function transpileScripts ( ) {
91
+ return src ( paths . scripts . filesToTranspile )
92
+ . pipe ( babel ( {
93
+ presets : [
94
+ [ '@babel/preset-env' , {
95
+ targets : {
96
+ 'ie' : '9'
97
+ }
98
+ } ]
99
+ ]
100
+ } ) )
101
+ . pipe ( dest ( 'build/tmp/transpiled' ) ) ;
102
+ }
103
+
104
+ // Concatenate core scripts
105
+ function concatCoreScripts ( ) {
106
+ return src ( paths . scripts . core )
107
+ . pipe ( concat ( 'scripts-core.js' ) )
108
+ . pipe ( dest ( 'build/tmp' ) ) ;
109
+ }
110
+
111
+ // Build Bootstrap version
112
+ function buildBootstrapScripts ( ) {
113
+ return src ( paths . scripts . bootstrap )
114
+ . pipe ( concat ( 'alpaca.js' ) )
115
+ . pipe ( wrapUmd ( umdConfigs . bootstrap ) )
116
+ . pipe ( dest ( 'build/alpaca/bootstrap' ) )
117
+ . pipe ( concat ( 'alpaca.min.js' ) )
118
+ // .pipe(uglify()) // Commented out in original
119
+ . pipe ( dest ( 'build/alpaca/bootstrap' ) ) ;
120
+ }
121
+
122
+ // Build Web version (commented out in original)
123
+ function buildWebScripts ( ) {
124
+ return src ( paths . scripts . web )
125
+ . pipe ( concat ( 'alpaca.js' ) )
126
+ . pipe ( wrapUmd ( umdConfigs . web ) )
127
+ . pipe ( dest ( 'build/alpaca/web' ) )
128
+ . pipe ( concat ( 'alpaca.min.js' ) )
129
+ . pipe ( uglify ( ) )
130
+ . pipe ( dest ( 'build/alpaca/web' ) ) ;
131
+ }
132
+
133
+ // Build jQuery UI version (commented out in original)
134
+ function buildJQueryUIScripts ( ) {
135
+ return src ( paths . scripts . jqueryui )
136
+ . pipe ( concat ( 'alpaca.js' ) )
137
+ . pipe ( wrapUmd ( umdConfigs . jqueryui ) )
138
+ . pipe ( dest ( 'build/alpaca/jqueryui' ) )
139
+ . pipe ( concat ( 'alpaca.min.js' ) )
140
+ . pipe ( uglify ( ) )
141
+ . pipe ( dest ( 'build/alpaca/jqueryui' ) ) ;
142
+ }
143
+
144
+ // Build jQuery Mobile version (commented out in original)
145
+ function buildJQueryMobileScripts ( ) {
146
+ return src ( paths . scripts . jquerymobile )
147
+ . pipe ( concat ( 'alpaca.js' ) )
148
+ . pipe ( wrapUmd ( umdConfigs . jquerymobile ) )
149
+ . pipe ( dest ( 'build/alpaca/jquerymobile' ) )
150
+ . pipe ( concat ( 'alpaca.min.js' ) )
151
+ . pipe ( uglify ( ) )
152
+ . pipe ( dest ( 'build/alpaca/jquerymobile' ) ) ;
153
+ }
154
+
155
+ // Build distribution scripts
156
+ function buildDistScripts ( ) {
157
+ // Note: In the original gulpfile, only bootstrap is built
158
+ // Other builds are commented out
159
+ return buildBootstrapScripts ( )
160
+ . pipe ( notify ( { message : "Built Alpaca JS" } ) ) ;
161
+ }
162
+
163
+ // Main scripts task
164
+ const buildScripts = series (
165
+ transpileScripts ,
166
+ concatCoreScripts ,
167
+ buildDistScripts
168
+ ) ;
169
+
170
+ buildScripts . displayName = 'build-scripts' ;
171
+ buildScripts . description = 'Build all JavaScript files' ;
172
+
173
+ module . exports = {
174
+ buildScripts,
175
+ transpileScripts,
176
+ concatCoreScripts,
177
+ buildBootstrapScripts,
178
+ buildWebScripts,
179
+ buildJQueryUIScripts,
180
+ buildJQueryMobileScripts
181
+ } ;
0 commit comments