Skip to content

Commit 294a6f6

Browse files
authored
Merge pull request #63 from jabbany/dev-new-loader
Merge the new version of CommentCoreLibrary with enhanced APIs
2 parents 684d54c + 71afc6f commit 294a6f6

File tree

198 files changed

+45265
-13426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+45265
-13426
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tab_width = 2
1010
indent_size = 2
1111

1212
[*.js]
13-
indent_style = tab
13+
indent_style = space
1414
tab_width = 2
1515

1616
[*.css]

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/.idea
33
*.iml
44

5+
# Eclipse
6+
/.project
7+
58
# Ignore Node Modules
69
/node_modules/*
710

@@ -11,3 +14,10 @@
1114

1215
# Ignore tscache
1316
.tscache
17+
18+
# Ignore .baseDir related things
19+
# These are only used as transient items due to compiling TypeScript. They may
20+
# become useful when the project can fully move to TypeScript.
21+
.baseDir.ts
22+
.baseDir.js
23+
.baseDir.js.map

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- "6.7.0"
4+
- "7.9.0"
55
before_install:
66
- npm install npm -g
77
before_script:

BUILDING.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
Building 编译项目
2-
==============================
3-
本项目采用 grunt 管理编译,有关 Grunt 系统的使用请参考[官方文档](http://gruntjs.com/getting-started)
4-
脚本弹幕部分的编译还需要 [TypeScript](http://www.typescriptlang.org/) 。这些库还会依赖于
5-
NodeJS环境。
1+
# Building 编译项目
62

7-
### 确定你是否需要编译 (Do I need to build CCL?)
3+
本项目采用 grunt 管理编译,有关 Grunt 系统的使用请参考
4+
[官方文档](http://gruntjs.com/getting-started) 脚本弹幕部分的编译需要
5+
[TypeScript](http://www.typescriptlang.org/)
6+
这些库还会依赖于NodeJS环境。
7+
8+
### 确定你是否需要编译 Do I need to build CCL?
89
CommentCoreLibrary在库外提供了很多可扩展的空间,你可以相对简单的增加新的弹幕格式的支持,新的弹幕
910
运行模式的支持和挂载各种不同的定时元件。CCL提供了丰富的扩展支持,通过预处理过滤器和运行时过滤器可以
1011
实现非常多的特殊功能支持。编译库意味着你可能需要一些默认环境没有的软件,比如 NodeJS 平台,为此需要
@@ -13,8 +14,8 @@ CommentCoreLibrary在库外提供了很多可扩展的空间,你可以相对
1314
当然自己编译也会带来一些优势,比如更小的库大小和更加专注的功能支持。还有,希望帮助CCL实现更多支持的
1415
开发者们也需要知道如何有效的编译。
1516

16-
### 配置编译环境(Setup Build Environment
17-
初次编译请确保你安装了 `node>=0.8.0`,为全局系统安装 grunt 请执行:
17+
### 配置编译环境Setup Build Environment
18+
初次编译请确保你安装了 `node>=1.0.0`,为全局系统安装 grunt 请执行:
1819

1920
npm install -g grunt-cli
2021

@@ -31,10 +32,10 @@ CommentCoreLibrary在库外提供了很多可扩展的空间,你可以相对
3132

3233
即可按照默认模板编译。除此之外,你还可以改变编译目标:
3334

34-
- build : 只编译项目,不会clean掉build文件夹下的产物
35-
- build-core : 只编译弹幕核心,不包括Acfun和Bilibili的解析器。这个更加适用各种二次开发不需要
36-
已有的弹幕格式的
37-
- build-scripting : 只编译代码弹幕支持
35+
- `build` : 只编译项目,不会clean掉build文件夹下的产物
36+
- `build:core` : 只编译弹幕核心,不包括CommentProvider和parsers里面的解析器。
37+
这个更加适用不需要已有的弹幕格式的各种二次开发
38+
- `build:scripting` : 只编译代码弹幕支持
3839

3940
默认模式会自动看管 `src` 源码文件夹,并且在产生变化的时候自动生成新版。
4041

Gruntfile.coffee

Lines changed: 93 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -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']

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014 Jim Chen
1+
Copyright (c) 2017 Jim Chen
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
44
and associated documentation files (the "Software"), to deal in the Software without restriction,

0 commit comments

Comments
 (0)