Add typescript definition generation

This add a gulp task (`gulp docs:typescript`) to automatically generate
a typescript definition for the library. This should solve the problem
of having an out of sync type definition when we change the API.

This task takes advantage of existing JSDoc parsing to generate a
temporary file which is later formatted through a mustache template to
generate the final definition. This definition is then tested by
compiling a typescript file that use it.
The generated definition is added to the `gulp zip` task in order to be
published along with the bundled library.

So 2 new dev-dependencies are added with this change: `mustache` and
`typescript` packages. Using node and mustache to generate the
definition instead of relying on existing templating system is
motivated by a better development experience, with easier debugging
possibilities... through the usage of more modern tools.

As a side note, support of "rest parameters" (when a parameter can be
present multiple times) is added to existing JSDoc parser in order to
support this pattern on typescript side (E.g. for `Color#set()` method
which accept any sequence of parameters that is supported by `Color`
constructors).
This commit is contained in:
sasensi 2018-11-21 12:18:21 +01:00 committed by Jürg Lehni
parent 0cced9788c
commit bbd65324bc
11 changed files with 1591 additions and 9 deletions

View file

@ -22,6 +22,7 @@ gulp.task('zip', ['clean:zip', 'dist'], function() {
gulp.src([
'dist/paper-full*.js',
'dist/paper-core*.js',
'dist/index.d.ts',
'dist/node/**/*',
'LICENSE.txt',
'examples/**/*',