Skip to main content

Script Helpers

Helper functions for creating TypeScript project scripts.

Type Aliases

ScriptCallback()

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

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

Parameters

ParameterType
packageRootstring

Returns

Promise<void> | void

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:20

Functions

buildScript()

function buildScript(func): Promise<void>

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
funcScriptCallback

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:30


echo()

function echo(...args): void

Alias for "console.log".

Parameters

ParameterType
...argsreadonly unknown[]

Returns

void

Allow Empty Variadic

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:162


exit()

function exit(code): never

Alias for "process.exit".

Parameters

ParameterTypeDefault value
codenumber0

Returns

never

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:167


lintScript()

function lintScript(func): Promise<void>

See the documentation for the script helper function.

Parameters

ParameterType
funcScriptCallback

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:40


printSuccess()

function printSuccess(
startTime,
verb,
noun): void

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

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:145


script()

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

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 $ and $s helper functions so that you can make a TypeScript script in the style of a Bash script.

Specifically, this helper function will:

  1. Change the working directory to the package root (i.e. the place where the nearest "package.json" file is).
  2. Run the provided logic.
  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

ParameterTypeDefault valueDescription
funcScriptCallbackundefinedThe function that contains the build logic for the particular script. This is passed the path to the package root and other metadata about the project. (See the ScriptCallbackData interface.)
verb?stringundefinedOptional. The verb for when the script completes. For example, "built".
upStackBy?number1Optional. The number of functions to rewind in the calling stack before attempting to find the closest "package.json" file. Default is 1.

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:110


sleep()

function sleep(seconds): Promise<unknown>

Helper function to sleep for a certain number of seconds.

Under the hood, this uses promises with setTimeout.

Parameters

ParameterType
secondsnumber

Returns

Promise<unknown>

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:176


standardLintFunction()

function standardLintFunction(): Promise<void>

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);

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:57


testScript()

function testScript(func): Promise<void>

See the documentation for the script helper function.

Parameters

ParameterType
funcScriptCallback

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/scriptHelpers.ts:84