Script Helpers
Helper functions for creating TypeScript project scripts.
Type Aliases
Section titled “Type Aliases”LintCommand
Section titled “LintCommand”type LintCommand = string | readonly [string, Promise<unknown>];Defined in: functions/scriptHelpers.ts:180
The type given to the lintCommands helper function.
ScriptCallback
Section titled “ScriptCallback”type ScriptCallback = (packageRoot) => Promise<void> | void;Defined in: functions/scriptHelpers.ts:60
The type of the function passed to the script helper function. (And the
related helper functions.)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
packageRoot |
string |
Returns
Section titled “Returns”Promise<void> | void
Functions
Section titled “Functions”buildScript()
Section titled “buildScript()”function buildScript(importMetaDirname, func): Promise<void>;Defined in: functions/scriptHelpers.ts:70
Removes the “dist” directory (if it exists), then runs the provided logic.
For more information, see the documentation for the script helper function.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
importMetaDirname |
string |
func |
ScriptCallback |
Returns
Section titled “Returns”Promise<void>
echo()
Section titled “echo()”function echo(...args): void;Defined in: functions/scriptHelpers.ts:364
Alias for “console.log”.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…args |
readonly unknown[] |
Returns
Section titled “Returns”void
Allow Empty Variadic
Section titled “Allow Empty Variadic”exit()
Section titled “exit()”function exit(code?): never;Defined in: functions/scriptHelpers.ts:369
Alias for “process.exit”.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
code |
number |
0 |
Returns
Section titled “Returns”never
lintCommands()
Section titled “lintCommands()”function lintCommands(importMetaDirname, commands?, quiet?): Promise<void>;Defined in: functions/scriptHelpers.ts:194
Helper function to run a series of concurrent lint commands. Nice console output will be shown with the “listr2” library.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
importMetaDirname |
string |
undefined |
The value of import.meta.dirname (so that this function can find the package root). |
commands |
readonly LintCommand[] |
DEFAULT_LINT_COMMANDS |
Optional. 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 |
quiet |
boolean |
false |
Optional. If true, will not print the time taken. Defaults to false. |
Returns
Section titled “Returns”Promise<void>
lintScript()
Section titled “lintScript()”function lintScript(importMetaDirname, func): Promise<void>;Defined in: functions/scriptHelpers.ts:83
See the documentation for the script helper function.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
importMetaDirname |
string |
func |
ScriptCallback |
Returns
Section titled “Returns”Promise<void>
printSuccess()
Section titled “printSuccess()”function printSuccess(startTime, verb, noun): void;Defined in: functions/scriptHelpers.ts:347
Helper function to print a success message with the number of elapsed seconds.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
startTime |
number |
The start time in milliseconds (as recorded by the Date.now method). |
verb |
string |
The verb to print. For example, “built”. |
noun |
string |
The noun to print. For example, “foo”. |
Returns
Section titled “Returns”void
script()
Section titled “script()”function script(importMetaDirname, func, verb?): Promise<void>;Defined in: functions/scriptHelpers.ts:121
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:
- Change the working directory to where the nearest “package.json” file is.
- Run the provided function.
- 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
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
importMetaDirname |
string |
The value of import.meta.dirname (so that this function can find the package root). |
func |
ScriptCallback |
The function that contains the build logic for the particular script. This is passed the path to the package root. (See the ScriptCallbackData interface.) |
verb? |
string |
Optional. The verb for when the script completes. For example, “built”. |
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”If the provided function fails.
sleep()
Section titled “sleep()”function sleep(seconds): Promise<unknown>;Defined in: functions/scriptHelpers.ts:378
Helper function to sleep for a certain number of seconds.
Under the hood, this uses promises with setTimeout.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
seconds |
number |
Returns
Section titled “Returns”Promise<unknown>
testScript()
Section titled “testScript()”function testScript(importMetaDirname, func): Promise<void>;Defined in: functions/scriptHelpers.ts:91
See the documentation for the script helper function.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
importMetaDirname |
string |
func |
ScriptCallback |
Returns
Section titled “Returns”Promise<void>
