@@ -14,35 +14,43 @@ const targetDir = path.join(thisSourceFileDir, "importers", "generated");
1414const generateTypes = async ( ) => {
1515 const allPlugins = await fetchSchemas ( ) ;
1616
17- // Store list of used interface names to ensure global uniqueness so that we
17+ // Store set of used interface names to ensure global uniqueness so that we
1818 // can export * from generated files. However, note this may not work because
1919 // the intermediate types are also exported, and those will have collisions
2020 const usedInterfaceNames = new Set < string > ( ) ;
2121
22+ // Set of plugin class names (same comment as above applies, i.e. uniqueness is expected anyway)
23+ const usedPluginClassNames = new Set < string > ( ) ;
24+
2225 for ( let plugin of allPlugins . externalPlugins ) {
2326 log ( "generateTypes:" , plugin . pluginName ) ;
2427 let pluginTargetDir = path . join ( targetDir , plugin . pluginName ) ;
2528
2629 log ( "mkdir:" , fdir ( pluginTargetDir ) ) ;
2730 await mkdir ( pluginTargetDir , { recursive : true } ) ;
2831
29- let schemas = [
32+ let schemas : [ schema : any , schemaName : string , interfaceName : string ] [ ] = [
3033 [ plugin . credentialsSchema , "CredentialsSchema" ] ,
3134 [ plugin . paramsSchema , "ParamsSchema" ] ,
3235 [ plugin . tableParamsSchema , "TableParamsSchema" ] ,
33- ] ;
34-
35- for ( let [ schema , schemaName ] of schemas ) {
36+ ] . map ( ( [ schema , schemaName ] ) => [
37+ schema ,
38+ schemaName ,
39+ ( ( ) => {
40+ // Generate a name that's safe for interface type name and hasn't been used yet
41+ // We don't expect collisions, since pluginName is unique, but just in case
42+ const interfaceName = generateName (
43+ plugin . pluginName + schemaName ,
44+ usedInterfaceNames
45+ ) ;
46+ usedInterfaceNames . add ( interfaceName ) ;
47+
48+ return interfaceName ;
49+ } ) ( ) ,
50+ ] ) ;
51+
52+ for ( let [ schema , schemaName , interfaceName ] of schemas ) {
3653 let schemaOutFile = path . join ( pluginTargetDir , `${ schemaName } .ts` ) ;
37-
38- // Generate a name that's safe for interface type name and hasn't been used yet
39- // We don't expect collisions, since pluginName is unique, but just in case
40- let interfaceName = generateName (
41- plugin . pluginName + schemaName ,
42- usedInterfaceNames
43- ) ;
44- usedInterfaceNames . add ( interfaceName ) ;
45-
4654 log ( "interfaceName:" , interfaceName ) ;
4755
4856 let generatedTypescript = await compile ( schema , interfaceName , {
@@ -52,6 +60,40 @@ const generateTypes = async () => {
5260 log ( "write schema:" , fdir ( schemaOutFile ) ) ;
5361 await writeFile ( schemaOutFile , generatedTypescript ) ;
5462 }
63+
64+ const [
65+ [ _cs , _csn , credentialsSchemaInterfaceName ] ,
66+ [ _ps , _psn , paramsSchemaInterfaceName ] ,
67+ [ _tps , _tpsn , tableParamsSchemaInterfaceName ] ,
68+ ] = schemas ;
69+
70+ // NOTE: Concatenate "Splitgraph" outside of generated name to ensure PascalCasing
71+ // (otherwise we get "SplitgraphairbyteGitHubImportPlugin" instead of "SplitgraphAirbyteGitHubImportPlugin")
72+ let pluginClassName =
73+ "Splitgraph" +
74+ generateName ( plugin . pluginName + "ImportPlugin" , usedPluginClassNames ) ;
75+ let pluginOutFile = path . join ( pluginTargetDir , "plugin.ts" ) ;
76+
77+ log ( "create plugin: " , pluginClassName , "in" , pluginOutFile ) ;
78+
79+ await writeFile (
80+ pluginOutFile ,
81+ `/** Auto-generated plugin **/
82+
83+ import type { ${ paramsSchemaInterfaceName } } from "./ParamsSchema";
84+ import type { ${ tableParamsSchemaInterfaceName } } from "./TableParamsSchema";
85+ import type { ${ credentialsSchemaInterfaceName } } from "./CredentialsSchema";
86+ import { makeGeneratedImportPlugin } from "../../splitgraph-generated-import-plugin";
87+
88+ export const ${ pluginClassName } = makeGeneratedImportPlugin<
89+ "${ plugin . pluginName } ",
90+ ${ paramsSchemaInterfaceName } ,
91+ ${ tableParamsSchemaInterfaceName } ,
92+ ${ credentialsSchemaInterfaceName }
93+ >("${ plugin . pluginName } ");
94+
95+ `
96+ ) ;
5597 }
5698} ;
5799
0 commit comments