1
- import { pascalCase } from ' change-case' ;
1
+ import { pascalCase } from " change-case" ;
2
2
import { existsSync } from "node:fs" ;
3
3
import { mkdir , readFile , readdir , rm , writeFile } from "node:fs/promises" ;
4
4
import { basename , dirname , extname , join } from "node:path" ;
5
- import { fileURLToPath } from ' node:url' ;
5
+ import { fileURLToPath } from " node:url" ;
6
6
7
7
const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
8
8
9
- const ICON_FOLDER = join ( __dirname , '..' , 'public' , 'icons' )
10
- const COMPONENT_ICON_FOLDER = join ( __dirname , '..' , 'addon' , 'components' , 'icons' ) ;
9
+ const ICON_FOLDER = join ( __dirname , ".." , "public" , "icons" ) ;
10
+ const COMPONENT_ICON_FOLDER = join (
11
+ __dirname ,
12
+ ".." ,
13
+ "addon" ,
14
+ "components" ,
15
+ "icons" ,
16
+ ) ;
11
17
12
18
const files = await readdir ( ICON_FOLDER ) ;
13
- const icons = files . filter ( file => extname ( file ) === '.svg' ) . map ( svg => basename ( svg , '.svg' ) ) ;
19
+ const icons = files
20
+ . filter ( ( file ) => extname ( file ) === ".svg" )
21
+ . map ( ( svg ) => basename ( svg , ".svg" ) ) ;
14
22
15
23
await prepareOutputDir ( ) ;
16
24
17
- const promises = icons . map ( svg => {
25
+ const promises = icons . map ( ( svg ) => {
18
26
return generateComponent ( svg ) ;
19
27
} ) ;
20
28
await Promise . all ( promises ) ;
21
29
22
30
async function generateComponent ( iconName ) {
23
31
const componentName = pascalCase ( iconName ) ;
24
32
25
- const iconContent = await readFile ( join ( ICON_FOLDER , iconName + '.svg' ) ) ;
26
- const iconContentWithAttributes = iconContent . toString ( ) . replace ( '>' , ' ...attributes>' ) ; // We assume the first closing element is the svg element
33
+ const iconContent = await readFile ( join ( ICON_FOLDER , iconName + ".svg" ) ) ;
34
+ const iconContentWithAttributes = iconContent
35
+ . toString ( )
36
+ . replace ( ">" , " ...attributes>" ) ; // We assume the first closing element is the svg element
27
37
28
38
const component = `// THIS FILE IS GENERATED. ANY CHANGES TO THIS FILE WILL BE LOST.
29
39
import type { TOC } from '@ember/component/template-only';
@@ -33,9 +43,9 @@ export interface ${componentName}IconSignature {
33
43
}
34
44
35
45
export const ${ componentName } Icon: TOC<${ componentName } IconSignature> = <template>${ iconContentWithAttributes } </template>;
36
- export default ${ componentName } Icon;`
46
+ export default ${ componentName } Icon;` ;
37
47
38
- await writeFile ( join ( COMPONENT_ICON_FOLDER , iconName + ' .gts' ) , component )
48
+ await writeFile ( join ( COMPONENT_ICON_FOLDER , iconName + " .gts" ) , component ) ;
39
49
}
40
50
41
51
async function prepareOutputDir ( ) {
0 commit comments