1
+ var gulp = require ( 'gulp' ) ,
2
+ argv = require ( 'minimist' ) ,
3
+ path = require ( 'path' ) ,
4
+ config = require ( './config' ) ,
5
+ $ = require ( 'gulp-load-plugins' ) ( {
6
+ pattern : [ 'gulp-*' , 'event-stream' , 'main-bower-files' , 'uglify-save-license' , 'del' ]
7
+ } ) ,
8
+ gulpsync = $ . sync ( gulp ) ,
9
+ sass = require ( 'gulp-sass' ) ,
10
+ replace = require ( 'gulp-replace' ) ;
11
+ let eoSetPointSrc = ( ) => {
12
+ let pointLangIsEn = argv ( process . argv . slice ( 2 ) ) . en ;
13
+ if ( pointLangIsEn ) {
14
+ config . paths . src = '.tmp/enApp' ;
15
+ config . vendor . base . dest = '.tmp/enApp/app'
16
+ }
17
+ }
18
+ gulp . task ( 'dev-config' , function ( ) {
19
+ eoSetPointSrc ( ) ;
20
+ return gulp . src ( 'app.conf.json' )
21
+ . pipe ( $ . ngConfig ( config . modules . ConstantModuleName , {
22
+ environment : 'development' ,
23
+ createModule : false ,
24
+ wrap : true
25
+ } ) )
26
+ . pipe ( gulp . dest ( path . join ( config . paths . src , '/app' ) ) ) //join() 方法用于把数组中的所有元素放入一个字符串。
27
+ } ) ;
28
+ gulp . task ( 'prod-config' , function ( ) {
29
+ eoSetPointSrc ( ) ;
30
+ return gulp . src ( 'app.conf.json' )
31
+ . pipe ( $ . ngConfig ( config . modules . ConstantModuleName , {
32
+ environment : 'production' ,
33
+ createModule : false ,
34
+ wrap : true //生成闭包
35
+ } ) )
36
+ . pipe ( gulp . dest ( path . join ( config . paths . src , '/app' ) ) )
37
+ } ) ;
38
+ gulp . task ( 'test-config' , function ( ) {
39
+ eoSetPointSrc ( ) ;
40
+ return gulp . src ( 'app.conf.json' )
41
+ . pipe ( $ . ngConfig ( config . modules . ConstantModuleName , {
42
+ environment : 'test' ,
43
+ createModule : false ,
44
+ wrap : true //生成闭包
45
+ } ) )
46
+ . pipe ( gulp . dest ( path . join ( config . paths . src , '/app' ) ) )
47
+ } ) ;
48
+ gulp . task ( 'clean:dist' , function ( ) {
49
+ $ . del ( [ path . join ( config . paths . dist , '/' ) ] ) ;
50
+ } ) ;
51
+
52
+ /**
53
+ * [清理DIST,TEMP文件夹]
54
+ */
55
+
56
+ gulp . task ( 'clean' , function ( ) {
57
+ $ . del ( [ path . join ( config . paths . dist , '/' ) , path . join ( config . paths . tmp , '/' ) ] ) ;
58
+ } ) ;
59
+
60
+ gulp . task ( 'vendor' , gulpsync . sync ( [ 'vendor:base' ] ) ) ;
61
+
62
+ /**
63
+ * [复制依赖文件]
64
+ */
65
+
66
+ gulp . task ( 'vendor:base' , function ( ) {
67
+ var jsFilter = $ . filter ( '**/*.js' , {
68
+ restore : true
69
+ } ) ,
70
+ cssFilter = $ . filter ( '**/*.css' , {
71
+ restore : true
72
+ } ) ;
73
+ return gulp . src ( config . vendor . base . source )
74
+ . pipe ( $ . expectFile ( config . vendor . base . source ) )
75
+ . pipe ( jsFilter )
76
+ . pipe ( $ . concat ( config . vendor . base . name + '.js' ) )
77
+ . pipe ( jsFilter . restore )
78
+ . pipe ( cssFilter )
79
+ . pipe ( $ . concat ( config . vendor . base . name + '.scss' ) )
80
+ . pipe ( cssFilter . restore )
81
+ . pipe ( gulp . dest ( config . vendor . base . dest ) ) ;
82
+ } ) ;
83
+
84
+ gulp . task ( 'vendor:app' , function ( ) {
85
+
86
+ var jsFilter = $ . filter ( '*.js' , {
87
+ restore : true
88
+ } ) ,
89
+ cssFilter = $ . filter ( '*.css' , {
90
+ restore : true
91
+ } ) ;
92
+
93
+ return gulp . src ( config . vendor . app . source , {
94
+ base : 'bower_components'
95
+ } )
96
+ . pipe ( $ . expectFile ( config . vendor . app . source ) )
97
+ . pipe ( jsFilter )
98
+ . pipe ( jsFilter . restore )
99
+ . pipe ( cssFilter )
100
+ . pipe ( cssFilter . restore )
101
+ . pipe ( gulp . dest ( config . vendor . app . dest ) ) ;
102
+
103
+ } ) ;
104
+
105
+ /**
106
+ * [图片压缩]
107
+ */
108
+ gulp . task ( 'images' , function ( ) {
109
+ return gulp . src ( [
110
+ path . join ( config . paths . src , '/assets/images/**/*' ) ,
111
+ path . join ( '!' + config . paths . src , '/assets/images/sprite/**/*' )
112
+ ] )
113
+ . pipe ( $ . imagemin ( {
114
+ progressive : true ,
115
+ svgoPlugins : [ {
116
+ removeViewBox : false
117
+ } ] ,
118
+ use : [ $ . imageminPngquant ( ) ]
119
+ } ) )
120
+ . pipe ( gulp . dest ( path . join ( config . paths . dist , '/assets/images' ) ) ) ;
121
+ } ) ;
122
+
123
+ gulp . task ( 'fonts' , function ( ) {
124
+
125
+ return gulp . src ( config . vendor . base . source , {
126
+ base : 'bower_components'
127
+ } )
128
+ . pipe ( $ . filter ( '**/*.{eot,svg,ttf,woff,woff2}' ) )
129
+ . pipe ( $ . flatten ( ) )
130
+ . pipe ( gulp . dest ( path . join ( config . paths . dist , '/fonts/' ) ) ) ;
131
+ } ) ;
132
+
133
+ /**
134
+ * [复制文件] 前端依赖库以及静态文件
135
+ */
136
+ gulp . task ( 'other:vendor' , function ( ) {
137
+ return gulp . src ( [
138
+ path . join ( config . paths . src , '/vendor/**/*' ) ,
139
+ ] )
140
+ . pipe ( $ . filter ( function ( file ) {
141
+ return file . stat . isFile ( ) ;
142
+ } ) )
143
+ . pipe ( gulp . dest ( path . join ( config . paths . dist , '/vendor' ) ) ) ;
144
+ } ) ;
145
+ gulp . task ( 'other:libs:js' , function ( ) {
146
+ return gulp . src ( [
147
+ path . join ( config . paths . src , '/libs/**/*.js' )
148
+ ] )
149
+ . pipe ( $ . filter ( function ( file ) {
150
+ return file . stat . isFile ( ) ;
151
+ } ) )
152
+ // .pipe($.babel())
153
+ . pipe ( $ . stripDebug ( ) )
154
+ . pipe ( $ . uglify ( ) )
155
+ . pipe ( gulp . dest ( path . join ( config . paths . dist , '/libs' ) ) ) ;
156
+ } ) ;
157
+ gulp . task ( 'other:libs' , [ 'other:libs:js' ] , function ( ) {
158
+ return gulp . src ( [
159
+ path . join ( config . paths . src , '/libs/**/*' ) ,
160
+ path . join ( '!' + config . paths . src , '/libs/**/*.js' )
161
+ ] )
162
+ . pipe ( $ . filter ( function ( file ) {
163
+ return file . stat . isFile ( ) ;
164
+ } ) )
165
+ . pipe ( gulp . dest ( path . join ( config . paths . dist , '/libs' ) ) ) ;
166
+ } ) ;
167
+ gulp . task ( 'other:assets' , function ( ) {
168
+ return gulp . src ( [
169
+ path . join ( config . paths . src , '/app/assets/**/*' )
170
+ ] )
171
+ . pipe ( $ . filter ( function ( file ) {
172
+ return file . stat . isFile ( ) ;
173
+ } ) )
174
+ . pipe ( gulp . dest ( path . join ( config . paths . dist , '/assets' ) ) ) ;
175
+ } ) ;
176
+
177
+
178
+ gulp . task ( 'version:scar' , function ( ) {
179
+ gulp . src ( [
180
+ path . join ( config . paths . src , '../version/*.md' ) ,
181
+ ] )
182
+ . pipe ( replace ( / ( p o s i t i o n \s ) ( [ ^ \u4e00 - \u9fa5 ] .* ) / g, function ( match ) {
183
+ return match . replace ( / p o s i t i o n \s / , "position " + config . version . scar ) . replace ( / \\ / g, "/" ) ;
184
+ } ) )
185
+ . pipe ( gulp . dest ( path . join ( config . paths . version , '/file' ) ) ) ;
186
+ } ) ;
187
+ gulp . task ( 'version:lethe' , function ( ) {
188
+ gulp . src ( [
189
+ path . join ( config . paths . src , '../version/*.md' ) ,
190
+ ] )
191
+ . pipe ( replace ( / ( p o s i t i o n \s ) ( [ ^ \u4e00 - \u9fa5 ] .* ) / g, function ( match ) {
192
+ return match . replace ( / p o s i t i o n \s / , "position " + config . version . lethe ) . replace ( / \\ / g, "/" ) ;
193
+ } ) )
194
+ . pipe ( gulp . dest ( path . join ( config . paths . version , '/file' ) ) ) ;
195
+ } ) ;
0 commit comments