Skip to main content

Script Helpers

Helper functions for creating TypeScript project scripts.

Type Aliases

ScriptCallback()

type ScriptCallback = (packageRoot) => Promise<void> | void;

Defined in: functions/scriptHelpers.ts:57

The type of the function passed to the script helper function. (And the related helper functions.)

Parameters

ParameterType
packageRootstring

Returns

Promise<void> | void

Functions

buildScript()

function buildScript(importMetaDirname, func): Promise<void>;

Defined in: functions/scriptHelpers.ts:67

Removes the "dist" directory (if it exists), then runs the provided logic.

For more information, see the documentation for the script helper function.

Parameters

ParameterType
importMetaDirnamestring
funcScriptCallback

Returns

Promise<void>


echo()

function echo(...args): void;

Defined in: functions/scriptHelpers.ts:269

Alias for "console.log".

Parameters

ParameterType
...argsreadonly unknown[]

Returns

void

Allow Empty Variadic


exit()

function exit(code): never;

Defined in: functions/scriptHelpers.ts:274

Alias for "process.exit".

Parameters

ParameterTypeDefault value
codenumber0

Returns

never


lintCommands()

function lintCommands(
importMetaDirname,
commands,
quiet): Promise<void>;

Defined in: functions/scriptHelpers.ts:186

Helper function to run a series of concurrent lint commands. Nice console output will be shown with the "listr2" library.

Parameters

ParameterTypeDefault valueDescription
importMetaDirnamestringundefinedThe value of import.meta.dirname (so that this function can find the package root).
commandsreadonly (string | [string, Promise<unknown>])[]DEFAULT_LINT_COMMANDSOptional. The commands or functions to run. Defaults to the standard tools that are listed in the documentation for complete-lint: https://complete-ts.github.io/complete-lint#step-5---create-a-lint-script
quietbooleanfalseOptional. If true, will not print the time taken. Defaults to false.

Returns

Promise<void>


lintScript()

function lintScript(importMetaDirname, func): Promise<void>;

Defined in: functions/scriptHelpers.ts:80

See the documentation for the script helper function.

Parameters

ParameterType
importMetaDirnamestring
funcScriptCallback

Returns

Promise<void>


printSuccess()

function printSuccess(
startTime,
verb,
noun): void;

Defined in: functions/scriptHelpers.ts:252

Helper function to print a success message with the number of elapsed seconds.

Parameters

ParameterTypeDescription
startTimenumberThe start time in milliseconds (as recorded by the Date.now method).
verbstringThe verb to print. For example, "built".
nounstringThe noun to print. For example, "foo".

Returns

void


script()

function script(
importMetaDirname,
func,
verb?): Promise<void>;

Defined in: functions/scriptHelpers.ts:117

Helper function to create a script for a TypeScript project. You can pass any arbitrary logic you want.

This is intended to be used with the $ function from either execa or Bun so that you can make a TypeScript script in the style of a Bash script.

(This function will work in both the Node.js and Bun runtimes.)

Specifically, this helper function will:

  1. Change the working directory to where the nearest "package.json" file is.
  2. Run the provided function.
  3. Print a success message with the total amount of seconds taken (if a verb was provided and there is not a quiet/silent flag).

Parameters

ParameterTypeDescription
importMetaDirnamestringThe value of import.meta.dirname (so that this function can find the package root).
funcScriptCallbackThe function that contains the build logic for the particular script. This is passed the path to the package root. (See the ScriptCallbackData interface.)
verb?stringOptional. The verb for when the script completes. For example, "built".

Returns

Promise<void>


sleep()

function sleep(seconds): Promise<unknown>;

Defined in: functions/scriptHelpers.ts:283

Helper function to sleep for a certain number of seconds.

Under the hood, this uses promises with setTimeout.

Parameters

ParameterType
secondsnumber

Returns

Promise<unknown>


testScript()

function testScript(importMetaDirname, func): Promise<void>;

Defined in: functions/scriptHelpers.ts:88

See the documentation for the script helper function.

Parameters

ParameterType
importMetaDirnamestring
funcScriptCallback

Returns

Promise<void>