poise-application-javascript 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.kitchen.travis.yml +9 -0
  4. data/.kitchen.yml +9 -0
  5. data/.travis.yml +20 -0
  6. data/.yardopts +7 -0
  7. data/Berksfile +35 -0
  8. data/CHANGELOG.md +5 -0
  9. data/Gemfile +37 -0
  10. data/LICENSE +201 -0
  11. data/README.md +132 -0
  12. data/Rakefile +17 -0
  13. data/SUPPORTERS.md +81 -0
  14. data/lib/poise_application_javascript.rb +23 -0
  15. data/lib/poise_application_javascript/app_mixin.rb +67 -0
  16. data/lib/poise_application_javascript/cheftie.rb +17 -0
  17. data/lib/poise_application_javascript/error.rb +25 -0
  18. data/lib/poise_application_javascript/resources.rb +22 -0
  19. data/lib/poise_application_javascript/resources/javascript.rb +64 -0
  20. data/lib/poise_application_javascript/resources/javascript_execute.rb +88 -0
  21. data/lib/poise_application_javascript/resources/javascript_service.rb +59 -0
  22. data/lib/poise_application_javascript/resources/node_package.rb +63 -0
  23. data/lib/poise_application_javascript/resources/npm_install.rb +45 -0
  24. data/lib/poise_application_javascript/resources/npm_start.rb +78 -0
  25. data/lib/poise_application_javascript/service_mixin.rb +57 -0
  26. data/lib/poise_application_javascript/version.rb +19 -0
  27. data/poise-application-javascript.gemspec +45 -0
  28. data/test/cookbooks/application_javascript_test/attributes/default.rb +17 -0
  29. data/test/cookbooks/application_javascript_test/metadata.rb +20 -0
  30. data/test/cookbooks/application_javascript_test/recipes/default.rb +32 -0
  31. data/test/cookbooks/application_javascript_test/recipes/express.rb +22 -0
  32. data/test/gemfiles/chef-12.gemfile +19 -0
  33. data/test/gemfiles/master.gemfile +27 -0
  34. data/test/integration/default/serverspec/default_spec.rb +34 -0
  35. data/test/integration/default/serverspec/express_spec.rb +47 -0
  36. data/test/spec/app_mixin_spec.rb +69 -0
  37. data/test/spec/resources/javascript_execute_spec.rb +46 -0
  38. data/test/spec/resources/javascript_service_spec.rb +28 -0
  39. data/test/spec/resources/javascript_spec.rb +44 -0
  40. data/test/spec/resources/npm_install_spec.rb +28 -0
  41. data/test/spec/resources/npm_start_spec.rb +38 -0
  42. data/test/spec/spec_helper.rb +18 -0
  43. metadata +204 -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,81 @@
1
+ # Supporters
2
+
3
+ This cookbook wouldn't have been possible without the generous support of my
4
+ Kickstarter backers. Thanks so much to every one of you!
5
+
6
+ * @kcunning
7
+ * Alberto Lorenzo Pulido
8
+ * Alex Gaynor
9
+ * Alexander Myasnikov
10
+ * Brooke Schreier Ganz
11
+ * Bryan McLellan
12
+ * Charles Johnson
13
+ * Chef Software, Inc.
14
+ * Chris Adams
15
+ * Christopher Petrilli
16
+ * David Thornton
17
+ * Derek Murawsky
18
+ * Fast Robot, LLC
19
+ * Fatty McAwesome Pants (Kate Heddleston)
20
+ * Greg Albrecht
21
+ * JD Harrington
22
+ * Jake Plimack
23
+ * Jason Cook
24
+ * Jeff Byrnes
25
+ * Jeff Forcier
26
+ * Jeff Lindsay
27
+ * Jennifer Davis
28
+ * John Fitch
29
+ * Jon Stacks
30
+ * Joshua SS Miller
31
+ * Julian Dunn
32
+ * Julien Phalip
33
+ * Kennon Kwok
34
+ * Kevin Duane
35
+ * Krzysztof Wilczynski
36
+ * Linda Goldstein
37
+ * Manny Toledo
38
+ * Marco A Morales
39
+ * Marcus Morris
40
+ * Mark Luntzel
41
+ * Martin B. Smith
42
+ * Mathieu Sauve-Frankel
43
+ * Matt Good
44
+ * Matt Juszczak
45
+ * Matt Ray
46
+ * Matt Stratton
47
+ * Michael Burns
48
+ * Miguel Landaeta
49
+ * Mike Schueler
50
+ * Nathan L Smith
51
+ * Nathen Harvey
52
+ * Paul Welch
53
+ * Peter Kropf
54
+ * Phil Mocek
55
+ * Practice Fusion Inc
56
+ * Ranjib
57
+ * Richard Jones
58
+ * Robert J. Berger
59
+ * Robin Levin
60
+ * Roland Moriz
61
+ * Ruben Orduz
62
+ * Russell Keith-Magee
63
+ * Ryan Hass
64
+ * Sam Clements
65
+ * Sean OMeara
66
+ * Seva Feldman
67
+ * Soo Choi
68
+ * Steven Danna
69
+ * Symonds & Son
70
+ * Todd Michael Bushnell
71
+ * Tracy Osborn
72
+ * Troy Ready
73
+ * Tyler Ball
74
+ * Vicky Tuite
75
+ * Ying Li
76
+ * Yvo van Doorn
77
+ * Zac Stevens
78
+ * lvh
79
+ * oolongtea
80
+ * smeuser
81
+ * tmonk42
@@ -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
+
18
+ module PoiseApplicationJavascript
19
+ autoload :AppMixin, 'poise_application_javascript/app_mixin'
20
+ autoload :Error, 'poise_application_javascript/error'
21
+ autoload :Resources, 'poise_application_javascript/resources'
22
+ autoload :VERSION, 'poise_application_javascript/version'
23
+ end
@@ -0,0 +1,67 @@
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/backports'
18
+ require 'poise/utils'
19
+ require 'poise_application/app_mixin'
20
+ require 'poise_javascript/javascript_command_mixin'
21
+
22
+
23
+ module PoiseApplicationJavascript
24
+ # A helper mixin for Javascript application resources and providers.
25
+ #
26
+ # @since 4.0.0
27
+ module AppMixin
28
+ include Poise::Utils::ResourceProviderMixin
29
+
30
+ # A helper mixin for Javascript application resources.
31
+ module Resource
32
+ include PoiseApplication::AppMixin::Resource
33
+ include PoiseJavascript::JavascriptCommandMixin::Resource
34
+
35
+ # @!attribute parent_javascript
36
+ # Override the #parent_javascript from JavascriptCommandMixin to grok the
37
+ # application level parent as a default value.
38
+ # @return [PoiseJavascript::Resources::JavascriptRuntime::Resource, nil]
39
+ parent_attribute(:javascript, type: :javascript_runtime, optional: true, default: lazy { app_state_javascript.equal?(self) ? nil : app_state_javascript })
40
+
41
+ # @attribute app_state_javascript
42
+ # The application-level Javascript parent.
43
+ # @return [PoiseJavascript::Resources::JavascriptRuntime::Resource, nil]
44
+ def app_state_javascript(javascript=Poise::NOT_PASSED)
45
+ unless javascript == Poise::NOT_PASSED
46
+ app_state[:javascript] = javascript
47
+ end
48
+ app_state[:javascript]
49
+ end
50
+
51
+ # A merged hash of environment variables for both the application state
52
+ # and parent javascript.
53
+ #
54
+ # @return [Hash<String, String>]
55
+ def app_state_environment_javascript
56
+ env = app_state_environment
57
+ env = env.merge(parent_javascript.javascript_environment) if parent_javascript
58
+ env
59
+ end
60
+ end
61
+
62
+ # A helper mixin for Javascript application providers.
63
+ module Provider
64
+ include PoiseApplication::AppMixin::Provider
65
+ end
66
+ end
67
+ end
@@ -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_application_javascript/resources'
@@ -0,0 +1,25 @@
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_application/error'
18
+
19
+ module PoiseApplicationJavascript
20
+ # Base exception class for poise-application-javascript errors.
21
+ #
22
+ # @since 1.0.0
23
+ class Error < PoiseApplication::Error
24
+ end
25
+ end
@@ -0,0 +1,22 @@
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_application_javascript/resources/javascript'
18
+ require 'poise_application_javascript/resources/javascript_execute'
19
+ require 'poise_application_javascript/resources/javascript_service'
20
+ require 'poise_application_javascript/resources/node_package'
21
+ require 'poise_application_javascript/resources/npm_install'
22
+ require 'poise_application_javascript/resources/npm_start'
@@ -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 'poise_javascript/resources/javascript_runtime'
18
+
19
+ require 'poise_application_javascript/app_mixin'
20
+
21
+
22
+ module PoiseApplicationJavascript
23
+ module Resources
24
+ # (see Javascript::Resource)
25
+ # @since 1.0.0
26
+ module Javascript
27
+ # An `application_javascript` resource to manage Javascript runtimes
28
+ # inside an Application cookbook deployment.
29
+ #
30
+ # @provides application_javascript
31
+ # @provides application_javascript_runtime
32
+ # @action install
33
+ # @action uninstall
34
+ # @example
35
+ # application '/app' do
36
+ # javascript '3'
37
+ # end
38
+ class Resource < PoiseJavascript::Resources::JavascriptRuntime::Resource
39
+ include PoiseApplicationJavascript::AppMixin
40
+ provides(:application_javascript)
41
+ # Need the double javascript for application resource rewriting.
42
+ provides(:application_javascript_runtime)
43
+ container_default(false)
44
+ subclass_providers!
45
+
46
+ # We want to run the base class version of this, not the one from the
47
+ # mixin. HULK SMASH.
48
+ def npm_binary
49
+ self.class.superclass.instance_method(:npm_binary).bind(self).call
50
+ end
51
+
52
+ # Set this resource as the app_state's parent javascript.
53
+ #
54
+ # @api private
55
+ def after_created
56
+ super.tap do |val|
57
+ app_state_javascript(self)
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,88 @@
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
+
19
+ require 'poise_application_javascript/app_mixin'
20
+
21
+
22
+ module PoiseApplicationJavascript
23
+ module Resources
24
+ # (see JavascriptExecute::Resource)
25
+ # @since 1.0.0
26
+ module JavascriptExecute
27
+ # An `application_javascript_execute` resource to run Javascript commands inside an
28
+ # Application cookbook deployment.
29
+ #
30
+ # @provides application_javascript_execute
31
+ # @action run
32
+ # @example
33
+ # application '/srv/myapp' do
34
+ # javascript_execute 'setup.py install'
35
+ # end
36
+ class Resource < PoiseJavascript::Resources::JavascriptExecute::Resource
37
+ include PoiseApplicationJavascript::AppMixin
38
+ provides(:application_javascript_execute)
39
+ def initialize(*args)
40
+ super
41
+ # Clear some instance variables so my defaults work.
42
+ remove_instance_variable(:@cwd)
43
+ remove_instance_variable(:@group)
44
+ remove_instance_variable(:@user)
45
+ end
46
+
47
+ # #!attribute cwd
48
+ # Override the default directory to be the app path if unspecified.
49
+ # @return [String]
50
+ attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path })
51
+
52
+ # #!attribute group
53
+ # Override the default group to be the app group if unspecified.
54
+ # @return [String, Integer]
55
+ attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
56
+
57
+ # #!attribute user
58
+ # Override the default user to be the app owner if unspecified.
59
+ # @return [String, Integer]
60
+ attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
61
+ end
62
+
63
+ # The default provider for `application_javascript_execute`.
64
+ #
65
+ # @see Resource
66
+ # @provides application_javascript_execute
67
+ class Provider < PoiseJavascript::Resources::JavascriptExecute::Provider
68
+ provides(:application_javascript_execute)
69
+
70
+ private
71
+
72
+ # Override environment to add the application envivonrment instead.
73
+ #
74
+ # @return [Hash]
75
+ def environment
76
+ super.tap do |environment|
77
+ # Don't use the app_state_environment_javascript because we already have
78
+ # those values in place.
79
+ environment.update(new_resource.app_state_environment)
80
+ # Re-apply the resource environment for correct ordering.
81
+ environment.update(new_resource.environment) if new_resource.environment
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,59 @@
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
+ require 'poise_application_javascript/service_mixin'
22
+
23
+
24
+ module PoiseApplicationJavascript
25
+ module Resources
26
+ # (see JavascriptService::Resource)
27
+ # @since 1.0.0
28
+ module JavascriptService
29
+ class Resource < Chef::Resource
30
+ include PoiseApplicationJavascript::ServiceMixin
31
+ provides(:application_javascript_service)
32
+
33
+ # @!attribute command
34
+ # Command to run.
35
+ # @return [String]
36
+ attribute(:command, kind_of: String, name_attribute: true)
37
+ # @!attribute path
38
+ # Override {PoiseApplicationJavascript::ServiceMixin#path} to make it
39
+ # not the name_attribute.
40
+ # @return [String]
41
+ attribute(:path, kind_of: String, default: lazy { parent && parent.path })
42
+ end
43
+
44
+ class Provider < Chef::Provider
45
+ include PoiseApplicationJavascript::ServiceMixin
46
+ provides(:application_javascript_service)
47
+
48
+ private
49
+
50
+ # (see PoiseApplication::ServiceMixin#service_options)
51
+ def service_options(resource)
52
+ super
53
+ resource.javascript_command(new_resource.command)
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end