mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
feat: generator updates
This commit is contained in:
@@ -1,22 +1,17 @@
|
||||
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
|
||||
* @typedef {import('./types.js').PluginContext} PluginContext
|
||||
* @typedef {import('./types.js').Plugin} Plugin
|
||||
*
|
||||
* @param label {string}
|
||||
* @param build {(this: PluginContext) => Promise<Record<string, string | Buffer>>}
|
||||
* @returns {(this: PluginContext) => Promise<void>}
|
||||
*/
|
||||
export function generateFiles(
|
||||
label: string,
|
||||
build: (this: PluginContext) => Promise<Record<string, string | Buffer>>,
|
||||
) {
|
||||
return async function (this: PluginContext) {
|
||||
export function generateFiles(label, build) {
|
||||
return async function () {
|
||||
this.logger.info(label, 'Build start');
|
||||
const time = performance.now();
|
||||
const result = await build.call(this);
|
||||
10
packages/tsup-plugin/src/types.d.ts
vendored
Normal file
10
packages/tsup-plugin/src/types.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import {Options} from 'tsup';
|
||||
|
||||
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']>;
|
||||
|
||||
export {generateFiles} from './index.js';
|
||||
Reference in New Issue
Block a user