Skip to content

Commit edee713

Browse files
authored
build: Auto generate the Typescript Definition file (hiloteam#20)
* build: init tsd jsdoc * docs: update jsdoc * use hilo/tsd-jsdoc * fix types * build .d.ts * eslint-fix * more tsd fix * fix types * fix geometrydata tsd * fix geo tsd * fix light tsd * fix tsd * fix types * fix tsd * fix type * fix tsd * fix typo
1 parent f67696d commit edee713

Some content is hidden

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

62 files changed

+7961
-14359
lines changed

gulpfile.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,35 @@ const testTask = () => {
2323
}));
2424
};
2525

26+
const hilo3dTSDHeader = `export = hilo3d;
27+
export as namespace hilo3d;
28+
declare namespace hilo3d {
29+
30+
type TypedArray =
31+
| Int8Array
32+
| Uint8Array
33+
| Uint8ClampedArray
34+
| Int16Array
35+
| Uint16Array
36+
| Int32Array
37+
| Uint32Array
38+
| Float32Array
39+
| Float64Array;
40+
41+
`;
42+
43+
const hilo3dTSDFooter = `
44+
45+
}
46+
`;
47+
48+
const addHilo3dTSD = () => {
49+
return src('./types/index.d.ts')
50+
.pipe(replace(/^/, hilo3dTSDHeader))
51+
.pipe(replace(/$/, hilo3dTSDFooter))
52+
.pipe(dest('types'));
53+
};
54+
2655
const readmeTask = () => {
2756
return src(['./README.md', './README_ZH.md'])
2857
.pipe(replace(/Hilo3d\/[\d\.]+\/Hilo3d\.js/g, `Hilo3d/${pkg.version}/Hilo3d.js`))
@@ -35,4 +64,5 @@ const watchTask = () => {
3564

3665
exports.test = series(testBuildTask, testTask);
3766
exports.watch = series(testBuildTask, testTask, watchTask);
38-
exports.readme = readmeTask;
67+
exports.readme = readmeTask;
68+
exports.addHilo3dTSD = addHilo3dTSD;

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build": " webpack",
1313
"release": "tnpm update && webpack -p",
1414
"doc": "gulp readme && jsdoc -c doc.conf.json",
15+
"doc-tsd": "jsdoc -c tsd-doc.conf.json && gulp addHilo3dTSD",
1516
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r",
1617
"eslint-fix": "eslint --fix ./src",
1718
"seinjs-dev": "webpack --watch --env.development --seinjs",
@@ -40,6 +41,7 @@
4041
"devDependencies": {
4142
"@babel/core": "^7.1.0",
4243
"@babel/preset-env": "^7.1.0",
44+
"@hilo/tsd-jsdoc": "^0.1.0",
4345
"babel-loader": "^8.0.2",
4446
"conventional-changelog-cli": "^2.0.31",
4547
"del": "^3.0.0",
@@ -54,7 +56,7 @@
5456
"gulp-concat": "^2.6.1",
5557
"gulp-replace": "^1.0.0",
5658
"gulp-uitest": "^1.0.0",
57-
"jsdoc": "^3.5.5",
59+
"jsdoc": "^3.6.4",
5860
"mocha": "^5.2.0",
5961
"raw-loader": "^0.5.1",
6062
"should": "^13.2.3",

src/animation/Animation.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const Animation = Class.create(/** @lends Animation.prototype */{
1616
/**
1717
* tick
1818
* @memberOf Animation
19-
* @static
20-
* @param {Number} dt 一帧时间
19+
* @method tick
20+
* @param {Number} dt 一帧时间
2121
*/
2222
tick(dt) {
2323
this._anims.forEach(anim => anim.tick(dt));
@@ -111,7 +111,7 @@ const Animation = Class.create(/** @lends Animation.prototype */{
111111
validAnimationIds: null,
112112
/**
113113
* @constructs
114-
* @param {Object} parmas 创建对象的属性参数。可包含此类的所有属性。
114+
* @param {Object} [parmas] 创建对象的属性参数。可包含此类的所有属性。
115115
*/
116116
constructor(parmas) {
117117
/**
@@ -138,7 +138,7 @@ const Animation = Class.create(/** @lends Animation.prototype */{
138138
* @param {string} name 剪辑名字
139139
* @param {number} start 动画开始时间
140140
* @param {number} end 动画结束时间
141-
* @param {Array.<AnimationState>} animStatesList 动画帧列表
141+
* @param {AnimationStates[]} animStatesList 动画帧列表
142142
*/
143143
addClip(name, start, end, animStatesList) {
144144
this.clips[name] = {
@@ -191,6 +191,10 @@ const Animation = Class.create(/** @lends Animation.prototype */{
191191
}, false);
192192
}
193193
},
194+
/**
195+
* tick
196+
* @param {Number} dt
197+
*/
194198
tick(dt) {
195199
if (this.paused) {
196200
return;

src/camera/Camera.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const Camera = Class.create(/** @lends Camera.prototype */ {
3636

3737
/**
3838
* @constructs
39-
* @param {object} params 创建对象的属性参数。可包含此类的所有属性。
39+
* @param {object} [params] 创建对象的属性参数。可包含此类的所有属性。
4040
*/
4141
constructor(params) {
4242
/**

src/camera/OrthographicCamera.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const OrthographicCamera = Class.create(/** @lends OrthographicCamera.prototype
120120

121121
/**
122122
* @constructs
123-
* @param {object} params 创建对象的属性参数。可包含此类的所有属性。
123+
* @param {object} [params] 创建对象的属性参数。可包含此类的所有属性。
124124
*/
125125
constructor(params) {
126126
OrthographicCamera.superclass.constructor.call(this, params);

src/camera/PerspectiveCamera.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const PerspectiveCamera = Class.create(/** @lends PerspectiveCamera.prototype */
5959

6060
_fov: 50,
6161
/**
62-
* 相机视野大小,角度
62+
* 相机视野大小,角度制
6363
* @default 50
6464
* @type {number}
6565
*/
@@ -93,7 +93,7 @@ const PerspectiveCamera = Class.create(/** @lends PerspectiveCamera.prototype */
9393

9494
/**
9595
* @constructs
96-
* @param {object} params 创建对象的属性参数。可包含此类的所有属性。
96+
* @param {object} [params] 创建对象的属性参数。可包含此类的所有属性。
9797
*/
9898
constructor(params) {
9999
PerspectiveCamera.superclass.constructor.call(this, params);

src/constants/index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import webgl from './webgl';
22
import webglExtensions from './webglExtensions';
33
import * as Hilo from './Hilo';
44

5+
/**
6+
* WebGL, WebGL extensions 枚举值
7+
* @constant
8+
* @type {Object}
9+
* @example
10+
* Hilo3d.constants.LINEAR_MIPMAP_NEAREST
11+
*/
512
const constants = {
613
webgl,
714
webglExtensions,
@@ -10,7 +17,3 @@ const constants = {
1017
Object.assign(constants, webgl, webglExtensions, Hilo);
1118

1219
export default constants;
13-
/**
14-
* Hilo3d 枚举值,可通过 Hilo3d.constants.xxx 获取
15-
* @typedef {Number} GLenum
16-
*/

src/core/Class.js

+16
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@ import Class from 'hilojs/core/Class';
66
* @see {@link https://hiloteam.github.io/Hilo/docs/api-zh/symbols/Class.html}
77
*/
88
export default Class;
9+
10+
11+
/**
12+
* @memberOf Class
13+
* @method create
14+
* @param {ClassProperty | Object} props
15+
*/
16+
17+
/**
18+
* 类属性
19+
* @interface ClassProperty
20+
* @property {Object} [Statics] 静态属性
21+
* @property {Object} [Extends] 继承
22+
* @property {Object} [Mixes] mixes
23+
* @property {Function} [constructor] 构造函数
24+
*/

src/core/EventMixin.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,52 @@ import EventMixin from 'hilojs/event/EventMixin';
22

33
/**
44
* EventMixin是一个包含事件相关功能的mixin。可以通过 Object.assign(target, EventMixin) 来为target增加事件功能。
5-
* @namespace EventMixin
5+
* @class EventMixin
66
* @see {@link https://hiloteam.github.io/Hilo/docs/api-zh/symbols/EventMixin.html}
77
*/
88
export default EventMixin;
9+
10+
/**
11+
* 增加一个事件监听。
12+
* @name EventMixin#on
13+
* @function
14+
* @param {String} type 要监听的事件类型。
15+
* @param {EventMixinCallback} listener 事件监听回调函数。
16+
* @param {Boolean} [once] 是否是一次性监听,即回调函数响应一次后即删除,不再响应。
17+
* @returns {any} 对象本身。链式调用支持。
18+
*/
19+
20+
21+
/**
22+
* 删除一个事件监听。如果不传入任何参数,则删除所有的事件监听;如果不传入第二个参数,则删除指定类型的所有事件监听。
23+
* @name EventMixin#off
24+
* @function
25+
* @param {String} [type] 要删除监听的事件类型。
26+
* @param {EventMixinCallback} [listener] 要删除监听的回调函数。
27+
* @returns {any} 对象本身。链式调用支持。
28+
*/
29+
30+
/**
31+
* 发送事件。当第一个参数类型为Object时,则把它作为一个整体事件对象。
32+
* @name EventMixin#fire
33+
* @function
34+
* @param {String|EventObject} [type] 要发送的事件类型或者一个事件对象。
35+
* @param {Object} [detail] 要发送的事件的具体信息,即事件随带参数。
36+
* @returns {Boolean} 是否成功调度事件。
37+
*/
38+
39+
/**
40+
* 事件对象
41+
* @interface EventObject
42+
* @property {String} type 事件类型
43+
* @property {any} [detail=null] 事件数据
44+
*/
45+
46+
/**
47+
* @callback EventMixinCallback
48+
* @param {Object} [e] 事件对象
49+
* @param {String} e.type 事件类型
50+
* @param {Object} e.detail 事件数据
51+
* @param {Object} e.target 事件触发对象
52+
* @param {Date} e.timeStamp 时间戳
53+
*/

src/core/Mesh.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const Mesh = Class.create(/** @lends Mesh.prototype */ {
5454
frustumTest: true,
5555
/**
5656
* @constructs
57-
* @param {object} params 初始化参数,所有params都会复制到实例上
57+
* @param {object} [params] 初始化参数,所有params都会复制到实例上
5858
*/
5959
constructor(params) {
6060
Mesh.superclass.constructor.call(this, params);

src/core/Node.js

+39-11
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ const Node = Class.create(/** @lends Node.prototype */ {
3737
/**
3838
* traverse callback 返回值,执行后不暂停 traverse
3939
* @memberOf Node
40-
* @type {Enum}
40+
* @type {any}
4141
*/
4242
TRAVERSE_STOP_NONE,
4343
/**
4444
* traverse callback 返回值,执行后暂停子元素 traverse
4545
* @memberOf Node
46-
* @type {Enum}
46+
* @type {any}
4747
*/
4848
TRAVERSE_STOP_CHILDREN,
4949
/**
5050
* traverse callback 返回值,执行后暂停所有 traverse
5151
* @memberOf Node
52-
* @type {Enum}
52+
* @type {any}
5353
*/
5454
TRAVERSE_STOP_ALL
5555
},
@@ -69,11 +69,24 @@ const Node = Class.create(/** @lends Node.prototype */ {
6969
* @type {string}
7070
*/
7171
name: '',
72+
/**
73+
* 动画
74+
* @type {Animation}
75+
* @default null
76+
*/
77+
anim: null,
7278
/**
7379
* animation 查找 id
7480
* @type {String}
81+
* @default ''
7582
*/
7683
animationId: '',
84+
/**
85+
* 骨骼名称
86+
* @type {String}
87+
* @default ''
88+
*/
89+
jointName: '',
7790
/**
7891
* 是否自动更新世界矩阵
7992
* @default true
@@ -139,7 +152,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
139152

140153
/**
141154
* @constructs
142-
* @param {object} params 初始化参数,所有params都会复制到实例上
155+
* @param {object} [params] 初始化参数,所有params都会复制到实例上
143156
*/
144157
constructor(params) {
145158
/**
@@ -383,7 +396,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
383396
/**
384397
* _traverse
385398
* @private
386-
* @param {Function(Node)} callback
399+
* @param {NodeTraverseCallback} callback
387400
* @param {Boolean} onlyChild
388401
* @return {Enum} TRAVERSE_STOP_ALL, TRAVERSE_STOP_CHILDREN, TRAVERSE_STOP_NONE
389402
*/
@@ -407,7 +420,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
407420
},
408421
/**
409422
* 遍历当前元素的子孙元素
410-
* @param {Function(Node)} callback 每个元素都会调用这个函数处理
423+
* @param {NodeTraverseCallback} callback 每个元素都会调用这个函数处理
411424
* @param {Boolean} [onlyChild=false] 是否只遍历子元素
412425
* @return {Node} this
413426
*/
@@ -417,7 +430,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
417430
},
418431
/**
419432
* 遍历当前元素的子孙元素(广度优先)
420-
* @param {Function(Node)} callback 每个元素都会调用这个函数处理
433+
* @param {NodeTraverseCallback} callback 每个元素都会调用这个函数处理
421434
* @param {Boolean} [onlyChild=false] 是否只遍历子元素
422435
* @return {Node} this
423436
*/
@@ -447,7 +460,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
447460
},
448461
/**
449462
* 根据函数来获取一个子孙元素(广度优先)
450-
* @param {Function} fn 判读函数
463+
* @param {NodeGetChildByCallback} fn 判读函数
451464
* @return {Node|null} 返回获取到的子孙元素
452465
*/
453466
getChildByFnBFS(fn) {
@@ -500,7 +513,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
500513
},
501514
/**
502515
* 根据函数来获取一个子孙元素
503-
* @param {Function} fn 判读函数
516+
* @param {NodeGetChildByCallback} fn 判读函数
504517
* @return {Node|null} 返回获取到的子孙元素
505518
*/
506519
getChildByFn(fn) {
@@ -517,7 +530,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
517530
},
518531
/**
519532
* 根据函数来获取匹配的所有子孙元素
520-
* @param {Function} fn 判读函数
533+
* @param {NodeGetChildByCallback} fn 判读函数
521534
* @return {Node[]} 返回获取到的子孙元素
522535
*/
523536
getChildrenByFn(fn) {
@@ -976,7 +989,7 @@ const Node = Class.create(/** @lends Node.prototype */ {
976989
},
977990
/**
978991
* 销毁 Node 资源
979-
* @param {WebGLRenderer} renderer
992+
* @param {WebGLRenderer} [renderer] stage时可以不传
980993
* @param {Boolean} [destroyTextures=false] 是否销毁材质的贴图,默认不销毁
981994
* @return {Node} this
982995
*/
@@ -1045,3 +1058,18 @@ export default Node;
10451058
* @property {Mesh} mesh 碰撞的 mesh
10461059
* @property {Vector3} point 碰撞得点
10471060
*/
1061+
1062+
1063+
/**
1064+
* Node traverse 回调
1065+
* @callback NodeTraverseCallback
1066+
* @param {Node} node
1067+
* @return {any} Node.TRAVERSE_STOP_NONE | Node.TRAVERSE_STOP_CHILDREN | Node.TRAVERSE_STOP_ALL
1068+
*/
1069+
1070+
/**
1071+
* Node getChildByCallback 回调
1072+
* @callback NodeGetChildByCallback
1073+
* @param {Node} node
1074+
* @return {boolean}
1075+
*/

src/core/SkinedMesh.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const SkinedMesh = Class.create(/** @lends SkinedMesh.prototype */{
5050
skeleton: null,
5151
/**
5252
* @constructs
53-
* @param {object} params 初始化参数,所有params都会复制到实例上
53+
* @param {object} [params] 初始化参数,所有params都会复制到实例上
5454
*/
5555
constructor(params) {
5656
SkinedMesh.superclass.constructor.call(this, params);

0 commit comments

Comments
 (0)