|
1 | 1 | #!/usr/bin/env node |
2 | 2 | 'use strict' |
3 | 3 | const path = require('path') |
4 | | -const fs = require('fs-extra') |
5 | 4 | const { IconSvgPaths16, IconSvgPaths20 } = require('@blueprintjs/icons') |
6 | 5 | const camelCase = require('camelcase') |
| 6 | +const fs = require('fs-extra') |
7 | 7 | const prettier = require('prettier') |
8 | 8 |
|
9 | 9 | const iconsPath = path.resolve(__dirname, '../src/icons/generated') |
10 | 10 | const iconsIndexPath = path.resolve(__dirname, '../src/icons/index.js') |
11 | 11 | const indexPath = path.resolve(__dirname, '../src/index.js') |
12 | 12 | const typedefPath = path.resolve(__dirname, '../index.d.ts') |
13 | | -const iconNamesMapperPath = path.resolve( |
14 | | - __dirname, |
15 | | - '../src/icons/generated/IconNameMapper.js' |
16 | | -) |
| 13 | +const iconNamesMapperPath = path.resolve(__dirname, '../src/icons/generated/IconNameMapper.js') |
17 | 14 | const fileHeader = `// This is a generated file. DO NOT modify directly.\n\n` |
18 | 15 |
|
19 | 16 | async function main() { |
@@ -122,22 +119,15 @@ export const ${iconName} = memo(forwardRef(function ${iconName}(props, ref) { |
122 | 119 | // update the typedefs to include icons |
123 | 120 | // ===================== |
124 | 121 |
|
125 | | - const iconTypeDefs = iconNames |
126 | | - .map( |
127 | | - componentName => `export declare const ${componentName}: IconComponent` |
128 | | - ) |
129 | | - .join('\n') |
| 122 | + const iconTypeDefs = iconNames.map(componentName => `export declare const ${componentName}: IconComponent`).join('\n') |
130 | 123 |
|
131 | 124 | const iconsTypeDefs = `/* Start generated icons */ |
132 | | -type IconComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<IconProps> & React.RefAttributes<SVGElement>> |
| 125 | +export type IconComponent = React.ForwardRefExoticComponent<React.PropsWithoutRef<IconProps> & React.RefAttributes<SVGElement>> |
133 | 126 | ${iconTypeDefs} |
134 | 127 | /* End generated icons */` |
135 | 128 |
|
136 | 129 | let typedefs = await fs.readFile(typedefPath, 'utf8') |
137 | | - typedefs = typedefs.replace( |
138 | | - /\/\* Start generated icons \*\/[\s\S]*?\/\* End generated icons \*\//i, |
139 | | - iconsTypeDefs |
140 | | - ) |
| 130 | + typedefs = typedefs.replace(/\/\* Start generated icons \*\/[\s\S]*?\/\* End generated icons \*\//i, iconsTypeDefs) |
141 | 131 |
|
142 | 132 | await fs.writeFile(typedefPath, typedefs) |
143 | 133 | } |
|
0 commit comments