forked from jabbany/CommentCoreLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
215 lines (189 loc) · 6.1 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
module.exports = (grunt) ->
require('load-grunt-tasks') grunt , {
pattern: ['grunt-*', '!grunt-template-jasmine-istanbul']
}
grunt.file.readJSON('package.json')
# !! Compile configurations
License = '/*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */'
FilterType = "Simple" # "Comment" || "Simple"
# !! End of config area
CSS = [
'src/css/base.css',
'src/css/fontalias.css'
]
SRC_CORE_CMP = [
'Comment'
'CommentSpaceAllocator'
]
SRC_CORE = [
'src/Array.js'
'src/core/CommentSpaceAllocator.js'
'src/core/Comment.js'
'src/filter/' + FilterType + 'Filter.js'
'src/CommentCoreLibrary.js'
]
SRC_SCRIPTING_KAGEROU =
display: 'src/scripting/api/Display/Display.ts'
runtime: 'src/scripting/api/Runtime/Runtime.ts'
player: 'src/scripting/api/Player/Player.ts'
utils: 'src/scripting/api/Utils/Utils.ts'
tween: 'src/scripting/api/Tween/Tween.ts'
SRC_PARSER = [
'src/parsers/AcfunFormat.js'
'src/parsers/BilibiliFormat.js'
]
# !! Below are compile settings
# Dynamically generate the core ts targets
CMP_CORE_TS = { }
CMP_CORE_NAME = [ ]
for target in SRC_CORE_CMP
CMP_CORE_NAME.push ("typescript:" + target)
CMP_CORE_TS[target] =
options:
target: 'es5'
basePath: 'src/core'
src: "src/core/" + target + ".ts"
dest: "src/core/" + target + ".js"
# Dynamically generate the kagerou ts targets
CMP_KAGEROU_TS = { }
CMP_KAGEROU_NAME = [ ]
for target,src of SRC_SCRIPTING_KAGEROU
CMP_KAGEROU_NAME.push ('typescript:kagerou_engine_' + target)
CMP_KAGEROU_TS['kagerou_engine_' + target] =
options:
target: 'es5'
basePath: src.split('/')[0..-1].join('/')
src: src
dest: 'build/scripting/api/' + src.split('/').pop().split('.')[0] + '.js'
# Append Typescript Tasks
ts_config = {}
for key,value of CMP_CORE_TS
ts_config[key] = value
for key,value of CMP_KAGEROU_TS
ts_config[key] = value
# Core concatenated with libraries
# Actual concat ordering does not/should not matter
SRC_CORELIB = SRC_CORE.concat(SRC_PARSER)
grunt.loadNpmTasks('grunt-contrib-coffee')
grunt.loadNpmTasks('grunt-contrib-jasmine')
grunt.initConfig(
clean:
scripting: ['build/scripting']
build: ['build']
# Concat CSS and JS files
# core_only : builds CCL without parsers
# all : builds CCL with everything
concat:
scripting_host:
files:
'build/scripting/Host.js': ['src/scripting/Host.js','src/scripting/Unpacker.js']
core_only:
files:
'build/style.css': CSS
'build/CommentCore.js': SRC_CORE
all:
files:
'build/style.css': CSS
'build/CommentCoreLibrary.js': SRC_CORELIB
# Compile TypeScript
typescript: ts_config
# Copy
copy:
scripting_sandbox:
files:[
{expand: true, cwd:'src/scripting/api/', src: ['*.js'], dest:'build/scripting/api/'},
{expand: true, cwd:'src/scripting/', src: ['OOAPI.js','Worker.js'], dest:'build/scripting/'}
]
# Auto-prefix CSS properties using Can I Use?
autoprefixer:
options:
browsers: ['last 3 versions', 'bb 10', 'android 3']
no_dest:
# File to output
src: 'build/style.css'
# Minify CSS
cssmin:
minify:
src: ['build/style.css']
dest: 'build/style.min.css'
uglify:
options: banner: License
core_only:
files:
'build/CommentCore.min.js': SRC_CORE
all:
files:
'build/CommentCoreLibrary.min.js': SRC_CORELIB
# Watch files for changes
#
watch:
all:
files: ['src/**/*', '!node_modules']
# Run concat, autoprefixer, cssmin and uglify
tasks: ['build']
jshint:
options:
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
node: true,
strict: false,
mocha: true
all:
src: ['src/*.js']
# Jasmine test
jasmine:
coverage:
src: 'src/**/*.js'
options:
specs: 'compiled_spec/*spec.js'
helpers: 'spec/*helper.js'
vendor: [
'node_modules/jasmine-jquery/vendor/jquery/jquery.js'
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
]
template: require('grunt-template-jasmine-istanbul')
templateOptions:
report: 'coverage'
coverage: 'coverage/coverage.json'
ci:
src: 'build/CommentCoreLibrary.js'
options:
specs: 'compiled_spec/*spec.js'
helpers: 'spec/*helper.js'
vendor: [
'node_modules/jasmine-jquery/vendor/jquery/jquery.js'
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
]
template: require('grunt-template-jasmine-istanbul')
templateOptions:
report:
type: 'lcovonly'
options:
dir: 'coverage'
coverage: 'coverage/coverage.json'
coffee:
glob_to_multiple:
expand: true,
flatten: true,
src: ['spec/**/*.coffee']
dest: 'compiled_spec/'
ext: '.js'
)
# Register special compiles
grunt.registerTask 'compile-ts-kagerou', CMP_KAGEROU_NAME
grunt.registerTask 'compile-ts-core', CMP_CORE_NAME
# Register our tasks
grunt.registerTask 'test', ['coffee', 'jasmine:coverage']
grunt.registerTask 'build-scripting', ['clean:scripting','concat:scripting_host', 'compile-ts-kagerou', 'copy:scripting_sandbox']
grunt.registerTask 'build-core', ['compile-ts-core', 'concat:core_only', 'autoprefixer', 'cssmin', 'uglify:core_only']
grunt.registerTask 'build', ['compile-ts-core', 'concat:all', 'autoprefixer', 'cssmin', 'uglify:all']
grunt.registerTask 'ci', ['build', 'coffee', 'jasmine:ci']
grunt.registerTask 'default', ['clean', 'build', 'build-scripting', 'watch']