Skip to content

Commit

Permalink
Code Connect v1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
figma-bot committed Nov 5, 2024
1 parent 60b9be4 commit 245eacf
Show file tree
Hide file tree
Showing 43 changed files with 1,002 additions and 58 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Code Connect v1.2.2 (5th November 2024)

## Features

### General
- Added support to create Custom parsers. Those allow users to add support for languages which aren't natively supported by Code Connect. Check the [documentation](https://github.com/figma/code-connect/blob/main/docs/custom.md) for more details.

## Fixed

### React
- Only show AI question for React
- Fix error in autolinking in reduce function

# Code Connect v1.2.1 (23rd October 2024)

### General
- Added a `--exit-on-unreadable-files` flag to all commands to exit if any Code Connect files cannot be parsed. We recommend using this option for CI/CD.

## Fixed

### React
Expand Down
4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@figma/code-connect",
"version": "1.2.1",
"version": "1.2.2",
"description": "A tool for connecting your design system components in code with your design system in Figma",
"keywords": [],
"author": "Figma",
Expand Down Expand Up @@ -105,7 +105,7 @@
"prompts": "^2.4.2",
"strip-ansi": "^6.0.0",
"ts-morph": "^23.0.0",
"typescript": "5.4.2",
"typescript": "5.5.4",
"undici": "^5.28.4",
"zod": "^3.23.8",
"zod-validation-error": "^3.2.0"
Expand Down
15 changes: 14 additions & 1 deletion cli/src/commands/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type BaseCommand = commander.Command & {
dir: string
jsonFile: string
skipUpdateCheck: boolean
exitOnUnreadableFiles: boolean
}

function addBaseCommand(command: commander.Command, name: string, description: string) {
Expand All @@ -59,6 +60,10 @@ function addBaseCommand(command: commander.Command, name: string, description: s
.option('-o --outDir <dir>', 'specify a directory to output generated Code Connect')
.option('-c --config <path>', 'path to a figma config file')
.option('--skip-update-check', 'skips checking for an updated version of the Figma CLI')
.option(
'--exit-on-unreadable-files',
'exit if any Code Connect files cannot be parsed. We recommend using this option for CI/CD.',
)
.option('--dry-run', 'tests publishing without actually publishing')
.addHelpText(
'before',
Expand Down Expand Up @@ -316,6 +321,10 @@ async function getCodeConnectObjectsFromParseFn({
} else {
logger.error(e.toString())
}
if (cmd.exitOnUnreadableFiles) {
logger.info('Exiting due to unreadable files')
process.exit(1)
}
} else {
if (cmd.verbose) {
console.trace(e)
Expand Down Expand Up @@ -354,7 +363,11 @@ async function getReactCodeConnectObjects(
}

async function handlePublish(
cmd: BaseCommand & { skipValidation: boolean; label: string; batchSize: string },
cmd: BaseCommand & {
skipValidation: boolean
label: string
batchSize: string
},
) {
setupHandler(cmd)

Expand Down
2 changes: 1 addition & 1 deletion cli/src/connect/__test__/e2e/e2e_create_command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Errors encountered calling parser, exiting`)
} catch (e: any) {
expect(e.code).toBe(1)
expect(tidyStdOutput(e.stderr)).toBe(`${getPreamble(testPath)}
Invalid parser specified: "does-not-exist". Valid parsers are: swift, compose, __unit_test__.`)
Invalid parser specified: "does-not-exist". Valid parsers are: swift, compose, custom, __unit_test__.`)
}
})

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OtherFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"codeConnect": {
"parser": "custom",
"parserCommand": "node parser/custom_parser.js",
"include": ["*.test"],
"exclude": ["Excluded.test"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
let data = ''

process.stdin.on('data', function (chunk) {
data += chunk
})

process.stdin.on('end', function () {
const parsed = JSON.parse(data)
// Fake result which passes back the input, formatted to match the expected
// schema, so we can validate it was passed in correctly
const result = {
docs: parsed.paths.map((path) => ({
figmaNode: path,
template: JSON.stringify({
config: parsed.config,
mode: parsed.mode,
}),
source: path,
templateData: { props: {} },
language: 'test',
label: 'Test',
})),
messages: [
{ level: 'DEBUG', message: 'Debug message from parser!' },
{ level: 'INFO', message: 'Success from parser!' },
],
}

process.stdout.write(JSON.stringify(result))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"codeConnect": {
"parser": "custom",
"parserCommand": "node parser/custom_parser.js",
"include": ["*.test"],
"exclude": ["Excluded.test"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let data = ''

process.stdin.on('data', function (chunk) {
data += chunk
})

process.stdin.on('end', function () {
const parsed = JSON.parse(data)
const result = {
docs: [],
messages: [{ level: 'ERROR', message: 'Error from parser!' }],
}

process.stdout.write(JSON.stringify(result))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"codeConnect": {
"parser": "custom",
"parserCommand": "node parser/custom_parser.js",
"include": [],
"exclude": ["Excluded.test"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let data = ''

process.stdin.on('data', function (chunk) {
data += chunk
})

process.stdin.on('end', function () {
const parsed = JSON.parse(data)
const result = {
docs: [],
messages: [{ level: 'ERROR', message: 'Error from parser!' }],
}

process.stdout.write(JSON.stringify(result))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"codeConnect": {
"parser": "custom",
"parserCommand": "node parser/custom_parser.js",
"exclude": ["Excluded.test"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let data = ''

process.stdin.on('data', function (chunk) {
data += chunk
})

process.stdin.on('end', function () {
const parsed = JSON.parse(data)
const result = {
docs: [],
messages: [{ level: 'ERROR', message: 'Error from parser!' }],
}

process.stdout.write(JSON.stringify(result))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OtherFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"codeConnect": {
"parser": "custom",
"include": ["*.test"],
"exclude": ["Excluded.test"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
let data = ''

process.stdin.on('data', function (chunk) {
data += chunk
})

process.stdin.on('end', function () {
const parsed = JSON.parse(data)
// Fake result which passes back the input, formatted to match the expected
// schema, so we can validate it was passed in correctly
const result = {
docs: parsed.paths.map((path) => ({
figmaNode: path,
template: JSON.stringify({
config: parsed.config,
mode: parsed.mode,
}),
source: path,
templateData: { props: {} },
language: 'test',
label: 'Test',
})),
messages: [
{ level: 'DEBUG', message: 'Debug message from parser!' },
{ level: 'INFO', message: 'Success from parser!' },
],
}

process.stdout.write(JSON.stringify(result))
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"codeConnect": {
"parser": "custom",
"parserCommand": "node parser/custom_parser.js",
"include": ["*.test"],
"exclude": ["Excluded.test"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let data = ''

process.stdin.on('data', function (chunk) {
data += chunk
})

process.stdin.on('end', function () {
const parsed = JSON.parse(data)
// Fake result which passes back the input, formatted to match the expected
// schema, so we can validate it was passed in correctly
const result = {
docs: parsed.paths.map((path) => ({
test: 123,
})),
messages: [
{ level: 'DEBUG', message: 'Debug message from parser!' },
{ level: 'INFO', message: 'Success from parser!' },
],
}

process.stdout.write(JSON.stringify(result))
})
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OtherFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"codeConnect": {
"parser": "custom",
"parserCommand": "node parser/custom_parser.js",
"include": ["*.test"],
"exclude": ["Excluded.test"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let data = ''

process.stdin.on('data', function (chunk) {
data += chunk
})

process.stdin.on('end', function () {
const parsed = JSON.parse(data)
// Fake result which passes back the input, formatted to match the expected
// schema, so we can validate it was passed in correctly
const result = {
docs: parsed.paths.map((path) => ({
figmaNode: path,
template: JSON.stringify({
config: parsed.config,
mode: parsed.mode,
}),
source: path,
templateData: { props: {} },
language: 'test',
label: 'Test',
})),
messages: [{ level: 'WARN', message: 'Warning from parser!' }],
}

process.stdout.write(JSON.stringify(result))
})
Loading

0 comments on commit 245eacf

Please sign in to comment.