poise-javascript 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.kitchen.travis.yml +9 -0
  4. data/.kitchen.yml +8 -0
  5. data/.travis.yml +21 -0
  6. data/.yardopts +7 -0
  7. data/Berksfile +28 -0
  8. data/CHANGELOG.md +6 -0
  9. data/Gemfile +33 -0
  10. data/LICENSE +201 -0
  11. data/README.md +332 -0
  12. data/Rakefile +17 -0
  13. data/chef/attributes/default.rb +23 -0
  14. data/chef/recipes/default.rb +19 -0
  15. data/lib/poise_javascript.rb +24 -0
  16. data/lib/poise_javascript/cheftie.rb +18 -0
  17. data/lib/poise_javascript/error.rb +23 -0
  18. data/lib/poise_javascript/javascript_command_mixin.rb +56 -0
  19. data/lib/poise_javascript/javascript_providers.rb +40 -0
  20. data/lib/poise_javascript/javascript_providers/base.rb +97 -0
  21. data/lib/poise_javascript/javascript_providers/dummy.rb +77 -0
  22. data/lib/poise_javascript/javascript_providers/iojs.rb +64 -0
  23. data/lib/poise_javascript/javascript_providers/nodejs.rb +64 -0
  24. data/lib/poise_javascript/javascript_providers/scl.rb +79 -0
  25. data/lib/poise_javascript/javascript_providers/system.rb +71 -0
  26. data/lib/poise_javascript/resources.rb +29 -0
  27. data/lib/poise_javascript/resources/javascript_execute.rb +83 -0
  28. data/lib/poise_javascript/resources/javascript_runtime.rb +85 -0
  29. data/lib/poise_javascript/resources/javascript_runtime_test.rb +226 -0
  30. data/lib/poise_javascript/resources/node_package.rb +254 -0
  31. data/lib/poise_javascript/resources/npm_install.rb +94 -0
  32. data/lib/poise_javascript/version.rb +20 -0
  33. data/poise-javascript.gemspec +41 -0
  34. data/test/cookbooks/poise-javascript_test/metadata.rb +18 -0
  35. data/test/cookbooks/poise-javascript_test/recipes/default.rb +49 -0
  36. data/test/gemfiles/chef-12.gemfile +19 -0
  37. data/test/gemfiles/master.gemfile +23 -0
  38. data/test/integration/default/serverspec/default_spec.rb +107 -0
  39. data/test/spec/javascript_command_mixin_spec.rb +59 -0
  40. data/test/spec/javascript_providers/base_spec.rb +89 -0
  41. data/test/spec/javascript_providers/dummy_spec.rb +62 -0
  42. data/test/spec/javascript_providers/iojs_spec.rb +77 -0
  43. data/test/spec/javascript_providers/nodejs_spec.rb +82 -0
  44. data/test/spec/javascript_providers/scl_spec.rb +68 -0
  45. data/test/spec/javascript_providers/system_spec.rb +73 -0
  46. data/test/spec/resources/javascript_execute_spec.rb +67 -0
  47. data/test/spec/resources/node_package_spec.rb +324 -0
  48. data/test/spec/resources/npm_install_spec.rb +118 -0
  49. data/test/spec/spec_helper.rb +19 -0
  50. metadata +169 -0
@@ -0,0 +1,64 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/resource'
18
+ require 'poise_languages/static'
19
+
20
+ require 'poise_javascript/error'
21
+ require 'poise_javascript/javascript_providers/base'
22
+
23
+
24
+ module PoiseJavascript
25
+ module JavascriptProviders
26
+ class NodeJS < Base
27
+ provides(:nodejs)
28
+ include PoiseLanguages::Static(
29
+ versions: %w{4.1.1 4.0.0 0.12.7 0.11.16 0.10.40 0.9.12 0.8.28 0.7.12 0.6.21 0.5.10},
30
+ machines: %w{linux-i686 linux-x86_64 darwin-x86_64},
31
+ url: 'https://nodejs.org/dist/v%{version}/node-v%{version}-%{kernel}-%{machine}.tar.gz',
32
+ )
33
+
34
+ def self.provides_auto?(node, resource)
35
+ # Also work if we have a blank or numeric-y version. This should make
36
+ # it the default provider on supported platforms.
37
+ super || (resource.version.to_s =~ /^(\d|$)/ && static_machines.include?(static_machine_label(node)))
38
+ end
39
+
40
+ MACHINE_LABELS = {'i386' => 'x86', 'i686' => 'x86', 'x86_64' => 'x64'}
41
+
42
+ def static_url_variables
43
+ machine = node['kernel']['machine']
44
+ super.merge(machine: MACHINE_LABELS[machine] || machine)
45
+ end
46
+
47
+ def javascript_binary
48
+ ::File.join(static_folder, 'bin', 'node')
49
+ end
50
+
51
+ private
52
+
53
+ def install_javascript
54
+ install_static
55
+ end
56
+
57
+ def uninstall_javascript
58
+ uninstall_static
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,79 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/resource'
18
+ require 'poise_languages'
19
+
20
+ require 'poise_javascript/error'
21
+ require 'poise_javascript/javascript_providers/base'
22
+
23
+
24
+ module PoiseJavascript
25
+ module JavascriptProviders
26
+ class Scl < Base
27
+ include PoiseLanguages::Scl::Mixin
28
+ provides(:scl)
29
+ scl_package('0.10.35', 'nodejs010', 'nodejs010-nodejs-devel', {
30
+ ['redhat', 'centos'] => {
31
+ '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/nodejs010/epel-7-x86_64/download/rhscl-nodejs010-epel-7-x86_64.noarch.rpm',
32
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/nodejs010/epel-6-x86_64/download/rhscl-nodejs010-epel-6-x86_64.noarch.rpm',
33
+ },
34
+ })
35
+
36
+ V8_SCL_URLS = {
37
+ ['redhat', 'centos'] => {
38
+ '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/v8314/epel-7-x86_64/download/rhscl-v8314-epel-7-x86_64.noarch.rpm',
39
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/v8314/epel-6-x86_64/download/rhscl-v8314-epel-6-x86_64.noarch.rpm',
40
+ },
41
+ }
42
+
43
+ def javascript_binary
44
+ ::File.join(scl_folder, 'root', 'usr', 'bin', 'node')
45
+ end
46
+
47
+ def javascript_environment
48
+ scl_environment
49
+ end
50
+
51
+ private
52
+
53
+ def install_javascript
54
+ install_v8_scl_package
55
+ install_scl_package
56
+ end
57
+
58
+ def uninstall_javascript
59
+ uninstall_scl_package
60
+ uninstall_v8_scl_package
61
+ end
62
+
63
+ def install_v8_scl_package
64
+ poise_languages_scl 'v8314' do
65
+ parent new_resource
66
+ url node.value_for_platform(V8_SCL_URLS)
67
+ end
68
+ end
69
+
70
+ def uninstall_v8_scl_package
71
+ install_v8_scl_package.tap do |r|
72
+ r.action(:uninstall)
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,71 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/resource'
18
+ require 'poise_languages'
19
+
20
+ require 'poise_javascript/error'
21
+ require 'poise_javascript/javascript_providers/base'
22
+
23
+
24
+ module PoiseJavascript
25
+ module JavascriptProviders
26
+ class System < Base
27
+ include PoiseLanguages::System::Mixin
28
+ provides(:system)
29
+ packages('nodejs', {
30
+ debian: {default: %w{nodejs}},
31
+ ubuntu: {default: %w{nodejs}},
32
+ # Empty arrays because no package in the base OS.
33
+ redhat: {default: %w{}},
34
+ centos: {default: %w{}},
35
+ fedora: {default: %w{nodejs}},
36
+ amazon: {default: %w{}},
37
+ })
38
+
39
+ def self.provides_auto?(node, resource)
40
+ # Don't auto on platforms I know have no system package by default. Kind
41
+ # of pointless since the nodejs provider will hit on these platforms
42
+ # anyway so this shouldn't ever happen.
43
+ super && !node.platform_family?('rhel') && !node.platform?('amazon')
44
+ end
45
+
46
+ def javascript_binary
47
+ # Debian and Ubuntu after 12.04 changed the binary name ಠ_ಠ.
48
+ binary_name = node.value_for_platform(debian: {default: 'nodejs'}, ubuntu: {'12.04' => 'node', default: 'nodejs'}, default: 'node')
49
+ ::File.join('', 'usr', 'bin', binary_name)
50
+ end
51
+
52
+ private
53
+
54
+ def install_javascript
55
+ install_system_packages
56
+ package %w{npm nodejs-legacy} if node.platform_family?('debian')
57
+ end
58
+
59
+ def uninstall_javascript
60
+ uninstall_system_packages
61
+ package(%w{npm nodejs-legacy}) { action :purge } if node.platform_family?('debian')
62
+ end
63
+
64
+ def system_package_candidates(version)
65
+ # Boring :-(.
66
+ %w{nodejs nodejs-legacy node}
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_javascript/resources/javascript_execute'
18
+ require 'poise_javascript/resources/javascript_runtime'
19
+ require 'poise_javascript/resources/node_package'
20
+ require 'poise_javascript/resources/npm_install'
21
+
22
+
23
+ module PoiseJavascript
24
+ # Chef resources and providers for poise-javascript.
25
+ #
26
+ # @since 1.0.0
27
+ module Resources
28
+ end
29
+ end
@@ -0,0 +1,83 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/mixin/which'
18
+ require 'chef/provider/execute'
19
+ require 'chef/resource/execute'
20
+ require 'poise'
21
+
22
+ require 'poise_javascript/javascript_command_mixin'
23
+
24
+
25
+ module PoiseJavascript
26
+ module Resources
27
+ # (see JavascriptExecute::Resource)
28
+ # @since 1.0.0
29
+ module JavascriptExecute
30
+ # A `javascript_execute` resource to run Javascript scripts and commands.
31
+ #
32
+ # @provides javascript_execute
33
+ # @action run
34
+ # @example
35
+ # javascript_execute 'myapp.js' do
36
+ # user 'myuser'
37
+ # end
38
+ class Resource < Chef::Resource::Execute
39
+ include PoiseJavascript::JavascriptCommandMixin
40
+ provides(:javascript_execute)
41
+ actions(:run)
42
+ end
43
+
44
+ # The default provider for `javascript_execute`.
45
+ #
46
+ # @see Resource
47
+ # @provides javascript_execute
48
+ class Provider < Chef::Provider::Execute
49
+ include Chef::Mixin::Which
50
+ provides(:javascript_execute)
51
+
52
+ private
53
+
54
+ # Command to pass to shell_out.
55
+ #
56
+ # @return [String, Array<String>]
57
+ def command
58
+ if new_resource.command.is_a?(Array)
59
+ [new_resource.javascript] + new_resource.command
60
+ else
61
+ "#{new_resource.javascript} #{new_resource.command}"
62
+ end
63
+ end
64
+
65
+ # Environment variables to pass to shell_out.
66
+ #
67
+ # @return [Hash]
68
+ def environment
69
+ if new_resource.parent_javascript
70
+ environment = new_resource.parent_javascript.javascript_environment
71
+ if new_resource.environment
72
+ environment = environment.merge(new_resource.environment)
73
+ end
74
+ environment
75
+ else
76
+ new_resource.environment
77
+ end
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/resource'
18
+ require 'poise'
19
+
20
+
21
+ module PoiseJavascript
22
+ module Resources
23
+ # (see JavascriptRuntime::Resource)
24
+ # @since 1.0.0
25
+ module JavascriptRuntime
26
+ # A `javascript_runtime` resource to manage Javascript installations.
27
+ #
28
+ # @provides javascript_runtime
29
+ # @action install
30
+ # @action uninstall
31
+ # @example
32
+ # javascript_runtime '2.7'
33
+ class Resource < Chef::Resource
34
+ include Poise(inversion: true, container: true)
35
+ provides(:javascript_runtime)
36
+ actions(:install, :uninstall)
37
+
38
+ # @!attribute version
39
+ # Version of Javascript to install. This is generally a NodeJS version
40
+ # but because of io.js there are shenanigans.
41
+ # @return [String]
42
+ # @example Install any version
43
+ # javascript_runtime 'any' do
44
+ # version ''
45
+ # end
46
+ attribute(:version, kind_of: String, name_attribute: true)
47
+
48
+ # The path to the `node` binary for this Javascript installation. This is
49
+ # an output property.
50
+ #
51
+ # @return [String]
52
+ # @example
53
+ # execute "#{resources('javascript_runtime[nodejs]').javascript_binary} myapp.js"
54
+ def javascript_binary
55
+ provider_for_action(:javascript_binary).javascript_binary
56
+ end
57
+
58
+ # The environment variables for this Javascript installation. This is an
59
+ # output property.
60
+ #
61
+ # @return [Hash<String, String>]
62
+ # @example
63
+ # execute '/opt/myapp.js' do
64
+ # environment resources('javascript_runtime[nodejs]').javascript_environment
65
+ # end
66
+ def javascript_environment
67
+ provider_for_action(:javascript_environment).javascript_environment
68
+ end
69
+
70
+ # The path to the `npm` binary for this Javascript installation. This is
71
+ # an output property. Can raise an exception if NPM is not supported for
72
+ # this runtime.
73
+ #
74
+ # @return [String]
75
+ # @example
76
+ # execute "#{resources('javascript_runtime[nodejs]').npm_binary} install"
77
+ def npm_binary
78
+ provider_for_action(:npm_binary).npm_binary
79
+ end
80
+ end
81
+
82
+ # Providers can be found under lib/poise_javascript/javascript_providers/
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,226 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/provider'
18
+ require 'chef/resource'
19
+ require 'poise'
20
+
21
+
22
+ module PoiseJavascript
23
+ module Resources
24
+ # (see JavascriptRuntimeTest::Resource)
25
+ # @since 1.0.0
26
+ # @api private
27
+ module JavascriptRuntimeTest
28
+ # A `javascript_runtime_test` resource for integration testing of this
29
+ # cookbook. This is an internal API and can change at any time.
30
+ #
31
+ # @provides javascript_runtime_test
32
+ # @action run
33
+ class Resource < Chef::Resource
34
+ include Poise
35
+ provides(:javascript_runtime_test)
36
+ actions(:run)
37
+
38
+ attribute(:version, kind_of: String, name_attribute: true)
39
+ attribute(:runtime_provider, kind_of: Symbol)
40
+ attribute(:path, kind_of: String, default: lazy { default_path })
41
+ attribute(:test_yo, equal_to: [true, false], default: true)
42
+
43
+ def default_path
44
+ ::File.join('', 'root', "javascript_test_#{name}")
45
+ end
46
+ end
47
+
48
+ # The default provider for `javascript_runtime_test`.
49
+ #
50
+ # @see Resource
51
+ # @provides javascript_runtime_test
52
+ class Provider < Chef::Provider
53
+ include Poise
54
+ provides(:javascript_runtime_test)
55
+
56
+ # The `run` action for the `javascript_runtime_test` resource.
57
+ #
58
+ # @return [void]
59
+ def action_run
60
+ notifying_block do
61
+ # Top level directory for this test.
62
+ directory new_resource.path
63
+
64
+ # Install and log the version.
65
+ javascript_runtime new_resource.name do
66
+ provider new_resource.runtime_provider if new_resource.runtime_provider
67
+ version new_resource.version
68
+ end
69
+ test_version
70
+
71
+ # Create a package and test npm_install.
72
+ pkg_path = ::File.join(new_resource.path, 'pkg')
73
+ directory pkg_path
74
+ file ::File.join(pkg_path, 'package.json') do
75
+ content <<-EOH
76
+ {
77
+ "name": "mypkg",
78
+ "version": "1.0.0",
79
+ "description": "",
80
+ "main": "index.js",
81
+ "scripts": {
82
+ "test": "echo \\"Error: no test specified\\" && exit 1"
83
+ },
84
+ "author": "",
85
+ "license": "ISC",
86
+ "dependencies": {
87
+ "express": "4.13.3"
88
+ },
89
+ "devDependencies": {
90
+ "handlebars": "4.0.2"
91
+ }
92
+ }
93
+ EOH
94
+ end
95
+ npm_install pkg_path do
96
+ notifies :create, sentinel_file('npm_install_one'), :immediately
97
+ end
98
+ npm_install pkg_path+'2' do
99
+ path pkg_path
100
+ notifies :create, sentinel_file('npm_install_two'), :immediately
101
+ end
102
+ test_require('express', pkg_path)
103
+ test_require('handlebars', pkg_path)
104
+
105
+ # Test node_package.
106
+ test1_path = ::File.join(new_resource.path, 'test1')
107
+ directory test1_path
108
+ node_package 'express' do
109
+ path test1_path
110
+ notifies :create, sentinel_file('test1_express_one'), :immediately
111
+ end
112
+ node_package 'express two' do
113
+ package_name 'express'
114
+ path test1_path
115
+ notifies :create, sentinel_file('test1_express_two'), :immediately
116
+ end
117
+ node_package %w{gulp less} do
118
+ path test1_path
119
+ notifies :create, sentinel_file('test1_multi'), :immediately
120
+ end
121
+ node_package %w{express bower} do
122
+ path test1_path
123
+ notifies :create, sentinel_file('test1_multi_overlap'), :immediately
124
+ end
125
+ node_package 'bower' do
126
+ path test1_path
127
+ notifies :create, sentinel_file('test1_bower'), :immediately
128
+ end
129
+ node_package 'yo' do
130
+ path test1_path
131
+ version '1.4.5'
132
+ end if new_resource.test_yo
133
+ node_package 'forever' do
134
+ path test1_path
135
+ version '0.13.0'
136
+ end
137
+ test_require('express', test1_path, 'node_package_express')
138
+ test_require('gulp', test1_path)
139
+ test_require('less', test1_path)
140
+ test_require('bower', test1_path)
141
+ if new_resource.test_yo
142
+ test_require('yo', test1_path)
143
+ else
144
+ file ::File.join(new_resource.path, 'no_yo')
145
+ end
146
+ test_require('forever', test1_path)
147
+
148
+ # Check we don't get cross talk between paths.
149
+ test2_path = ::File.join(new_resource.path, 'test2')
150
+ directory test2_path
151
+ node_package 'express' do
152
+ path test2_path
153
+ notifies :create, sentinel_file('test2_express'), :immediately
154
+ end
155
+
156
+ # Test global installs.
157
+ node_package 'grunt-cli' do
158
+ notifies :create, sentinel_file('grunt_one'), :immediately
159
+ end
160
+ node_package 'grunt-cli two' do
161
+ package_name 'grunt-cli'
162
+ notifies :create, sentinel_file('grunt_two'), :immediately
163
+ end
164
+ test_require('grunt-cli', new_resource.path)
165
+ javascript_execute 'grunt-cli --version' do
166
+ command lazy {
167
+ # Check local/bin first and then just bin/.
168
+ grunt_path = ::File.expand_path('../../local/bin/grunt', javascript)
169
+ grunt_path = ::File.expand_path('../grunt', javascript) unless ::File.exist?(grunt_path)
170
+ "#{grunt_path} --version > #{::File.join(new_resource.path, 'grunt_version')}"
171
+ }
172
+ end
173
+
174
+ end
175
+ end
176
+
177
+ def sentinel_file(name)
178
+ file ::File.join(new_resource.path, "sentinel_#{name}") do
179
+ action :nothing
180
+ end
181
+ end
182
+
183
+ private
184
+
185
+ def test_version(javascript: new_resource.name)
186
+ # Only queue up this resource once, the ivar is just for tracking.
187
+ @javascript_version_test ||= file ::File.join(new_resource.path, 'javascript_version.js') do
188
+ user 'root'
189
+ group 'root'
190
+ mode '644'
191
+ content <<-EOH
192
+ var fs = require('fs');
193
+ fs.writeFileSync(process.argv[2], process.version);
194
+ EOH
195
+ end
196
+
197
+ javascript_execute "#{@javascript_version_test.path} #{::File.join(new_resource.path, 'version')}" do
198
+ javascript javascript if javascript
199
+ end
200
+ end
201
+
202
+ def test_require(name, cwd, path=name, javascript: new_resource.name)
203
+ javascript_require_test = file ::File.join(cwd, 'javascript_require.js') do
204
+ user 'root'
205
+ group 'root'
206
+ mode '644'
207
+ content <<-EOH
208
+ var fs = require('fs');
209
+ try {
210
+ var version = require(process.argv[2] + '/package.json').version;
211
+ fs.writeFileSync(process.argv[3], version);
212
+ } catch(e) {
213
+ }
214
+ EOH
215
+ end
216
+
217
+ javascript_execute "#{javascript_require_test.path} #{name} #{::File.join(new_resource.path, "require_#{path}")}" do
218
+ javascript javascript if javascript
219
+ cwd cwd
220
+ end
221
+ end
222
+
223
+ end
224
+ end
225
+ end
226
+ end