@@ -17,8 +17,13 @@ const carbonDir = path.resolve(themesDir + '/svelte/carbon');
17
17
// main
18
18
//
19
19
( async ( ) => {
20
- let themeType = ( ( process . argv [ 2 ] || '' ) . trim ( ) || await ask ( 'Theme type? (svelte, react, vue)' ) ) . toLowerCase ( ) ;
21
- let themeName = ( ( process . argv [ 3 ] || '' ) . trim ( ) || await ask ( 'What is the name of your new theme? (only lowercase letters and underscores)' ) ) . toLowerCase ( ) ;
20
+ let themeType = (
21
+ ( process . argv [ 2 ] || '' ) . trim ( ) || ( await ask ( 'Theme type? (svelte, react, vue)' ) )
22
+ ) . toLowerCase ( ) ;
23
+ let themeName = (
24
+ ( process . argv [ 3 ] || '' ) . trim ( ) ||
25
+ ( await ask ( 'What is the name of your new theme? (only lowercase letters and underscores)' ) )
26
+ ) . toLowerCase ( ) ;
22
27
23
28
if ( ! themeName ) {
24
29
throw new Error ( 'No theme name provided.' ) ;
@@ -31,29 +36,37 @@ const carbonDir = path.resolve(themesDir + '/svelte/carbon');
31
36
throw new Error ( 'Wrong template type provided. Allowed: svelte, react, vue' ) ;
32
37
}
33
38
34
- const newThemePath = carbonDir . replace ( / \\ / g, '/' ) . replace ( / \/ s v e l t e \/ c a r b o n $ / g, `/${ themeType } /${ themeName } ` ) . replace ( / \/ / g, path . sep ) ;
39
+ const newThemePath = carbonDir
40
+ . replace ( / \\ / g, '/' )
41
+ . replace ( / \/ s v e l t e \/ c a r b o n $ / g, `/${ themeType } /${ themeName } ` )
42
+ . replace ( / \/ / g, path . sep ) ;
35
43
36
- const files = ( await getAllFiles ( carbonDir ) ) ;
44
+ const files = await getAllFiles ( carbonDir ) ;
37
45
38
46
for ( const file of files ) {
39
47
if ( ! file . match ( / \. s v e l t e $ / gi) ) {
40
48
continue ;
41
49
}
42
50
const newPath = path . resolve ( file . replace ( carbonDir , newThemePath ) ) ;
43
- const basename = newPath . replace ( projectDir + path . sep , '' ) . replace ( new RegExp ( '\\\\' , 'g' ) , '/' ) ;
51
+ const basename = newPath
52
+ . replace ( projectDir + path . sep , '' )
53
+ . replace ( new RegExp ( '\\\\' , 'g' ) , '/' ) ;
44
54
const dir = path . dirname ( newPath ) ;
45
- await fs . mkdir ( dir , { recursive : true } ) ;
46
- await fs . writeFile ( newPath , `TODO: Implement template "${ basename } " for "${ themeType } /${ themeName } " theme.\n` ) ;
55
+ await fs . mkdir ( dir , { recursive : true } ) ;
56
+ await fs . writeFile (
57
+ newPath ,
58
+ `TODO: Implement template "${ basename } " for "${ themeType } /${ themeName } " theme.\n`
59
+ ) ;
47
60
}
48
61
49
- await fs . copyFile ( carbonDir + '/index.ts' , newThemePath + '/index.ts' ) ;
62
+ await fs . copyFile ( carbonDir + '/index.ts' , newThemePath + '/index.ts' ) ;
50
63
51
- const themesIndex = themesDir + '/' + themeType + '/index.ts' ;
64
+ const themesIndex = themesDir + '/' + themeType + '/index.ts' ;
52
65
let indexContent = ( await fs . readFile ( themesIndex ) ) . toString ( ) ;
53
66
if ( ! indexContent . match ( new RegExp ( `export *\\{ *default as ${ themeName } ` ) , 'gi' ) ) {
54
- indexContent += `\nexport { default as ${ themeName } } from './${ themeName } ';`
67
+ indexContent += `\nexport { default as ${ themeName } } from './${ themeName } ';` ;
55
68
}
56
- indexContent = indexContent . replace ( / \n \n + / , "\n" ) . trim ( ) + "\n" ;
69
+ indexContent = indexContent . replace ( / \n \n + / , '\n' ) . trim ( ) + '\n' ;
57
70
await fs . writeFile ( themesIndex , indexContent ) ;
58
71
} ) ( ) ;
59
72
@@ -83,18 +96,18 @@ async function ask(question) {
83
96
}
84
97
85
98
async function getAllFiles ( dirPath , arrayOfFiles = [ ] ) {
86
- const files = await fs . readdir ( dirPath )
99
+ const files = await fs . readdir ( dirPath ) ;
87
100
88
- arrayOfFiles = arrayOfFiles || [ ]
101
+ arrayOfFiles = arrayOfFiles || [ ] ;
89
102
90
103
for ( const file of files ) {
91
104
const stat = await fs . stat ( dirPath + path . sep + file ) ;
92
105
if ( stat . isDirectory ( ) ) {
93
- arrayOfFiles = await getAllFiles ( dirPath + path . sep + file , arrayOfFiles )
106
+ arrayOfFiles = await getAllFiles ( dirPath + path . sep + file , arrayOfFiles ) ;
94
107
} else {
95
- arrayOfFiles . push ( path . join ( dirPath , path . sep , file ) )
108
+ arrayOfFiles . push ( path . join ( dirPath , path . sep , file ) ) ;
96
109
}
97
110
}
98
111
99
- return arrayOfFiles
112
+ return arrayOfFiles ;
100
113
}
0 commit comments