11import fetch from 'node-fetch'
22import { JSDOM } from 'jsdom'
33import fs from 'fs-extra'
4+ import path from 'path'
45import { transform } from '@babel/core'
56import {
67 moduleBabelConfig , allModulesBabelConfig , replaceAll ,
7- toHumpName , toComponentName ,
8+ toHumpName , toComponentName , makeBasicDefinition ,
89} from './utils'
910
10- const sourceFile = `${ __dirname } /../.source`
11+ const outputDir = path . join ( __dirname , '../' , 'dist' )
12+ const sourceFile = path . join ( __dirname , '../' , '.source' )
1113
1214export default ( async ( ) => {
13- await fs . remove ( './dist' )
15+ await fs . remove ( outputDir )
1416 let html = ''
1517 try {
1618 html = await fs . readFile ( sourceFile , 'utf8' )
@@ -22,12 +24,7 @@ export default (async () => {
2224
2325 const document = new JSDOM ( html ) . window . document
2426 let exports = ''
25- let definition = `import React from 'react';
26- interface Props extends React.SVGProps {
27- color?: string;
28- size?: number;
29- }
30- type Icon = React.FunctionComponent<Props>;\n`
27+ let definition = makeBasicDefinition ( )
3128
3229 const icons = document . querySelectorAll ( '.geist-list .icon' )
3330 const promises = Array . from ( icons ) . map ( ( icon : Element ) => {
@@ -48,18 +45,24 @@ export default ${componentName};`
4845
4946 exports += `export { default as ${ componentName } } from './${ fileName } ';\n`
5047 definition += `export const ${ componentName } : Icon;\n`
51-
48+
49+ const singleDefinition = `${ makeBasicDefinition ( ) } declare const _default: Icon;\nexport default _default\n`
50+
51+ fs . outputFile (
52+ path . join ( outputDir , `${ fileName } .d.ts` ) ,
53+ singleDefinition ,
54+ )
5255 return fs . outputFile (
53- `${ __dirname } /../dist/ ${ fileName } .js` ,
54- transform ( component , moduleBabelConfig ) . code
56+ path . join ( outputDir , `${ fileName } .js` ) ,
57+ transform ( component , moduleBabelConfig ) . code ,
5558 )
5659 } )
5760
5861 await Promise . all ( promises )
59- await fs . outputFile ( ` ${ __dirname } /../dist/ index.d.ts` , definition )
62+ await fs . outputFile ( path . join ( outputDir , ' index.d.ts' ) , definition )
6063 await fs . outputFile (
61- ` ${ __dirname } /../dist/ index.js` ,
62- transform ( exports , allModulesBabelConfig ) . code
64+ path . join ( outputDir , ' index.js' ) ,
65+ transform ( exports , allModulesBabelConfig ) . code ,
6366 )
6467} ) ( )
6568
0 commit comments