@@ -21,6 +21,7 @@ import { runWizard } from '../connect/wizard/run_wizard'
2121import { callParser , handleMessages } from '../connect/parser_executables'
2222import { fromError } from 'zod-validation-error'
2323import { ParseRequestPayload , ParseResponsePayload } from '../connect/parser_executable_types'
24+ import { parse } from 'yaml'
2425import z from 'zod'
2526import { withUpdateCheck } from '../common/updates'
2627import { exitWithFeedbackMessage } from '../connect/helpers'
@@ -187,15 +188,37 @@ function transformDocFromParser(
187188 }
188189}
189190
190- export function parseRawFile ( filePath : string , label : string | undefined ) : CodeConnectJSON {
191- const fileContent = fs . readFileSync ( filePath , 'utf-8' )
191+ const getRawFileData = ( fileContent : string ) => {
192192 const [ firstLine , ...templateLines ] = fileContent . split ( '\n' )
193- const figmaNodeUrl = firstLine . replace ( / \/ \/ \s * u r l = / , '' ) . trim ( )
194- const template = templateLines . join ( '\n' )
193+ const delimeterStart = '/*---'
194+ const delimeterEnd = '---*/'
195+ if ( firstLine !== delimeterStart ) {
196+ return {
197+ template : templateLines . join ( '\n' ) ,
198+ figmaNode : firstLine . replace ( / \/ \/ \s * u r l = / , '' ) . trim ( ) ,
199+ }
200+ }
201+ const nextDelimeterIndex = templateLines . findIndex ( ( line ) => line === delimeterEnd )
202+ if ( nextDelimeterIndex === - 1 ) {
203+ return {
204+ figmaNode : '' , // invalid data
205+ }
206+ }
207+ const data = templateLines . slice ( 0 , nextDelimeterIndex ) . join ( '\n' )
208+ const { url : figmaNode , component, variant, links } = parse ( data ) ;
209+ return {
210+ component,
211+ variant,
212+ links,
213+ figmaNode,
214+ template : templateLines . slice ( nextDelimeterIndex + 1 ) . join ( '\n' ) ,
215+ } ;
216+ } ;
195217
218+ export function parseRawFile ( filePath : string , label : string | undefined ) : CodeConnectJSON {
219+ const fileContent = fs . readFileSync ( filePath , 'utf-8' )
196220 return {
197- figmaNode : figmaNodeUrl ,
198- template,
221+ ...getRawFileData ( fileContent ) ,
199222 // nestable by default unless user specifies otherwise
200223 templateData : { nestable : true } ,
201224 language : 'raw' ,
0 commit comments