1
1
import { svgo } from './svgo' ;
2
2
import { getInterfaceDefenition } from './interface-def' ;
3
+ import * as camelCase from 'lodash.camelcase' ;
3
4
4
5
const util = require ( 'util' ) ;
5
6
const path = require ( 'path' ) ;
@@ -24,22 +25,28 @@ export const convert = async (convertionOptions: ConvertionOptions) => {
24
25
const files = await readdir ( directoryPath ) ;
25
26
let types = `type ${ convertionOptions . typeName } = ` ;
26
27
27
- for ( const fileName of files ) {
28
+ for ( let i = 0 ; i < files . length ; i ++ ) {
29
+ const fileName = files [ i ] ;
28
30
const filenameWithoutEnding = fileName . split ( '.' ) [ 0 ] ;
29
31
const rawSvg = await extractSvgContent ( fileName , directoryPath ) ;
30
32
const optimizedSvg = await svgo . optimize ( rawSvg ) ;
31
33
32
34
const fileNameUpperCase = filenameWithoutEnding [ 0 ] . toUpperCase ( ) + filenameWithoutEnding . slice ( 1 ) ;
33
- const variableName = `${ convertionOptions . prefix } ${ fileNameUpperCase } ` ;
34
- // TODO kk: check if file is last
35
- types += `'${ filenameWithoutEnding } ' | ` ;
36
- fileContent += `export const ${ variableName } : SVGIcon = {
35
+ const variableName = `${ convertionOptions . prefix } ${ camelCase ( fileNameUpperCase ) } ` ;
36
+
37
+ if ( i === files . length - 1 ) {
38
+ types += `'${ filenameWithoutEnding } '` ;
39
+ } else {
40
+ types += `'${ filenameWithoutEnding } ' | ` ;
41
+ }
42
+
43
+ fileContent += `export const ${ variableName } : ${ convertionOptions . interfaceName } = {
37
44
name: '${ filenameWithoutEnding } ',
38
45
data: '${ optimizedSvg . data } '
39
46
};` ;
40
47
}
41
48
fileContent += types += getInterfaceDefenition ( convertionOptions . interfaceName ) ;
42
- if ( ! fs . existsSync ( convertionOptions . outputDirectory ) ) {
49
+ if ( ! fs . existsSync ( convertionOptions . outputDirectory ) ) {
43
50
fs . mkdirSync ( convertionOptions . outputDirectory ) ;
44
51
}
45
52
console . log ( 'FileContent' , fileContent ) ;
0 commit comments