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