@@ -4,6 +4,7 @@ import path from 'path';
44import chalk from 'chalk' ;
55import Handlebars from 'handlebars' ;
66import { fileURLToPath } from 'url' ;
7+ import { afLogger } from '../modules/logger.js' ;
78
89async function renderHBSTemplate ( templatePath , data ) {
910 try {
@@ -31,7 +32,7 @@ async function generateVueContent(fieldType, { resource, column }) {
3132 ? path . join ( __dirname , 'templates' , 'customFields' , `${ fieldType } .vue.hbs` )
3233 : path . join ( __dirname , 'templates' , 'customCrud' , `${ fieldType } .vue.hbs` ) ;
3334
34- console . log ( chalk . dim ( `Using template: ${ templatePath } ` ) ) ;
35+ afLogger . info ( chalk . dim ( `Using template: ${ templatePath } ` ) ) ;
3536
3637 const context = {
3738 componentName,
@@ -61,24 +62,24 @@ export async function generateComponentFile(componentFileName, fieldType, contex
6162 const customDirPath = path . resolve ( projectRoot , customDirRelative ) ;
6263 const absoluteComponentPath = path . resolve ( customDirPath , componentFileName ) ;
6364 if ( fsSync . existsSync ( absoluteComponentPath ) ) {
64- console . log ( chalk . yellow ( `⚠️ Component file already exists: ${ absoluteComponentPath } ` ) ) ;
65+ afLogger . warn ( chalk . yellow ( `⚠️ Component file already exists: ${ absoluteComponentPath } ` ) ) ;
6566 return { "alreadyExists" : true , "path" : absoluteComponentPath }
6667 }
6768 try {
6869 await fs . mkdir ( customDirPath , { recursive : true } ) ;
69- console . log ( chalk . dim ( `Ensured custom directory exists: ${ customDirPath } ` ) ) ;
70+ afLogger . info ( chalk . dim ( `Ensured custom directory exists: ${ customDirPath } ` ) ) ;
7071
7172 const fileContent = await generateVueContent ( fieldType , context ) ;
7273
7374 await fs . writeFile ( absoluteComponentPath , fileContent , 'utf-8' ) ;
74- console . log ( chalk . green ( `✅ Generated component file: ${ absoluteComponentPath } ` ) ) ;
75+ afLogger . info ( chalk . green ( `✅ Generated component file: ${ absoluteComponentPath } ` ) ) ;
7576
7677 return { "alreadyExists" : false , "path" : absoluteComponentPath }
7778
7879 } catch ( error ) {
79- console . error ( chalk . red ( `❌ Error creating component file at ${ absoluteComponentPath } :` ) ) ;
80+ afLogger . error ( chalk . red ( `❌ Error creating component file at ${ absoluteComponentPath } :` ) ) ;
8081 if ( ! error . message . includes ( 'template' ) ) {
81- console . error ( error ) ;
82+ afLogger . error ( error ) ;
8283 }
8384 throw error ;
8485 }
@@ -91,22 +92,22 @@ export async function generateCrudInjectionComponent(componentFileName, crudType
9192 const absoluteComponentPath = path . resolve ( customDirPath , componentFileName ) ;
9293
9394 if ( fsSync . existsSync ( absoluteComponentPath ) ) {
94- console . log ( chalk . yellow ( `⚠️ Component file already exists: ${ absoluteComponentPath } ` ) ) ;
95+ afLogger . warn ( chalk . yellow ( `⚠️ Component file already exists: ${ absoluteComponentPath } ` ) ) ;
9596 return { alreadyExists : true , path : absoluteComponentPath } ;
9697 }
9798
9899 try {
99100 await fs . mkdir ( customDirPath , { recursive : true } ) ;
100- console . log ( chalk . dim ( `Ensured custom directory exists: ${ customDirPath } ` ) ) ;
101+ afLogger . warn ( chalk . dim ( `Ensured custom directory exists: ${ customDirPath } ` ) ) ;
101102
102103 const fileContent = await generateVueContent ( crudType , context ) ;
103104
104105 await fs . writeFile ( absoluteComponentPath , fileContent , 'utf-8' ) ;
105- console . log ( chalk . green ( `✅ Generated component file: ${ absoluteComponentPath } ` ) ) ;
106+ afLogger . info ( chalk . green ( `✅ Generated component file: ${ absoluteComponentPath } ` ) ) ;
106107
107108 return { alreadyExists : false , path : absoluteComponentPath } ;
108109 } catch ( error ) {
109- console . error ( chalk . red ( `❌ Error creating component file at ${ absoluteComponentPath } :` ) ) ;
110+ afLogger . error ( chalk . red ( `❌ Error creating component file at ${ absoluteComponentPath } :` ) ) ;
110111 throw error ;
111112 }
112113}
@@ -118,13 +119,13 @@ export async function generateLoginOrGlobalComponentFile(componentFileName, inje
118119 const absoluteComponentPath = path . resolve ( customDirPath , componentFileName ) ;
119120
120121 if ( fsSync . existsSync ( absoluteComponentPath ) ) {
121- console . log ( chalk . yellow ( `⚠️ Component file already exists: ${ absoluteComponentPath } ` ) ) ;
122+ afLogger . warn ( chalk . yellow ( `⚠️ Component file already exists: ${ absoluteComponentPath } ` ) ) ;
122123 return { alreadyExists : true , path : absoluteComponentPath } ;
123124 }
124125
125126 try {
126127 await fs . mkdir ( customDirPath , { recursive : true } ) ;
127- console . log ( chalk . dim ( `Ensured custom directory exists: ${ customDirPath } ` ) ) ;
128+ afLogger . warn ( chalk . dim ( `Ensured custom directory exists: ${ customDirPath } ` ) ) ;
128129
129130 const __filename = fileURLToPath ( import . meta. url ) ;
130131 const __dirname = path . dirname ( __filename ) ;
@@ -138,11 +139,11 @@ export async function generateLoginOrGlobalComponentFile(componentFileName, inje
138139 const fileContent = await renderHBSTemplate ( templatePath , context ) ;
139140
140141 await fs . writeFile ( absoluteComponentPath , fileContent , 'utf-8' ) ;
141- console . log ( chalk . green ( `✅ Generated login injection component: ${ absoluteComponentPath } ` ) ) ;
142+ afLogger . info ( chalk . green ( `✅ Generated login injection component: ${ absoluteComponentPath } ` ) ) ;
142143
143144 return { alreadyExists : false , path : absoluteComponentPath } ;
144145 } catch ( error ) {
145- console . error ( chalk . red ( `❌ Error creating login component at ${ absoluteComponentPath } ` ) ) ;
146+ afLogger . error ( chalk . red ( `❌ Error creating login component at ${ absoluteComponentPath } ` ) ) ;
146147 throw error ;
147148 }
148149}
0 commit comments