2
0

♻️ Include forged blocks schema in typebot schema

Closes #1364
This commit is contained in:
Baptiste Arnaud
2024-03-18 16:09:19 +01:00
parent 26a9282c20
commit ed5096e2b6
93 changed files with 8599 additions and 4965 deletions

View File

@ -83,7 +83,7 @@ const main = async () => {
await createIndexFile(newBlockPath, prompt)
await createLogoFile(newBlockPath, prompt)
if (prompt.auth !== 'none') await createAuthFile(newBlockPath, prompt)
await addNewIntegrationToRepository(prompt)
await createSchemasFile(newBlockPath, prompt)
s.stop('Creating files...')
s.start('Installing dependencies...')
await new Promise<void>((resolve, reject) => {
@ -138,7 +138,7 @@ const createIndexFile = async (
import { ${capitalize(camelCaseId)}Logo } from './logo'
${auth !== 'none' ? `import { auth } from './auth'` : ''}
export const ${camelCaseName} = createBlock({
export const ${camelCaseName}Block = createBlock({
id: '${id}',
name: '${name}',
tags: [],
@ -175,51 +175,6 @@ const createPackageJson = async (path: string, { id }: { id: unknown }) => {
)
}
const addNewIntegrationToRepository = async ({
camelCaseId,
id,
}: {
camelCaseId: string
id: string
}) => {
const schemasPath = join(process.cwd(), `../schemas`)
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,
})
)
const repoIndexFile = readFileSync(join(schemasPath, 'index.ts')).toString()
writeFileSync(
join(schemasPath, 'index.ts'),
await prettier.format(
repoIndexFile
.replace(
'] as BlockDefinition<(typeof enabledBlocks)[number], any, any>[]',
`${camelCaseId},] as BlockDefinition<(typeof enabledBlocks)[number], any, any>[]`
)
.replace(
'// Do not edit this file manually',
`// Do not edit this file manually\nimport {${camelCaseId}} from '@typebot.io/${id}-block'`
),
{ parser: 'typescript', ...prettierRc }
)
)
const repoPath = join(process.cwd(), `../repository`)
const enabledIndexFile = readFileSync(join(repoPath, 'index.ts')).toString()
writeFileSync(
join(repoPath, 'index.ts'),
await prettier.format(
enabledIndexFile.replace('] as const', `'${id}'] as const`),
{ parser: 'typescript', ...prettierRc }
)
)
}
const createTsConfig = async (path: string) => {
writeFileSync(
join(path, 'tsconfig.json'),
@ -289,6 +244,27 @@ const createAuthFile = async (
)
)
const createSchemasFile = async (
path: string,
{
id,
}: { id: string; name: string; auth: 'apiKey' | 'encryptedData' | 'none' }
) => {
const camelCaseName = camelize(id as string)
writeFileSync(
join(path, 'schemas.ts'),
await prettier.format(
`// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { ${camelCaseName}Block } from '.'
export const ${camelCaseName}BlockSchema = parseBlockSchema(${camelCaseName}Block)
export const ${camelCaseName}CredentialsSchema = parseBlockCredentials(${camelCaseName}Block)`,
{ parser: 'typescript', ...prettierRc }
)
)
}
main()
.then()
.catch((err) => {