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,31 @@
import {Options} from 'tsup';
import {writeFile, stat} from 'fs/promises';
import {bold, green} from 'colorette';
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[]
? ElementType
: never;
export type Plugin = ArrayElement<Required<Options>['plugins']>;
export type PluginContext = ThisParameterType<Required<Plugin>['buildEnd']>;
/**
* Utility function for generating files in a TSUp plugin
*/
export function generateFiles(
label: string,
build: (this: PluginContext) => Promise<Record<string, string | Buffer>>,
) {
return async function (this: PluginContext) {
this.logger.info(label, 'Build start');
const time = performance.now();
const result = await build.call(this);
this.logger.success(label, `⚡️ Build success in ${Math.floor(performance.now() - time)}ms`);
for (const file in result) {
const filePath = `${this.options.outDir}/${file}`;
await writeFile(filePath, result[file]);
const info = await stat(filePath);
this.logger.success(label, bold(filePath), green(`${(info.size / 1000).toFixed(2)} KB`));
}
};
}