swig 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 +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +30 -0
- data/README.md +28 -0
- data/Rakefile +6 -0
- data/TODO.markdown +14 -0
- data/bin/swig +45 -0
- data/lib/swig/all.rb +4 -0
- data/lib/swig/file_in_stream.rb +17 -0
- data/lib/swig/stream.rb +46 -0
- data/lib/swig/swig.rb +56 -0
- data/lib/swig/worker.rb +7 -0
- data/lib/swig/workers/concat.rb +14 -0
- data/spec/fixtures/init.js +1 -0
- data/spec/fixtures/script.js +1 -0
- data/spec/fixtures/style.css +1 -0
- data/spec/lib/swig/stream_spec.rb +52 -0
- data/spec/lib/swig/swig_spec.rb +66 -0
- data/spec/lib/workers/concat_spec.rb +27 -0
- data/spec/spec_helper.rb +17 -0
- data/swig.gemspec +21 -0
- data/swig_file.rb +7 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c1d3f94a3dab8e4f1abec68f314d07baae8fc1c
|
4
|
+
data.tar.gz: 571cfabdaea4e56e084f0b706dcb39f4a1e4730b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6cc66f2a52994fdab262e23f923a8f97f7fa00e4d73b92fd25ba3c649537d63ad22de658554525bea544459006e3673e7f27ada49815a64d31a36fcc321ec65c
|
7
|
+
data.tar.gz: a8730c523463038c2ccf9236007edd1acbf2c6a1c0a62e7512a0c1d82f40f6d2956dd79cf4190d666476ed4992c8211201cb441c1bff86da280138963c5f4cd8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
swig (0.0.1)
|
5
|
+
colorize
|
6
|
+
trollop
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
colorize (0.6.0)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
rake (10.1.1)
|
14
|
+
rspec (2.14.1)
|
15
|
+
rspec-core (~> 2.14.0)
|
16
|
+
rspec-expectations (~> 2.14.0)
|
17
|
+
rspec-mocks (~> 2.14.0)
|
18
|
+
rspec-core (2.14.7)
|
19
|
+
rspec-expectations (2.14.5)
|
20
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
21
|
+
rspec-mocks (2.14.5)
|
22
|
+
trollop (2.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
rake
|
29
|
+
rspec
|
30
|
+
swig!
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Swig
|
2
|
+
====
|
3
|
+
|
4
|
+
Install it with
|
5
|
+
|
6
|
+
```
|
7
|
+
gem install swig
|
8
|
+
```
|
9
|
+
|
10
|
+
Make a file called `swig_file.rb` containing
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
require 'swig/all'
|
14
|
+
|
15
|
+
Swig.new_task(:concat) do
|
16
|
+
read("spec/fixtures/*.js").
|
17
|
+
then(Concat, name: "app.js").
|
18
|
+
write("tmp")
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
Then run this from the command line
|
23
|
+
|
24
|
+
```
|
25
|
+
swig concat
|
26
|
+
```
|
27
|
+
|
28
|
+
And see magic!
|
data/Rakefile
ADDED
data/TODO.markdown
ADDED
data/bin/swig
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'swig/all'
|
4
|
+
require 'trollop'
|
5
|
+
|
6
|
+
opts = Trollop::options do
|
7
|
+
banner <<-EOS
|
8
|
+
Swig is a streaming task runner
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
swig [options] <task name>
|
12
|
+
|
13
|
+
where [options] are:
|
14
|
+
|
15
|
+
EOS
|
16
|
+
opt :tasks, "Show tasks", default: false
|
17
|
+
end
|
18
|
+
|
19
|
+
# Go to config file
|
20
|
+
begin
|
21
|
+
Swig.cd_to_config_file
|
22
|
+
eval File.read("swig_file.rb")
|
23
|
+
rescue Swig::NoSwigFile
|
24
|
+
puts "Hit edge of file system searching for swig file"
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
# Show tasks
|
29
|
+
if opts[:tasks]
|
30
|
+
Swig.tasks.keys.each do |name|
|
31
|
+
puts "swig #{name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
exit 0
|
35
|
+
end
|
36
|
+
|
37
|
+
# Run task
|
38
|
+
puts Swig.divider
|
39
|
+
if ARGV.empty?
|
40
|
+
Swig.tasks.keys.each do |task|
|
41
|
+
Swig.invoke(task)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
Swig.invoke(ARGV.first.to_sym)
|
45
|
+
end
|
data/lib/swig/all.rb
ADDED
data/lib/swig/stream.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'swig/swig'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Swig
|
5
|
+
class Stream
|
6
|
+
attr_reader :files
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@files = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def read(path_or_paths)
|
13
|
+
Dir.glob(path_or_paths).each do |path|
|
14
|
+
basename = File.basename(path)
|
15
|
+
content = File.read(path)
|
16
|
+
@files << Swig::FileInStream.new(basename, content)
|
17
|
+
end
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(path)
|
23
|
+
FileUtils.mkdir_p(path)
|
24
|
+
|
25
|
+
@files.each do |file|
|
26
|
+
File.write(File.join(path, file.basename), file.read)
|
27
|
+
end
|
28
|
+
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def clean(pattern = //)
|
33
|
+
@files = @files.reject do |file|
|
34
|
+
pattern =~ file.basename
|
35
|
+
end
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def then(klass, options = {})
|
41
|
+
@files = klass.new(options).eval(@files)
|
42
|
+
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/swig/swig.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'swig/stream'
|
4
|
+
require 'swig/file_in_stream'
|
5
|
+
|
6
|
+
class Swig
|
7
|
+
class NoSuchTask < Exception; end
|
8
|
+
class NoSwigFile < Exception; end
|
9
|
+
|
10
|
+
def self.new_task(name, &block)
|
11
|
+
@@tasks ||= {}
|
12
|
+
|
13
|
+
@@tasks[name] = block
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.invoke(name)
|
17
|
+
@@tasks ||= {}
|
18
|
+
|
19
|
+
block = @@tasks.fetch(name)
|
20
|
+
|
21
|
+
time = (Benchmark.realtime do
|
22
|
+
Swig::Stream.new.instance_eval(&block)
|
23
|
+
end * 1000).round(2)
|
24
|
+
|
25
|
+
show_message(name, time)
|
26
|
+
rescue KeyError
|
27
|
+
raise NoSuchTask.new("task named \"#{name}\" doesn't exist")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.cd_to_config_file
|
31
|
+
until File.exists?("swig_file.rb")
|
32
|
+
Dir.chdir("../")
|
33
|
+
|
34
|
+
raise NoSwigFile if Dir.pwd == "/"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.tasks
|
39
|
+
@@tasks
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.divider
|
43
|
+
"=======================================".green
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def self.show_message(name, time)
|
49
|
+
print "swig: ".blue
|
50
|
+
print "#{name}, "
|
51
|
+
puts "#{time} milliseconds"
|
52
|
+
print divider
|
53
|
+
print "\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/lib/swig/worker.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'swig/file_in_stream'
|
2
|
+
require 'swig/worker'
|
3
|
+
|
4
|
+
class Concat < Swig::Worker
|
5
|
+
def eval(files)
|
6
|
+
[Swig::FileInStream.new(@options[:name], concatenated_content(files))]
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def concatenated_content(files)
|
12
|
+
files.inject("") { |acc, file| acc += file.read }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
alert('bar');
|
@@ -0,0 +1 @@
|
|
1
|
+
console.log('foo');
|
@@ -0,0 +1 @@
|
|
1
|
+
body { background: red; }
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'swig/all'
|
4
|
+
|
5
|
+
describe Swig::Stream do
|
6
|
+
let(:stream) { Swig::Stream.new }
|
7
|
+
let(:css_file) { "spec/fixtures/style.css" }
|
8
|
+
let(:all_js_files) { "spec/fixtures/*.js" }
|
9
|
+
let(:js_file) { "spec/fixtures/init.js" }
|
10
|
+
|
11
|
+
after { FileUtils.rm_rf("tmp") }
|
12
|
+
|
13
|
+
it "can read one file" do
|
14
|
+
stream.read(css_file)
|
15
|
+
|
16
|
+
stream.should have(1).files
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can read several files" do
|
20
|
+
stream.read([all_js_files, css_file])
|
21
|
+
|
22
|
+
stream.should have(3).files
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can write its files to a directory" do
|
26
|
+
filename = File.basename(css_file)
|
27
|
+
stream.read(css_file)
|
28
|
+
stream.write("tmp")
|
29
|
+
|
30
|
+
File.exists?("tmp/#{filename}").should be_true
|
31
|
+
File.read("tmp/#{filename}").should eq File.read("spec/fixtures/#{filename}")
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#clean" do
|
35
|
+
before do
|
36
|
+
stream.read(js_file)
|
37
|
+
stream.read(css_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can clean away all files" do
|
41
|
+
stream.clean
|
42
|
+
|
43
|
+
stream.should have(0).files
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can clean away matching files" do
|
47
|
+
stream.clean(/.*\.js/)
|
48
|
+
|
49
|
+
stream.should have(1).files
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'swig/all'
|
4
|
+
|
5
|
+
describe Swig do
|
6
|
+
it "blows up when you try to invoke an undefined task" do
|
7
|
+
expect do
|
8
|
+
Swig.invoke(:no_task)
|
9
|
+
end.to raise_error(Swig::NoSuchTask, "task named \"no_task\" doesn't exist")
|
10
|
+
end
|
11
|
+
|
12
|
+
context "a task that just moves files" do
|
13
|
+
it "moves files" do
|
14
|
+
Swig.new_task(:move) do
|
15
|
+
read("spec/fixtures/init.js").
|
16
|
+
write("tmp")
|
17
|
+
end
|
18
|
+
|
19
|
+
Swig.invoke(:move)
|
20
|
+
|
21
|
+
File.exists?("tmp/init.js").should be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "a task that concatenates files" do
|
26
|
+
it "concatenates files and saves" do
|
27
|
+
Swig.new_task(:concat) do
|
28
|
+
read("spec/fixtures/*.js").
|
29
|
+
then(Concat, name: "app.js").
|
30
|
+
write("tmp")
|
31
|
+
end
|
32
|
+
|
33
|
+
Swig.invoke(:concat)
|
34
|
+
|
35
|
+
File.exists?("tmp/app.js").should be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "finding the config file" do
|
40
|
+
after(:each) do
|
41
|
+
FileUtils.rm_rf("swig_file.rb") if File.exists?("swig_file.rb")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "finds it when it is in the same dir" do
|
45
|
+
File.write("swig_file.rb", "require 'swig/all'")
|
46
|
+
|
47
|
+
Swig.cd_to_config_file
|
48
|
+
File.exists?("swig_file.rb").should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "finds it when it is in a lower dir" do
|
52
|
+
File.write("swig_file.rb", "require 'swig/all'")
|
53
|
+
Dir.chdir("spec/fixtures/")
|
54
|
+
|
55
|
+
Swig.cd_to_config_file
|
56
|
+
|
57
|
+
File.exists?("swig_file.rb").should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "raises and error if it hits the edge of the file system" do
|
61
|
+
expect do
|
62
|
+
Swig.cd_to_config_file
|
63
|
+
end.to raise_error Swig::NoSwigFile
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'swig/all'
|
4
|
+
|
5
|
+
describe Concat do
|
6
|
+
let(:stream) { Swig::Stream.new }
|
7
|
+
let(:content) { File.read("spec/fixtures/init.js") + File.read("spec/fixtures/script.js") }
|
8
|
+
|
9
|
+
before do
|
10
|
+
stream.read("spec/fixtures/init.js")
|
11
|
+
stream.read("spec/fixtures/script.js")
|
12
|
+
|
13
|
+
stream.then(Concat, name: "foo.css")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "merges the files" do
|
17
|
+
stream.should have(1).files
|
18
|
+
end
|
19
|
+
|
20
|
+
it "concatenates the files content" do
|
21
|
+
stream.files.first.read.should eq content
|
22
|
+
end
|
23
|
+
|
24
|
+
it "sets the name of the file" do
|
25
|
+
stream.files.first.basename.should eq "foo.css"
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
data/swig.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'swig'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2014-02-08'
|
5
|
+
s.summary = "Task runner"
|
6
|
+
s.description = "Task runner"
|
7
|
+
s.authors = ["David Pedersen"]
|
8
|
+
s.email = 'david.pdrsn@gmail.com'
|
9
|
+
s.homepage = 'http://github.com/davidpdrsn/swig'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.add_development_dependency 'rake'
|
13
|
+
s.add_development_dependency 'rspec'
|
14
|
+
|
15
|
+
s.add_runtime_dependency 'trollop'
|
16
|
+
s.add_runtime_dependency 'colorize'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/swig_file.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Pedersen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: trollop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Task runner
|
70
|
+
email: david.pdrsn@gmail.com
|
71
|
+
executables:
|
72
|
+
- swig
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- TODO.markdown
|
83
|
+
- bin/swig
|
84
|
+
- lib/swig/all.rb
|
85
|
+
- lib/swig/file_in_stream.rb
|
86
|
+
- lib/swig/stream.rb
|
87
|
+
- lib/swig/swig.rb
|
88
|
+
- lib/swig/worker.rb
|
89
|
+
- lib/swig/workers/concat.rb
|
90
|
+
- spec/fixtures/init.js
|
91
|
+
- spec/fixtures/script.js
|
92
|
+
- spec/fixtures/style.css
|
93
|
+
- spec/lib/swig/stream_spec.rb
|
94
|
+
- spec/lib/swig/swig_spec.rb
|
95
|
+
- spec/lib/workers/concat_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- swig.gemspec
|
98
|
+
- swig_file.rb
|
99
|
+
homepage: http://github.com/davidpdrsn/swig
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.0
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Task runner
|
123
|
+
test_files: []
|