mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Add script to generate TypeScript declarations.
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.
This commit is contained in:
18
gen-tsd.json
Normal file
18
gen-tsd.json
Normal file
@@ -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
gulpfile.js
21
gulpfile.js
@@ -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');
|
||||
@@ -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'));
|
||||
});
|
||||
});
|
||||
|
||||
913
package-lock.json
generated
913
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -9,12 +9,14 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polymer/gen-closure-declarations": "^0.4.0",
|
||||
"@polymer/gen-typescript-declarations": "^0.2.0",
|
||||
"@webcomponents/shadycss": "^1.1.0",
|
||||
"@webcomponents/webcomponentsjs": "^1.0.20",
|
||||
"babel-preset-minify": "^0.2.0",
|
||||
"del": "^3.0.0",
|
||||
"dom5": "^2.3.0",
|
||||
"eslint-plugin-html": "^4.0.1",
|
||||
"fs-extra": "^4.0.3",
|
||||
"google-closure-compiler": "^20171112.0.0",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-babel": "^6.1.2",
|
||||
|
||||
158
types/extra-types.d.ts
vendored
Normal file
158
types/extra-types.d.ts
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* This file contains the types that are required for compilation of the
|
||||
* Polymer generated type declarations, but which could not themselves be
|
||||
* automatically generated.
|
||||
*/
|
||||
|
||||
/// <reference path="lib/mixins/property-effects.d.ts" />
|
||||
|
||||
/**
|
||||
* Types from "externs/closure-types.js"
|
||||
*/
|
||||
|
||||
type Polymer_PropertyEffects = Polymer.PropertyEffects;
|
||||
|
||||
/**
|
||||
* Types from "externs/polymer-externs.js"
|
||||
*/
|
||||
|
||||
interface PolymerElementPropertiesMeta {
|
||||
type?: Function;
|
||||
value?: any;
|
||||
readOnly?: boolean;
|
||||
computed?: string;
|
||||
reflectToAttribute?: boolean;
|
||||
notify?: boolean;
|
||||
observer?: string;
|
||||
}
|
||||
|
||||
type PolymerElementProperties = {
|
||||
[key: string]: PolymerElementPropertiesMeta
|
||||
};
|
||||
|
||||
interface PolymerInit {
|
||||
is: string;
|
||||
extends?: string;
|
||||
properties?: PolymerElementProperties;
|
||||
observers?: string[];
|
||||
template?: HTMLTemplateElement|string;
|
||||
hostAttributes?: {[key: string]: any};
|
||||
listeners?: {[key: string]: string};
|
||||
}
|
||||
|
||||
/**
|
||||
* Types from "externs/polymer-internal-shared-types.js"
|
||||
*/
|
||||
|
||||
interface StampedTemplate extends DocumentFragment {
|
||||
__noInsertionPoint: boolean;
|
||||
nodeList: Node[];
|
||||
$: {[key: string]: Node};
|
||||
templateInfo?: TemplateInfo;
|
||||
}
|
||||
|
||||
interface NodeInfo {
|
||||
id: string;
|
||||
events: {name: string, value: string}[];
|
||||
hasInsertionPoint: boolean;
|
||||
templateInfo: TemplateInfo;
|
||||
parentInfo: NodeInfo;
|
||||
parentIndex: number;
|
||||
infoIndex: number;
|
||||
bindings: Binding[];
|
||||
}
|
||||
|
||||
interface TemplateInfo {
|
||||
nodeInfoList: NodeInfo[];
|
||||
nodeList: Node[];
|
||||
stripWhitespace: boolean;
|
||||
hasInsertionPoint?: boolean;
|
||||
hostProps: Object;
|
||||
propertyEffects: Object;
|
||||
nextTemplateInfo?: TemplateInfo;
|
||||
previousTemplateInfo?: TemplateInfo;
|
||||
childNodes: Node[];
|
||||
wasPreBound: boolean;
|
||||
}
|
||||
|
||||
interface LiteralBindingPart {
|
||||
literal: string;
|
||||
compoundIndex?: number;
|
||||
}
|
||||
|
||||
interface MethodArg {
|
||||
literal: boolean;
|
||||
name: string;
|
||||
value: string|number;
|
||||
rootProperty?: string;
|
||||
structured?: boolean;
|
||||
wildcard?: boolean;
|
||||
}
|
||||
|
||||
interface MethodSignature {
|
||||
methodName: string;
|
||||
static: boolean;
|
||||
args: MethodArg[];
|
||||
dynamicFn?: boolean;
|
||||
}
|
||||
|
||||
interface ExpressionBindingPart {
|
||||
mode: string;
|
||||
negate: boolean;
|
||||
source: string;
|
||||
dependencies: Array<MethodArg|string>;
|
||||
customEvent: boolean;
|
||||
signature: Object|null;
|
||||
event: string;
|
||||
}
|
||||
|
||||
type BindingPart = LiteralBindingPart|ExpressionBindingPart;
|
||||
|
||||
interface Binding {
|
||||
kind: string;
|
||||
target: string;
|
||||
parts: BindingPart[];
|
||||
literal?: string;
|
||||
isCompound: boolean;
|
||||
listenerEvent?: string;
|
||||
listenerNegate?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Types from "lib/utils/async.html"
|
||||
*/
|
||||
|
||||
interface AsyncInterface {
|
||||
run: (fn: Function, delay?: number) => number;
|
||||
cancel: (handle: number) => any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Types from "lib/utils/debounce.html"
|
||||
*/
|
||||
|
||||
type AsyncModule = AsyncInterface;
|
||||
|
||||
/**
|
||||
* Types from "lib/utils/gestures.html"
|
||||
*/
|
||||
|
||||
interface GestureRecognizer {
|
||||
reset: () => any;
|
||||
mousedown?: (e: MouseEvent) => any;
|
||||
mousemove?: (e: MouseEvent) => any;
|
||||
mouseup?: (e: MouseEvent) => any;
|
||||
touchstart?: (e: TouchEvent) => any;
|
||||
touchmove?: (e: TouchEvent) => any;
|
||||
touchend?: (e: TouchEvent) => any;
|
||||
click?: (e: MouseEvent) => any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not defined in the TypeScript DOM library.
|
||||
* See https://developer.mozilla.org/en-US/docs/Web/API/IdleDeadline
|
||||
*/
|
||||
interface IdleDeadline {
|
||||
didTimeout: boolean;
|
||||
timeRemaining(): number;
|
||||
}
|
||||
Reference in New Issue
Block a user