UNPKG

@dovenv/workspace

Version:

A dovenv plugin with utilities for the workspace

238 lines (224 loc) 6.5 kB
import * as _dovenv_core from '@dovenv/core'; import { CommandUtils } from '@dovenv/core'; import { setDirTree, Prettify, PackageJSON, Validate, ValidateAnyType, catchError } from '@dovenv/core/utils'; type CheckOpts = { /** * Directory to check. */ dir: string; /** * Path to package.json. */ path: string; /** * Object data from package.json. */ content: PackageJSON; /** Dovenv configuration */ utils: CommandUtils; }; type PatternCheck = string[] | ((opts: CheckOpts) => Promise<string[] | undefined> | (string[] | undefined)); type Sharedcheck = { desc?: string; /** * Files that must exist. */ include?: PatternCheck; /** * Files that must not exist. */ exclude?: PatternCheck; /** * Custom check function. */ custom?: (opts: CheckOpts) => Promise<void>; }; type Config = { /** * Information for the workspace. */ info?: { /** * Instructions for the workspace. * Must be markdown format. * Accepts string, URL or path. * * @example * ```markdown * ## Pre-requisites * project needs the following tools to work: * - `node` > 20 installed * - `pnpm` > 9 installed * - `gh` > 2 installed * - `git` > 2 installed * ## Init workspace * pnpm install * ``` */ instructions?: string; /** * Add more commands to the list of useful commands. * * @example * usefullCmds : [ * { * desc : 'Checks for outdated packages.', * cmd : 'pnpm -r outdated', * }, * ] */ usefulCmds?: { desc: string; cmd: string; /** * URL to more info. */ info?: string; }[]; /** * Structure of the workspace. */ structure?: Parameters<typeof setDirTree>[0]['structure']; }; check?: { /** * Checks for workspace package(s). */ pkg?: Record<string, Prettify<Sharedcheck & { /** * Schema for own package.json. * * @example * const schema = ({v, path, data}) => { * if(data.private) return * return v.object({ * name: v.string(), * version: v.string(), * description: v.string(), * }) * } */ schema?: (opts: { /** * Validation (Zod wrapper). */ v: Validate; /** * Path to package.json. */ path: string; /** * Object data from package.json. */ content: PackageJSON; /** Dovenv utilities */ utils: CommandUtils; }) => Promise<ValidateAnyType | void> | (ValidateAnyType | void); }>>; }; /** List of commands for run */ /** Reinstall the workspace options */ reinstall?: { hook?: { /** Hook before reinstallation */ before?: () => Promise<void>; /** Hook after reinstallation */ after?: () => Promise<void>; }; }; /** Custom configration for ws */ custom?: NonNullable<CommandUtils['config']>['custom']; }; declare class Super { opts: Config | undefined; protected utils: CommandUtils; protected _themeInfo: string; constructor(opts: Config | undefined, utils: CommandUtils); protected _title(title: string): void; protected _sectionTitle(title: string): void; _envolvefn(fn: Parameters<typeof catchError>[0]): Promise<unknown>; } type InfoInterface = { get: () => Promise<unknown>; run: () => Promise<void | unknown>; }; declare class UsefulCmds extends Super implements InfoInterface { #private; get(): Promise<string | undefined>; run(): Promise<unknown>; } declare class Donate extends Super implements InfoInterface { #private; get(): Promise<string | undefined>; run(open?: boolean): Promise<unknown>; } declare class Instructions extends Super implements InfoInterface { #private; get(): Promise<string | undefined>; run(): Promise<unknown>; } declare class Scripts extends Super implements InfoInterface { #private; get(key?: string[]): Promise<string | undefined>; run(key?: string[]): Promise<void>; } declare class Size extends Super implements InfoInterface { #private; get(): Promise<{ files: number; chars: number; words: number; } | undefined>; run(): Promise<unknown>; } declare class Structure extends Super implements InfoInterface { #private; get(): Promise<string | undefined>; run(): Promise<unknown>; } declare class Info extends Super { #private; size: Size; instructions: Instructions; donate: Donate; usefulCmds: UsefulCmds; structure: Structure; scripts: Scripts; constructor(opts: Config | undefined, utils: CommandUtils); run(): Promise<void>; } declare class Workspace { #private; opts: Config | undefined; protected utils: CommandUtils; constructor({ opts, utils, }: { opts?: Config; utils: CommandUtils; }); getPkgPaths(): Promise<any>; audit(fix?: boolean): Promise<void>; outdated(): Promise<void>; reinstall(): Promise<void>; check(): Promise<void>; scripts(opts?: Parameters<Info['scripts']['run']>[0]): Promise<void>; usefulCmds(): Promise<void>; instructions(): Promise<void>; donate(open?: boolean): Promise<void>; size(): Promise<void>; info(): Promise<void>; structure(): Promise<void>; } /** * Workspace plugin for Dovenv. * * @param {Config} [params] - Plugin config. * @returns {import('@dovenv/core').Config} - A config with commands for workspace. * @example * import { defineConfig } from '@dovenv/core' * import { workspacePlugin } from '@dovenv/workspace' * * export default defineConfig( workspacePlugin() ) */ declare const workspacePlugin: (params?: Config) => _dovenv_core.Config; export { Workspace, workspacePlugin as default, workspacePlugin }; export type { Config };