guard-preserves 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/guard-preserves.gemspec +25 -0
- data/lib/guard/preserves.rb +118 -0
- data/lib/guard/preserves/version.rb +5 -0
- metadata +104 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Rebel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Guard::Preserves
|
2
|
+
|
3
|
+
This gem allows you to make changes to files in the preserves repository and
|
4
|
+
have those changes automatically compiled if in a coffeescript file. The
|
5
|
+
resulting files will then be copied to a directory with the same name as the
|
6
|
+
modified package located in the directory specified by the `destination`
|
7
|
+
option.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'guard-preserves'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The `destination` must be provided. An optional `app_root` can be set, but
|
22
|
+
defaults to the location of the Guardfile. If no watch is provided, all
|
23
|
+
`.js` and `.coffee` files in the directory will be watched.
|
24
|
+
|
25
|
+
````ruby
|
26
|
+
guard 'preserves', destination: 'public/foo/lib' do
|
27
|
+
#optional watch('foo/src/foo.coffee')
|
28
|
+
end
|
29
|
+
````
|
30
|
+
|
31
|
+
To start the guard run:
|
32
|
+
|
33
|
+
````
|
34
|
+
bundle exec guard --watchdir [absolute path to directory to watch] --guardfile [absolute path to directory with guardfile]
|
35
|
+
````
|
36
|
+
|
37
|
+
For example, given a Rails application named 'cool-stuff' in the same parent
|
38
|
+
directory as the preserves repo with the jam assets stored in
|
39
|
+
`app/assets/javascripts/lib` with a Guardfile named
|
40
|
+
`Preserves-Guardfile` that looks like
|
41
|
+
|
42
|
+
````
|
43
|
+
guard 'preserves', destination: 'app/assets/javascripts/lib'
|
44
|
+
````
|
45
|
+
|
46
|
+
run `bundle exec guard --watchdir ~/source/preserves --guardfile ~/source/cool-stuff/Preserves-Guardfile` to start the guard.
|
47
|
+
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'guard/preserves/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "guard-preserves"
|
8
|
+
spec.version = Guard::PreservesVersion::VERSION
|
9
|
+
spec.authors = ["Chris Rebel", "Colin Rymer"]
|
10
|
+
spec.email = ["chrebel@gmail.com", "colin.rymer@gmail.com"]
|
11
|
+
spec.description = %q{This gem provides a guard plug-in to watch the Preserves repo and compile/copy js files to the project it is included in.}
|
12
|
+
spec.summary = %q{Preserves compiler/copier guard plugin}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'guard'
|
25
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'json'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module Guard
|
7
|
+
class Preserves < Guard
|
8
|
+
attr_reader :app_root, :destination
|
9
|
+
# Initializes a Guard plugin.
|
10
|
+
# Don't do any work here, especially as Guard plugins get initialized even if they are not in an active group!
|
11
|
+
#
|
12
|
+
# @param [Array<Guard::Watcher>] watchers the Guard plugin file watchers
|
13
|
+
# @param [Hash] options the custom Guard plugin options
|
14
|
+
# @option options [Symbol] group the group this Guard plugin belongs to
|
15
|
+
# @option options [Boolean] any_return allow any object to be returned from a watcher
|
16
|
+
#
|
17
|
+
def initialize(watchers = [], options = {})
|
18
|
+
@destination = options[:destination]
|
19
|
+
@app_root = options[:app_root] || File.dirname(::Guard.options[:guardfile])
|
20
|
+
watchers = [::Guard::Watcher.new(%r{^.+\.(js|coffee)$})] if watchers.empty?
|
21
|
+
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
# Called once when Guard starts. Please override initialize method to init stuff.
|
26
|
+
#
|
27
|
+
# @raise [:task_has_failed] when start has failed
|
28
|
+
# @return [Object] the task result
|
29
|
+
#
|
30
|
+
def start
|
31
|
+
end
|
32
|
+
|
33
|
+
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
|
34
|
+
#
|
35
|
+
# @raise [:task_has_failed] when stop has failed
|
36
|
+
# @return [Object] the task result
|
37
|
+
#
|
38
|
+
def stop
|
39
|
+
end
|
40
|
+
|
41
|
+
# Called when `reload|r|z + enter` is pressed.
|
42
|
+
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
43
|
+
#
|
44
|
+
# @raise [:task_has_failed] when reload has failed
|
45
|
+
# @return [Object] the task result
|
46
|
+
#
|
47
|
+
def reload
|
48
|
+
end
|
49
|
+
|
50
|
+
# Called when just `enter` is pressed
|
51
|
+
# This method should be principally used for long action like running all specs/tests/...
|
52
|
+
#
|
53
|
+
# @raise [:task_has_failed] when run_all has failed
|
54
|
+
# @return [Object] the task result
|
55
|
+
#
|
56
|
+
def run_all
|
57
|
+
end
|
58
|
+
|
59
|
+
# Default behaviour on file(s) changes that the Guard plugin watches.
|
60
|
+
# @param [Array<String>] paths the changes files or paths
|
61
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
62
|
+
# @return [Object] the task result
|
63
|
+
#
|
64
|
+
def run_on_changes(paths)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Called on file(s) additions that the Guard plugin watches.
|
68
|
+
#
|
69
|
+
# @param [Array<String>] paths the changes files or paths
|
70
|
+
# @raise [:task_has_failed] when run_on_additions has failed
|
71
|
+
# @return [Object] the task result
|
72
|
+
#
|
73
|
+
def run_on_additions(paths)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Called on file(s) modifications that the Guard plugin watches.
|
77
|
+
#
|
78
|
+
# @param [Array<String>] paths the changes files or paths
|
79
|
+
# @raise [:task_has_failed] when run_on_modifications has failed
|
80
|
+
# @return [Object] the task result
|
81
|
+
#
|
82
|
+
def run_on_modifications(paths)
|
83
|
+
paths.each do |path|
|
84
|
+
package = package_name(path)
|
85
|
+
compile_package package if File.extname(path) == '.coffee'
|
86
|
+
copy_package package if File.extname(path) == '.js'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Called on file(s) removals that the Guard plugin watches.
|
91
|
+
#
|
92
|
+
# @param [Array<String>] paths the changes files or paths
|
93
|
+
# @raise [:task_has_failed] when run_on_removals has failed
|
94
|
+
# @return [Object] the task result
|
95
|
+
#
|
96
|
+
def run_on_removals(paths)
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
def package_name(path)
|
101
|
+
path.split('/').first
|
102
|
+
end
|
103
|
+
|
104
|
+
def compile_package(package)
|
105
|
+
::Guard::UI.info "Compiling #{package}"
|
106
|
+
Dir.chdir package
|
107
|
+
`coffee -c --output ./ src/`
|
108
|
+
Dir.chdir '..'
|
109
|
+
end
|
110
|
+
|
111
|
+
def copy_package(package)
|
112
|
+
package_destination = File.join(app_root, destination, package)
|
113
|
+
::Guard::UI.info "Copying #{package} to #{package_destination}"
|
114
|
+
FileUtils.mkdir_p package_destination
|
115
|
+
FileUtils.cp_r("#{package}/.", package_destination)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-preserves
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Rebel
|
9
|
+
- Colin Rymer
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
none: false
|
22
|
+
name: bundler
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
requirement: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
none: false
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
none: false
|
38
|
+
name: rake
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
none: false
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
none: false
|
54
|
+
name: guard
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
none: false
|
63
|
+
description: This gem provides a guard plug-in to watch the Preserves repo and compile/copy
|
64
|
+
js files to the project it is included in.
|
65
|
+
email:
|
66
|
+
- chrebel@gmail.com
|
67
|
+
- colin.rymer@gmail.com
|
68
|
+
executables: []
|
69
|
+
extensions: []
|
70
|
+
extra_rdoc_files: []
|
71
|
+
files:
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- guard-preserves.gemspec
|
77
|
+
- lib/guard/preserves.rb
|
78
|
+
- lib/guard/preserves/version.rb
|
79
|
+
homepage: ''
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
none: false
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
none: false
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.23
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Preserves compiler/copier guard plugin
|
104
|
+
test_files: []
|