-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgruntfile.coffee
153 lines (135 loc) · 3.75 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
151
152
153
path = require "path"
buildConfig = require "./build-configs"
currentDir = __dirname
module.exports = (grunt) ->
grunt.initConfig
build: buildConfig
clean:
dest: ["dest"]
jade:
compile:
options:
pretty: true,
data:
siteRoot: "<%=configure.siteRoot%>"
contextPath: "<%=configure.contextPath%>"
serviceRoot: "<%=configure.serviceRoot%>"
htmlSuffix: "<%=configure.htmlSuffix%>"
siteContext: "<%=configure.siteContext%>"
files: [
{
expand: true
cwd: "views/"
src: ["**/*.jade"]
dest: "<%=configure.dest%>"
ext: ".html"
}
]
coffee:
compile:
options:
sourceMap: false
join: true
files: [{
expand: true
cwd: "public/"
src: ["**/*.coffee"]
dest: "<%=configure.dest%>"
ext: ".js"
}]
less:
compile:
files: [{
expand: true
cwd: "public/"
src: ["**/*.less",
"!**/.*.less"]
dest: "<%=configure.dest%>"
ext: ".css"
}]
copy:
css:
expand: true
cwd: "public"
src: ["resources/**/*", "!**/*.less", "!.**"]
dest: "<%=configure.dest%>"
uglify:
all:
files: [
{
expand: true
preserveComments: "some"
cwd: "<%=configure.dest%>"
src: "**/*.js"
dest: "<%=configure.dest%>"
ext: ".js"
}
]
cssmin:
all:
files: [
{
expand: true
cwd: "<%=configure.dest%>"
src: "**/*.css"
dest: "<%=configure.dest%>"
ext: ".css"
}
]
grunt.loadNpmTasks "grunt-contrib-clean"
grunt.loadNpmTasks "grunt-contrib-jade"
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-less"
grunt.loadNpmTasks "grunt-contrib-copy"
grunt.loadNpmTasks "grunt-contrib-uglify"
grunt.loadNpmTasks "grunt-contrib-cssmin"
grunt.loadNpmTasks "grunt-contrib-compress"
grunt.task.registerMultiTask("replaceConfig", "replace ...", ()->
commonJsPath = path.join(currentDir, "dest", "app", "common.js")
content = grunt.file.read(commonJsPath)
replace = (content, configure, key, defaultValue)->
value = configure[key]
if typeof value == "string"
defaultValue or= ""
console.log("#{key}: \"#{defaultValue}\"" + " | " + "#{key}: \"#{value}\"")
return content.replace("#{key}: \"#{defaultValue}\"", "#{key}: \"#{value}\"")
else
defaultValue or= "null"
return content.replace("#{key}: #{defaultValue}", "#{key}: #{value}");
configure = grunt.config("configure")
content = replace(content, configure, "version", "0.0.0")
content = replace(content, configure, "siteRoot", "/")
content = replace(content, configure, "contextPath", "/")
content = replace(content, configure, "serviceRoot", "/")
content = replace(content, configure, "htmlSuffix", "")
content = replace(content, configure, "language", "zh-Hans")
grunt.file.write(commonJsPath, content)
)
grunt.task.registerMultiTask("build", "Build all...", ()->
endWithDelim = (path)->
if (path.charAt(path.length - 1) != "/") then path += "/"
return path
startWithDelim = (path)->
if (path.charAt(0) != "/") then path = "/" + path
return path
removeLastDelim = (path)->
if (path.charAt(path.length - 1) == "/") then path = path.substring(0, path.length - 1)
return path
grunt.log.writeln("# Running ...")
configure = this.data
configure.dest = "dest";
configure.contextPath = removeLastDelim(configure.contextPath)
configure.siteRoot = endWithDelim(configure.siteRoot)
configure.siteContext = "#{removeLastDelim(configure.siteRoot)}#{endWithDelim(startWithDelim(configure.contextPath))}"
grunt.config("configure", configure)
console.dir(configure)
unless grunt._cleaned
grunt._cleaned = true
grunt.task.run("clean")
grunt.task.run([
"jade"
"copy"
"coffee"
"less"
])
)