Script Helpers
Helper functions for creating TypeScript project scripts.
Type Aliases
ScriptCallback()
type ScriptCallback = (packageRoot) => Promise<void> | void;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:21
The type of the function passed to the script
helper function. (And the related helper
functions.)
Parameters
Parameter | Type |
---|---|
packageRoot | string |
Returns
Promise
<void
> | void
Functions
buildScript()
function buildScript(func, packageRoot?): Promise<void>;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:31
Removes the "dist" directory (if it exists), then runs the provided logic.
For more information, see the documentation for the script
helper function.
Parameters
Parameter | Type |
---|---|
func | ScriptCallback |
packageRoot? | string |
Returns
Promise
<void
>
echo()
function echo(...args): void;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:203
Alias for "console.log".
Parameters
Parameter | Type |
---|---|
...args | readonly unknown [] |
Returns
void
Allow Empty Variadic
exit()
function exit(code): never;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:208
Alias for "process.exit".
Parameters
Parameter | Type | Default value |
---|---|---|
code | number | 0 |
Returns
never
lintScript()
function lintScript(func, packageRoot?): Promise<void>;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:44
See the documentation for the script
helper function.
Parameters
Parameter | Type |
---|---|
func | ScriptCallback |
packageRoot? | string |
Returns
Promise
<void
>
printSuccess()
function printSuccess(
startTime,
verb,
noun): void;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:141
Helper function to print a success message with the number of elapsed seconds.
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
void
script()
function script(
func,
verb?,
upStackBy?,
packageRoot?): Promise<void>;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:85
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
Parameter | Type | Default value | Description |
---|---|---|---|
func | ScriptCallback | undefined | 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 | undefined | Optional. The verb for when the script completes. For example, "built". |
upStackBy? | number | 1 | Optional. The number of functions to rewind in the calling stack before attempting to find the closest "package.json" file. Default is 1. |
packageRoot? | string | undefined | Optional. The directory path of the package root. In most cases, this does not need to be specified and will be automatically inferred based on the directory of the file of the calling function. If specified, the upStackBy parameter will not be used. |
Returns
Promise
<void
>
sleep()
function sleep(seconds): Promise<unknown>;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:217
Helper function to sleep for a certain number of seconds.
Under the hood, this uses promises with setTimeout
.
Parameters
Parameter | Type |
---|---|
seconds | number |
Returns
Promise
<unknown
>
standardLintFunction()
function standardLintFunction(): Promise<void>;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:169
Use this function with the lintScript
helper function if you want to just use the standard
linting checks for a TypeScript project without any project-specific customization.
For example:
import { lintScript, standardLintFunction } from "complete-node";
await lintScript(standardLintFunction);
See the official docs for what specific checks are performed.
Returns
Promise
<void
>
testScript()
function testScript(func, packageRoot?): Promise<void>;
Defined in: packages/complete-node/src/functions/scriptHelpers.ts:52
See the documentation for the script
helper function.
Parameters
Parameter | Type |
---|---|
func | ScriptCallback |
packageRoot? | string |
Returns
Promise
<void
>