Skip to content

Commit 8e0d532

Browse files
committed
WIP: codegen plugin scaffolding
1 parent 7125a02 commit 8e0d532

File tree

11 files changed

+767
-10281
lines changed

11 files changed

+767
-10281
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ web_modules/
8989
.yarn-integrity
9090

9191
# dotenv environment variables file
92-
.env
93-
.env.*.local
92+
.env.*
93+
!.env.example
94+
9495
# parcel-bundler cache (https://parceljs.org/)
9596
.cache
9697
.parcel-cache

codegen/plugin/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
gecko_generated
3+
node_modules

codegen/plugin/gecko.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/** @jsx geckoJSX */
2+
/** @jsxFrag geckoJSX */
3+
4+
import { FileFormatter, Folder, Root, geckoJSX } from '@flatfile/gecko'
5+
import prompts from 'prompts'
6+
import { ChangelogFile } from './templates/Changelog'
7+
import { IndexFile } from './templates/IndexFile'
8+
import { PackageJsonFile } from './templates/PackageJson'
9+
import { ReadmeFile } from './templates/Readme'
10+
11+
export default async function () {
12+
const response = await prompts([
13+
{
14+
type: 'text',
15+
name: 'name',
16+
message: 'Name?',
17+
format: (value: string) => value.trim(),
18+
validate: (value: string) =>
19+
value.trim() === '' ? 'A name must be provided' : true,
20+
},
21+
{
22+
type: 'text',
23+
name: 'description',
24+
message: 'Description',
25+
format: (value: string) => (value ? value.trim() : ''),
26+
},
27+
{
28+
type: 'select',
29+
name: 'category',
30+
message: 'Category',
31+
choices: [
32+
{ title: 'Export', value: 'plugin' },
33+
{ title: 'Transform', value: 'transform' },
34+
{ title: 'Automation', value: 'automation' },
35+
{ title: 'Records', value: 'records' },
36+
{ title: 'Extractors', value: 'extractors' },
37+
{ title: 'Utilities', value: 'utilities' },
38+
{ title: 'Core', value: 'core' },
39+
{
40+
title: 'Schema Converters',
41+
value: 'schema-converters',
42+
},
43+
{ title: 'Connect', value: 'connect' },
44+
{ title: 'Egress', value: 'egress' },
45+
],
46+
},
47+
{
48+
type: 'text',
49+
name: 'job',
50+
message: 'Job',
51+
format: (value: string) => value.trim(),
52+
validate: (value: string) =>
53+
value.trim() === '' ? 'A job must be provided' : true,
54+
},
55+
{
56+
type: 'text',
57+
name: 'author',
58+
message: 'Author',
59+
format: (value: string) => (value ? value.trim() : ''),
60+
},
61+
])
62+
63+
console.log(response)
64+
65+
return (
66+
<Root path={`../../plugins/${response.name}`} erase>
67+
<FileFormatter formatter='prettier' match='*.{js,ts,yaml}'>
68+
<Folder name='src'>
69+
<IndexFile job={response.job} />
70+
</Folder>
71+
<PackageJsonFile
72+
pluginName={response.name}
73+
description={response.description}
74+
category={response.category}
75+
author={response.author}
76+
/>
77+
<ReadmeFile pluginName={response.name} />
78+
<ChangelogFile pluginName={response.name} />
79+
</FileFormatter>
80+
</Root>
81+
)
82+
}

codegen/plugin/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@flatfile/gecko-codegen-plugins",
3+
"private": true,
4+
"scripts": {
5+
"format": "npx prettier -w **/*.{js,json,ts,tsx,yaml}",
6+
"gecko": "gecko \"$@\""
7+
},
8+
"dependencies": {
9+
"@flatfile/gecko": "latest",
10+
"tsconfig-paths": "^4.2.0",
11+
"tsx": "^4.10.2",
12+
"prompts": "^2.4.2"
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @jsx geckoJSX */
2+
/** @jsxFrag geckoJSX */
3+
4+
import { File, Text, geckoJSX } from '@flatfile/gecko'
5+
6+
export function ChangelogFile(props: {
7+
pluginName: string
8+
}) {
9+
return (
10+
<File name="CHANGELOG.md">
11+
<Text>
12+
{`# @flatfile/plugin-${props.pluginName}`}
13+
</Text>
14+
</File>
15+
)
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** @jsx geckoJSX */
2+
/** @jsxFrag geckoJSX */
3+
4+
import { File, Text, geckoJSX } from '@flatfile/gecko'
5+
6+
export function IndexFile(props: { job: string }) {
7+
return (
8+
<File name="index.ts">
9+
<Text>{`import type { Flatfile } from '@flatfile/api'`}</Text>
10+
<Text>{`import type { FlatfileEvent } from '@flatfile/listener'`}</Text>
11+
<Text />
12+
<Text>{`import { FlatfileClient } from '@flatfile/api'`}</Text>
13+
<Text>{`import { jobHandler } from '@flatfile/plugin-job-handler'`}</Text>
14+
<Text />
15+
<Text>const api = new FlatfileClient()</Text>
16+
<Text />
17+
<Text>
18+
{`export default jobHandler(
19+
'${props.job}',
20+
async (
21+
event: FlatfileEvent,
22+
tick: (
23+
progress: number,
24+
message?: string
25+
) => Promise<Flatfile.JobResponse>
26+
) => {
27+
}
28+
)`}
29+
</Text>
30+
<Text />
31+
</File>
32+
)
33+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/** @jsx geckoJSX */
2+
/** @jsxFrag geckoJSX */
3+
4+
import { File, Text, geckoJSX } from '@flatfile/gecko'
5+
6+
export function PackageJsonFile(props: {
7+
pluginName: string
8+
description?: string
9+
category: string
10+
author?: string
11+
}) {
12+
return (
13+
<File name="package.json">
14+
<Text>
15+
{`{
16+
"name": "@flatfile/plugin-${props.pluginName}",
17+
"version": "0.0.0",
18+
"url": "https://github.com/FlatFilers/flatfile-plugins/tree/main/plugins/${props.pluginName}",
19+
"description": "${props.description}",
20+
"registryMetadata": {
21+
"category": "${props.category}"
22+
},
23+
"engines": {
24+
"node": ">= 16"
25+
},
26+
"source": "src/index.ts",
27+
"main": "dist/main.js",
28+
"module": "dist/module.mjs",
29+
"types": "dist/types.d.ts",
30+
"scripts": {
31+
"build": "parcel build",
32+
"build:watch": "parcel watch",
33+
"build:prod": "NODE_ENV=production parcel build",
34+
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
35+
"test": "jest --passWithNoTests"
36+
},
37+
"keywords": [
38+
"flatfile-plugins",
39+
"category-${props.category}"
40+
],
41+
"author": "${props.author}",
42+
"repository": {
43+
"type": "git",
44+
"url": "https://github.com/FlatFilers/flatfile-plugins.git",
45+
"directory": "plugins/${props.pluginName}"
46+
},
47+
"license": "ISC",
48+
"dependencies": {
49+
},
50+
"peerDependencies": {
51+
"@flatfile/api": "^1.8.0",
52+
"@flatfile/listener": "^1.0.1"
53+
}
54+
}
55+
`}
56+
</Text>
57+
</File>
58+
)
59+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @jsx geckoJSX */
2+
/** @jsxFrag geckoJSX */
3+
4+
import { File, Text, geckoJSX } from '@flatfile/gecko'
5+
6+
export function ReadmeFile(props: { pluginName: string }) {
7+
return (
8+
<File name="README.md">
9+
<Text>
10+
{`# @flatfile/plugin-${props.pluginName}`}
11+
</Text>
12+
</File>
13+
)
14+
}

codegen/plugin/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"jsx": "react",
5+
"jsxFactory": "geckoJSX",
6+
"jsxFragmentFactory": "geckoJSX"
7+
}
8+
}

0 commit comments

Comments
 (0)