magnit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +22 -0
  2. data/README.md +45 -0
  3. data/bin/magnit +140 -0
  4. data/magnit.gemspec +22 -0
  5. metadata +59 -0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Galymzhan Kozhayev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ magnit is a CLI tool to watch & recompile compass/stylus/less projects. It is
2
+ a simple alternative to GUI applications like Scout and Koala, but it does not
3
+ do watching and compilation itself, rather it uses existing executables of
4
+ preprocessors.
5
+
6
+ # Installing
7
+
8
+ `gem install magnit`
9
+
10
+ # Specifying projects
11
+
12
+ Create a file ~/.magnitrc and specify your projects in the format:
13
+
14
+ `/path/to/project/directory: command`
15
+
16
+ For example:
17
+
18
+ ```
19
+ ~/my/compass/project: compass watch
20
+ /var/www/site 1/css/: stylus -w -c
21
+ /var/www/site 2/css/: stylus -w -c base.styl main.styl
22
+ ```
23
+
24
+ The "command" must be a watcher command, here are examples:
25
+
26
+ - Sass: `sass --watch`
27
+ - Compass: `compass watch`
28
+ - Stylus: `stylus -w -c`
29
+
30
+ The command's working directory will be set to project's directory.
31
+
32
+ # Usage
33
+
34
+ After running `magnit` you can interact with it using these commands:
35
+
36
+ - `l`: list projects
37
+ - `w N`: start watching project N (execute associated command)
38
+ - `s N`: stop watching N
39
+ - `q`: quit
40
+
41
+ N is zero-based index of the project displayed in the listing
42
+
43
+ # License
44
+
45
+ Licensed under the MIT License. See LICENSE file for details.
data/bin/magnit ADDED
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class String
4
+ def colorize(color_code)
5
+ "\e[#{color_code}m#{self}\e[0m"
6
+ end
7
+
8
+ def green
9
+ colorize(32)
10
+ end
11
+
12
+ def red
13
+ colorize(31)
14
+ end
15
+ end
16
+
17
+ begin
18
+ rc_contents = IO.read(ENV['HOME'] + '/.magnitrc')
19
+ rescue Errno::ENOENT
20
+ $stderr.puts <<-HELP
21
+ Create a file ~/.magnitrc and specify your projects in the format:
22
+
23
+ /path/to/project/directory: command
24
+
25
+ For example:
26
+
27
+ ~/my/compass/project: compass watch
28
+ /var/www/site 1/css/: stylus -w -c
29
+ /var/www/site 2/css/: stylus -w -c base.styl main.styl
30
+
31
+ The "command" must be a watcher command, here are examples:
32
+
33
+ - Sass: `sass --watch`
34
+ - Compass: `compass watch`
35
+ - Stylus: `stylus -w -c`
36
+
37
+ The command's working directory will be set to project's directory.
38
+
39
+ HELP
40
+ exit 1
41
+ end
42
+
43
+ $cmds = []
44
+ $dirs = []
45
+ rc_contents.split("\n").each do |entry|
46
+ colon = entry.rindex(':')
47
+ if colon.nil?
48
+ $stderr.puts "Malformed entry: #{entry}"
49
+ else
50
+ $dirs << entry[0, colon].strip
51
+ $cmds << entry[(colon + 1)..(entry.length - 1)].strip
52
+ end
53
+ end
54
+
55
+ $pids = Array.new($dirs.length, nil)
56
+
57
+ def list
58
+ $dirs.each_with_index do |dir, i|
59
+ status = $pids[i] ? 'STARTED'.green : 'STOPPED'.red
60
+ puts "#{i.to_s} [ #{status} ]: #{dir}"
61
+ end
62
+ end
63
+
64
+ def help
65
+ puts <<-HELP
66
+ Available commands:
67
+
68
+ l - list directories
69
+ w N - start watching N
70
+ s N - stop watching N
71
+ q - quit
72
+ h - this help
73
+
74
+ N is zero-based index of the directory displayed in the listing
75
+
76
+ HELP
77
+ end
78
+
79
+ def valid_identifier?(identifier)
80
+ identifier >= 0 && identifier < $dirs.length
81
+ end
82
+
83
+ def watch(identifier)
84
+ raise "Invalid identifier #{identifier.to_s}" unless valid_identifier?(identifier)
85
+ raise "Already watching #{identifier.to_s}" if $pids[identifier]
86
+ puts File.expand_path($dirs[identifier])
87
+ $pids[identifier] = spawn($cmds[identifier], chdir: File.expand_path($dirs[identifier]))
88
+ puts "spawned watcher with pid: #{$pids[identifier]}"
89
+ end
90
+
91
+ def stop(identifier)
92
+ raise "Invalid identifier #{identifier.to_s}" unless valid_identifier?(identifier)
93
+ raise "Not watching #{identifier.to_s}" unless $pids[identifier]
94
+ Process.kill('KILL', $pids[identifier])
95
+ Process.wait($pids[identifier])
96
+ puts "killed watcher with pid: #{$pids[identifier]}"
97
+ $pids[identifier] = nil
98
+ end
99
+
100
+ def quit
101
+ puts 'Killing remaining watchers'
102
+ $pids.each_index do |identifier|
103
+ stop(identifier) if $pids[identifier]
104
+ end
105
+ puts 'bye...'
106
+ exit
107
+ end
108
+
109
+ trap('INT') { quit }
110
+
111
+ list
112
+
113
+ while true
114
+ print '> '
115
+ command = gets
116
+ break unless command
117
+ command.strip!
118
+ next if command.empty?
119
+
120
+ begin
121
+ case command
122
+ when 'l'
123
+ list
124
+ when 'h'
125
+ help
126
+ when 'q'
127
+ break
128
+ when /^w (\d+)$/
129
+ watch($1.to_i)
130
+ when /^s (\d+)$/
131
+ stop($1.to_i)
132
+ else
133
+ puts 'Huh ?'
134
+ end
135
+ rescue RuntimeError => e
136
+ $stderr.puts "magnet error: #{e.to_s}"
137
+ end
138
+ end
139
+
140
+ quit
data/magnit.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ require 'base64'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'magnit'
5
+ s.version = '0.0.1'
6
+ s.summary = 'watch & recompile compass/stylus/less/etc'
7
+ s.description = <<-EOF
8
+ magnit is a CLI tool to watch & recompile compass/stylus/less projects. It is a
9
+ simple alternative to GUI applications like Scout and Koala, but it does not do
10
+ watching and compilation itself, rather it uses existing executables of
11
+ preprocessors.
12
+ EOF
13
+ s.required_ruby_version = '>= 1.9.2'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+
17
+ s.executables << 'magnit'
18
+
19
+ s.authors = ['Galymzhan Kozhayev']
20
+ s.email = Base64.decode64("a296aGF5ZXZAZ21haWwuY29t\n")
21
+ s.homepage = 'https://github.com/galymzhan/magnit'
22
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magnit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Galymzhan Kozhayev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'magnit is a CLI tool to watch & recompile compass/stylus/less projects.
15
+ It is a
16
+
17
+ simple alternative to GUI applications like Scout and Koala, but it does not do
18
+
19
+ watching and compilation itself, rather it uses existing executables of
20
+
21
+ preprocessors.
22
+
23
+ '
24
+ email: !binary |-
25
+ a296aGF5ZXZAZ21haWwuY29t
26
+ executables:
27
+ - magnit
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - LICENSE
32
+ - README.md
33
+ - bin/magnit
34
+ - magnit.gemspec
35
+ homepage: https://github.com/galymzhan/magnit
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.9.2
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.23
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: watch & recompile compass/stylus/less/etc
59
+ test_files: []