@decaf-ts/utils
Version:
module management utils for decaf-ts
133 lines (132 loc) • 5.4 kB
TypeScript
import { Command } from "../command";
import { CommandOptions } from "../types";
import { DefaultCommandValues } from "../constants";
import { LoggingConfig } from "@decaf-ts/logging";
declare module "@rollup/plugin-terser";
export declare function parseList(input?: string | string[]): string[];
export declare function packageToGlobal(name: string): string;
export declare function getPackageDependencies(): string[];
declare enum Modes {
CJS = "commonjs",
ESM = "es2022"
}
declare enum BuildMode {
BUILD = "build",
BUNDLE = "bundle",
ALL = "all"
}
declare const options: {
prod: {
type: string;
default: boolean;
};
dev: {
type: string;
default: boolean;
};
buildMode: {
type: string;
default: BuildMode;
};
includes: {
type: string;
default: string;
};
externals: {
type: string;
default: string;
};
docs: {
type: string;
default: boolean;
};
commands: {
type: string;
default: boolean;
};
banner: {
type: string;
default: boolean;
};
};
/**
* @description A command-line script for building and bundling TypeScript projects.
* @summary This class provides a comprehensive build script that handles TypeScript compilation,
* bundling with Rollup, and documentation generation. It supports different build modes
* (development, production), module formats (CJS, ESM), and can be extended with custom
* configurations.
* @class BuildScripts
*/
export declare class BuildScripts extends Command<CommandOptions<typeof options>, void> {
private replacements;
private readonly pkgVersion;
private readonly pkgName;
constructor();
/**
* @description Patches files with version and package name.
* @summary This method reads all files in a directory, finds placeholders for version
* and package name, and replaces them with the actual values from package.json.
* @param {string} p - The path to the directory containing the files to patch.
*/
patchFiles(p: string): void;
private reportDiagnostics;
private formatDiagnostics;
private readConfigFile;
private evalDiagnostics;
private preCheckDiagnostics;
private checkTsDiagnostics;
private buildTs;
private build;
/**
* @description Copies assets to the build output directory.
* @summary This method checks for the existence of an 'assets' directory in the source
* and copies it to the appropriate build output directory (lib or dist).
* @param {Modes} mode - The build mode (CJS or ESM).
*/
copyAssets(mode: Modes): void;
/**
* @description Bundles the project using Rollup.
* @summary This method configures and runs Rollup to bundle the project. It handles
* different module formats, development and production builds, and external dependencies.
* @param {Modes} mode - The module format (CJS or ESM).
* @param {boolean} isDev - Whether it's a development build.
* @param {boolean} isLib - Whether it's a library build.
* @param {string} [entryFile="src/index.ts"] - The entry file for the bundle.
* @param {string} [nameOverride=this.pkgName] - The name of the output bundle.
* @param {string|string[]} [externalsArg] - A list of external dependencies.
* @param {string|string[]} [includeArg] - A list of dependencies to include.
* @returns {Promise<void>}
*/
bundle(mode: Modes, isDev: boolean, isLib: boolean, entryFile?: string, nameOverride?: string, externalsArg?: string | string[], includeArg?: string | string[]): Promise<void>;
private buildByEnv;
/**
* @description Builds the project for development.
* @summary This method runs the build process with development-specific configurations.
* @param {BuildMode} [mode=BuildMode.ALL] - The build mode (build, bundle, or all).
* @param {string|string[]} [includesArg] - A list of dependencies to include.
* @param {string|string[]} [externalsArg] - A list of external dependencies.
* @returns {Promise<void>}
*/
buildDev(mode?: BuildMode, includesArg?: string | string[], externalsArg?: string | string[]): Promise<void>;
/**
* @description Builds the project for production.
* @summary This method runs the build process with production-specific configurations,
* including minification and other optimizations.
* @param {BuildMode} [mode=BuildMode.ALL] - The build mode (build, bundle, or all).
* @param {string|string[]} [includesArg] - A list of dependencies to include.
* @param {string|string[]} [externalsArg] - A list of external dependencies.
* @returns {Promise<void>}
*/
buildProd(mode?: BuildMode, includesArg?: string | string[], externalsArg?: string | string[]): Promise<void>;
/**
* @description Generates the project documentation.
* @summary This method uses JSDoc and other tools to generate HTML documentation for the project.
* It also patches the README.md file with version and package size information.
* @returns {Promise<void>}
*/
buildDocs(): Promise<void>;
protected run<R>(answers: LoggingConfig & typeof DefaultCommandValues & {
[k in keyof typeof options]: unknown;
}): Promise<string | void | R>;
}
export {};