guard-xcoder 0.1.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.
- data/LICENSE +20 -0
- data/README.md +59 -0
- data/lib/guard/xcoder.rb +142 -0
- data/lib/guard/xcoder/templates/Guardfile +24 -0
- metadata +94 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Franklin Webber
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Guard-Shell
|
2
|
+
|
3
|
+
This little addition (1 proper line of code!) to guard allows you to run shell
|
4
|
+
commands when certain files are altered.
|
5
|
+
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
Make sure you have [guard](http://github.com/guard/guard) installed.
|
10
|
+
|
11
|
+
Install the gem with:
|
12
|
+
|
13
|
+
gem install guard-shell
|
14
|
+
|
15
|
+
Add it to your Gemfile:
|
16
|
+
|
17
|
+
gem 'guard-shell'
|
18
|
+
|
19
|
+
And then add a basic setup to your Guardfile:
|
20
|
+
|
21
|
+
guard init shell
|
22
|
+
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
If you can do something in your shell, it is probably very easy to setup with guard-shell, here are a few examples.
|
27
|
+
|
28
|
+
|
29
|
+
#### Creating Backups of Files On Change
|
30
|
+
|
31
|
+
guard 'shell' do
|
32
|
+
# create a copy of the file with '.backup' at the end
|
33
|
+
watch('(.*)') {|m| `cp #{m[0]} #{m[0]}.backup` }
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
#### Showing git st
|
38
|
+
|
39
|
+
guard 'shell' do
|
40
|
+
watch('.*') { `git st` }
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#### Rebuilding a LaTeX File
|
45
|
+
|
46
|
+
guard 'shell' do
|
47
|
+
# builds latex file to pdf and hides output
|
48
|
+
watch('(.*).tex') do |m|
|
49
|
+
`pdflatex -shell-escape #{m[0]} 1>/dev/null`
|
50
|
+
puts "built #{m[1]}.pdf"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
#### Saying the Name of the File You Changed
|
56
|
+
|
57
|
+
guard 'shell' do
|
58
|
+
watch('(.*)') {|m| `say #{m[0]}` }
|
59
|
+
end
|
data/lib/guard/xcoder.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'xcoder'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class Xcoder < Guard
|
7
|
+
|
8
|
+
VERSION = '0.1.0'
|
9
|
+
|
10
|
+
def default_builder_actions
|
11
|
+
[ :build ]
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_paths
|
15
|
+
[ '.' ]
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(watchers=[], options = {})
|
19
|
+
@options = {
|
20
|
+
:actions => default_builder_actions,
|
21
|
+
:paths => default_paths,
|
22
|
+
}.update(options)
|
23
|
+
|
24
|
+
@paths = @options[:paths]
|
25
|
+
file_watchers = file_watchers_for_project_watchers watchers
|
26
|
+
watchers.replace file_watchers
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
projects
|
33
|
+
UI.info "[Guard::Xcoder] is now monitoring #{projects.map {|p| p.name }.join(", ")}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_all
|
37
|
+
|
38
|
+
projects.each do |project|
|
39
|
+
project.targets.each do |target|
|
40
|
+
config = target.config('Debug')
|
41
|
+
UI.info(("*" * 80))
|
42
|
+
UI.info "Building #{project.name} - #{target.name} - #{config.name}"
|
43
|
+
UI.info(("*" * 80))
|
44
|
+
config.builder.build
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# @param [Array<String>] commands to execute
|
52
|
+
#
|
53
|
+
def run_on_change(commands)
|
54
|
+
|
55
|
+
project_name, target_name, config_name = commands.first.split("//")
|
56
|
+
builder = Xcode.project(project_name).target(target_name).config(config_name).builder
|
57
|
+
|
58
|
+
UI.info "[Guard::Xcoder] Performing [ #{@options[:actions].join(", ")} ] for #{project_name} > #{target_name} > #{config_name}"
|
59
|
+
|
60
|
+
Array(@options[:actions]).each do |operation|
|
61
|
+
builder.send(operation)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def projects
|
67
|
+
@project ||= begin
|
68
|
+
# TODO: projects found multiple times will be duplicated.
|
69
|
+
@paths.map {|path| Xcode.find_projects path }.flatten.compact
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# @param [Array<Watcher>] watchers the existing watchers defined within the Guardfile that specify the path the project, target,
|
75
|
+
# and config.
|
76
|
+
# @return [Array<Watcher>] a new list of watchers for every file within the matching project > target. Each watcher when matched
|
77
|
+
# will return a path to the project//target//config that needs to be built.
|
78
|
+
#
|
79
|
+
def file_watchers_for_project_watchers(watchers)
|
80
|
+
|
81
|
+
watchers.map do |watcher|
|
82
|
+
watchers_for_source_files_in(watcher.pattern)
|
83
|
+
end.flatten.compact
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def watchers_for_source_files_in pattern
|
88
|
+
|
89
|
+
targets_in_path(pattern).map do |target|
|
90
|
+
|
91
|
+
# TODO: this is currently hard-coded to Debug configuration, though the user can specify Release
|
92
|
+
|
93
|
+
build_action = lambda { "#{target.project.name}//#{target.name}//Debug" }
|
94
|
+
|
95
|
+
project_root_dir = File.join(File.dirname(target.project.path), target.name)
|
96
|
+
|
97
|
+
# Create a watcher for all source build files specified within the target
|
98
|
+
|
99
|
+
new_guards = target.sources_build_phase.build_files.map do |file|
|
100
|
+
full_source_path = File.join(project_root_dir,file.path)
|
101
|
+
puts "Source Path: #{full_source_path}"
|
102
|
+
create_guard_for full_source_path, build_action
|
103
|
+
end
|
104
|
+
|
105
|
+
# Create a watcher for the pch if one has been specified.
|
106
|
+
if target.config('Debug').prefix_header
|
107
|
+
prefix_header_path = File.join(File.dirname(target.project.path), target.config('Debug').prefix_header)
|
108
|
+
puts prefix_header_path
|
109
|
+
new_guards << create_guard_for(prefix_header_path, build_action)
|
110
|
+
end
|
111
|
+
|
112
|
+
new_guards
|
113
|
+
|
114
|
+
end.flatten.compact
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
def targets_in_path(pattern)
|
119
|
+
|
120
|
+
project_name, target_name, config_name = pattern.split("//")
|
121
|
+
projects.find_all {|project| project.name == project_name }.map do |project|
|
122
|
+
if target_name
|
123
|
+
project.targets.find_all {|target| target.name == target_name }
|
124
|
+
else
|
125
|
+
project.targets
|
126
|
+
end
|
127
|
+
end.flatten.compact
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
def create_guard_for full_source_path, command
|
132
|
+
relative_source_path = full_source_path.gsub("#{::Guard.listener.directory}/",'')
|
133
|
+
|
134
|
+
# Given a file that is meant for the sources build phase, it
|
135
|
+
# is likely that the file has an accompanying header file so
|
136
|
+
# we expand the pattern to include that.
|
137
|
+
|
138
|
+
source_regex = Regexp.new( Regexp.escape(relative_source_path).to_s.gsub(/(?:m?m)$/,'(?:m?m|h)') )
|
139
|
+
::Guard::Watcher.new(source_regex,command)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# guard-xcoder accepts the following parameters:
|
3
|
+
#
|
4
|
+
# actions => a list of actions that you want to take with the
|
5
|
+
# instance of the Builder object for the matching file. This
|
6
|
+
# is generally actions like :clean, :build, and :package
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# guard-xcoder defines watchers differently as individual files
|
10
|
+
# identified instead the path to the particular project target
|
11
|
+
# that you want built.
|
12
|
+
guard 'xcoder', :actions => [ :clean, :build ] do
|
13
|
+
#
|
14
|
+
# builds when any source file within the 'ProjectName' project changes
|
15
|
+
# for any target
|
16
|
+
watch('ProjectName')
|
17
|
+
|
18
|
+
#
|
19
|
+
# builds when any source file within the project 'Project2' target named
|
20
|
+
# 'FirstTarget' has changed.
|
21
|
+
#
|
22
|
+
watch('Project2//FirstTarget')
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-xcoder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Franklin Webber
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-04 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: &70236298801440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70236298801440
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &70236298800540 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70236298800540
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70236298799500 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70236298799500
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard-rspec
|
49
|
+
requirement: &70236298798520 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70236298798520
|
58
|
+
description: Guard::Xcoder performs project operations when project files are modified.
|
59
|
+
email:
|
60
|
+
- franklin.webber@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- lib/guard/xcoder/templates/Guardfile
|
66
|
+
- lib/guard/xcoder.rb
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
homepage: http://github.com/burtlo/guard-xcoder
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.3.6
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project: guard-xcoder
|
89
|
+
rubygems_version: 1.8.15
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Guard gem for performing commands with Xcode projects
|
93
|
+
test_files: []
|
94
|
+
has_rdoc:
|