Skip to content

Commit

Permalink
Add script to generate TypeScript declarations.
Browse files Browse the repository at this point in the history
Includes hand written types for cases that couldn't be generated.

Uses https://github.com/Polymer/gen-typescript-declarations.

Run with `gulp generate-typescript`.

Also asyncify the gulpfile with fs-extra.
  • Loading branch information
aomarks committed Dec 8, 2017
1 parent b02c458 commit 1f9be78
Show file tree
Hide file tree
Showing 5 changed files with 927 additions and 287 deletions.
18 changes: 18 additions & 0 deletions gen-tsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"exclude": [
"dist/",
"externs/",
"gulpfile.js",
"test/",
"util/"
],
"removeReferences": [
"../shadycss/apply-shim.d.ts",
"../shadycss/custom-style-interface.d.ts"
],
"addReferences": {
"lib/utils/boot.d.ts": [
"extra-types.d.ts"
]
}
}
21 changes: 15 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const gulpif = require('gulp-if');
const runseq = require('run-sequence');
const del = require('del');
const eslint = require('gulp-eslint');
const fs = require('fs');
const fs = require('fs-extra');
const path = require('path');
const mergeStream = require('merge-stream');
const babel = require('gulp-babel');
Expand Down Expand Up @@ -260,15 +260,24 @@ gulp.task('lint', (done) => {
runseq('lint-eslint', 'lint-closure', done);
});

gulp.task('generate-externs', ['clean'], () => {
gulp.task('generate-externs', ['clean'], async () => {
let genClosure = require('@polymer/gen-closure-declarations').generateDeclarations;
return genClosure().then((declarations) => {
fs.writeFileSync('externs/closure-types.js', `${header}${declarations}`);
});
const declarations = await genClosure();
await fs.writeFile('externs/closure-types.js', `${header}${declarations}`);
});

gulp.task('generate-typescript', async () => {
let genTs = require('@polymer/gen-typescript-declarations').generateDeclarations;
await del(['types/**/*.d.ts', '!types/extra-types.d.ts']);
const config = await fs.readJson('gen-tsd.json');
const files = await genTs('.', config);
for (const [filePath, contents] of files) {
await fs.outputFile(path.join('types', filePath), contents);
}
});

gulp.task('update-version', () => {
gulp.src('lib/utils/boot.html')
.pipe(replace(/(window.Polymer.version = )'\d+\.\d+\.\d+'/, `$1'${require('./package.json').version}'`))
.pipe(gulp.dest('lib/utils'));
});
});
Loading

0 comments on commit 1f9be78

Please sign in to comment.