NPM.Init (NPM v0.6.0)

Copy Markdown View Source

Generates package.json files with sensible defaults.

Implements the npm init functionality — creates a new package.json with project metadata derived from the current directory or Mix project.

Summary

Functions

Infers project name from the current directory.

Returns default scripts for a new package.

Checks if a package.json already exists in the directory.

Detects if this is an Elixir/Mix project and adjusts defaults.

Generates a default package.json map from the given options.

Generates a minimal package.json (name and version only).

Writes a package.json to disk.

Functions

default_name()

@spec default_name() :: String.t()

Infers project name from the current directory.

default_scripts()

@spec default_scripts() :: map()

Returns default scripts for a new package.

exists?(dir \\ ".")

@spec exists?(String.t()) :: boolean()

Checks if a package.json already exists in the directory.

from_mix_project(mix_config \\ [])

@spec from_mix_project(keyword()) :: map()

Detects if this is an Elixir/Mix project and adjusts defaults.

generate(opts \\ [])

@spec generate(keyword()) :: map()

Generates a default package.json map from the given options.

generate_minimal(name, version \\ "1.0.0")

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

Generates a minimal package.json (name and version only).

write(dir \\ ".", opts \\ [])

@spec write(
  String.t(),
  keyword()
) :: :ok | {:error, term()}

Writes a package.json to disk.