magnit 0.0.1 → 0.0.2

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 (3) hide show
  1. data/bin/magnit +16 -3
  2. data/magnit.gemspec +1 -1
  3. metadata +2 -2
data/bin/magnit CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'rbconfig'
3
+ IS_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
2
4
 
3
5
  class String
4
6
  def colorize(color_code)
@@ -84,14 +86,25 @@ def watch(identifier)
84
86
  raise "Invalid identifier #{identifier.to_s}" unless valid_identifier?(identifier)
85
87
  raise "Already watching #{identifier.to_s}" if $pids[identifier]
86
88
  puts File.expand_path($dirs[identifier])
87
- $pids[identifier] = spawn($cmds[identifier], chdir: File.expand_path($dirs[identifier]))
89
+ options = { chdir: File.expand_path($dirs[identifier]) }
90
+ # On *nix launch process as process group leader to be able to
91
+ # kill all children processes later
92
+ options[:pgroup] = true unless IS_WINDOWS
93
+ $pids[identifier] = spawn($cmds[identifier], options)
88
94
  puts "spawned watcher with pid: #{$pids[identifier]}"
89
95
  end
90
96
 
91
97
  def stop(identifier)
92
98
  raise "Invalid identifier #{identifier.to_s}" unless valid_identifier?(identifier)
93
99
  raise "Not watching #{identifier.to_s}" unless $pids[identifier]
94
- Process.kill('KILL', $pids[identifier])
100
+ # Take care of child processes
101
+ # On Windows it's better handled by taskkill
102
+ # On nix just pass negative process group
103
+ if IS_WINDOWS
104
+ `taskkill /F /T /PID #{$pids[identifier]}`
105
+ else
106
+ Process.kill('INT', -$pids[identifier])
107
+ end
95
108
  Process.wait($pids[identifier])
96
109
  puts "killed watcher with pid: #{$pids[identifier]}"
97
110
  $pids[identifier] = nil
@@ -133,7 +146,7 @@ while true
133
146
  puts 'Huh ?'
134
147
  end
135
148
  rescue RuntimeError => e
136
- $stderr.puts "magnet error: #{e.to_s}"
149
+ $stderr.puts "magnit error: #{e.to_s}"
137
150
  end
138
151
  end
139
152
 
data/magnit.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'base64'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'magnit'
5
- s.version = '0.0.1'
5
+ s.version = '0.0.2'
6
6
  s.summary = 'watch & recompile compass/stylus/less/etc'
7
7
  s.description = <<-EOF
8
8
  magnit is a CLI tool to watch & recompile compass/stylus/less projects. It is a
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magnit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-09 00:00:00.000000000 Z
12
+ date: 2014-01-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'magnit is a CLI tool to watch & recompile compass/stylus/less projects.
15
15
  It is a