2
0

💚 Fix embeds build and create-block CLI

This commit is contained in:
Baptiste Arnaud
2024-03-19 10:38:55 +01:00
parent 56a23a14b6
commit a4c865ca26
35 changed files with 204 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const AnthropicLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 16 16" fill="currentColor" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const CalComLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 31 31" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const ChatNodeLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 25 25" xmlns="http://www.w3.org/2000/svg" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const DifyAiLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 25 25" xmlns="http://www.w3.org/2000/svg" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const ElevenlabsLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 100 100" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const MistralLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 256 233" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const OpenRouterLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 512 512" fill="#71717A" stroke="#71717A" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const OpenAILightLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 24 24" fill="#000100" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const QrCodeLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const TogetherAiLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 32 32" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */
export const ZemanticAiLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 24 24" {...props}>

View File

@@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}

View File

@@ -84,6 +84,7 @@ const main = async () => {
await createLogoFile(newBlockPath, prompt)
if (prompt.auth !== 'none') await createAuthFile(newBlockPath, prompt)
await createSchemasFile(newBlockPath, prompt)
await addBlockToRepository(prompt)
s.stop('Creating files...')
s.start('Installing dependencies...')
await new Promise<void>((resolve, reject) => {
@@ -186,7 +187,8 @@ const createTsConfig = async (path: string) => {
compilerOptions: {
lib: ['ESNext', 'DOM'],
noEmit: true,
jsx: 'react',
jsx: 'preserve',
jsxImportSource: 'react',
},
}),
{ parser: 'json', ...prettierRc }
@@ -201,7 +203,7 @@ const createLogoFile = async (
writeFileSync(
join(path, 'logo.tsx'),
await prettier.format(
`import React from 'react'
`/** @jsxImportSource react */
export const ${capitalize(
camelCaseId
@@ -244,6 +246,19 @@ const createAuthFile = async (
)
)
const addBlockToRepository = async ({
camelCaseId,
id,
}: {
camelCaseId: string
id: string
}) => {
const schemasPath = await addBlockToRepoPackageJson(id)
await addBlockToRepoDefinitions(schemasPath, camelCaseId, id)
await addBlockToRepoConstants(schemasPath, id)
await addBlockToRepoSchemas(schemasPath, camelCaseId, id)
}
const createSchemasFile = async (
path: string,
{
@@ -265,6 +280,111 @@ export const ${camelCaseName}CredentialsSchema = parseBlockCredentials(${camelCa
)
}
async function addBlockToRepoDefinitions(
schemasPath: string,
camelCaseId: string,
id: string
) {
const existingDefinitionsData = readFileSync(
join(schemasPath, 'definitions.ts')
).toString()
const importStatement = `import { ${camelCaseId}Block } from '@typebot.io/${id}-block'`
const objectEntry = ` [${camelCaseId}Block.id]: ${camelCaseId}Block,`
const nextLineImportIndex = existingDefinitionsData.indexOf(
'\n',
existingDefinitionsData.lastIndexOf('import')
)
const newObjectEntryIndex = existingDefinitionsData.lastIndexOf(',') + 1
const newDefinitionsData = `${existingDefinitionsData.slice(
0,
nextLineImportIndex
)}
${importStatement}
${existingDefinitionsData.slice(nextLineImportIndex, newObjectEntryIndex)}
${objectEntry}
${existingDefinitionsData.slice(newObjectEntryIndex)}`
writeFileSync(
join(schemasPath, 'definitions.ts'),
await prettier.format(newDefinitionsData, {
parser: 'typescript',
...prettierRc,
})
)
}
async function addBlockToRepoSchemas(
schemasPath: string,
camelCaseId: string,
id: string
) {
const existingDefinitionsData = readFileSync(
join(schemasPath, 'schemas.ts')
).toString()
const importStatement = `import { ${camelCaseId}Block } from '@typebot.io/${id}-block'
import { ${camelCaseId}BlockSchema } from '@typebot.io/${id}-block/schemas'`
const objectEntry = ` [${camelCaseId}Block.id]: ${camelCaseId}BlockSchema,`
const nextLineImportIndex = existingDefinitionsData.indexOf(
'\n',
existingDefinitionsData.lastIndexOf('import')
)
const newObjectEntryIndex = existingDefinitionsData.lastIndexOf(',') + 1
const newDefinitionsData = `${existingDefinitionsData.slice(
0,
nextLineImportIndex
)}
${importStatement}
${existingDefinitionsData.slice(nextLineImportIndex, newObjectEntryIndex)}
${objectEntry}
${existingDefinitionsData.slice(newObjectEntryIndex)}`
writeFileSync(
join(schemasPath, 'schemas.ts'),
await prettier.format(newDefinitionsData, {
parser: 'typescript',
...prettierRc,
})
)
}
async function addBlockToRepoConstants(schemasPath: string, id: string) {
const existingDefinitionsData = readFileSync(
join(schemasPath, 'constants.ts')
).toString()
writeFileSync(
join(schemasPath, 'constants.ts'),
await prettier.format(
existingDefinitionsData.replace(
`] as const satisfies ForgedBlock['type'][]`,
`'${id}'] as const satisfies ForgedBlock['type'][]`
),
{
parser: 'typescript',
...prettierRc,
}
)
)
}
async function addBlockToRepoPackageJson(id: string) {
const schemasPath = join(process.cwd(), `../repository`)
const packageJson = require(join(schemasPath, 'package.json'))
packageJson.devDependencies[`@typebot.io/${id}-block`] = 'workspace:*'
writeFileSync(
join(schemasPath, 'package.json'),
await prettier.format(JSON.stringify(packageJson, null, 2), {
parser: 'json',
...prettierRc,
})
)
return schemasPath
}
main()
.then()
.catch((err) => {

View File

@@ -1,3 +1,4 @@
// Do not edit this file manually
import { ForgedBlock } from './types'
export const forgedBlockIds = [

View File

@@ -23,4 +23,4 @@ export const forgedBlocks = {
[anthropicBlock.id]: anthropicBlock,
[togetherAiBlock.id]: togetherAiBlock,
[openRouterBlock.id]: openRouterBlock,
} as const
}

View File

@@ -1,3 +1,4 @@
// Do not edit this file manually
import { anthropicBlock } from '@typebot.io/anthropic-block'
import { anthropicBlockSchema } from '@typebot.io/anthropic-block/schemas'
import { calComBlock } from '@typebot.io/cal-com-block'