Skip to content

Raw Template - Support variant and links in raw #262

@amoshydra

Description

@amoshydra

Describe the feature you'd like:

Currently parseReactDoc is capable of returning variant and link to the CodeConnectJSON

const variant = variantArg ? parseVariant(variantArg, sourceFile, checker) : undefined
const links = linksArg ? parseLinks(linksArg, parserContext) : undefined

It would be nice to also be able to specify variant and link in the Raw template.

export function parseRawFile(filePath: string, label: string | undefined): CodeConnectJSON {
const fileContent = fs.readFileSync(filePath, 'utf-8')
const [firstLine, ...templateLines] = fileContent.split('\n')
const figmaNodeUrl = firstLine.replace(/\/\/\s*url=/, '').trim()
const template = templateLines.join('\n')
return {
figmaNode: figmaNodeUrl,
template,
// nestable by default unless user specifies otherwise
templateData: { nestable: true },
language: 'raw',
label: label || 'Code',
source: '',
sourceLocation: { line: -1 },
metadata: {
cliVersion: require('../../package.json').version,
},
}
}

Suggestion

Allow usage of frontmatter to specify more data for the CodeConnectJSON

---
url: https://www.figma.com/file/your-file-id/Component?node-id=123
component: Button
variant:
  type: primary
  has outline: true
links:
  - name: Awesome Document
    url: https://example.com
---

const figma = require('figma')
const instance = figma.selectedInstance

it can be kept forward compatible too. yaml parsing can be enabled if the file starts with "---\n".

See POC in #263

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions