-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
163 lines (140 loc) · 3.89 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
154
155
156
157
158
159
160
161
162
163
module.exports = (grunt) ->
# Output
libName = "ajs.js"
productionName = "ajs-prod.min.js"
productionNameFull = "ajs-prod-full.min.js"
# Directories
buildDir = "build"
libDir = "lib"
testDir = "test"
devDir = "dev"
production = "#{buildDir}/#{productionName}"
productionFull = "#{buildDir}/#{productionNameFull}"
productionConcatFull = [
"#{devDir}/components/adefyre/build/are-prod-full.min.js"
"#{devDir}/ajs.js"
]
# Intermediate vars
__adefyOut = {}
__adefyOut["#{buildDir}/ajs-concat.coffee"] = [ "#{libDir}/AJS.coffee" ]
__adefyOut["#{devDir}/ajs-concat.coffee"] = [ "#{libDir}/AJS.coffee" ]
__coffeeConcatFiles = {}
# Build concat output
__coffeeConcatFiles["#{buildDir}/#{libName}"] = "#{buildDir}/ajs-concat.coffee";
# Dev concat output, used for browser testing
__coffeeConcatFiles["#{devDir}/#{libName}"] = "#{buildDir}/ajs-concat.coffee";
# 1 to 1 compiled files, for unit tests
__coffeeFiles = [
"#{libDir}/*.coffee"
"#{libDir}/**/*.coffee"
]
__testFiles = {}
__testFiles["#{buildDir}/test/spec.js"] = [
"#{testDir}/spec/*.coffee"
"#{testDir}/spec/**/*.coffee"
]
_uglify = {}
_uglify[production] = "#{buildDir}/#{libName}"
_uglify[productionFull] = productionFull
grunt.initConfig
pkg: grunt.file.readJSON "package.json"
coffee:
concat:
options:
sourceMap: true
bare: true
cwd: buildDir
files: __coffeeConcatFiles
lib:
expand: true
options:
bare: true
src: __coffeeFiles
dest: buildDir
ext: ".js"
tests:
expand: true
options:
bare: true
files: __testFiles
concat_in_order:
lib:
files: __adefyOut
options:
extractRequired: (path, content) ->
workingDir = path.split "/"
workingDir.pop()
deps = @getMatches /\#\s\@depend\s(.*\.coffee)/g, content
deps.forEach (dep, i) ->
deps[i] = "#{workingDir.join().replace(',', '/')}/#{dep}"
console.log "Got dep #{deps[i]}"
return deps
extractDeclared: (path) -> [path]
onlyConcatRequiredFiles: true
watch:
coffeescript:
files: [
"#{libDir}/**/*.coffee"
"#{libDir}/*.coffee"
"#{testDir}/**/*.coffee"
"#{testDir}/*.coffee"
]
tasks: ["concat_in_order", "coffee", "mocha"]
connect:
server:
options:
port: 8081
base: "./dev"
mocha:
all:
src: [ "#{buildDir}/#{testDir}/test.html" ]
options:
bail: false
log: true
reporter: "Nyan"
run: true
copy:
test_page:
files: [
expand: true
cwd: "#{testDir}/env"
src: [ "**" ]
dest: "#{buildDir}/#{testDir}"
]
clean: [
buildDir
]
# Production concat
concat:
options:
stripBanners: true
distFull:
src: productionConcatFull
dest: productionFull
uglify:
options:
preserveComments: false
banner: "/* Copyright © 2013 Spectrum IT Solutions Gmbh - All Rights Reserved */\n"
production:
files: _uglify
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-connect"
grunt.loadNpmTasks "grunt-contrib-clean"
grunt.loadNpmTasks "grunt-concat-in-order"
grunt.loadNpmTasks "grunt-contrib-copy"
grunt.loadNpmTasks "grunt-contrib-concat"
grunt.loadNpmTasks "grunt-contrib-uglify"
grunt.loadNpmTasks "grunt-mocha"
# Perform a full build
grunt.registerTask "default", ["full"]
grunt.registerTask "full", [
"clean"
"copy:test_page"
"concat_in_order"
"coffee"
"mocha"
"concat"
"uglify"
]
grunt.registerTask "dev", ["connect", "copy:test_page", "watch"]