11module .exports = (grunt ) ->
22 require (' load-grunt-tasks' ) grunt
33 grunt .file .readJSON (' package.json' )
4-
4+
55 # !! Compile configurations
66 License = ' /*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */'
77 FilterType = " Simple" # "Comment" || "Simple"
@@ -36,14 +36,14 @@ module.exports = (grunt) ->
3636 ' src/parsers/AcfunFormat.js'
3737 ' src/parsers/BilibiliFormat.js'
3838 ]
39-
39+
4040 # !! Below are compile settings
4141 # Dynamically generate the core ts targets
4242 CMP_CORE_TS = { }
4343 CMP_CORE_NAME = [ ]
4444 for target in SRC_CORE_CMP
4545 CMP_CORE_NAME .push (" typescript:" + target)
46- CMP_CORE_TS[target] =
46+ CMP_CORE_TS[target] =
4747 options :
4848 target : ' es5'
4949 basePath : ' src/core'
@@ -55,29 +55,31 @@ module.exports = (grunt) ->
5555 CMP_KAGEROU_NAME = [ ]
5656 for target,src of SRC_SCRIPTING_KAGEROU
5757 CMP_KAGEROU_NAME .push (' typescript:kagerou_engine_' + target)
58- CMP_KAGEROU_TS[' kagerou_engine_' + target] =
59- options :
58+ CMP_KAGEROU_TS[' kagerou_engine_' + target] =
59+ options :
6060 target : ' es5'
6161 basePath : src .split (' /' )[0 .. - 1 ].join (' /' )
6262 src : src
6363 dest : ' build/scripting/api/' + src .split (' /' ).pop ().split (' .' )[0 ] + ' .js'
64-
64+
6565 # Append Typescript Tasks
6666 ts_config = {}
6767 for key,value of CMP_CORE_TS
6868 ts_config[key] = value
6969 for key,value of CMP_KAGEROU_TS
7070 ts_config[key] = value
71-
71+
7272 # Core concatenated with libraries
7373 # Actual concat ordering does not/should not matter
7474 SRC_CORELIB = SRC_CORE .concat (SRC_PARSER)
7575
76+ grunt .loadNpmTasks (' grunt-contrib-coffee' )
77+ grunt .loadNpmTasks (' grunt-contrib-jasmine' )
7678 grunt .initConfig (
7779 clean :
7880 scripting : [' build/scripting' ]
7981 build : [' build' ]
80-
82+
8183 # Concat CSS and JS files
8284 # core_only : builds CCL without parsers
8385 # all : builds CCL with everything
@@ -93,18 +95,18 @@ module.exports = (grunt) ->
9395 files :
9496 ' build/style.css' : CSS
9597 ' build/CommentCoreLibrary.js' : SRC_CORELIB
96-
98+
9799 # Compile TypeScript
98100 typescript : ts_config
99-
101+
100102 # Copy
101103 copy :
102104 scripting_sandbox :
103105 files : [
104106 {expand : true , cwd : ' src/scripting/api/' , src : [' *.js' ], dest : ' build/scripting/api/' },
105107 {expand : true , cwd : ' src/scripting/' , src : [' OOAPI.js' ,' Worker.js' ], dest : ' build/scripting/' }
106108 ]
107-
109+
108110 # Auto-prefix CSS properties using Can I Use?
109111 autoprefixer :
110112 options :
@@ -130,19 +132,42 @@ module.exports = (grunt) ->
130132 ' build/CommentCoreLibrary.min.js' : SRC_CORELIB
131133
132134 # Watch files for changes
135+ #
133136 watch :
134137 all :
135138 files : [' src/**/*' , ' !node_modules' ]
136139
137140 # Run concat, autoprefixer, cssmin and uglify
138141 tasks : [' build' ]
142+
143+ # Jasmine test
144+
145+ jasmine :
146+ coverage :
147+ src : ' src/**/*.js'
148+ # src: 'build/CommentCoreLibrary.js'
149+ options :
150+ specs : ' compiled_spec/*spec.js'
151+ helpers : ' spec/*helper.js'
152+ template : require (' grunt-template-jasmine-istanbul' )
153+ templateOptions :
154+ report : ' coverage'
155+ coverage : ' coverage/coverage.json'
156+ coffee :
157+ glob_to_multiple :
158+ expand : true ,
159+ flatten : true ,
160+ src : [' spec/**/*.coffee' ]
161+ dest : ' compiled_spec/'
162+ ext : ' .js'
139163 )
140-
164+
141165 # Register special compiles
142166 grunt .registerTask ' compile-ts-kagerou' , CMP_KAGEROU_NAME
143167 grunt .registerTask ' compile-ts-core' , CMP_CORE_NAME
144-
168+
145169 # Register our tasks
170+ grunt .registerTask ' test' , [' coffee' , ' jasmine' ]
146171 grunt .registerTask ' build-scripting' , [' clean:scripting' ,' concat:scripting_host' , ' compile-ts-kagerou' , ' copy:scripting_sandbox' ]
147172 grunt .registerTask ' build-core' , [' compile-ts-core' , ' concat:core_only' , ' autoprefixer' , ' cssmin' , ' uglify:core_only' ]
148173 grunt .registerTask ' build' , [' compile-ts-core' , ' concat:all' , ' autoprefixer' , ' cssmin' , ' uglify:all' ]
0 commit comments