Below is the order of things that need to be checked for
-
Create nodes
- Walk node
- If instance -> Check doesn't already exist -> Push component to array
- Push font to array
- Create nodes
- If component check it doesn't match one in component array
- Do not create nested instances
- Walk node
-
Create components
- Walk nodes
-
Create nodes
- Do not create nested instances
- Do not push component to array
- Do not push font to array
-
- Walk nodes
-
Create fonts
Order in which nodes are created
- Create components in reverse
- Create all other nodes
- If
A function which loops through each node, with special properties.
`${createProps()}`
`${Ref(node.parent)}.appendChild(${Ref(node)})\n`
`// Create ${node.type}
var ${Ref(node.parent)} = figma.create${v.titleCase(node.type)}
${createProps}`
function createInstance(node) {
var components = [];
walkNodes([node], {
during(node) {
components.push(node.mainComponent)
},
after(node) {
`// Create INSTANCE
var ${Ref(node)} = ${Ref(node.mainComponent)}.createInstance()\n`
}
})
}
`// Create GROUP
figma.group([${Ref(node.children)}], ${Ref(node.parent)})\n`
`// Create COMPONENT_SET
var ${Ref(node)} = figma.combineAsVariants([${Ref(node.children).join(", ")}], ${Ref(node.parent)})
${createProps}`
var fonts, components;
walkNodes(nodes, {
during(node) {
// If instance push component to array
createNode()
createInstance()
appendNode()
},
after(node) {
createGroup()
createComponent(() => {
walkNodes(node.children, {
during(node) {
createProps()
}
})
}
)
}
}
)
createFonts(fonts)
- Should children of COMPONENT_SETs be appended?
- Should Auto Layout be applied after all children are created?
- Should appending happen after or before props are applied?
- Consider modifying so that it creates a new object/array which the plugin then creates a string from. This would be better because it would avoid the need to use eval when decoding.