forked from RubyLouvre/avalon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
179 lines (155 loc) · 7.15 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
var gulp = require('gulp');
var path = require('path');
var concat = require('gulp-concat')
var replace = require('gulp-replace')
//http://www.cnblogs.com/code/articles/4103070.html
//https://github.com/basecss/jshint-doc-cn/blob/master/options.md
var jshint = require('gulp-jshint')
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
function replaceUrls(array, hash) {
for (var i = 0, href; href = array[i]; i++) {
for (var key in hash) {
if (href.indexOf(key) !== -1) {
array[i] = href.replace(key, hash[key])
delete hash[key]
continue
}
}
}
}
gulp.task('combo', function () {
//https://github.com/isaacs/node-glob
//http://www.linuxjournal.com/content/bash-extended-globbing
return gulp.src('./src/**/*.js', function (a, b) {
var compatibleFiles = b.filter(function (f) {
return !/\$\$|noop|modern|next|observe|touch/.test(f)
})
var version = 1.44 //当前版本号
var now = new Date //构建日期
var date = now.getFullYear() + "." + (now.getMonth() + 1) + "." + now.getDate()
gulp.src(compatibleFiles)
.pipe(concat('avalon.js'))
.pipe(replace(/version:\s+([\d\.]+)/, function (a, b) {
return "version: " + version
}))
.pipe(replace(/!!/, function (a, b) {
return "avalon.js " + version + " built in " + date + "\n support IE6+ and other browsers"
}))
.pipe(gulp.dest('./'))
.pipe(gulp.dest('./dist/'))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gulp.dest('../avalon.test/src/'))
.pipe(uglify())
.pipe(rename('avalon.min.js'))
.pipe(gulp.dest('./dist/'))
var $$pathName = compatibleFiles[0]
$$pathName = $$pathName.slice(0, $$pathName.indexOf("00"))
var fixPath = function (name) {
return path.join($$pathName, name + ".js")
}
//avalon.shim.js 所需要合并的子文件
var shimFiles = compatibleFiles.slice(0, -3).concat(fixPath("22 domReady.noop"), fixPath("24 outer"))
gulp.src(shimFiles)
.pipe(concat('avalon.shim.js'))
.pipe(replace(/version:\s+([\d\.]+)/, function (a, b) {
return "version: " + version
}))
.pipe(replace(/!!/, function (a, b) {
return "avalon.shim.js(无加载器版本) " + version + " built in " + date + "\n support IE6+ and other browsers"
}))
.pipe(gulp.dest('./dist/'))
//avalon.modern.js 所需要合并的子文件
var modernFiles = compatibleFiles.filter(function (el) {
return !/shim/.test(el)
})
replaceUrls(modernFiles, {
"01 variable": "01 variable.modern",
"02 core": "02 core.modern",
"05 dom.polyfill": "05 dom.polyfill.modern",
"07 EventBus": "07 EventBus.modern",
"08 modelFactory": "08 modelFactory.modern",
"15 HTML": "15 HTML.modern",
"16 dom": "16 dom.modern",
"17 parser": "17 parser.modern",
"18 scanAttr": "18 scanAttr.modern",
"18 scanTag": "18 scanTag.modern",
"21 loader": "21 loader.modern",
"text": "text.modern",
"duplex.2": "duplex.2.modern",
"22 domReady": "22 domReady.modern"
})
gulp.src(modernFiles)
.pipe(concat('avalon.modern.js'))
.pipe(replace(/version:\s+([\d\.]+)/, function (a, b) {
return "version: " + version
}))
.pipe(replace(/!!/, function (a, b) {
return "avalon.modern.js " + version + " built in " + date + "\n support IE10+ and other browsers"
}))
.pipe(gulp.dest('./dist/'))
.pipe(gulp.dest('../avalon.test/src/'))
.pipe(uglify())
.pipe(rename('avalon.modern.min.js'))
.pipe(gulp.dest('./dist/'))
var modernShimFiles = modernFiles.slice(0, -3).concat(fixPath("22 domReady.noop"), fixPath("24 outer"))
gulp.src(modernShimFiles)
.pipe(concat('avalon.modern.shim.js'))
.pipe(replace(/version:\s+([\d\.]+)/, function (a, b) {
return "version: " + version
}))
.pipe(replace(/loader:\s*true/, "loader: false"))
.pipe(replace(/!!/, function (a, b) {
return "avalon.modern.shim.js(无加载器版本) " + version + " built in " + date + "\n support IE10+ and other browsers"
}))
.pipe(gulp.dest('./dist/'))
//avalon.mobiles.js 所需要合并的子文件
var mobileFiles = modernFiles.concat()
mobileFiles.pop()
mobileFiles.push(fixPath("23 touch"), fixPath("24 outer"))
gulp.src(mobileFiles)
.pipe(concat('avalon.mobile.js'))
.pipe(replace(/version:\s+([\d\.]+)/, function (a, b) {
return "version: " + version
}))
.pipe(replace(/!!/, function (a, b) {
return "avalon.mobile.js " + version + " built in " + date + "\n support IE10+ and other browsers"
}))
.pipe(gulp.dest('./dist/'))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(uglify())
.pipe(rename('avalon.mobile.min.js'))
.pipe(gulp.dest('./dist/'))
//avalon.mobiles.shim.js 所需要合并的子文件
var mobileShimFiles = modernFiles.slice(0, -3).concat(fixPath("22 domReady.noop"), fixPath("23 touch"), fixPath("24 outer"))
console.log(mobileShimFiles)
gulp.src(mobileShimFiles)
.pipe(concat('avalon.mobile.shim.js'))
.pipe(replace(/version:\s+([\d\.]+)/, function (a, b) {
return "version: " + version
}))
.pipe(replace(/loader:\s*true/, "loader: false"))
.pipe(replace(/!!/, function (a, b) {
return "avalon.mobile.shim.js " + version + " built in " + date
}))
.pipe(gulp.dest('./dist/'))
//avalon.mobiles.old.js 所需要合并的子文件
var mobileOldFiles = compatibleFiles.concat()
mobileOldFiles.pop()
mobileOldFiles.push(fixPath("23 touch"), fixPath("24 outer"))
gulp.src(mobileOldFiles)
.pipe(concat('avalon.mobile.old.js'))
.pipe(replace(/version:\s+([\d\.]+)/, function (a, b) {
return "version: " + version
}))
.pipe(replace(/!!/, function (a, b) {
return "avalon.mobile.old.js " + version + " built in " + date + "\n support IE8 and other browsers"
}))
.pipe(gulp.dest('./dist/'))
})
})
gulp.task('default', ['combo'], function () {
console.log('合并完毕')
});