feat: improve monorepo dev experience

This commit is contained in:
2023-10-27 22:45:44 +02:00
parent f618725598
commit c6ab4ae48b
124 changed files with 2647 additions and 2857 deletions

View File

@@ -0,0 +1,37 @@
import {compileSchema} from './generator/compile-schema.js';
import {generateFiles, Plugin, PluginContext} from '@openstapps/tsup-plugin';
export type SchemaConsumer = (
this: PluginContext,
schema: ReturnType<typeof compileSchema>,
) => Record<string, string | Buffer>;
/**
* TSUp plugin for generating JSONSchema files
* @param schemaName the name of the generated schema
* @param schemaConsumers any consumers that can directly use the schema
*/
export function jsonSchemaPlugin(
schemaName: string,
...schemaConsumers: Array<[string, SchemaConsumer]>
): Plugin {
return {
name: 'json-schema-generator',
async buildEnd() {
let schema: ReturnType<typeof compileSchema>;
await generateFiles('JSON-Schema', async function () {
schema = compileSchema((this.options.entry as string[])[0], this.options.tsconfig!);
return {
[schemaName]: JSON.stringify(schema),
};
}).call(this);
for (const [name, consumer] of schemaConsumers) {
await generateFiles(name, async function () {
return consumer.call(this, schema);
}).call(this);
}
},
};
}