88 postSettingsChanged ,
99} from "backend" ;
1010import { nodesToJSON } from "backend/src/altNodes/jsonNodeConversion" ;
11+ import { log , error } from "backend/src/common/log" ;
1112import { retrieveGenericSolidUIColors } from "backend/src/common/retrieveUI/retrieveColors" ;
1213import { flutterCodeGenTextStyles } from "backend/src/flutter/flutterMain" ;
1314import { htmlCodeGenTextStyles } from "backend/src/html/htmlMain" ;
@@ -41,10 +42,10 @@ function isKeyOfPluginSettings(key: string): key is keyof PluginSettings {
4142}
4243
4344const getUserSettings = async ( ) => {
44- console . log ( "[DEBUG] getUserSettings - Starting to fetch user settings" ) ;
45+ log ( "[DEBUG] getUserSettings - Starting to fetch user settings" ) ;
4546 const possiblePluginSrcSettings =
4647 ( await figma . clientStorage . getAsync ( "userPluginSettings" ) ) ?? { } ;
47- console . log (
48+ log (
4849 "[DEBUG] getUserSettings - Raw settings from storage:" ,
4950 possiblePluginSrcSettings ,
5051 ) ;
@@ -65,22 +66,22 @@ const getUserSettings = async () => {
6566 } ;
6667
6768 userPluginSettings = updatedPluginSrcSettings as PluginSettings ;
68- console . log ( "[DEBUG] getUserSettings - Final settings:" , userPluginSettings ) ;
69+ log ( "[DEBUG] getUserSettings - Final settings:" , userPluginSettings ) ;
6970 return userPluginSettings ;
7071} ;
7172
7273const initSettings = async ( ) => {
73- console . log ( "[DEBUG] initSettings - Initializing plugin settings" ) ;
74+ log ( "[DEBUG] initSettings - Initializing plugin settings" ) ;
7475 await getUserSettings ( ) ;
7576 postSettingsChanged ( userPluginSettings ) ;
76- console . log ( "[DEBUG] initSettings - Calling safeRun with settings" ) ;
77+ log ( "[DEBUG] initSettings - Calling safeRun with settings" ) ;
7778 safeRun ( userPluginSettings ) ;
7879} ;
7980
8081// Used to prevent running from happening again.
8182let isLoading = false ;
8283const safeRun = async ( settings : PluginSettings ) => {
83- console . log (
84+ log (
8485 "[DEBUG] safeRun - Called with isLoading =" ,
8586 isLoading ,
8687 "selection =" ,
@@ -89,25 +90,25 @@ const safeRun = async (settings: PluginSettings) => {
8990 if ( isLoading === false ) {
9091 try {
9192 isLoading = true ;
92- console . log ( "[DEBUG] safeRun - Starting run execution" ) ;
93+ log ( "[DEBUG] safeRun - Starting run execution" ) ;
9394 await run ( settings ) ;
94- console . log ( "[DEBUG] safeRun - Run execution completed" ) ;
95+ log ( "[DEBUG] safeRun - Run execution completed" ) ;
9596 // hack to make it not immediately set to false when complete. (executes on next frame)
9697 setTimeout ( ( ) => {
97- console . log ( "[DEBUG] safeRun - Resetting isLoading to false" ) ;
98+ log ( "[DEBUG] safeRun - Resetting isLoading to false" ) ;
9899 isLoading = false ;
99100 } , 1 ) ;
100101 } catch ( e ) {
101- console . log ( "[DEBUG] safeRun - Error caught in execution" ) ;
102+ log ( "[DEBUG] safeRun - Error caught in execution" ) ;
102103 isLoading = false ; // Make sure to reset the flag on error
103104 if ( e && typeof e === "object" && "message" in e ) {
104105 const error = e as Error ;
105- console . log ( "error: " , error . stack ) ;
106+ log ( "error: " , error . stack ) ;
106107 figma . ui . postMessage ( { type : "error" , error : error . message } ) ;
107108 } else {
108109 // Handle non-standard errors or unknown error types
109110 const errorMessage = String ( e ) ;
110- console . log ( "Unknown error: " , errorMessage ) ;
111+ log ( "Unknown error: " , errorMessage ) ;
111112 figma . ui . postMessage ( {
112113 type : "error" ,
113114 error : errorMessage || "Unknown error occurred" ,
@@ -118,21 +119,21 @@ const safeRun = async (settings: PluginSettings) => {
118119 figma . ui . postMessage ( { type : "conversion-complete" , success : false } ) ;
119120 }
120121 } else {
121- console . log (
122+ log (
122123 "[DEBUG] safeRun - Skipping execution because isLoading =" ,
123124 isLoading ,
124125 ) ;
125126 }
126127} ;
127128
128129const standardMode = async ( ) => {
129- console . log ( "[DEBUG] standardMode - Starting standard mode initialization" ) ;
130+ log ( "[DEBUG] standardMode - Starting standard mode initialization" ) ;
130131 figma . showUI ( __html__ , { width : 450 , height : 700 , themeColors : true } ) ;
131132 await initSettings ( ) ;
132133
133134 // Listen for selection changes
134135 figma . on ( "selectionchange" , ( ) => {
135- console . log (
136+ log (
136137 "[DEBUG] selectionchange event - New selection:" ,
137138 figma . currentPage . selection ,
138139 ) ;
@@ -142,7 +143,7 @@ const standardMode = async () => {
142143 // Listen for page changes
143144 figma . loadAllPagesAsync ( ) ;
144145 figma . on ( "documentchange" , ( ) => {
145- console . log ( "[DEBUG] documentchange event triggered" ) ;
146+ log ( "[DEBUG] documentchange event triggered" ) ;
146147 // Node: This was causing an infinite load when you try to export a background image from a group that contains children.
147148 // The reason for this is that the code will temporarily hide the children of the group in order to export a clean image
148149 // then restores the visibility of the children. This constitutes a document change so it's restarting the whole conversion.
@@ -151,16 +152,16 @@ const standardMode = async () => {
151152 } ) ;
152153
153154 figma . ui . onmessage = async ( msg ) => {
154- console . log ( "[DEBUG] figma.ui.onmessage" , msg ) ;
155+ log ( "[DEBUG] figma.ui.onmessage" , msg ) ;
155156
156157 if ( msg . type === "pluginSettingWillChange" ) {
157158 const { key, value } = msg as SettingWillChangeMessage < unknown > ;
158- console . log ( `[DEBUG] Setting changed: ${ key } = ${ value } ` ) ;
159+ log ( `[DEBUG] Setting changed: ${ key } = ${ value } ` ) ;
159160 ( userPluginSettings as any ) [ key ] = value ;
160161 figma . clientStorage . setAsync ( "userPluginSettings" , userPluginSettings ) ;
161162 safeRun ( userPluginSettings ) ;
162163 } else if ( msg . type === "get-selection-json" ) {
163- console . log ( "[DEBUG] get-selection-json message received" ) ;
164+ log ( "[DEBUG] get-selection-json message received" ) ;
164165
165166 const nodes = figma . currentPage . selection ;
166167 if ( nodes . length === 0 ) {
@@ -187,8 +188,8 @@ const standardMode = async () => {
187188 ) . document ,
188189 ) ,
189190 ) ) as SceneNode [ ] ;
190- } catch ( error ) {
191- console . error ( "Error exporting JSON:" , error ) ;
191+ } catch ( err ) {
192+ error ( "Error exporting JSON:" , err ) ;
192193 }
193194
194195 try {
@@ -203,13 +204,13 @@ const standardMode = async () => {
203204 } ;
204205 newNodes . forEach ( removeParent ) ;
205206 result . newConversion = newNodes ;
206- } catch ( error ) {
207- console . error ( "Error in new conversion:" , error ) ;
207+ } catch ( err ) {
208+ error ( "Error in new conversion:" , err ) ;
208209 }
209210
210211 const nodeJson = result ;
211212
212- console . log ( "[DEBUG] Exported node JSON:" , nodeJson ) ;
213+ log ( "[DEBUG] Exported node JSON:" , nodeJson ) ;
213214
214215 // Send the JSON data back to the UI
215216 figma . ui . postMessage ( {
@@ -221,20 +222,20 @@ const standardMode = async () => {
221222} ;
222223
223224const codegenMode = async ( ) => {
224- console . log ( "[DEBUG] codegenMode - Starting codegen mode initialization" ) ;
225+ log ( "[DEBUG] codegenMode - Starting codegen mode initialization" ) ;
225226 // figma.showUI(__html__, { visible: false });
226227 await getUserSettings ( ) ;
227228
228229 figma . codegen . on (
229230 "generate" ,
230231 async ( { language, node } : CodegenEvent ) : Promise < CodegenResult [ ] > => {
231- console . log (
232+ log (
232233 `[DEBUG] codegen.generate - Language: ${ language } , Node:` ,
233234 node ,
234235 ) ;
235236
236237 const convertedSelection = await nodesToJSON ( [ node ] , userPluginSettings ) ;
237- console . log (
238+ log (
238239 "[DEBUG] codegen.generate - Converted selection:" ,
239240 convertedSelection ,
240241 ) ;
@@ -406,14 +407,14 @@ const codegenMode = async () => {
406407switch ( figma . mode ) {
407408 case "default" :
408409 case "inspect" :
409- console . log ( "[DEBUG] Starting plugin in" , figma . mode , "mode" ) ;
410+ log ( "[DEBUG] Starting plugin in" , figma . mode , "mode" ) ;
410411 standardMode ( ) ;
411412 break ;
412413 case "codegen" :
413- console . log ( "[DEBUG] Starting plugin in codegen mode" ) ;
414+ log ( "[DEBUG] Starting plugin in codegen mode" ) ;
414415 codegenMode ( ) ;
415416 break ;
416417 default :
417- console . log ( "[DEBUG] Unknown plugin mode:" , figma . mode ) ;
418+ log ( "[DEBUG] Unknown plugin mode:" , figma . mode ) ;
418419 break ;
419420}
0 commit comments