-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
106 lines (93 loc) · 3.17 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
(function(){
var gulp = require('gulp')
var replace = require('gulp-replace')
gulp.task('default', gulp.series(
clean,
gulp.parallel(copyDoTA, copyNgDoTA),
uglify
))
gulp.task('watch', function() {
gulp.watch(['doTA.js', 'ngDoTA.js'],
gulp.parallel(copyDoTA, copyNgDoTA)
)
})
//////////////////////////////
function clean() {
var del = require('del')
return del(['dist/*'])
}
function copyDoTA() {
return gulp.src(['doTA.js'])
.pipe(replace.apply(this, inline1))
.pipe(replace.apply(this, inline2))
.pipe(gulp.dest('dist'))
}
function copyNgDoTA() {
var concat = require('gulp-concat')
return gulp.src(['doTA.js', 'ngDoTA.js'])
.pipe(replace.apply(this, inline1))
.pipe(replace.apply(this, inline2))
.pipe(concat('ngDoTA.js'))
.pipe(gulp.dest('dist'))
}
function uglify() {
var closure = require('gulp-closure-compiler-service')
var gulpUglify = require('gulp-uglify')
var rename = require('gulp-rename')
var sourcemaps = require('gulp-sourcemaps')
return gulp.src(['dist/*.js', '!dist/*.min.js'])
// .pipe(replace(/^\s*console\.log.*$/gm, ''))
.pipe(sourcemaps.init())
.pipe(replace(/^\s*console\..*$/gm, ''))
.pipe(replace(/\bindent\([^)]+\)\s*\+\s*|\\n(?=['"}]|$)/g, ''))
.pipe(closure())
.pipe(gulpUglify({mangle:true, compress:{drop_console: true}}))
.on('error', console.error)
.pipe(rename({
extname: '.min.js'
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'))
}
gulp.task('docs', makeExampleIndex)
////////////////////////
var inline1 = [
/(\w+)\s*=\s*getOuterHTMLEnd\((\w+)\s*,\s*(\w+)\);/g,
'LVL=1,$1=$3;for(;;){$1=$2.indexOf(">",$1);if("/"===$2.charAt($1-1)&&(LVL--,0>=LVL))break;$1=$2.indexOf("<",$1);if("/"===$2.charAt($1+1)){if(LVL--,0>=LVL){$1=$2.indexOf(">",$1+2);break}}else"!"!==$2.charAt($1+1)&&LVL++}$1++; //INLINE'
]
var inline2 = [
/=\s*decodeEntities\(([^)]+)\)/g,
'=0>$1.indexOf("&")?$1:$1.replace(/>/g,">").replace(/</g,"<").replace(/&/g,"&").replace(/"/g,\'"\'); //INLINE'
]
function makeExampleIndex() {
var BASE = './examples'
var TITLE = 'doTA - Examples Index'
var before = '<html><head><meta charset="utf-8"><title>' + TITLE + '</title></head><body><h1>' + TITLE + '</h1><ul>'
var fs = require('fs')
var path = require('path')
var dirs = fs.readdirSync(BASE)
var ret = []
dirs.forEach(function(subFolder) {
subFolder = path.join(BASE, subFolder)
var stats = fs.statSync(subFolder)
// console.log('stats', stats)
if (stats.isDirectory(subFolder)) {
fs.readdirSync(subFolder).forEach(function(file) {
if (/\.htm.?$/i.test(file)) {
var fullPath = path.join(subFolder, file)
var buffer = fs.readFileSync(fullPath)
var title = /<title>([\s\S]+?)<\/title>/.test(buffer) && RegExp.$1.trim()
ret.push([stats.ctime, '<li><a href="../' + fullPath + '">' + title + '</a></li>'])
// console.log(fullPath, title)
}
})
}
})
ret.sort(function(a, b) { return a[0] - b[0]; })
var after = '</ul></body></html>'
fs.writeFileSync(path.join(BASE, 'index.html'),
before + ret.map(function(x){ return x[1]; }).join('') + after)
// return ret
}
// console.log(makeExampleIndex())
})()