@oazmi/build-tools
Version:
general deno build tool scripts which I practically use in all of my typescript repos
80 lines • 5.36 kB
TypeScript
import { type BuildDistConfig, type EsBuildOptions, type TransformationConfig } from "../dist.js";
/** the cli args for generating the documentation of your deno project to via the {@link buildDistFn | buildDist} function. */
export interface CliArgs {
/** {@inheritDoc dist!BuildDistConfig.dir} */
dir?: BuildDistConfig["dir"];
/** {@inheritDoc dist!BuildDistConfig.deno} */
deno?: BuildDistConfig["deno"];
/** {@inheritDoc dist!BuildDistConfig.log} */
log?: BuildDistConfig["log"];
/** {@inheritDoc dist!BuildDistConfig.dryrun} */
dryrun?: BuildDistConfig["dryrun"];
/** specify the number of compilation passes to perform:
* - `"1"` implies a single-pass compilation, and only uses the {@link buildDistFn | buildDist} function under the hood.
* - `"2"` implies a double-pass compilation, which consists of two compilations, and is performed in the following set of steps:
* 1) your source files are first bundled in-memory via the {@link bundleFn | bundle} function (which uses esbuild's build api).
* 2) the resulting virtual files are then individually transformed via the {@link transformFn | transform} function (which uses esbuild's transform api). <br>
* you can configure this step through custom transformation functions and capture patterns, by specifying them in the {@link TransformationCliConfig.pattern} field of your {@link CliConfigJson}.
* but by default, only javascript files are further minified. (no css minification or transformation of other file/content types). see the default transformation {@link CliDistConfig.transform | here}.
* 3) the virtual files emitted by the {@link transformFn | transform} function are then fed to the {@link createFiles} utility function which writes them onto your filesystem.
*
* @defaultValue `"1"`
*/
passes?: "1" | "2";
/** enable esbuild's code splitting option. <br>
* you will probably want this turned on if you are transpiling multiple entry-points, so that the distribution files are overall shared and smaller in size.
*
* @defaultValue `false`
*/
split?: boolean;
/** minify the output code, or apply minification of only one type (`"syntax"`, `"whitespace"`, or `"identifiers"`). <br>
* note that when `minify` is `true`, {@link EsBuildOptions.treeShaking} also occurs by default.
*
* @defaultValue `"syntax"`
*/
minify?: boolean | "syntax" | "whitespace" | "identifiers";
/** {@inheritDoc dist!EsBuildOptions.format}
*
* @defaultValue `"esm"`
*/
format?: EsBuildOptions["format"];
/** a path to an dist-build configuration json file that provides additional modifiable parameters.
* see {@link CliConfigJson} for more details on the available extended configurations.
* in case there is a contradiction between the {@link CliConfigJson} setting and the current cli args, the cli arg will take precedence.
*/
config?: string;
}
/** contains the relevant fields within the {@link CliConfigJson | configuration json file}, that are used for configuring distribution generation. */
export interface CliDistConfig extends Omit<CliArgs, "config"> {
/** {@inheritDoc dist!BuildDistConfig.input} */
input?: BuildDistConfig["input"];
/** {@inheritDoc dist!BuildDistConfig.copy} */
copy?: BuildDistConfig["copy"];
/** {@inheritDoc dist!BuildDistConfig.text} */
text?: BuildDistConfig["text"];
/** {@inheritDoc dist!BuildDistConfig.esbuild} */
esbuild?: BuildDistConfig["esbuild"];
/** when using two {@link passes} (i.e. `passes === "2"`), in the second stage compilation (transformation),
* the transformations listed in this array will be applied sequentially to whichever output file that matches the given {@link TransformationCliConfig.pattern | glob pattern}.
*
* by default, when nothing is provided, only javascript esm-minification transformation will take place.
* meaning that it will take shape of the following default value:
*
* @defaultValue `[{ pattern: "./**\/*.js", loader: "js", options: { minify: true, platform: "browser", format: "esm", target: "esnext" } }, ]`
*/
transform?: Array<TransformationCliConfig>;
}
/** the schema of a docs-generation configuration json file, which can be referenced in the {@link CliArgs}, by passing its file-path with the `--config` switch. <br>
* notice that there is only one property named {@link buildDist | `buildDist`}, which then holds all of the relevant configuration (as specified in {@link CliDistConfig}).
* this is because doing so allows one to embed this configuration within other json files, such as "deno.json" itself, or a single dedicated configuration json file,
* containing the configurations of different build tools altogether. <br>
* in case there is a contradiction between the configurations in this json file and the current cli args, the cli arg will take precedence.
*/
export interface CliConfigJson {
buildDist?: CliDistConfig;
}
export interface TransformationCliConfig extends TransformationConfig {
/** in cli mode, only glob string patterns are accepted. for details on what the pattern does, see {@link TransformationConfig.pattern}. */
pattern?: null | undefined | string;
}
//# sourceMappingURL=dist.d.ts.map