11module .exports = (grunt ) ->
2- require (' load-grunt-tasks' ) grunt
2+ require (' load-grunt-tasks' ) grunt , {
3+ pattern : [' grunt-*' , ' !grunt-template-jasmine-istanbul' ]
4+ }
35 grunt .file .readJSON (' package.json' )
4-
6+
57 # !! Compile configurations
68 License = ' /*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */'
79 FilterType = " Simple" # "Comment" || "Simple"
@@ -36,14 +38,14 @@ module.exports = (grunt) ->
3638 ' src/parsers/AcfunFormat.js'
3739 ' src/parsers/BilibiliFormat.js'
3840 ]
39-
41+
4042 # !! Below are compile settings
4143 # Dynamically generate the core ts targets
4244 CMP_CORE_TS = { }
4345 CMP_CORE_NAME = [ ]
4446 for target in SRC_CORE_CMP
4547 CMP_CORE_NAME .push (" typescript:" + target)
46- CMP_CORE_TS[target] =
48+ CMP_CORE_TS[target] =
4749 options :
4850 target : ' es5'
4951 basePath : ' src/core'
@@ -55,29 +57,31 @@ module.exports = (grunt) ->
5557 CMP_KAGEROU_NAME = [ ]
5658 for target,src of SRC_SCRIPTING_KAGEROU
5759 CMP_KAGEROU_NAME .push (' typescript:kagerou_engine_' + target)
58- CMP_KAGEROU_TS[' kagerou_engine_' + target] =
59- options :
60+ CMP_KAGEROU_TS[' kagerou_engine_' + target] =
61+ options :
6062 target : ' es5'
6163 basePath : src .split (' /' )[0 .. - 1 ].join (' /' )
6264 src : src
6365 dest : ' build/scripting/api/' + src .split (' /' ).pop ().split (' .' )[0 ] + ' .js'
64-
66+
6567 # Append Typescript Tasks
6668 ts_config = {}
6769 for key,value of CMP_CORE_TS
6870 ts_config[key] = value
6971 for key,value of CMP_KAGEROU_TS
7072 ts_config[key] = value
71-
73+
7274 # Core concatenated with libraries
7375 # Actual concat ordering does not/should not matter
7476 SRC_CORELIB = SRC_CORE .concat (SRC_PARSER)
7577
78+ grunt .loadNpmTasks (' grunt-contrib-coffee' )
79+ grunt .loadNpmTasks (' grunt-contrib-jasmine' )
7680 grunt .initConfig (
7781 clean :
7882 scripting : [' build/scripting' ]
7983 build : [' build' ]
80-
84+
8185 # Concat CSS and JS files
8286 # core_only : builds CCL without parsers
8387 # all : builds CCL with everything
@@ -93,18 +97,18 @@ module.exports = (grunt) ->
9397 files :
9498 ' build/style.css' : CSS
9599 ' build/CommentCoreLibrary.js' : SRC_CORELIB
96-
100+
97101 # Compile TypeScript
98102 typescript : ts_config
99-
103+
100104 # Copy
101105 copy :
102106 scripting_sandbox :
103107 files : [
104108 {expand : true , cwd : ' src/scripting/api/' , src : [' *.js' ], dest : ' build/scripting/api/' },
105109 {expand : true , cwd : ' src/scripting/' , src : [' OOAPI.js' ,' Worker.js' ], dest : ' build/scripting/' }
106110 ]
107-
111+
108112 # Auto-prefix CSS properties using Can I Use?
109113 autoprefixer :
110114 options :
@@ -130,21 +134,82 @@ module.exports = (grunt) ->
130134 ' build/CommentCoreLibrary.min.js' : SRC_CORELIB
131135
132136 # Watch files for changes
137+ #
133138 watch :
134139 all :
135140 files : [' src/**/*' , ' !node_modules' ]
136141
137142 # Run concat, autoprefixer, cssmin and uglify
138143 tasks : [' build' ]
144+
145+ jshint :
146+ options :
147+ curly : true ,
148+ eqeqeq : true ,
149+ immed : true ,
150+ latedef : true ,
151+ newcap : true ,
152+ noarg : true ,
153+ sub : true ,
154+ undef : true ,
155+ boss : true ,
156+ eqnull : true ,
157+ node : true ,
158+ strict : false ,
159+ mocha : true
160+ all :
161+ src : [' src/*.js' ]
162+
163+ # Jasmine test
164+
165+ jasmine :
166+ coverage :
167+ src : ' src/**/*.js'
168+ options :
169+ specs : ' compiled_spec/*spec.js'
170+ helpers : ' spec/*helper.js'
171+ vendor : [
172+ ' node_modules/jasmine-jquery/vendor/jquery/jquery.js'
173+ ' node_modules/jasmine-jquery/lib/jasmine-jquery.js'
174+ ]
175+ template : require (' grunt-template-jasmine-istanbul' )
176+ templateOptions :
177+ report : ' coverage'
178+ coverage : ' coverage/coverage.json'
179+ ci :
180+ src : ' build/CommentCoreLibrary.js'
181+ options :
182+ specs : ' compiled_spec/*spec.js'
183+ helpers : ' spec/*helper.js'
184+ vendor : [
185+ ' node_modules/jasmine-jquery/vendor/jquery/jquery.js'
186+ ' node_modules/jasmine-jquery/lib/jasmine-jquery.js'
187+ ]
188+ template : require (' grunt-template-jasmine-istanbul' )
189+ templateOptions :
190+ report :
191+ type : ' lcovonly'
192+ options :
193+ dir : ' coverage'
194+ coverage : ' coverage/coverage.json'
195+ coffee :
196+ glob_to_multiple :
197+ expand : true ,
198+ flatten : true ,
199+ src : [' spec/**/*.coffee' ]
200+ dest : ' compiled_spec/'
201+ ext : ' .js'
139202 )
140-
203+
141204 # Register special compiles
142205 grunt .registerTask ' compile-ts-kagerou' , CMP_KAGEROU_NAME
143206 grunt .registerTask ' compile-ts-core' , CMP_CORE_NAME
144-
207+
145208 # Register our tasks
209+ grunt .registerTask ' test' , [' coffee' , ' jasmine:coverage' ]
146210 grunt .registerTask ' build-scripting' , [' clean:scripting' ,' concat:scripting_host' , ' compile-ts-kagerou' , ' copy:scripting_sandbox' ]
147211 grunt .registerTask ' build-core' , [' compile-ts-core' , ' concat:core_only' , ' autoprefixer' , ' cssmin' , ' uglify:core_only' ]
148212 grunt .registerTask ' build' , [' compile-ts-core' , ' concat:all' , ' autoprefixer' , ' cssmin' , ' uglify:all' ]
213+ grunt .registerTask ' ci' , [' build' , ' coffee' , ' jasmine:ci' ]
149214 grunt .registerTask ' default' , [' clean' , ' build' , ' build-scripting' , ' watch' ]
150215
0 commit comments