Skip to content

Commit

Permalink
Merge pull request #63 from jabbany/dev-new-loader
Browse files Browse the repository at this point in the history
Merge the new version of CommentCoreLibrary with enhanced APIs
  • Loading branch information
jabbany committed Apr 25, 2017
2 parents 684d54c + 71afc6f commit 294a6f6
Show file tree
Hide file tree
Showing 198 changed files with 45,265 additions and 13,426 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tab_width = 2
indent_size = 2

[*.js]
indent_style = tab
indent_style = space
tab_width = 2

[*.css]
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/.idea
*.iml

# Eclipse
/.project

# Ignore Node Modules
/node_modules/*

Expand All @@ -11,3 +14,10 @@

# Ignore tscache
.tscache

# Ignore .baseDir related things
# These are only used as transient items due to compiling TypeScript. They may
# become useful when the project can fully move to TypeScript.
.baseDir.ts
.baseDir.js
.baseDir.js.map
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
sudo: false
node_js:
- "6.7.0"
- "7.9.0"
before_install:
- npm install npm -g
before_script:
Expand Down
25 changes: 13 additions & 12 deletions BUILDING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Building 编译项目
==============================
本项目采用 grunt 管理编译,有关 Grunt 系统的使用请参考[官方文档](http://gruntjs.com/getting-started)
脚本弹幕部分的编译还需要 [TypeScript](http://www.typescriptlang.org/) 。这些库还会依赖于
NodeJS环境。
# Building 编译项目

### 确定你是否需要编译 (Do I need to build CCL?)
本项目采用 grunt 管理编译,有关 Grunt 系统的使用请参考
[官方文档](http://gruntjs.com/getting-started) 脚本弹幕部分的编译需要
[TypeScript](http://www.typescriptlang.org/)
这些库还会依赖于NodeJS环境。

### 确定你是否需要编译 Do I need to build CCL?
CommentCoreLibrary在库外提供了很多可扩展的空间,你可以相对简单的增加新的弹幕格式的支持,新的弹幕
运行模式的支持和挂载各种不同的定时元件。CCL提供了丰富的扩展支持,通过预处理过滤器和运行时过滤器可以
实现非常多的特殊功能支持。编译库意味着你可能需要一些默认环境没有的软件,比如 NodeJS 平台,为此需要
Expand All @@ -13,8 +14,8 @@ CommentCoreLibrary在库外提供了很多可扩展的空间,你可以相对
当然自己编译也会带来一些优势,比如更小的库大小和更加专注的功能支持。还有,希望帮助CCL实现更多支持的
开发者们也需要知道如何有效的编译。

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

npm install -g grunt-cli

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

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

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

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

Expand Down
172 changes: 93 additions & 79 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,111 @@ module.exports = (grunt) ->
require('load-grunt-tasks') grunt , {
pattern: ['grunt-*', '!grunt-template-jasmine-istanbul']
}
grunt.file.readJSON('package.json')
# Read package.json to make sure it's there
pkg = grunt.file.readJSON('package.json')

# !! Compile configurations
License = '/*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */'
FilterType = "Simple" # "Comment" || "Simple"
LICENSE = '/*!Copyright(c) CommentCoreLibrary v' + pkg.version +
' (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */'
# !! 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/core/js/CommentUtils.js'
'src/core/js/Comment.js'
'src/core/js/css-renderer/CssComment.js'
'src/core/js/CommentFactory.js'
'src/core/js/CommentSpaceAllocator.js'
'src/CommentManager.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'
SRC_MODULES =
'filter': ['src/filter/CommentFilter.js']
'provider': ['src/CommentProvider.js', 'src/Promises.js']
'format-bilibili': ['src/parsers/BilibiliFormat.js']
'format-acfun': ['src/parsers/AcfunFormat.js']
'format-common': ['src/parsers/CommonDanmakuFormat.js']

# Typescript targets
SRC_TS_CORE = [
'src/core/Comment.ts'
'src/core/css-renderer/CssComment.ts'
'src/core/CommentFactory.ts'
'src/core/CommentSpaceAllocator.ts'
'src/core/CommentUtils.ts'
]

# !! 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 ("ts:" + target)
CMP_CORE_TS[target] =
src: ["src/core/" + target + ".ts"]
out: "src/core/" + target + ".js"
SRC_TS_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']

# ==== Below this point is logic to generate compile configurations ====
# You probably do not need to edit anything below here

# Dynamically generate the target for all
CMP_ALL = []
CMP_ALL = CMP_ALL.concat SRC_CORE
for name, source of SRC_MODULES
CMP_ALL = CMP_ALL.concat source

# Generate the core ts targets
CMP_CORE_TS =
'core':
src: SRC_TS_CORE
outDir: 'src/core/js/'
CMP_CORE_NAME = ['ts:core']

# Dynamically generate the kagerou ts targets
CMP_KAGEROU_TS = { }
CMP_KAGEROU_NAME = [ ]
for target,src of SRC_SCRIPTING_KAGEROU
CMP_KAGEROU_NAME.push ('ts:kagerou_engine_' + target)
CMP_KAGEROU_TS['kagerou_engine_' + target] =
CMP_KAGEROU_TS = {}
CMP_KAGEROU_NAME = []
for target, src of SRC_TS_SCRIPTING_KAGEROU
CMP_KAGEROU_NAME.push ('ts:kagerou_engine_' + target.toLowerCase())
CMP_KAGEROU_TS['kagerou_engine_' + target.toLowerCase()] =
src: src
out: 'build/scripting/api/' + src.split('/').pop().split('.')[0] + '.js'
out: 'dist/scripting/api/' + target + '.js'

# Append Typescript Tasks
ts_config =
ts_config =
options:
target: 'es5'
sourceMap: false
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.loadNpmTasks('grunt-contrib-coffee')
grunt.loadNpmTasks('grunt-contrib-jasmine')
grunt.initConfig(
clean:
scripting: ['build/scripting']
build: ['build']
scripting: ['dist/scripting']
dist: ['dist']

# Concat CSS and JS files
# core_only : builds CCL without parsers
# all : builds CCL with everything
# dist_core : builds CCL with just the comment system
# dist_all : builds CCL with everything
# scripting_host : builds just the scripting host
concat:
scripting_host:
dist_core:
files:
'build/scripting/Host.js': ['src/scripting/Host.js','src/scripting/Unpacker.js']
core_only:
'dist/css/style.css': CSS
'dist/CommentCoreLibrary.js': SRC_CORE
dist_all:
files:
'build/style.css': CSS
'build/CommentCore.js': SRC_CORE
all:
'dist/css/style.css': CSS
'dist/CommentCoreLibrary.js': CMP_ALL
scripting_host:
files:
'build/style.css': CSS
'build/CommentCoreLibrary.js': SRC_CORELIB
'dist/scripting/Host.js': ['src/scripting/Host.js','src/scripting/Unpacker.js']

# Compile TypeScript
ts: ts_config
Expand All @@ -101,43 +115,42 @@ module.exports = (grunt) ->
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/'}
{expand: true, cwd:'src/scripting/api/', src: ['*.js'], dest:'dist/scripting/api/'},
{expand: true, cwd:'src/scripting/', src: ['OOAPI.js','Worker.js'], dest:'dist/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'
src: 'dist/css/style.css'

# Minify CSS
cssmin:
minify:
src: ['build/style.css']
dest: 'build/style.min.css'
src: ['dist/css/style.css']
dest: 'dist/css/style.min.css'

# Minify JS
uglify:
options: banner: License
core_only:
files:
'build/CommentCore.min.js': SRC_CORE
options:
banner: LICENSE
all:
files:
'build/CommentCoreLibrary.min.js': SRC_CORELIB
'dist/CommentCoreLibrary.min.js': ['dist/CommentCoreLibrary.js']

# Watch files for changes
#
watch:
all:
files: ['src/**/*', '!node_modules']

# Run concat, autoprefixer, cssmin and uglify
scripting:
files: ['src/scripting/**/*', '!node_modules']
tasks: ['build:scripting']
core:
files: ['src/**/*', '!node_modules', '!src/scripting/**/*']
tasks: ['build']

# JSHint
jshint:
options:
curly: true,
Expand All @@ -157,7 +170,6 @@ module.exports = (grunt) ->
src: ['src/*.js']

# Jasmine test

jasmine:
coverage:
src: 'src/**/*.js'
Expand All @@ -169,13 +181,14 @@ module.exports = (grunt) ->
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
'node_modules/sinon/pkg/sinon.js'
'node_modules/jasmine-sinon/lib/jasmine-sinon.js'
'node_modules/promise-polyfill/promise.js' # TODO: remove when phantomjs supports promises
]
template: require('grunt-template-jasmine-istanbul')
templateOptions:
report: 'coverage'
coverage: 'coverage/coverage.json'
ci:
src: 'build/CommentCoreLibrary.js'
src: 'dist/CommentCoreLibrary.js'
options:
specs: 'compiled_spec/*spec.js'
helpers: 'spec/*helper.js'
Expand All @@ -184,6 +197,7 @@ module.exports = (grunt) ->
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
'node_modules/sinon/pkg/sinon.js'
'node_modules/jasmine-sinon/lib/jasmine-sinon.js'
'node_modules/promise-polyfill/promise.js' # TODO: remove when phantomjs supports promises
]
template: require('grunt-template-jasmine-istanbul')
templateOptions:
Expand All @@ -202,14 +216,14 @@ module.exports = (grunt) ->
)

# Register special compiles
grunt.registerTask 'compile-ts-kagerou', CMP_KAGEROU_NAME
grunt.registerTask 'compile-ts-core', CMP_CORE_NAME
grunt.registerTask 'compile:ts-core', CMP_CORE_NAME
grunt.registerTask 'compile:ts-kagerou', CMP_KAGEROU_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 'build', ['compile:ts-core', 'concat:dist_all', 'autoprefixer', 'cssmin', 'uglify:all']
grunt.registerTask 'build:core', ['compile:ts-core', 'concat:dist_core', 'autoprefixer', 'cssmin', 'uglify:core']
grunt.registerTask 'build:scripting', ['clean:scripting','concat:scripting_host', 'compile:ts-kagerou', 'copy:scripting_sandbox']
grunt.registerTask 'ci', ['build', 'coffee', 'jasmine:ci']
grunt.registerTask 'default', ['clean', 'build', 'build-scripting', 'watch']

grunt.registerTask 'default', ['clean', 'build', 'build:scripting', 'watch']
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 Jim Chen
Copyright (c) 2017 Jim Chen

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

0 comments on commit 294a6f6

Please sign in to comment.