|
1 | 1 | import type { BuildOptions } from "esbuild"; |
2 | 2 |
|
| 3 | +import Echo from "../Function/Echo.js"; |
3 | 4 | import type Interface from "../Interface/Build.js"; |
4 | 5 | import type Set from "../Interface/Build/Set.js"; |
5 | 6 |
|
6 | 7 | /** |
7 | 8 | * @module Build |
8 | 9 | * |
| 10 | + * Main build function that processes files and performs builds using ESBuild and TypeScript. |
| 11 | + * |
| 12 | + * This function handles the complete build pipeline including: |
| 13 | + * - Expanding file patterns (globbing) |
| 14 | + * - Loading ESBuild configuration |
| 15 | + * - Applying custom ESBuild presets |
| 16 | + * - Running TypeScript compilation |
| 17 | + * - Running tsc-alias for path aliases |
| 18 | + * - Watching for changes (optional) |
| 19 | + * |
| 20 | + * @param File - An array of file patterns to build. Patterns can include wildcards (*, **). |
| 21 | + * @param Option - Optional configuration object. |
| 22 | + * @param Option.ESBuild - Path to a custom ESBuild configuration file or function. |
| 23 | + * @param Option.TypeScript - Path to TypeScript configuration file (defaults to "tsconfig.json"). |
| 24 | + * @param Option.Watch - Enable watch mode to rebuild on file changes. |
| 25 | + * @param Option.Exclude - Array of file patterns to exclude from the build. |
| 26 | + * |
| 27 | + * @returns Promise<void> |
| 28 | + * |
| 29 | + * @example |
| 30 | + * Basic build: |
| 31 | + * ```typescript |
| 32 | + * import Build from "./Function/Build.js"; |
| 33 | + * |
| 34 | + * await Build(["Source/**\/*.ts"]); |
| 35 | + * ``` |
| 36 | + * |
| 37 | + * @example |
| 38 | + * Build with options: |
| 39 | + * ```typescript |
| 40 | + * await Build( |
| 41 | + * ["Source/**\/*.ts"], |
| 42 | + * { |
| 43 | + * ESBuild: "./Config/ESBuild.js", |
| 44 | + * TypeScript: "./tsconfig.build.json", |
| 45 | + * Watch: true, |
| 46 | + * Exclude: ["Source/**\/*.test.ts"], |
| 47 | + * } |
| 48 | + * ); |
| 49 | + * ``` |
| 50 | + * |
| 51 | + * @example |
| 52 | + * Custom ESBuild configuration: |
| 53 | + * ```typescript |
| 54 | + * // Config/ESBuild.js - returns BuildOptions |
| 55 | + * export default { |
| 56 | + * minify: true, |
| 57 | + * target: "es2020", |
| 58 | + * }; |
| 59 | + * ``` |
| 60 | + * |
| 61 | + * @example |
| 62 | + * Custom ESBuild configuration function: |
| 63 | + * ```typescript |
| 64 | + * // Config/ESBuild.js - returns function |
| 65 | + * import type BuildSetInterface from "../Interface/Build/Set.js"; |
| 66 | + * import type { BuildOptions } from "esbuild"; |
| 67 | + * |
| 68 | + * export default async (current: BuildOptions) => { |
| 69 | + * return { |
| 70 | + * ...current, |
| 71 | + * plugins: [...(current.plugins ?? []), myPlugin], |
| 72 | + * }; |
| 73 | + * }; |
| 74 | + * ``` |
| 75 | + * |
| 76 | + * @example |
| 77 | + * Using the Pipe for dependency order: |
| 78 | + * ```typescript |
| 79 | + * import { Pipe } from "./Function/Build.js"; |
| 80 | + * |
| 81 | + * // Pipe is populated with files in dependency order |
| 82 | + * await Build(["Index.ts", "Source/**\/*.ts"]); |
| 83 | + * console.log(Pipe); // ["Source/Module1.ts", "Source/Module2.ts", "Index.ts"] |
| 84 | + * ``` |
9 | 85 | */ |
10 | 86 | export default (async (...[File, Option]) => { |
11 | 87 | for (const _File of File) { |
@@ -81,9 +157,12 @@ export default (async (...[File, Option]) => { |
81 | 157 | } |
82 | 158 |
|
83 | 159 | try { |
84 | | - await Exec(`tsc -p ${Configuration.tsconfig}`); |
| 160 | + await Exec(`tsc -p ${Configuration.tsconfig}`, Echo); |
85 | 161 |
|
86 | | - await Exec(`tsc-alias -f -p ${Configuration.tsconfig}`); |
| 162 | + await Exec( |
| 163 | + `tsc-alias -f -p ${Configuration.tsconfig}`, |
| 164 | + Echo, |
| 165 | + ); |
87 | 166 | } catch (_Error) { |
88 | 167 | console.error(_Error); |
89 | 168 | } |
|
0 commit comments