Class: PackageJson::Managers::NpmLike

Inherits:
Base
  • Object
show all
Defined in:
lib/package_json/managers/npm_like.rb

Instance Attribute Summary

Attributes inherited from Base

#binary

Instance Method Summary collapse

Methods inherited from Base

#add!, #install!, #remove!, #run!, #version

Constructor Details

#initialize(package_json) ⇒ NpmLike

Returns a new instance of NpmLike.



4
5
6
# File 'lib/package_json/managers/npm_like.rb', line 4

def initialize(package_json)
  super(package_json, binary_name: "npm")
end

Instance Method Details

#add(packages, type: :production) ⇒ Object

Adds the given packages



25
26
27
# File 'lib/package_json/managers/npm_like.rb', line 25

def add(packages, type: :production)
  raw("install", [package_type_install_flag(type)] + packages)
end

#install(frozen: false) ⇒ Object

Installs the dependencies specified in the ‘package.json` file



9
10
11
12
13
14
# File 'lib/package_json/managers/npm_like.rb', line 9

def install(frozen: false)
  cmd = "install"
  cmd = "ci" if frozen

  raw(cmd, [])
end

#native_exec_command(script_name, args = []) ⇒ Object



52
53
54
55
56
57
# File 'lib/package_json/managers/npm_like.rb', line 52

def native_exec_command(
  script_name,
  args = []
)
  build_full_cmd("exec", ["--no", "--offline"] + build_run_args(script_name, args, silent: false))
end

#native_install_command(frozen: false) ⇒ Object

Provides the “native” command for installing dependencies with this package manager for embedding into scripts



17
18
19
20
21
22
# File 'lib/package_json/managers/npm_like.rb', line 17

def native_install_command(frozen: false)
  cmd = "install"
  cmd = "ci" if frozen

  build_full_cmd(cmd, [])
end

#native_run_command(script_name, args = [], silent: false) ⇒ Object

Provides the “native” command for running the script with args for embedding into shell scripts



44
45
46
47
48
49
50
# File 'lib/package_json/managers/npm_like.rb', line 44

def native_run_command(
  script_name,
  args = [],
  silent: false
)
  build_full_cmd("run", build_run_args(script_name, args, silent: silent))
end

#remove(packages) ⇒ Object

Removes the given packages



30
31
32
# File 'lib/package_json/managers/npm_like.rb', line 30

def remove(packages)
  raw("remove", packages)
end

#run(script_name, args = [], silent: false) ⇒ Object

Runs the script assuming it is defined in the ‘package.json` file



35
36
37
38
39
40
41
# File 'lib/package_json/managers/npm_like.rb', line 35

def run(
  script_name,
  args = [],
  silent: false
)
  raw("run", build_run_args(script_name, args, silent: silent))
end