@@ -2,97 +2,111 @@ module.exports = (grunt) ->
22 require (' load-grunt-tasks' ) grunt , {
33 pattern : [' grunt-*' , ' !grunt-template-jasmine-istanbul' ]
44 }
5- grunt .file .readJSON (' package.json' )
5+ # Read package.json to make sure it's there
6+ pkg = grunt .file .readJSON (' package.json' )
67
78 # !! Compile configurations
8- License = ' /*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */ '
9- FilterType = " Simple " # "Comment" || "Simple"
9+ LICENSE = ' /*!Copyright(c) CommentCoreLibrary v ' + pkg . version +
10+ ' (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */ '
1011 # !! End of config area
1112
1213 CSS = [
1314 ' src/css/base.css' ,
1415 ' src/css/fontalias.css'
1516 ]
1617
17- SRC_CORE_CMP = [
18- ' Comment'
19- ' CommentSpaceAllocator'
20- ]
21-
2218 SRC_CORE = [
2319 ' src/Array.js'
24- ' src/core/CommentSpaceAllocator.js'
25- ' src/core/Comment.js'
26- ' src/filter/' + FilterType + ' Filter.js'
27- ' src/CommentCoreLibrary.js'
20+ ' src/core/js/CommentUtils.js'
21+ ' src/core/js/Comment.js'
22+ ' src/core/js/css-renderer/CssComment.js'
23+ ' src/core/js/CommentFactory.js'
24+ ' src/core/js/CommentSpaceAllocator.js'
25+ ' src/CommentManager.js'
2826 ]
2927
30- SRC_SCRIPTING_KAGEROU =
31- display : ' src/scripting/api/Display/Display.ts'
32- runtime : ' src/scripting/api/Runtime/Runtime.ts'
33- player : ' src/scripting/api/Player/Player.ts'
34- utils : ' src/scripting/api/Utils/Utils.ts'
35- tween : ' src/scripting/api/Tween/Tween.ts'
36-
37- SRC_PARSER = [
38- ' src/parsers/AcfunFormat.js'
39- ' src/parsers/BilibiliFormat.js'
28+ SRC_MODULES =
29+ ' filter' : [' src/filter/CommentFilter.js' ]
30+ ' provider' : [' src/CommentProvider.js' , ' src/Promises.js' ]
31+ ' format-bilibili' : [' src/parsers/BilibiliFormat.js' ]
32+ ' format-acfun' : [' src/parsers/AcfunFormat.js' ]
33+ ' format-common' : [' src/parsers/CommonDanmakuFormat.js' ]
34+
35+ # Typescript targets
36+ SRC_TS_CORE = [
37+ ' src/core/Comment.ts'
38+ ' src/core/css-renderer/CssComment.ts'
39+ ' src/core/CommentFactory.ts'
40+ ' src/core/CommentSpaceAllocator.ts'
41+ ' src/core/CommentUtils.ts'
4042 ]
4143
42- # !! Below are compile settings
43- # Dynamically generate the core ts targets
44- CMP_CORE_TS = { }
45- CMP_CORE_NAME = [ ]
46- for target in SRC_CORE_CMP
47- CMP_CORE_NAME .push (" ts:" + target)
48- CMP_CORE_TS[target] =
49- src : [" src/core/" + target + " .ts" ]
50- out : " src/core/" + target + " .js"
44+ SRC_TS_SCRIPTING_KAGEROU =
45+ ' Display' : [' src/scripting/api/Display/Display.ts' ]
46+ ' Runtime' : [' src/scripting/api/Runtime/Runtime.ts' ]
47+ ' Player' : [' src/scripting/api/Player/Player.ts' ]
48+ ' Utils' : [' src/scripting/api/Utils/Utils.ts' ]
49+ ' Tween' : [' src/scripting/api/Tween/Tween.ts' ]
50+
51+ # ==== Below this point is logic to generate compile configurations ====
52+ # You probably do not need to edit anything below here
53+
54+ # Dynamically generate the target for all
55+ CMP_ALL = []
56+ CMP_ALL = CMP_ALL .concat SRC_CORE
57+ for name, source of SRC_MODULES
58+ CMP_ALL = CMP_ALL .concat source
59+
60+ # Generate the core ts targets
61+ CMP_CORE_TS =
62+ ' core' :
63+ src : SRC_TS_CORE
64+ outDir : ' src/core/js/'
65+ CMP_CORE_NAME = [' ts:core' ]
5166
5267 # Dynamically generate the kagerou ts targets
53- CMP_KAGEROU_TS = { }
54- CMP_KAGEROU_NAME = [ ]
55- for target,src of SRC_SCRIPTING_KAGEROU
56- CMP_KAGEROU_NAME .push (' ts:kagerou_engine_' + target)
57- CMP_KAGEROU_TS[' kagerou_engine_' + target] =
68+ CMP_KAGEROU_TS = {}
69+ CMP_KAGEROU_NAME = []
70+ for target, src of SRC_TS_SCRIPTING_KAGEROU
71+ CMP_KAGEROU_NAME .push (' ts:kagerou_engine_' + target . toLowerCase () )
72+ CMP_KAGEROU_TS[' kagerou_engine_' + target . toLowerCase () ] =
5873 src : src
59- out : ' build /scripting/api/' + src . split ( ' / ' ). pop (). split ( ' . ' )[ 0 ] + ' .js'
74+ out : ' dist /scripting/api/' + target + ' .js'
6075
6176 # Append Typescript Tasks
62- ts_config =
77+ ts_config =
6378 options :
6479 target : ' es5'
80+ sourceMap : false
6581 for key,value of CMP_CORE_TS
6682 ts_config[key] = value
6783 for key,value of CMP_KAGEROU_TS
6884 ts_config[key] = value
6985
70- # Core concatenated with libraries
71- # Actual concat ordering does not/should not matter
72- SRC_CORELIB = SRC_CORE .concat (SRC_PARSER)
86+ grunt .loadNpmTasks ' grunt-contrib-coffee'
87+ grunt .loadNpmTasks ' grunt-contrib-jasmine'
7388
74- grunt .loadNpmTasks (' grunt-contrib-coffee' )
75- grunt .loadNpmTasks (' grunt-contrib-jasmine' )
7689 grunt .initConfig (
7790 clean :
78- scripting : [' build /scripting' ]
79- build : [' build ' ]
91+ scripting : [' dist /scripting' ]
92+ dist : [' dist ' ]
8093
8194 # Concat CSS and JS files
82- # core_only : builds CCL without parsers
83- # all : builds CCL with everything
95+ # dist_core : builds CCL with just the comment system
96+ # dist_all : builds CCL with everything
97+ # scripting_host : builds just the scripting host
8498 concat :
85- scripting_host :
99+ dist_core :
86100 files :
87- ' build/scripting/Host.js' : [' src/scripting/Host.js' ,' src/scripting/Unpacker.js' ]
88- core_only :
101+ ' dist/css/style.css' : CSS
102+ ' dist/CommentCoreLibrary.js' : SRC_CORE
103+ dist_all :
89104 files :
90- ' build/ style.css' : CSS
91- ' build/CommentCore .js' : SRC_CORE
92- all :
105+ ' dist/css/ style.css' : CSS
106+ ' dist/CommentCoreLibrary .js' : CMP_ALL
107+ scripting_host :
93108 files :
94- ' build/style.css' : CSS
95- ' build/CommentCoreLibrary.js' : SRC_CORELIB
109+ ' dist/scripting/Host.js' : [' src/scripting/Host.js' ,' src/scripting/Unpacker.js' ]
96110
97111 # Compile TypeScript
98112 ts : ts_config
@@ -101,43 +115,42 @@ module.exports = (grunt) ->
101115 copy :
102116 scripting_sandbox :
103117 files : [
104- {expand : true , cwd : ' src/scripting/api/' , src : [' *.js' ], dest : ' build /scripting/api/' },
105- {expand : true , cwd : ' src/scripting/' , src : [' OOAPI.js' ,' Worker.js' ], dest : ' build /scripting/' }
118+ {expand : true , cwd : ' src/scripting/api/' , src : [' *.js' ], dest : ' dist /scripting/api/' },
119+ {expand : true , cwd : ' src/scripting/' , src : [' OOAPI.js' ,' Worker.js' ], dest : ' dist /scripting/' }
106120 ]
107121
108122 # Auto-prefix CSS properties using Can I Use?
109123 autoprefixer :
110124 options :
111125 browsers : [' last 3 versions' , ' bb 10' , ' android 3' ]
112-
113126 no_dest :
114127 # File to output
115- src : ' build /style.css'
128+ src : ' dist/css /style.css'
116129
117130 # Minify CSS
118131 cssmin :
119132 minify :
120- src : [' build /style.css' ]
121- dest : ' build /style.min.css'
133+ src : [' dist/css /style.css' ]
134+ dest : ' dist/css /style.min.css'
122135
136+ # Minify JS
123137 uglify :
124- options : banner : License
125- core_only :
126- files :
127- ' build/CommentCore.min.js' : SRC_CORE
138+ options :
139+ banner : LICENSE
128140 all :
129141 files :
130- ' build /CommentCoreLibrary.min.js' : SRC_CORELIB
142+ ' dist /CommentCoreLibrary.min.js' : [ ' dist/CommentCoreLibrary.js ' ]
131143
132144 # Watch files for changes
133- #
134145 watch :
135- all :
136- files : [' src/**/*' , ' !node_modules' ]
137-
138- # Run concat, autoprefixer, cssmin and uglify
146+ scripting :
147+ files : [' src/scripting/**/*' , ' !node_modules' ]
148+ tasks : [' build:scripting' ]
149+ core :
150+ files : [' src/**/*' , ' !node_modules' , ' !src/scripting/**/*' ]
139151 tasks : [' build' ]
140152
153+ # JSHint
141154 jshint :
142155 options :
143156 curly : true ,
@@ -157,7 +170,6 @@ module.exports = (grunt) ->
157170 src : [' src/*.js' ]
158171
159172 # Jasmine test
160-
161173 jasmine :
162174 coverage :
163175 src : ' src/**/*.js'
@@ -169,13 +181,14 @@ module.exports = (grunt) ->
169181 ' node_modules/jasmine-jquery/lib/jasmine-jquery.js'
170182 ' node_modules/sinon/pkg/sinon.js'
171183 ' node_modules/jasmine-sinon/lib/jasmine-sinon.js'
184+ ' node_modules/promise-polyfill/promise.js' # TODO: remove when phantomjs supports promises
172185 ]
173186 template : require (' grunt-template-jasmine-istanbul' )
174187 templateOptions :
175188 report : ' coverage'
176189 coverage : ' coverage/coverage.json'
177190 ci :
178- src : ' build /CommentCoreLibrary.js'
191+ src : ' dist /CommentCoreLibrary.js'
179192 options :
180193 specs : ' compiled_spec/*spec.js'
181194 helpers : ' spec/*helper.js'
@@ -184,6 +197,7 @@ module.exports = (grunt) ->
184197 ' node_modules/jasmine-jquery/lib/jasmine-jquery.js'
185198 ' node_modules/sinon/pkg/sinon.js'
186199 ' node_modules/jasmine-sinon/lib/jasmine-sinon.js'
200+ ' node_modules/promise-polyfill/promise.js' # TODO: remove when phantomjs supports promises
187201 ]
188202 template : require (' grunt-template-jasmine-istanbul' )
189203 templateOptions :
@@ -202,14 +216,14 @@ module.exports = (grunt) ->
202216 )
203217
204218 # Register special compiles
205- grunt .registerTask ' compile- ts-kagerou ' , CMP_KAGEROU_NAME
206- grunt .registerTask ' compile- ts-core ' , CMP_CORE_NAME
219+ grunt .registerTask ' compile: ts-core ' , CMP_CORE_NAME
220+ grunt .registerTask ' compile: ts-kagerou ' , CMP_KAGEROU_NAME
207221
208222 # Register our tasks
209223 grunt .registerTask ' test' , [' coffee' , ' jasmine:coverage' ]
210- grunt .registerTask ' build-scripting ' , [' clean:scripting ' , ' concat:scripting_host ' , ' compile-ts-kagerou ' , ' copy:scripting_sandbox ' ]
211- grunt .registerTask ' build- core' , [' compile- ts-core' , ' concat:core_only ' , ' autoprefixer' , ' cssmin' , ' uglify:core_only ' ]
212- grunt .registerTask ' build' , [' compile-ts-core ' , ' concat:all ' , ' autoprefixer ' , ' cssmin ' , ' uglify:all ' ]
224+ grunt .registerTask ' build' , [' compile:ts-core ' , ' concat:dist_all ' , ' autoprefixer ' , ' cssmin ' , ' uglify:all ' ]
225+ grunt .registerTask ' build: core' , [' compile: ts-core' , ' concat:dist_core ' , ' autoprefixer' , ' cssmin' , ' uglify:core ' ]
226+ grunt .registerTask ' build:scripting ' , [' clean:scripting ' , ' concat:scripting_host ' , ' compile:ts-kagerou ' , ' copy:scripting_sandbox ' ]
213227 grunt .registerTask ' ci' , [' build' , ' coffee' , ' jasmine:ci' ]
214- grunt .registerTask ' default' , [' clean' , ' build' , ' build-scripting' , ' watch' ]
215228
229+ grunt .registerTask ' default' , [' clean' , ' build' , ' build:scripting' , ' watch' ]
0 commit comments