@@ -21,8 +21,19 @@ const packages = [
21
21
] ;
22
22
23
23
/* Write custom packages */
24
+ function addTyping ( typings , component ) {
25
+ if ( _ . isEmpty ( typings ) ) {
26
+ typings += `{${ component } ` ;
27
+ } else {
28
+ typings += `, ${ component } ` ;
29
+ }
30
+
31
+ return typings ;
32
+ }
33
+
24
34
packages . forEach ( ( package ) => {
25
35
let content = package . content || '' ;
36
+ let typings = '' ;
26
37
27
38
if ( package . components || package . styleComponents ) {
28
39
content += 'module.exports = {\n' ;
@@ -32,6 +43,8 @@ packages.forEach((package) => {
32
43
component
33
44
) } ').default;`;
34
45
content += `},\n` ;
46
+
47
+ typings = addTyping ( typings , component ) ;
35
48
} ) ;
36
49
37
50
_ . forEach ( package . styleComponents , ( component ) => {
@@ -40,11 +53,19 @@ packages.forEach((package) => {
40
53
component
41
54
) } ').default;`;
42
55
content += `},\n` ;
56
+
57
+ typings = addTyping ( typings , component ) ;
43
58
} ) ;
44
59
content += '};\n' ;
60
+ typings += '}' ;
61
+ typings = `import ${ typings } from './generatedTypes';\nexport ${ typings } ;\n` ;
45
62
}
46
63
47
64
fs . writeFileSync ( package . filename , content ) ;
65
+ if ( ! _ . isEmpty ( typings ) ) {
66
+ const filename = `${ package . filename . substring ( 0 , package . filename . indexOf ( '.js' ) ) } .d.ts` ;
67
+ fs . writeFileSync ( filename , typings ) ;
68
+ }
48
69
} ) ;
49
70
50
71
/* Write all components as separate packages */
@@ -58,6 +79,11 @@ fs.readdir(path, (err, files) => {
58
79
`${ file } .js` ,
59
80
`module.exports = require('${ path } /${ file } ').default;\n`
60
81
) ;
82
+ const componentName = _ . upperFirst ( file ) ;
83
+ fs . writeFileSync (
84
+ `${ file } .d.ts` ,
85
+ `import {${ componentName } } from './generatedTypes';\nexport default ${ componentName } ;\n`
86
+ ) ;
61
87
} ) ;
62
88
}
63
89
} ) ;
0 commit comments