Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ web_modules/
.yarn-integrity

# dotenv environment variables file
.env
.env.*.local
.env.*
!.env.example

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
Expand Down
82 changes: 82 additions & 0 deletions codegen/plugin/gecko.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/** @jsx geckoJSX */
/** @jsxFrag geckoJSX */

import { FileFormatter, Folder, Root, geckoJSX } from '@flatfile/gecko'
import prompts from 'prompts'
import { ChangelogFile } from './templates/Changelog'
import { IndexFile } from './templates/IndexFile'
import { PackageJsonFile } from './templates/PackageJson'
import { ReadmeFile } from './templates/Readme'

export default async function () {
const response = await prompts([
{
type: 'text',
name: 'name',
message: 'Name?',
format: (value: string) => value.trim(),
validate: (value: string) =>
value.trim() === '' ? 'A name must be provided' : true,
},
{
type: 'text',
name: 'description',
message: 'Description',
format: (value: string) => (value ? value.trim() : ''),
},
{
type: 'select',
name: 'category',
message: 'Category',
choices: [
{ title: 'Export', value: 'plugin' },
{ title: 'Transform', value: 'transform' },
{ title: 'Automation', value: 'automation' },
{ title: 'Records', value: 'records' },
{ title: 'Extractors', value: 'extractors' },
{ title: 'Utilities', value: 'utilities' },
{ title: 'Core', value: 'core' },
{
title: 'Schema Converters',
value: 'schema-converters',
},
{ title: 'Connect', value: 'connect' },
{ title: 'Egress', value: 'egress' },
],
},
{
type: 'text',
name: 'job',
message: 'Job',
format: (value: string) => value.trim(),
validate: (value: string) =>
value.trim() === '' ? 'A job must be provided' : true,
},
{
type: 'text',
name: 'author',
message: 'Author',
format: (value: string) => (value ? value.trim() : ''),
},
])

console.log(response)

return (
<Root path={`../../plugins/${response.name}`} erase>
<FileFormatter formatter='prettier' match='*.{js,ts,yaml}'>
<Folder name='src'>
<IndexFile job={response.job} />
</Folder>
<PackageJsonFile
pluginName={response.name}
description={response.description}
category={response.category}
author={response.author}
/>
<ReadmeFile pluginName={response.name} />
<ChangelogFile pluginName={response.name} />
</FileFormatter>
</Root>
)
}
14 changes: 14 additions & 0 deletions codegen/plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@flatfile/gecko-codegen-plugins",
"private": true,
"scripts": {
"format": "npx prettier -w **/*.{js,json,ts,tsx,yaml}",
"gecko": "gecko \"$@\""
},
"dependencies": {
"@flatfile/gecko": "latest",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.10.2",
"prompts": "^2.4.2"
}
}
16 changes: 16 additions & 0 deletions codegen/plugin/templates/Changelog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @jsx geckoJSX */
/** @jsxFrag geckoJSX */

import { File, Text, geckoJSX } from '@flatfile/gecko'

export function ChangelogFile(props: {
pluginName: string
}) {
return (
<File name="CHANGELOG.md">
<Text>
{`# @flatfile/plugin-${props.pluginName}`}
</Text>
</File>
)
}
33 changes: 33 additions & 0 deletions codegen/plugin/templates/IndexFile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @jsx geckoJSX */
/** @jsxFrag geckoJSX */

import { File, Text, geckoJSX } from '@flatfile/gecko'

export function IndexFile(props: { job: string }) {
return (
<File name="index.ts">
<Text>{`import type { Flatfile } from '@flatfile/api'`}</Text>
<Text>{`import type { FlatfileEvent } from '@flatfile/listener'`}</Text>
<Text />
<Text>{`import { FlatfileClient } from '@flatfile/api'`}</Text>
<Text>{`import { jobHandler } from '@flatfile/plugin-job-handler'`}</Text>
<Text />
<Text>const api = new FlatfileClient()</Text>
<Text />
<Text>
{`export default jobHandler(
'${props.job}',
async (
event: FlatfileEvent,
tick: (
progress: number,
message?: string
) => Promise<Flatfile.JobResponse>
) => {
}
)`}
</Text>
<Text />
</File>
)
}
59 changes: 59 additions & 0 deletions codegen/plugin/templates/PackageJson.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/** @jsx geckoJSX */
/** @jsxFrag geckoJSX */

import { File, Text, geckoJSX } from '@flatfile/gecko'

export function PackageJsonFile(props: {
pluginName: string
description?: string
category: string
author?: string
}) {
return (
<File name="package.json">
<Text>
{`{
"name": "@flatfile/plugin-${props.pluginName}",
"version": "0.0.0",
"url": "https://github.com/FlatFilers/flatfile-plugins/tree/main/plugins/${props.pluginName}",
"description": "${props.description}",
"registryMetadata": {
"category": "${props.category}"
},
"engines": {
"node": ">= 16"
},
"source": "src/index.ts",
"main": "dist/main.js",
"module": "dist/module.mjs",
"types": "dist/types.d.ts",
"scripts": {
"build": "parcel build",
"build:watch": "parcel watch",
"build:prod": "NODE_ENV=production parcel build",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest --passWithNoTests"
},
"keywords": [
"flatfile-plugins",
"category-${props.category}"
],
"author": "${props.author}",
"repository": {
"type": "git",
"url": "https://github.com/FlatFilers/flatfile-plugins.git",
"directory": "plugins/${props.pluginName}"
},
"license": "ISC",
"dependencies": {
},
"peerDependencies": {
"@flatfile/api": "^1.8.0",
"@flatfile/listener": "^1.0.1"
}
}
`}
</Text>
</File>
)
}
14 changes: 14 additions & 0 deletions codegen/plugin/templates/Readme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @jsx geckoJSX */
/** @jsxFrag geckoJSX */

import { File, Text, geckoJSX } from '@flatfile/gecko'

export function ReadmeFile(props: { pluginName: string }) {
return (
<File name="README.md">
<Text>
{`# @flatfile/plugin-${props.pluginName}`}
</Text>
</File>
)
}
8 changes: 8 additions & 0 deletions codegen/plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"jsx": "react",
"jsxFactory": "geckoJSX",
"jsxFragmentFactory": "geckoJSX"
}
}
Loading