swift-gist 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07dc7f889af55eb6a518f8bf00e6f86bb83d5702
4
- data.tar.gz: fcd36b11560ffd97fe8365e7397c2b8ea9a331c9
3
+ metadata.gz: 0ce8536fe946be19b7b6f904f8b24fd884b0d7a8
4
+ data.tar.gz: 5fbc98be03c1be06a726e87ba4c8535fa33600c2
5
5
  SHA512:
6
- metadata.gz: 0312a7227f6f66da89ec6223f221b4eb0dfe8d575ecdc3f731669eac79b67e0ab71413c81fa03fb475e54de9db974f8dfc3c0f0d3cb2e39c7824e17f542b29af
7
- data.tar.gz: 622b8e3935c07d9ca07e0d93ac06ba23bba5e935ae9f9366ca63f77955981a7280f6b58c7b3526b36bb4c6974414084d68c4bd39643f047f1544994b8daad52e
6
+ metadata.gz: 82dbb712dbc77a88db8a355e2f3aebf6d9fd33954cb2d15e31d6f57302847fdb3b16d6f706e4e2c45662d55d7ad70c84617696c22ec4ae07880b2031cad6be0c
7
+ data.tar.gz: 69bc72e5d7cd2111fbd060254db10f89bd28b9fdfe77987caf9692832f02f8f1e624ae27cfa2fe9654aaeb868fddd30a5635662593d55c88b7eaeeea0a0011d8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swift-gist (0.0.2)
4
+ swift-gist (0.0.3)
5
5
  listen (~> 3.1.5)
6
6
 
7
7
  GEM
data/bin/swift-gist CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
4
4
 
5
- require "bundler/setup"
6
5
  require "swift/gist"
7
6
 
7
+ trap "SIGINT" do
8
+ puts "Exiting"
9
+ exit
10
+ end
11
+
8
12
  exit Swift::Gist::run(ARGV)
@@ -2,11 +2,27 @@ require 'optparse'
2
2
 
3
3
  module Swift
4
4
  module Gist
5
+ class CLIError < StandardError
6
+ attr_accessor :reason
7
+
8
+ def initialize reason
9
+ self.reason = reason
10
+ end
11
+ end
5
12
 
6
13
  # The CLI creates a new module for every `--module` or `--test-module`
7
14
  # argument. The `--source` and `--depends-on` arguments are all applied
8
15
  # to the last defined swift module.
9
16
  def self.parse_command_line_arguments arguments
17
+ unless arguments.count > 0
18
+ error = CLIError.new(<<REASON
19
+ Usage: swift-gist [--module[=<name>]] [--test-module[=<name>]]
20
+ [--source[=<glob>]] [--depends-on[=<module name>]]
21
+ REASON
22
+ )
23
+ raise error
24
+ end
25
+
10
26
  swift_modules = []
11
27
 
12
28
  OptionParser.new do |parser|
@@ -15,6 +31,10 @@ module Swift
15
31
  end
16
32
 
17
33
  parser.on('--source SOURCE') do |source|
34
+ if swift_modules.last.nil?
35
+ raise CLIError.new("Error: The `--source` argument requires that a `--module` or `--test-module` has already been defined.")
36
+ end
37
+
18
38
  swift_modules.last.sources |= Dir[source]
19
39
  end
20
40
 
@@ -23,10 +43,19 @@ module Swift
23
43
  end
24
44
 
25
45
  parser.on('--depends-on MODULE') do |module_name|
46
+ if swift_modules.last.nil?
47
+ raise CLIError.new("Error: The `--depends-on` argument requires that a `--module` or `--test-module` has already been defined.")
48
+ end
26
49
  swift_modules.last.depends_on << module_name
27
50
  end
28
51
  end.parse arguments
29
52
 
53
+ swift_modules.each do |swift_module|
54
+ if swift_module.sources.count == 0
55
+ raise CLIError.new("Error: The module '#{swift_module.name}' does not have any valid sources.")
56
+ end
57
+ end
58
+
30
59
  swift_modules
31
60
  end
32
61
 
@@ -2,7 +2,7 @@ require 'listen'
2
2
 
3
3
  module Swift
4
4
  module Gist
5
- def self.watch_sources swift_modules, listener: Listen, sleep: method(:sleep)
5
+ def self.watch_sources swift_modules, listener: Listen
6
6
  sources = Set.new(swift_modules.map { |swift_module| swift_module.sources }.flatten)
7
7
  dirs = Set.new(sources.map { |path| Dir.exist?(path) ? path : File.dirname(path) })
8
8
 
@@ -10,8 +10,6 @@ module Swift
10
10
  next unless sources.intersect?(Set.new(modified + created + deleted))
11
11
  yield
12
12
  end.start
13
-
14
- sleep.call
15
13
  end
16
14
  end
17
15
  end
@@ -17,33 +17,46 @@ module Swift
17
17
  project_art_generator: method(:generate_project_art),
18
18
  project_generator: method(:generate_project),
19
19
  rm_rf: FileUtils.method(:rm_rf),
20
- system: method(:system),
20
+ stdin_watcher: method(:watch_stdin),
21
21
  stdout: $stdout.method(:puts),
22
+ system: method(:system),
22
23
  watcher: method(:watch_sources)
23
24
  )
24
25
 
25
- swift_modules = cli.call arguments
26
- tmp_dir = project_generator.call(swift_modules)
27
- stdout.call project_art_generator.call(swift_modules, tmp_dir)
28
-
29
- chdir.call(tmp_dir) do
30
- system.call('swift test')
26
+ begin
27
+ swift_modules = cli.call arguments
28
+ rescue CLIError => error
29
+ puts error.reason
30
+ exit
31
31
  end
32
32
 
33
- counter = 1
34
- watcher.call(swift_modules) do
35
- stdout.call "\n\n-----> Running `$ swift test` @ '#{formatted_date.call}' - Build ##{counter}"
33
+ begin
34
+ tmp_dir = project_generator.call(swift_modules)
35
+ stdout.call project_art_generator.call(swift_modules, tmp_dir)
36
+
36
37
  chdir.call(tmp_dir) do
37
38
  system.call('swift test')
38
39
  end
39
40
 
40
- counter += 1
41
+ counter = 1
42
+
43
+ build_command = -> {
44
+ stdout.call "\n\n-----> Running `$ swift test` @ '#{formatted_date.call}' - Build ##{counter}"
45
+ chdir.call(tmp_dir) do
46
+ system.call('swift test')
47
+ end
48
+
49
+ counter += 1
50
+ }
51
+
52
+ watcher.call(swift_modules, &build_command)
53
+ stdin_watcher.call(&build_command)
54
+
55
+ ensure
56
+ rm_rf.call tmp_dir
41
57
  end
42
58
 
43
59
  0
44
-
45
- ensure
46
- rm_rf.call tmp_dir
47
60
  end
48
61
 
49
62
  end
@@ -0,0 +1,11 @@
1
+ module Swift
2
+ module Gist
3
+
4
+ def self.watch_stdin stdin: STDIN
5
+ while stdin.gets
6
+ yield
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Swift
2
2
  module Gist
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/lib/swift/gist.rb CHANGED
@@ -4,12 +4,13 @@ module Swift
4
4
  end
5
5
 
6
6
  require "swift/gist/cli"
7
+ require "swift/gist/file_watcher"
7
8
  require "swift/gist/format_swift_module"
8
9
  require "swift/gist/generate_project"
9
10
  require "swift/gist/generate_project_art"
10
11
  require "swift/gist/runner"
11
12
  require "swift/gist/spm_package_creator"
12
13
  require "swift/gist/spm_project_creator"
14
+ require "swift/gist/stdin_watcher"
13
15
  require "swift/gist/swift_module"
14
16
  require "swift/gist/version"
15
- require "swift/gist/watcher"
data/swift-gist.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.bindir = "bin"
21
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
+ spec.required_ruby_version = '>=2.3.3'
23
24
 
24
25
  spec.add_runtime_dependency 'listen', '~> 3.1.5'
25
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift-gist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Samuels
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen
@@ -99,15 +99,16 @@ files:
99
99
  - bin/swift-gist
100
100
  - lib/swift/gist.rb
101
101
  - lib/swift/gist/cli.rb
102
+ - lib/swift/gist/file_watcher.rb
102
103
  - lib/swift/gist/format_swift_module.rb
103
104
  - lib/swift/gist/generate_project.rb
104
105
  - lib/swift/gist/generate_project_art.rb
105
106
  - lib/swift/gist/runner.rb
106
107
  - lib/swift/gist/spm_package_creator.rb
107
108
  - lib/swift/gist/spm_project_creator.rb
109
+ - lib/swift/gist/stdin_watcher.rb
108
110
  - lib/swift/gist/swift_module.rb
109
111
  - lib/swift/gist/version.rb
110
- - lib/swift/gist/watcher.rb
111
112
  - swift-gist.gemspec
112
113
  homepage: https://github.com/paulsamuels/swift-gist
113
114
  licenses:
@@ -121,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
122
  requirements:
122
123
  - - ">="
123
124
  - !ruby/object:Gem::Version
124
- version: '0'
125
+ version: 2.3.3
125
126
  required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  requirements:
127
128
  - - ">="