swift-gist 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 34a4f21d64d9a746405bab46332c7c2f3b76d28b
4
+ data.tar.gz: 07f090ec0a08b41ab1b51e812a3ea838b68596a8
5
+ SHA512:
6
+ metadata.gz: 21f4194bbaf569276efbc421842b79128f0fb27e633de1915342eac1c75cf3dc3c403f535b132850116aba08cbea8ed4ef98c22981411c2700cdd2123b3731af
7
+ data.tar.gz: c564a8882bfde54a51797d4ea41bafa6971634f43b13f457eab249c35c2cbb9274b242078381d86ea5d0239ba7f8c5284653e8c58a4eaa3d759aace1a2a8cdb6
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in swift-gist.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ swift-gist (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ docile (1.3.0)
10
+ json (2.1.0)
11
+ minitest (5.11.3)
12
+ rake (10.5.0)
13
+ simplecov (0.16.1)
14
+ docile (~> 1.1)
15
+ json (>= 1.8, < 3)
16
+ simplecov-html (~> 0.10.0)
17
+ simplecov-html (0.10.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.16)
24
+ minitest (~> 5.0)
25
+ rake (~> 10.0)
26
+ simplecov (~> 0.16.1)
27
+ swift-gist!
28
+
29
+ BUNDLED WITH
30
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Paul Samuels
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ ...
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "spec"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["spec/**/*_spec.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "swift/gist"
5
+
6
+ require "irb"
7
+ IRB.start(__FILE__)
data/bin/swift-gist ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "bundler/setup"
6
+ require "swift/gist"
7
+
8
+ Swift::Gist::run ARGV
@@ -0,0 +1,34 @@
1
+ require 'optparse'
2
+
3
+ module Swift
4
+ module Gist
5
+
6
+ # The CLI creates a new module for every `--module` or `--test-module`
7
+ # argument. The `--source` and `--depends-on` arguments are all applied
8
+ # to the last defined swift module.
9
+ def self.parse_command_line_arguments arguments
10
+ swift_modules = []
11
+
12
+ OptionParser.new do |parser|
13
+ parser.on('--module MODULE') do |module_name|
14
+ swift_modules << SwiftModule.new(module_name, :src, [])
15
+ end
16
+
17
+ parser.on('--source SOURCE') do |source|
18
+ swift_modules.last.sources |= Dir[source]
19
+ end
20
+
21
+ parser.on('--test-module MODULE') do |module_name|
22
+ swift_modules << SwiftModule.new(module_name, :test, [])
23
+ end
24
+
25
+ parser.on('--depends-on MODULE') do |module_name|
26
+ swift_modules.last.depends_on << module_name
27
+ end
28
+ end.parse arguments
29
+
30
+ swift_modules
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Swift
2
+ module Gist
3
+
4
+ # This function generates a valid swift case for each SwiftModule.
5
+ #
6
+ # The resulting output will be something like:
7
+ #
8
+ # .target(name: "SomeModule")
9
+ # .target(name: "SomeModule", dependencies: ["SomeOtherModule"])
10
+ # .testTarget(name: "SomeModuleTests", dependencies: ["SomeOtherModule"])
11
+ def self.format_swift_module swift_module
12
+ target_type = swift_module.type == :src ? 'target' : 'testTarget'
13
+ formatted_name = %Q|name: "#{swift_module.name}"|
14
+ formatted_dependencies = "dependencies: [%s]" % swift_module.depends_on.map { |dependency| %Q|"#{dependency}"| }.join(', ')
15
+
16
+ %Q|.%{target_type}(%{formatted_name}%{formatted_dependencies})| % {
17
+ target_type: target_type,
18
+ formatted_name: formatted_name,
19
+ formatted_dependencies: swift_module.depends_on.count > 0 ? ", #{formatted_dependencies}" : ""
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ module Swift
5
+ module Gist
6
+
7
+ # This is the ugly command that binds everything together.
8
+ #
9
+ # 1 - Parses command line arguments
10
+ # 2 - Creates a SPM project linking just the files specified with `--source` arguments
11
+ # 3 - Starts watchman
12
+ def self.run(
13
+ arguments,
14
+ chdir: Dir.method(:chdir),
15
+ cli: method(:parse_command_line_arguments),
16
+ mktmpdir: Dir.method(:mktmpdir),
17
+ open: File.method(:open),
18
+ pwd: Dir.method(:pwd),
19
+ spm_package_creator: method(:spm_package_definition_from_swift_modules),
20
+ spm_project_creator: method(:spm_project_from_swift_modules),
21
+ system: method(:system),
22
+ watchman_command: method(:watchman_command)
23
+ )
24
+
25
+ swift_modules = cli.call arguments
26
+ project_dir = pwd.call
27
+
28
+ mktmpdir.call do |tmp_dir|
29
+ chdir.call(tmp_dir) do
30
+ spm_project_creator.call swift_modules, project_dir: project_dir
31
+
32
+ open.call('Package.swift', 'w') do |file|
33
+ file.puts spm_package_creator.call(swift_modules)
34
+ end
35
+ end
36
+
37
+ system.call(watchman_command.call(tmp_dir, swift_modules))
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ require 'erb'
2
+
3
+ module Swift
4
+ module Gist
5
+ def self.spm_package_definition_from_swift_modules swift_modules, format_swift_module: method(:format_swift_module)
6
+ formatted_modules = swift_modules.map { |swift_module| format_swift_module.call swift_module }
7
+ ERB.new(ERB_TEMPLATE).result(binding)
8
+ end
9
+
10
+ private
11
+
12
+ ERB_TEMPLATE = <<-ERB_TEMPLATE
13
+ // swift-tools-version:4.0
14
+
15
+ import PackageDescription
16
+
17
+ let package = Package(
18
+ name: "TestRunner",
19
+ targets: [ <%= formatted_modules.join(", ") %> ]
20
+ )
21
+ ERB_TEMPLATE
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module Swift
2
+ module Gist
3
+
4
+ def self.spm_project_from_swift_modules(
5
+ swift_modules,
6
+ project_dir:,
7
+ mkdir_p: FileUtils.method(:mkdir_p),
8
+ ln_s: FileUtils.method(:ln_s)
9
+ )
10
+
11
+ swift_modules.each do |swift_module|
12
+ mkdir_p.call "Sources/#{swift_module.name}"
13
+ swift_module.sources.each do |source|
14
+ ln_s.call "#{project_dir}/#{source}", "Sources/#{swift_module.name}"
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module Swift
2
+ module Gist
3
+ class SwiftModule
4
+ attr_accessor :name, :type, :sources, :depends_on
5
+
6
+ def initialize name, type, sources, depends_on=[]
7
+ @name, @type, @sources, @depends_on = name, type, sources, depends_on
8
+ end
9
+
10
+ def == other
11
+ name == other.name && sources == other.sources && depends_on == other.depends_on && type == other.type
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Swift
2
+ module Gist
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ module Swift
2
+ module Gist
3
+ def self.watchman_command dir, swift_modules, watchman_paths_from_swift_modules: method(:watchman_paths_from_swift_modules)
4
+ sources = watchman_paths_from_swift_modules.call(swift_modules)
5
+ "watchman-make -p #{sources} --run 'cd #{dir} && swift test'"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Swift
2
+ module Gist
3
+ def self.watchman_paths_from_swift_modules swift_modules
4
+ swift_modules
5
+ .map { |swift_module| swift_module.sources }
6
+ .flatten
7
+ .map { |path| %Q|'#{path}'| }
8
+ .join(' ')
9
+ end
10
+ end
11
+ end
data/lib/swift/gist.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Swift
2
+ module Gist
3
+ end
4
+ end
5
+
6
+ require "swift/gist/cli"
7
+ require "swift/gist/format_swift_module"
8
+ require "swift/gist/runner"
9
+ require "swift/gist/spm_package_creator"
10
+ require "swift/gist/spm_project_creator"
11
+ require "swift/gist/swift_module"
12
+ require "swift/gist/version"
13
+ require "swift/gist/watchman_command"
14
+ require "swift/gist/watchman_paths"
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "swift/gist/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "swift-gist"
8
+ spec.version = Swift::Gist::VERSION
9
+ spec.authors = ["Paul Samuels"]
10
+ spec.email = ["paulio1987@gmail.com"]
11
+
12
+ spec.summary = %q{A tool for watching a subset of Swift files and executing tests.}
13
+ spec.description = %q{A tool for watching a subset of Swift files and executing tests.}
14
+ spec.homepage = "https://github.com/paulsamuels/swift-gist"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "simplecov", "~> 0.16.1"
28
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swift-gist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Samuels
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.1
69
+ description: A tool for watching a subset of Swift files and executing tests.
70
+ email:
71
+ - paulio1987@gmail.com
72
+ executables:
73
+ - console
74
+ - swift-gist
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/swift-gist
86
+ - lib/swift/gist.rb
87
+ - lib/swift/gist/cli.rb
88
+ - lib/swift/gist/format_swift_module.rb
89
+ - lib/swift/gist/runner.rb
90
+ - lib/swift/gist/spm_package_creator.rb
91
+ - lib/swift/gist/spm_project_creator.rb
92
+ - lib/swift/gist/swift_module.rb
93
+ - lib/swift/gist/version.rb
94
+ - lib/swift/gist/watchman_command.rb
95
+ - lib/swift/gist/watchman_paths.rb
96
+ - swift-gist.gemspec
97
+ homepage: https://github.com/paulsamuels/swift-gist
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: A tool for watching a subset of Swift files and executing tests.
121
+ test_files: []