PackageJsonBuilder

class

PackageJsonBuilder

source
export class PackageJsonBuilder
export class PackageJsonBuilder
constructor(data?: Partial<PackageJson>)
constructor(data?: Partial<PackageJson>)
ParamDescriptionTypeRequired
data
data
The initial package.json data
Partial<PackageJson>
Partial<PackageJson>
No
public source

.toJSON()

toJSON(): PackageJson
toJSON(): PackageJson

Returns:

PackageJson
PackageJson

public async source

.write(...)

write(filepath: string, overwrite?: boolean): Promise<void>
write(filepath: string, overwrite?: boolean): Promise<void>
ParamDescriptionTypeRequired
filepath
filepath
The filepath to write the package.json data to
string
string
Yes
overwrite
overwrite
Whether to overwrite the file if it already exists
boolean
boolean
No

Returns:

Promise<void>
Promise<void>

public async source

.read(...)

read(filepath: string): Promise<this>
read(filepath: string): Promise<this>
ParamDescriptionTypeRequired
filepath
filepath
The filepath to read the package.json data from
string
string
Yes

Returns:

Promise<this>
Promise<this>

public source

.merge(...)

merge(data: Partial<PackageJson>): this
merge(data: Partial<PackageJson>): this
ParamDescriptionTypeRequired
data
data
The package.json data to merge
Partial<PackageJson>
Partial<PackageJson>
Yes

Returns:

this
this

public source

.remove(...)

remove(key: keyof PackageJson): this
remove(key: keyof PackageJson): this
ParamDescriptionTypeRequired
key
key
The key to remove
keyof PackageJson
keyof PackageJson
Yes

Returns:

this
this

public source

.setScripts(...)

setScripts(scripts: Record<string, string>): this
setScripts(scripts: Record<string, string>): this
ParamDescriptionTypeRequired
scripts
scripts
The scripts to set
Record<string, string>
Record<string, string>
Yes

Returns:

this
this

public source

.addScript(...)

addScript(name: string, script: string): this
addScript(name: string, script: string): this
ParamDescriptionTypeRequired
name
name
The name of the script
string
string
Yes
script
script
The script that will be executed
string
string
Yes

Returns:

this
this

public source

.removeScript(...)

removeScript(name: string): this
removeScript(name: string): this
ParamDescriptionTypeRequired
name
name
The name of the script
string
string
Yes

Returns:

this
this

setDependencies(dependencies: Record<string, string>): this
setDependencies(dependencies: Record<string, string>): this
ParamDescriptionTypeRequired
dependencies
dependencies
The dependencies to set
Record<string, string>
Record<string, string>
Yes

Returns:

this
this

addDependency(name: string, version: string, dev: boolean = false): this
addDependency(name: string, version: string, dev: boolean = false): this
ParamDescriptionTypeRequired
name
name
The name of the dependency
string
string
Yes
version
version
The version of the dependency
string
string
Yes
dev = false
dev = false
Whether the dependency is a dev dependency
boolean
boolean
No

Returns:

this
this

removeDependency(name: string, dev: boolean = false): this
removeDependency(name: string, dev: boolean = false): this
ParamDescriptionTypeRequired
name
name
The name of the dependency
string
string
Yes
dev = false
dev = false
Whether the dependency is a dev dependency
boolean
boolean
No

Returns:

this
this

public source

.data

PackageJson
PackageJson