-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGruntfile.coffee
174 lines (140 loc) · 5.6 KB
/
Gruntfile.coffee
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
module.exports = (grunt) ->
'use strict'
pkg = grunt.file.readJSON 'package.json'
convert = (name, path, contents) ->
while true
item = contents.match(/(.+) = require\(['"].+['"]\);/)
break if not item?
for k, v of item
moduleName = v.trim() if k is "1"
contents = contents.replace(new RegExp("(var.*) " + moduleName + ",?"), "$1")
contents = contents.replace(/(var.*), *;/, "$1;")
contents = contents.replace(/(.+) = require\(['"].+['"]\).*\n/, "")
contents = contents.replace(/.*Generated by CoffeeScript.*\n/, "")
exportVar = contents.match(/return module.exports = (.*);\n/)[1]
contents = contents.replace(/return module.exports = (.*);\n/, "return $1;")
contents = contents.replace(/(.+) = require\(['"]$/, "")
contents = contents.replace(/define\([^{]*?{/, "").replace(/\}\);[^}\w]*$/, "")
contents = contents.replace(/define\(\[[^\]]+\]\)[\W\n]+$/, "")
contents = contents.replace(/version = \"\";/, "version = \"#{pkg.version}\"")
contents = "var #{exportVar} = (function(){\n" + contents
contents += "\n})();\n"
# 特殊处理Promise
contents = contents.replace("var Promise =", "var Promise = Utils.isFunction(window.Promise) ? window.Promise :")
return contents
require('load-grunt-tasks')(grunt)
grunt.initConfig {
pkg: pkg
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' + '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n'
karma: {
unit: {
configFile: 'karma.conf.coffee'
singleRun: true
}
}
clean: {
build: ['dist/<%= pkg.version %>']
doc: ['docs']
# release: ['dist/*', '!dist/localdb{.,.min.}js']
}
requirejs: {
### r.js exmaple build file
* https://github.com/jrburke/r.js/blob/master/build/example.build.js
###
compile: {
options: {
name: "localdb"
# mainConfigFile: 'src/localdb.js'
baseUrl: "src/"
out: "dist/<%= pkg.version %>/localdb.js"
optimize: 'none'
# Include dependencies loaded with require
findNestedDependencies: true
# Avoid breaking semicolons inserted by r.js
skipSemiColonInsertion: true
wrap: {
startFile: "src/wrap.start"
endFile: "src/wrap.end"
}
onBuildWrite: convert
}
}
}
copy: {
main: {
files: {
"dist/<%= pkg.version %>/localdb-sea.js": ["dist/<%= pkg.version %>/localdb.js"]
}
options: {
process: (content, srcpath) -> "define(function(require, exports, module) {#{content}});"
}
}
}
uglify: {
standalone: {
files: {
"dist/<%= pkg.version %>/localdb.min.js": ["dist/<%= pkg.version %>/localdb.js"]
}
options: {
banner: '<%= banner %>'
preserveComments: false
sourceMap: true
sourceMapName: "dist/<%= pkg.version %>/localdb.min.map"
report: "min"
beautify: {
"ascii_only": true
}
compress: {
"hoist_funs": false
loops: false
unused: false
}
}
}
sea: {
files: {
"dist/<%= pkg.version %>/localdb-sea.min.js": ["dist/<%= pkg.version %>/localdb-sea.js"]
}
options: {
banner: '<%= banner %>'
preserveComments: false
sourceMap: true
sourceMapName: "dist/<%= pkg.version %>/localdb-sea.min.map"
report: "min"
beautify: {
"ascii_only": true
}
compress: {
"hoist_funs": false
loops: false
unused: false
}
}
}
}
coveralls: {
options: {
debug: true
coverage_dir: 'coverage/'
dryRun: if process.env.TRAVIS? then false else true
force: true
recursive: true
}
}
jsdoc: {
dist: {
src: ['src/**/*.js', 'README.md']
dest: "docs"
options: {
template: "node_modules/jaguarjs-jsdoc"
configure: "jsdoc.json"
private: false
}
}
}
}
grunt.registerTask 'test', ['karma', 'coveralls']
grunt.registerTask 'build-doc', ['clean:doc', 'jsdoc']
grunt.registerTask 'build', ['test', 'clean:build', 'requirejs', 'copy', 'uglify:*', 'build-doc']
grunt.registerTask 'default', ['test']
return