Skip to content

Commit

Permalink
docs: Documented the code connect scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecoomber committed Oct 9, 2024
1 parent afea682 commit 74bdfd2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/code-connect/generate-code-connect-call.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import ts from "typescript";
import { ZDS_ASSETS_FILE_ID } from "../../figmaConfig.js";

/**
* Generates a figma code connect template for a given icon.
* @param iconName The name of the icon.
* @param id The id of the icon .
* @returns A typescript expression containing a call to figma.connect.
*/
export const generateFigmaConnectCall = (iconName: string, id: string): ts.ExpressionStatement => {
return ts.factory.createExpressionStatement(
ts.factory.createCallExpression(
Expand All @@ -19,6 +25,10 @@ export const generateFigmaConnectCall = (iconName: string, id: string): ts.Expre

const getFigmaLink = (id: string) => `https://www.figma.com/design/${ZDS_ASSETS_FILE_ID}?node-id=${id}`;

/**
* props: { rounded: figma.enum("Style", { Round: true, Sharp: false }) }
* @returns A typescript property assignment containing the props object.
*/
const getPropsObject = () =>
ts.factory.createPropertyAssignment(
"props",
Expand All @@ -43,6 +53,11 @@ const getPropsObject = () =>
]),
);

/**
* example: (props) => html`<zeta-icon rounded={props.rounded}>icon name</zeta-icon>
* @param iconName The name of the icon.
* @returns A typescript property assignment containing the template.
*/
const getTemplate = (iconName: string) =>
ts.factory.createPropertyAssignment(
"example",
Expand Down
9 changes: 9 additions & 0 deletions scripts/code-connect/generate-code-connect-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { generateFigmaConnectCall } from "./generate-code-connect-call.js";
import ts from "typescript";
import { getNodeText } from "./get-node-text.js";

/**
* Generates a code connect file with code connect calls for each icon in the given icon manifest.
* @param outputDir The directory to write the code connect file to.
* @param iconManifest The icon manifest to generate code connect calls for.
*/
export const generateCodeConnectFile = async (outputDir: string, iconManifest: IconManifest) => {
mkdirSync(outputDir, { recursive: true });

Expand All @@ -23,6 +28,10 @@ export const generateCodeConnectFile = async (outputDir: string, iconManifest: I
writeFileSync(`${outputDir}/code-connect.figma.ts`, codeConnectFile);
};

/**
* import { figma, html } from "@figma/code-connect/html";
* @returns An import statement for the figma and html modules.
*/
const getImportStatement = () =>
ts.factory.createImportDeclaration(
undefined,
Expand Down
5 changes: 5 additions & 0 deletions scripts/code-connect/get-node-text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import ts from "typescript";

/**
* Converts a given typescript node into text.
* @param node The node to convert to text.
* @returns A string representation of the node.
*/
export const getNodeText = (node: ts.Node): string => {
return printer.printNode(ts.EmitHint.Unspecified, node, tsFile);
};
Expand Down

0 comments on commit 74bdfd2

Please sign in to comment.