/
package.rb
52 lines (46 loc) · 1.59 KB
/
package.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# encoding: utf-8
use_inline_resources if defined?(use_inline_resources)
action :install do
pkg_id = new_resource.name
pkg_id += "@#{new_resource.version}" if new_resource.version
execute "install NPM package #{new_resource.name}" do
command "npm -g install #{pkg_id}"
not_if "npm --no-color -g ls '#{pkg_id}' 2> /dev/null | grep ' #{pkg_id}'"
end
end
action :install_local do
path = new_resource.path if new_resource.path
pkg_id = new_resource.name
pkg_id += "@#{new_resource.version}" if new_resource.version
execute "install NPM package #{new_resource.name} into #{path}" do
cwd path
command "npm install #{pkg_id}"
not_if "cd #{path} && npm --no-color ls '#{pkg_id}' 2> /dev/null | grep ' #{pkg_id}'"
end
end
action :install_from_json do
path = new_resource.path
cmd = 'npm install'
execute "install NPM packages from package.json at #{path}" do
cwd path
command cmd
end
end
action :uninstall do
pkg_id = new_resource.name
pkg_id += "@#{new_resource.version}" if new_resource.version
execute "uninstall NPM package #{new_resource.name}" do
command "npm -g uninstall #{pkg_id}"
only_if "npm --no-color -g ls '#{pkg_id}' 2> /dev/null | grep ' #{pkg_id}'"
end
end
action :uninstall_local do
path = new_resource.path if new_resource.path
pkg_id = new_resource.name
pkg_id += "@#{new_resource.version}" if new_resource.version
execute "uninstall NPM package #{new_resource.name} from #{path}" do
cwd path
command "npm uninstall #{pkg_id}"
only_if "cd #{path} && npm --no-color ls '#{pkg_id}' 2> /dev/null | grep ' #{pkg_id}'"
end
end