1
- const fs = require ( "fs" ) ;
2
- const path = require ( "path" ) ;
3
- const prettier = require ( "prettier" ) ;
1
+ import fs from "node:fs" ;
2
+ import path , { dirname } from "node:path" ;
3
+ import prettier , { format } from "prettier" ;
4
+ import { fileURLToPath } from "node:url" ;
4
5
5
- const { format } = prettier ;
6
+ const __dirname = dirname ( fileURLToPath ( import . meta . url ) ) ;
6
7
7
8
const SOURCE_ICONS_PATH = path . resolve (
8
9
__dirname ,
9
10
"../node_modules/@tabler/icons/icons/"
10
11
) ;
11
12
const DIST_PATH = path . resolve ( __dirname , "../" ) ;
12
13
const DESTINATION_ICONS_PATH = path . resolve ( __dirname , "../icons" ) ;
14
+ const TYPES_PATH = path . resolve ( DIST_PATH , "types" ) ;
13
15
14
16
const prettierOptions = prettier . resolveConfig ( __dirname ) ;
15
17
@@ -62,9 +64,7 @@ function createComponentName(originalName) {
62
64
}
63
65
64
66
function removeOldComponents ( ) {
65
- const components = fs
66
- . readdirSync ( DESTINATION_ICONS_PATH )
67
- . filter ( ( file ) => file . endsWith ( ".svelte" ) ) ;
67
+ const components = fs . readdirSync ( DESTINATION_ICONS_PATH ) ;
68
68
for ( const file of components ) {
69
69
fs . unlinkSync ( path . join ( DESTINATION_ICONS_PATH , file ) ) ;
70
70
}
@@ -92,7 +92,7 @@ async function generateNewComponents() {
92
92
93
93
fs . writeFileSync (
94
94
path . resolve ( DESTINATION_ICONS_PATH , `${ componentName } .svelte` ) ,
95
- format ( source , { parser : "html " , ...( await prettierOptions ) } )
95
+ format ( source , { parser : "svelte " , ...( await prettierOptions ) } )
96
96
) ;
97
97
}
98
98
}
@@ -119,13 +119,7 @@ async function createTypesFile() {
119
119
const [ originalName ] = file . split ( "." ) ;
120
120
const componentName = createComponentName ( originalName ) ;
121
121
122
- return `\
123
- export class ${ componentName } extends SvelteComponentTyped<{
124
- color?: string;
125
- size?: string | number;
126
- strokeWidth?: string | number;
127
- }> {}\
128
- ` ;
122
+ return `export class ${ componentName } extends TablerIcon {}` ;
129
123
} ) ;
130
124
131
125
fs . writeFileSync (
0 commit comments