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 (not used in upstream)
90
+ function transpileScripts ( done ) {
91
+ // Upstream doesn't transpile, just complete the task
92
+ done ( ) ;
93
+ }
94
+
95
+ // Concatenate core scripts
96
+ function concatCoreScripts ( ) {
97
+ return src ( paths . scripts . core )
98
+ . pipe ( concat ( 'scripts-core.js' ) )
99
+ . pipe ( dest ( 'build/tmp' ) ) ;
100
+ }
101
+
102
+ // Build Bootstrap version
103
+ function buildBootstrapScripts ( ) {
104
+ return src ( paths . scripts . bootstrap )
105
+ . pipe ( concat ( 'alpaca.js' ) )
106
+ . pipe ( wrapUmd ( umdConfigs . bootstrap ) )
107
+ . pipe ( dest ( 'build/alpaca/bootstrap' ) )
108
+ . pipe ( concat ( 'alpaca.min.js' ) )
109
+ // .pipe(uglify()) // Commented out in original
110
+ . pipe ( dest ( 'build/alpaca/bootstrap' ) ) ;
111
+ }
112
+
113
+ // Build Web version (commented out in original)
114
+ function buildWebScripts ( ) {
115
+ return src ( paths . scripts . web )
116
+ . pipe ( concat ( 'alpaca.js' ) )
117
+ . pipe ( wrapUmd ( umdConfigs . web ) )
118
+ . pipe ( dest ( 'build/alpaca/web' ) )
119
+ . pipe ( concat ( 'alpaca.min.js' ) )
120
+ . pipe ( uglify ( ) )
121
+ . pipe ( dest ( 'build/alpaca/web' ) ) ;
122
+ }
123
+
124
+ // Build jQuery UI version (commented out in original)
125
+ function buildJQueryUIScripts ( ) {
126
+ return src ( paths . scripts . jqueryui )
127
+ . pipe ( concat ( 'alpaca.js' ) )
128
+ . pipe ( wrapUmd ( umdConfigs . jqueryui ) )
129
+ . pipe ( dest ( 'build/alpaca/jqueryui' ) )
130
+ . pipe ( concat ( 'alpaca.min.js' ) )
131
+ . pipe ( uglify ( ) )
132
+ . pipe ( dest ( 'build/alpaca/jqueryui' ) ) ;
133
+ }
134
+
135
+ // Build jQuery Mobile version (commented out in original)
136
+ function buildJQueryMobileScripts ( ) {
137
+ return src ( paths . scripts . jquerymobile )
138
+ . pipe ( concat ( 'alpaca.js' ) )
139
+ . pipe ( wrapUmd ( umdConfigs . jquerymobile ) )
140
+ . pipe ( dest ( 'build/alpaca/jquerymobile' ) )
141
+ . pipe ( concat ( 'alpaca.min.js' ) )
142
+ . pipe ( uglify ( ) )
143
+ . pipe ( dest ( 'build/alpaca/jquerymobile' ) ) ;
144
+ }
145
+
146
+ // Build distribution scripts
147
+ function buildDistScripts ( ) {
148
+ // Build all variants in parallel like upstream
149
+ const merge = require ( 'merge-stream' ) ;
150
+ return merge (
151
+ buildWebScripts ( ) ,
152
+ buildBootstrapScripts ( ) ,
153
+ buildJQueryUIScripts ( ) ,
154
+ buildJQueryMobileScripts ( )
155
+ ) . pipe ( notify ( { message : "Built Alpaca JS" } ) ) ;
156
+ }
157
+
158
+ // Main scripts task
159
+ const buildScripts = series (
160
+ concatCoreScripts ,
161
+ buildDistScripts
162
+ ) ;
163
+
164
+ buildScripts . displayName = 'build-scripts' ;
165
+ buildScripts . description = 'Build all JavaScript files' ;
166
+
167
+ module . exports = {
168
+ buildScripts,
169
+ transpileScripts,
170
+ concatCoreScripts,
171
+ buildBootstrapScripts,
172
+ buildWebScripts,
173
+ buildJQueryUIScripts,
174
+ buildJQueryMobileScripts
175
+ } ;
0 commit comments