rien 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
  SHA256:
3
- metadata.gz: 98c91f699f5e7d0919d39495d34bd70f89251f88c049442c3b3ffa75268d0b71
4
- data.tar.gz: 5172a96c5292175a2165b9f9f7e49646e3adee03eae1b5fe865e9cd9d72eef07
3
+ metadata.gz: 41db30d7cf5c9e875f8d5a6d501d31a870f86db9c6ced2df28b653e3702eb3d2
4
+ data.tar.gz: 8d80bc19aaebb6598ff34d31c14948974f69157d5d1c5c897d3c834a5ea11377
5
5
  SHA512:
6
- metadata.gz: a9cdd05af22e562479fde38e856514072825422671f21c65444bf8652cb66d70ebba43401ab9d5f72826201d5f269f1f51c9eec75e9a8b2ced3dd2032ca9d91f
7
- data.tar.gz: 6ba6743a3dba672fcbee2feb4065819b7442207f3c8be93436146a8d66689d406ea7b3d0983c5437760b2e03c2bbf525263e605dd0faf1588c628838e91d0a06
6
+ metadata.gz: eaf3df6e327068cd266cebbf20568458561b7e455380da5274d70dc488dfab3a0c2a5d52e0e4f112738f590df37a79bfbe86d3e72de81dc72fab2f0fa1a6c711
7
+ data.tar.gz: a3d37be26849827cb354b13719b2c32ecd0cc747a9f7615dcebc073b688d9c47575af25b518ebaed24bde660d27d76f99a617141ec8c397e0048c089b7466d28
data/bin/rien CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  require 'optparse'
4
4
  require 'rien'
5
+ require 'fileutils'
6
+ require 'ruby-progressbar'
5
7
 
6
8
  options = {
7
- mode: :help
9
+ mode: :help,
8
10
  }
9
11
 
10
12
  parser = OptionParser.new do |opts|
@@ -12,12 +14,18 @@ parser = OptionParser.new do |opts|
12
14
  opts.on('-e', '--encode [FILE]', 'Encode specific ruby file', String) do |v|
13
15
  options[:mode] = :encode
14
16
  options[:file] = v
17
+ options[:output] ||= "output.rb"
15
18
  end
16
19
 
17
- # opts.on('-p', '--pack [FILE]', 'Pack ruby file and all relative requirements into a single executable', String) do |v|
18
- # options[:mode] = :pack
19
- # options[:file] = v
20
- # end
20
+ opts.on('-p', '--pack [DIR]', 'Pack ruby directory into encoded files', String) do |v|
21
+ options[:mode] = :pack
22
+ options[:file] = v
23
+ options[:output] ||= "rien_output"
24
+ end
25
+
26
+ opts.on('-o' '--out [FILE/DIR]', 'Indicate the output of the encoded file(s)', String) do |v|
27
+ options[:output] = v
28
+ end
21
29
  end
22
30
 
23
31
  parser.parse!
@@ -26,15 +34,44 @@ case options[:mode]
26
34
  when :encode
27
35
  encoder = Rien::Encoder.new
28
36
  bytes = encoder.encode_file(options[:file])
29
- generated_name = "#{options[:file]}.encoded.rb"
30
- bootstrap = encoder.bootstrap(generated_name)
37
+ generated_name = options[:output]
38
+ # Check if end with .rb and no files generated existing
39
+
40
+ File.open("#{generated_name}.rbc", 'wb') do |f|
41
+ f.write bytes
42
+ end
31
43
 
32
44
  File.open(generated_name, 'w') do |f|
33
- f.write bootstrap
45
+ f.write encoder.bootstrap
34
46
  end
47
+ when :pack
48
+ source = options[:file]
49
+ destination = options[:output]
50
+ FileUtils.cp_r source, destination
51
+ encoder = Rien::Encoder.new
52
+
53
+ files = Dir.glob(File.join(destination, "**/*.rb"))
54
+ progressbar = ProgressBar.create(:title => "Generating", :starting_at => 0, :total => files.length)
35
55
 
36
- File.open("#{generated_name}.rien", 'wb') do |f|
37
- f.write bytes
56
+ files.each do |path|
57
+ progressbar.log("Compiling: #{path}")
58
+ begin
59
+ bytes = encoder.encode_file(path)
60
+ File.open("#{path}.rbc", 'wb') do |f|
61
+ f.write bytes
62
+ end
63
+
64
+ # Replace file with bootstrap
65
+ FileUtils.rm(path)
66
+ File.open(path, 'w') do |f|
67
+ f.write encoder.bootstrap
68
+ end
69
+
70
+ progressbar.increment
71
+ rescue Exception
72
+ # ignore
73
+ progressbar.increment
74
+ end
38
75
  end
39
76
  when :help
40
77
  puts parser
data/lib/rien/decoder.rb CHANGED
@@ -3,6 +3,13 @@ class Rien::Decoder
3
3
  version == RUBY_VERSION
4
4
  end
5
5
 
6
+ def self.check_version!(version)
7
+ unless self.check_version(version)
8
+ puts "Ruby Using: #{RUBY_VERSION}, Version Compiled: #{version}"
9
+ exit(1)
10
+ end
11
+ end
12
+
6
13
  def self.eval(filename)
7
14
  file = File.read(filename)
8
15
  ir_bin = Zlib::Inflate.inflate(file)
data/lib/rien/encoder.rb CHANGED
@@ -8,12 +8,12 @@ class Rien::Encoder
8
8
  Zlib::Deflate.deflate(bytecode.to_binary)
9
9
  end
10
10
 
11
- def bootstrap(path)
11
+ def bootstrap
12
12
  <<-EOL
13
13
  require 'rien'
14
14
 
15
- Rien::Decoder.check_version('#{RUBY_VERSION}')
16
- Rien::Decoder.eval('#{path}.rien')
15
+ Rien::Decoder.check_version!('#{RUBY_VERSION}')
16
+ Rien::Decoder.eval("\#{__FILE__}.rbc")
17
17
  EOL
18
18
  end
19
19
 
data/lib/rien/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rien
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/rien.rb CHANGED
@@ -5,4 +5,3 @@ require_relative 'rien/const'
5
5
 
6
6
  require_relative 'rien/decoder'
7
7
  require_relative 'rien/encoder'
8
- require_relative 'rien/pipe'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rien
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
  - CodeRemixer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir:
10
10
  - bin
11
11
  cert_chain: []
12
- date: 2018-12-19 00:00:00.000000000 Z
12
+ date: 2019-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-progressbar
@@ -39,7 +39,6 @@ files:
39
39
  - lib/rien/const.rb
40
40
  - lib/rien/decoder.rb
41
41
  - lib/rien/encoder.rb
42
- - lib/rien/pipe.rb
43
42
  - lib/rien/version.rb
44
43
  - rien.gemspec
45
44
  homepage: https://github.com/coderemixer/rien
@@ -62,8 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
61
  - !ruby/object:Gem::Version
63
62
  version: '0'
64
63
  requirements: []
65
- rubyforge_project:
66
- rubygems_version: 2.7.7
64
+ rubygems_version: 3.0.3
67
65
  signing_key:
68
66
  specification_version: 4
69
67
  summary: Ruby IR Encoding
data/lib/rien/pipe.rb DELETED
File without changes