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,17 @@
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_boiler/rakefile'
@@ -0,0 +1,23 @@
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
+ # Default inversion options.
18
+ default['poise-javascript']['provider'] = 'auto'
19
+ default['poise-javascript']['options'] = {}
20
+
21
+ # Used for the default recipe.
22
+ default['poise-javascript']['install_nodejs'] = true
23
+ default['poise-javascript']['install_iojs'] = false
@@ -0,0 +1,19 @@
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
+ # Default runtimes, last one will be the default.
18
+ javascript_runtime 'iojs' if node['poise-javascript']['install_iojs']
19
+ javascript_runtime 'nodejs' if node['poise-javascript']['install_nodejs']
@@ -0,0 +1,24 @@
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
+
18
+ module PoiseJavascript
19
+ autoload :Error, 'poise_javascript/error'
20
+ autoload :Resources, 'poise_javascript/resources'
21
+ autoload :JavascriptCommandMixin, 'poise_javascript/javascript_command_mixin'
22
+ autoload :JavascriptProviders, 'poise_javascript/javascript_providers'
23
+ autoload :VERSION, 'poise_javascript/version'
24
+ end
@@ -0,0 +1,18 @@
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'
18
+ require 'poise_javascript/javascript_providers'
@@ -0,0 +1,23 @@
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_languages'
18
+
19
+
20
+ module PoiseJavascript
21
+ class Error < PoiseLanguages::Error
22
+ end
23
+ end
@@ -0,0 +1,56 @@
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/utils'
18
+ require 'poise_languages'
19
+
20
+
21
+ module PoiseJavascript
22
+ # Mixin for resources and providers which run Javascript commands.
23
+ #
24
+ # @since 1.0.0
25
+ module JavascriptCommandMixin
26
+ include Poise::Utils::ResourceProviderMixin
27
+
28
+ # Mixin for resources which run Javascript commands.
29
+ module Resource
30
+ include PoiseLanguages::Command::Mixin::Resource(:javascript, default_binary: 'node')
31
+
32
+ # @!attribute npm_binary
33
+ # Path to the npm binary.
34
+ # @return [String]
35
+ attribute(:npm_binary, kind_of: String, default: lazy { default_npm_binary })
36
+
37
+ private
38
+
39
+ # Find the default gem binary. If there is a parent use that, otherwise
40
+ # use the same logic as {PoiseRuby::RubyProviders::Base#npm_binary}.
41
+ #
42
+ # @return [String]
43
+ def default_npm_binary
44
+ if parent_javascript
45
+ parent_javascript.npm_binary
46
+ else
47
+ ::File.expand_path('../npm', javascript)
48
+ end
49
+ end
50
+ end
51
+
52
+ module Provider
53
+ include PoiseLanguages::Command::Mixin::Provider(:javascript)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,40 @@
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/platform/provider_priority_map'
18
+
19
+ require 'poise_javascript/javascript_providers/dummy'
20
+ require 'poise_javascript/javascript_providers/iojs'
21
+ require 'poise_javascript/javascript_providers/nodejs'
22
+ require 'poise_javascript/javascript_providers/scl'
23
+ require 'poise_javascript/javascript_providers/system'
24
+
25
+
26
+ module PoiseJavascript
27
+ # Inversion providers for the javascript_runtime resource.
28
+ #
29
+ # @since 1.0.0
30
+ module JavascriptProviders
31
+ autoload :Base, 'poise_javascript/javascript_providers/base'
32
+
33
+ Chef::Platform::ProviderPriorityMap.instance.priority(:javascript_runtime, [
34
+ PoiseJavascript::JavascriptProviders::IOJS,
35
+ PoiseJavascript::JavascriptProviders::NodeJS,
36
+ PoiseJavascript::JavascriptProviders::Scl,
37
+ PoiseJavascript::JavascriptProviders::System,
38
+ ])
39
+ end
40
+ end
@@ -0,0 +1,97 @@
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 'poise'
19
+
20
+
21
+ module PoiseJavascript
22
+ module JavascriptProviders
23
+ class Base < Chef::Provider
24
+ include Poise(inversion: :javascript_runtime)
25
+
26
+ # Set default inversion options.
27
+ #
28
+ # @api private
29
+ def self.default_inversion_options(node, new_resource)
30
+ super.merge({
31
+ version: new_resource.version,
32
+ })
33
+ end
34
+
35
+ # The `install` action for the `javascript_runtime` resource.
36
+ #
37
+ # @return [void]
38
+ def action_install
39
+ notifying_block do
40
+ install_javascript
41
+ end
42
+ end
43
+
44
+ # The `uninstall` action for the `javascript_runtime` resource.
45
+ #
46
+ # @abstract
47
+ # @return [void]
48
+ def action_uninstall
49
+ notifying_block do
50
+ uninstall_javascript
51
+ end
52
+ end
53
+
54
+ # The path to the `javascript` binary. This is an output property.
55
+ #
56
+ # @abstract
57
+ # @return [String]
58
+ def javascript_binary
59
+ raise NotImplementedError
60
+ end
61
+
62
+ # The environment variables for this Javascript. This is an output property.
63
+ #
64
+ # @return [Hash<String, String>]
65
+ def javascript_environment
66
+ {}
67
+ end
68
+
69
+ # The path to the `npm` binary. This is an output property.
70
+ #
71
+ # @abstract
72
+ # @return [String]
73
+ def npm_binary
74
+ ::File.expand_path(::File.join('..', 'npm'), javascript_binary)
75
+ end
76
+
77
+ private
78
+
79
+ # Install the Javascript runtime. Must be implemented by subclass.
80
+ #
81
+ # @abstract
82
+ # @return [void]
83
+ def install_javascript
84
+ raise NotImplementedError
85
+ end
86
+
87
+ # Uninstall the Javascript runtime. Must be implemented by subclass.
88
+ #
89
+ # @abstract
90
+ # @return [void]
91
+ def uninstall_javascript
92
+ raise NotImplementedError
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,77 @@
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/javascript_providers/base'
18
+
19
+
20
+ module PoiseJavascript
21
+ module JavascriptProviders
22
+ # Inversion provider for the `javascript_runtime` resource to use a fake Javascript,
23
+ # for use in unit tests.
24
+ #
25
+ # @since 1.0.0
26
+ # @provides dummy
27
+ class Dummy < Base
28
+ provides(:dummy)
29
+
30
+ def self.default_inversion_options(node, resource)
31
+ super.merge({
32
+ # Manual overrides for dummy data.
33
+ javascript_binary: ::File.join('', 'node'),
34
+ javascript_environment: nil,
35
+ npm_binary: nil,
36
+ })
37
+ end
38
+
39
+ # The `install` action for the `javascript_runtime` resource.
40
+ #
41
+ # @return [void]
42
+ def action_install
43
+ # This space left intentionally blank.
44
+ end
45
+
46
+ # The `uninstall` action for the `javascript_runtime` resource.
47
+ #
48
+ # @return [void]
49
+ def action_uninstall
50
+ # This space left intentionally blank.
51
+ end
52
+
53
+ # Path to the non-existent Javascript.
54
+ #
55
+ # @return [String]
56
+ def javascript_binary
57
+ options['javascript_binary']
58
+ end
59
+
60
+ # Environment for the non-existent Javascript.
61
+ #
62
+ # @return [String]
63
+ def javascript_environment
64
+ options['javascript_environment'] || super
65
+ end
66
+
67
+ # Path to the non-existent npm.
68
+ #
69
+ # @return [String]
70
+ def npm_binary
71
+ options['npm_binary'] || super
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+
@@ -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 IOJS < Base
27
+ provides(:iojs)
28
+ include PoiseLanguages::Static(
29
+ versions: %w{3.2.0 3.1.0 3.0.0 2.5.0 2.4.0 2.3.4 2.2.1 2.1.0 2.0.2 1.8.4 1.7.1 1.6.4 1.5.1 1.4.3 1.3.0 1.2.0 1.1.0 1.0.4},
30
+ machines: %w{linux-i686 linux-x86_64 darwin-x86_64},
31
+ url: 'https://iojs.org/dist/v%{version}/iojs-v%{version}-%{kernel}-%{machine}.tar.gz',
32
+ )
33
+
34
+ def self.provides_auto?(node, resource)
35
+ # Also work if we have a version starting with 1. 2. or 3. since that has
36
+ # to be io.js and no other mechanism supports that.
37
+ super || (resource.version.to_s =~ /^[123](\.|$)/ && 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', 'iojs')
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
+