Skip to content

Commit

Permalink
💚 Fix embeds build and create-block CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 19, 2024
1 parent 56a23a1 commit a4c865c
Show file tree
Hide file tree
Showing 35 changed files with 204 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/embeds/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@rollup/plugin-babel": "6.0.3",
"@rollup/plugin-node-resolve": "15.1.0",
"@rollup/plugin-terser": "0.4.3",
"@rollup/plugin-typescript": "11.1.2",
"@typebot.io/bot-engine": "workspace:*",
"@typebot.io/env": "workspace:*",
"@typebot.io/lib": "workspace:*",
Expand Down
2 changes: 2 additions & 0 deletions packages/embeds/js/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { babel } from '@rollup/plugin-babel'
import postcss from 'rollup-plugin-postcss'
import autoprefixer from 'autoprefixer'
import tailwindcss from 'tailwindcss'
import typescript from '@rollup/plugin-typescript'
import { typescriptPaths } from 'rollup-plugin-typescript-paths'
import fs from 'fs'

Expand All @@ -28,6 +29,7 @@ const indexConfig = {
extensions,
}),
typescriptPaths({ preserveExtensions: true }),
typescript(),
postcss({
plugins: [autoprefixer(), tailwindcss()],
extract: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"rollup-plugin-typescript-paths": "1.4.0",
"tslib": "2.6.0",
"tsx": "3.12.7",
"typescript": "5.3.2"
"typescript": "5.3.2",
"@rollup/plugin-typescript": "11.1.2"
},
"peerDependencies": {
"next": "12.x || 13.x || 14.x",
Expand Down
2 changes: 2 additions & 0 deletions packages/embeds/nextjs/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import { babel } from '@rollup/plugin-babel'
import { typescriptPaths } from 'rollup-plugin-typescript-paths'
import typescript from '@rollup/plugin-typescript'
import fs from 'fs'

const extensions = ['.ts', '.tsx']
Expand All @@ -26,6 +27,7 @@ const indexConfig = {
extensions,
}),
typescriptPaths({ preserveExtensions: true }),
typescript(),
terser({ format: { preamble } }),
],
}
Expand Down
3 changes: 2 additions & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"rollup-plugin-typescript-paths": "1.4.0",
"tslib": "2.6.0",
"tsx": "3.12.7",
"typescript": "5.3.2"
"typescript": "5.3.2",
"@rollup/plugin-typescript": "11.1.2"
},
"peerDependencies": {
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/embeds/react/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import { babel } from '@rollup/plugin-babel'
import { typescriptPaths } from 'rollup-plugin-typescript-paths'
import typescript from '@rollup/plugin-typescript'
import fs from 'fs'

const extensions = ['.ts', '.tsx']
Expand All @@ -26,6 +27,7 @@ const indexConfig = {
extensions,
}),
typescriptPaths({ preserveExtensions: true }),
typescript(),
terser({ format: { preamble } }),
],
}
Expand Down
2 changes: 1 addition & 1 deletion packages/forge/blocks/anthropic/logo.tsx
Original file line number Diff line number Diff line change
@@ -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}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/anthropic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/calCom/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */

export const CalComLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 31 31" {...props}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/calCom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/chatNode/logo.tsx
Original file line number Diff line number Diff line change
@@ -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}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/chatNode/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/difyAi/logo.tsx
Original file line number Diff line number Diff line change
@@ -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}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/difyAi/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/elevenlabs/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */

export const ElevenlabsLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 100 100" {...props}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/elevenlabs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/mistral/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */

export const MistralLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 256 233" {...props}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/mistral/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/openRouter/logo.tsx
Original file line number Diff line number Diff line change
@@ -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}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/openRouter/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/openai/logo.tsx
Original file line number Diff line number Diff line change
@@ -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}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/openai/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/qrcode/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */

export const QrCodeLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/qrcode/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/togetherAi/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */

export const TogetherAiLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 32 32" {...props}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/togetherAi/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/zemanticAi/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
/** @jsxImportSource react */

export const ZemanticAiLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 24 24" {...props}>
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/zemanticAi/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
"jsx": "react"
"jsx": "preserve",
"jsxImportSource": "react"
}
}
124 changes: 122 additions & 2 deletions packages/forge/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -186,7 +187,8 @@ const createTsConfig = async (path: string) => {
compilerOptions: {
lib: ['ESNext', 'DOM'],
noEmit: true,
jsx: 'react',
jsx: 'preserve',
jsxImportSource: 'react',
},
}),
{ parser: 'json', ...prettierRc }
Expand All @@ -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
Expand Down Expand Up @@ -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,
{
Expand All @@ -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) => {
Expand Down
Loading

0 comments on commit a4c865c

Please sign in to comment.