Last active
July 29, 2023 03:57
-
-
Save guiseek/89c14032f191163508bd48be2836a9ea to your computer and use it in GitHub Desktop.
Create Nx Monorepo from Figma Figjam
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type NxPluginName = | |
| 'js' | |
| 'web' | |
| 'node' | |
| 'nest' | |
| 'react' | |
| 'angular' | |
| 'express' | |
type NxProjectType = 'application' | 'library' | |
type LibraryType = 'data-access' | 'domain' | 'feature' | 'util' | 'ui' | |
interface PluginProperties { | |
type: LibraryType | |
collection: NxProjectType | |
plugin: NxPluginName | |
} | |
interface VariantMixin { | |
readonly variantProperties: PluginProperties | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isRepoScope<T extends SceneNode>(node: T) { | |
return node.type === 'SECTION' | |
} | |
function isTextNode<T extends SceneNode>(node: T) { | |
return node.type === 'TEXT' | |
} | |
function isNxPlugin<T extends SceneNode>(node: T) { | |
return node.name === '@nx' && node.type === 'INSTANCE' | |
} | |
function findScopesOnPage<R extends SectionNode>(page: PageNode) { | |
return page.children.filter(isRepoScope) as R[] | |
} | |
function findLibsOnScope(scope: SectionNode) { | |
return scope.children.filter(isNxPlugin).filter((child: InstanceNode) => { | |
const {collection} = child.variantProperties | |
return collection === 'library' | |
}) as InstanceNode[] | |
} | |
function findLibTextNodes(libs: InstanceNode) { | |
const frame = libs.children[0] as FrameNode | |
return frame.children.filter(isTextNode) as TextNode[] | |
} | |
function getMetadata<T extends TextNode>(nodes: T[]) { | |
const chars = nodes.map((node) => node.characters) | |
const [plugin, collection, name, libraryType] = chars | |
return {plugin, collection, name, libraryType} | |
} | |
figma.on('run', () => { | |
findScopesOnPage(figma.currentPage).map((scope) => { | |
console.log('\n---------------------\n') | |
console.log('Scope: ', scope.name) | |
console.log('') | |
findLibsOnScope(scope).map((lib) => { | |
const {name, plugin, libraryType, collection} = getMetadata( | |
findLibTextNodes(lib) | |
) | |
console.log(`Name : ${name}`) | |
console.log(`Metadata : ${plugin}, ${libraryType}, ${collection}`) | |
console.log(``) | |
}) | |
}) | |
figma.closePlugin('Closed') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment