NPM.Scripts (NPM v0.6.0)

Copy Markdown View Source

Reads and manages npm scripts from package.json.

Provides the npm run functionality — listing, filtering, and determining execution order of scripts defined in package.json.

Summary

Functions

Categorizes scripts into well-known and custom.

Returns the execution order for a script, including pre/post hooks.

Returns scripts matching a pattern.

Formats a scripts map for display.

Checks if a script exists.

Returns pre/post hooks for a script.

Lists all available script names.

Reads all scripts from a package.json file.

Functions

categorize(scripts)

@spec categorize(map()) :: %{well_known: [String.t()], custom: [String.t()]}

Categorizes scripts into well-known and custom.

execution_order(scripts, name)

@spec execution_order(map(), String.t()) :: [String.t()]

Returns the execution order for a script, including pre/post hooks.

filter(scripts, pattern)

@spec filter(map(), String.t()) :: map()

Returns scripts matching a pattern.

format(scripts)

@spec format(map()) :: String.t()

Formats a scripts map for display.

has?(scripts, name)

@spec has?(map(), String.t()) :: boolean()

Checks if a script exists.

hooks_for(scripts, name)

@spec hooks_for(map(), String.t()) :: %{pre: String.t() | nil, post: String.t() | nil}

Returns pre/post hooks for a script.

list(scripts)

@spec list(map()) :: [String.t()]

Lists all available script names.

read(package_json_path)

@spec read(String.t()) :: {:ok, map()} | {:error, term()}

Reads all scripts from a package.json file.