@@ -26,18 +26,20 @@ var enabledFramework;
26
26
enabledFramework [ "Vue" ] = "vue" ;
27
27
enabledFramework [ "React" ] = "react" ;
28
28
} ) ( enabledFramework || ( enabledFramework = { } ) ) ;
29
- program . name ( 'make-js-component' ) . version ( packageJson . version ) ;
30
- program . option ( "--vue" , "creates a vue component" ) ;
31
- program . option ( "-c" , "creates a vue component using composition API: use options API instea" ) ;
32
- program . requiredOption ( '-n, --name <component name>' , "the name of the component" ) ;
29
+ //program config and setup
30
+ program . name ( 'make-js-component' )
31
+ . version ( packageJson . version )
32
+ . option ( "--vue" , "creates a vue component" )
33
+ . option ( "-c" , "creates a vue component using composition API: use options API instea" )
34
+ . requiredOption ( '-n, --name <component name>' , "the name of the component" )
35
+ . option ( "-f, --folder <custom folder path>" , "a custom folder inside components to save the component" )
36
+ . parse ( process . argv ) ;
37
+ var options = program . opts ( ) ;
33
38
var usedFramework = enabledFramework . Empty ;
34
39
var componentName = "" ;
35
- program . parse ( process . argv ) ;
36
- var options = program . opts ( ) ;
37
- console . log ( options ) ;
38
40
if ( options . vue )
39
41
usedFramework = enabledFramework . Vue ;
40
- // add here more options
42
+ // add here options for the framework
41
43
if ( options . name )
42
44
componentName = options . name ;
43
45
if ( usedFramework == "" ) {
@@ -46,20 +48,44 @@ if (usedFramework == "") {
46
48
}
47
49
var componentTemplate = options . c ? 'component-composition.vue' : 'component-options.vue' ;
48
50
try {
49
- var folderArgIndex = process . argv . indexOf ( '--f' ) ;
50
- var customFolder_1 = folderArgIndex > - 1 ? process . argv [ folderArgIndex + 1 ] : '' ;
51
- customFolder_1 = customFolder_1 . charAt ( - 1 ) == '/' ? customFolder_1 : "" . concat ( customFolder_1 , "/" ) ;
52
- customFolder_1 = customFolder_1 . charAt ( 0 ) == '/' ? customFolder_1 : "/" . concat ( customFolder_1 ) ;
51
+ var customFolder = options . folder || "" ;
52
+ createComponent ( componentName , usedFramework , componentTemplate , customFolder ) ;
53
+ /*if(!fs.existsSync(`${configs.BASE_DIR}${configs.COMPONENT_FOLDER}`)){
54
+ fs.mkdirSync(`${configs.BASE_DIR}${configs.COMPONENT_FOLDER}`);
55
+ }
56
+ fs.readFile(path.join(configs.INIT_PATH,'src',configs.STUBS_DIR,usedFramework,componentTemplate), 'utf8', (err: Error,data: String)=>{
57
+ data = data.replaceAll("Component",capitalizeFirstLetter(componentName))
58
+ if(!fs.existsSync(path.join(configs.BASE_DIR,configs.COMPONENT_FOLDER,customFolder))){
59
+ fs.mkdirSync(path.join(configs.BASE_DIR,configs.COMPONENT_FOLDER,customFolder));
60
+ }
61
+ const compFileName = componentName+'.vue';
62
+ fs.writeFile(path.join(configs.BASE_DIR,configs.COMPONENT_FOLDER,customFolder,compFileName),data, (err: Error)=>{
63
+ if(err){
64
+ console.error(err)
65
+ }else{
66
+ console.log('Done')
67
+ }
68
+ })
69
+ })*/
70
+ }
71
+ catch ( error ) {
72
+ console . error ( error ) ;
73
+ }
74
+ function capitalizeFirstLetter ( string ) {
75
+ return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
76
+ }
77
+ function createComponent ( componentName , framework , template , customFolder ) {
78
+ if ( customFolder === void 0 ) { customFolder = "" ; }
53
79
if ( ! fs . existsSync ( "" . concat ( configs . BASE_DIR ) . concat ( configs . COMPONENT_FOLDER ) ) ) {
54
80
fs . mkdirSync ( "" . concat ( configs . BASE_DIR ) . concat ( configs . COMPONENT_FOLDER ) ) ;
55
81
}
56
- console . log ( path . join ( configs . INIT_PATH , 'src' , configs . STUBS_DIR , usedFramework , componentTemplate ) ) ;
57
- fs . readFile ( path . join ( configs . INIT_PATH , 'src' , configs . STUBS_DIR , usedFramework , componentTemplate ) , 'utf8' , function ( err , data ) {
82
+ fs . readFile ( path . join ( configs . INIT_PATH , 'src' , configs . STUBS_DIR , framework , template ) , 'utf8' , function ( err , data ) {
58
83
data = data . replaceAll ( "Component" , capitalizeFirstLetter ( componentName ) ) ;
59
- if ( ! fs . existsSync ( "" . concat ( configs . BASE_DIR ) . concat ( configs . COMPONENT_FOLDER ) . concat ( customFolder_1 ) ) ) {
60
- fs . mkdirSync ( "" . concat ( configs . BASE_DIR ) . concat ( configs . COMPONENT_FOLDER ) . concat ( customFolder_1 ) ) ;
84
+ if ( ! fs . existsSync ( path . join ( configs . BASE_DIR , configs . COMPONENT_FOLDER , customFolder ) ) ) {
85
+ fs . mkdirSync ( path . join ( configs . BASE_DIR , configs . COMPONENT_FOLDER , customFolder ) ) ;
61
86
}
62
- fs . writeFile ( "" . concat ( configs . BASE_DIR ) . concat ( configs . COMPONENT_FOLDER ) . concat ( customFolder_1 ) . concat ( componentName , ".vue" ) , data , function ( err ) {
87
+ var compFileName = componentName + '.vue' ;
88
+ fs . writeFile ( path . join ( configs . BASE_DIR , configs . COMPONENT_FOLDER , customFolder , compFileName ) , data , function ( err ) {
63
89
if ( err ) {
64
90
console . error ( err ) ;
65
91
}
69
95
} ) ;
70
96
} ) ;
71
97
}
72
- catch ( error ) {
73
- console . error ( error ) ;
74
- }
75
- function capitalizeFirstLetter ( string ) {
76
- return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
77
- }
0 commit comments