-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildScript.js
More file actions
55 lines (42 loc) · 1.09 KB
/
buildScript.js
File metadata and controls
55 lines (42 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const fs = require('fs')
/*
This technique to get JSX types on the distributed package is inpired by
https://github.com/preactjs/preact/blob/master/src/index.d.ts
Difficulty was to get TS to understand that this is the JSX flavour we are talking about
*/
const jsxTypes = fs.readFileSync('src/jsx.d.ts', 'utf-8')
fs.writeFileSync(
'dist/jsx.d.ts',
jsxTypes.split('declare namespace JSX {').join('export namespace JSXInternal {'),
'utf-8'
)
// this part should be updated if API changes
const mainTypes = `
import { JSXInternal } from './jsx.d'
export = pdfmakejsx
export as namespace pdfmakejsx
declare namespace pdfmakejsx {
export import JSX = JSXInternal
interface HText {
type: 'text'
text: string
}
interface HElement {
type: 'element'
tagName: string
attributes: object
children: (HElement | HText)[]
}
type HResult = HElement | HText
function h(data: any): HResult
function toDocumentDefinition(data: HResult): any
namespace h {
export import JSX = JSXInternal;
}
}
`
fs.writeFileSync(
'dist/types.d.ts',
mainTypes,
'utf-8'
)