disclose 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 757b35f81aace385424eabbeea8283d95a90d0bc
4
- data.tar.gz: 59f851cdb6c0ec9d86de0e537cc3b8bae330b760
3
+ metadata.gz: a124f3bd76e5f76c9331eb28389d6ae062812c38
4
+ data.tar.gz: 1b38a9590f2b3802426e343fbd7e4a154edb8f63
5
5
  SHA512:
6
- metadata.gz: 145b6337add3a09f6ca13437f153ebdcd790aa066d738a3f440f41d87c6fba4bb0880fd301696fe232b5ac0e4c9d30db67d0f01552c883901c8e8b19f79d11b4
7
- data.tar.gz: 7316e703b7c9d5c4c947c8512fe29e873dc516222377f6f77b9cf356e98c074b6aec3f58c8d8d30695178d99c8f161a3600691ed9df62bc8d46f946f170d2da2
6
+ metadata.gz: a5d7274cee8b5f028528e28a078572e30cd00e7f074a75971c1de62bd6a6124c7b224c4e9018d2982029a989f7f10581a2687203cd81f5867acb600fc084d5cb
7
+ data.tar.gz: 0305f2417576f315a36e0fce53591dbe4c57936315b77a0a2c14662c3c5514d336bb0f9aaca18bc46a718a0e049c1e2a14ec827e109c96a85eae1529c62f37c1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Disclose
2
2
 
3
- Pack your Node.js project into an executable without compiling.
3
+ Pack your Node.js project into an executable without recompiling Node.js.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,7 +8,11 @@ Pack your Node.js project into an executable without compiling.
8
8
 
9
9
  ## Usage
10
10
 
11
- $ disclose path_to_your_node_js_project
11
+ $ disclose <node_path> <project_path>
12
+
13
+ ## Example
14
+
15
+ $ disclose /usr/local/bin/node /usr/local/lib/node_modules/coffee-script
12
16
 
13
17
  ## License
14
18
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["The rugged tests are fragile"]
10
10
  spec.email = ["pmq2001@gmail.com"]
11
11
 
12
- spec.summary = %q{Pack your Node.js project into an executable without compiling.}
13
- spec.description = %q{Pack your Node.js project into an executable without compiling.}
12
+ spec.summary = %q{Pack your Node.js project into an executable without recompiling Node.js.}
13
+ spec.description = %q{Pack your Node.js project into an executable without recompiling Node.js.}
14
14
  spec.homepage = "https://github.com/pmq20/disclose"
15
15
  spec.license = "MIT"
16
16
 
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.12"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "pry"
25
26
  end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless 2 == ARGV.size
4
+ puts Disclose.usage
5
+ end
6
+
7
+ instance = Disclose.new *ARGV
8
+
9
+ begin
10
+ instance.run!
11
+ rescue Disclose::Error => e
12
+ STDERR.puts e.message
13
+ exit 1
14
+ end
@@ -1,5 +1,81 @@
1
1
  require "disclose/version"
2
+ require "disclose/c"
3
+ require 'fileutils'
4
+ require 'shellwords'
5
+ require 'json'
2
6
 
3
- module Disclose
4
- # Your code goes here...
7
+ class Disclose
8
+ class Error < RuntimeError; end
9
+
10
+ def initialize(node_path, project_path)
11
+ @node_path = node_path
12
+ @project_path = project_path
13
+ @working_dir = Dir.mktmpdir
14
+ parse_binaries!
15
+ end
16
+
17
+ def parse_binaries!
18
+ @package_path = File.join(@project_path, 'package.json')
19
+ raise "No package.json exist at #{@package_path}." unless File.exist?(@package_path)
20
+ @package_json = JSON.parse File.read @package_path
21
+ @binaries = @package_json['bin']
22
+ if @binaries
23
+ STDERR.puts "Detected binaries: #{@binaries}"
24
+ else
25
+ raise "No Binaries detected inside #{@package_path}."
26
+ end
27
+ end
28
+
29
+ def run!
30
+ tar!
31
+ header!
32
+ c!
33
+ end
34
+
35
+ def tar!
36
+ chdir(@project_path) do
37
+ @tar_path = "#{@working_dir}/tar.tar"
38
+ exe("tar cf #{Shellwords.escape(@tar_path)} . -C #{Shellwords.escape File.dirname @node_path} #{Shellwords.escape File.basename @node_path}")
39
+ end
40
+ end
41
+
42
+ def header!
43
+ chdir(@working_dir) do
44
+ exe("xxd -i tar.tar > tar.h")
45
+ end
46
+ end
47
+
48
+ def c!
49
+ chdir(@working_dir) do
50
+ @binaries.each do |key,value|
51
+ FileUtils.cp('tar.h', "#{key}.c")
52
+ File.open("#{key}.c", "a") do |f|
53
+ f.puts C.src(value)
54
+ end
55
+ exe("cc #{key}.c -o #{key}")
56
+
57
+ puts "======= Success ======="
58
+ puts File.join(@working_dir, key)
59
+ puts "======================="
60
+ end
61
+ end
62
+ end
63
+
64
+ def usage
65
+ 'Usage: disclose <node_path> <project_path>'
66
+ end
67
+
68
+ private
69
+
70
+ def exe(cmd)
71
+ STDERR.puts "$ #{cmd}"
72
+ STDERR.print `#{cmd}`
73
+ raise "#{cmd} failed!" unless $?.success?
74
+ end
75
+
76
+ def chdir(path)
77
+ STDERR.puts "$ cd #{path}"
78
+ Dir.chdir(path) { yield }
79
+ STDERR.puts "$ cd #{Dir.pwd}"
80
+ end
5
81
  end
@@ -0,0 +1,40 @@
1
+ class Disclose
2
+ module C
3
+ def self.src(name)
4
+ %Q{
5
+ #include <unistd.h>
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <assert.h>
9
+
10
+ int main(){
11
+ char file[] = "/tmp/disclose.file.XXXXXX";
12
+ char dir[] = "/tmp/disclose.dir.XXXXXX";
13
+ FILE *fp = NULL;
14
+ int ret = -1;
15
+ char cmd[256] = {0};
16
+ char arg[256] = {0};
17
+
18
+ mktemp(file);
19
+ mkdtemp(dir);
20
+
21
+ fp = fopen(file, "wb");
22
+ assert(fp);
23
+
24
+ fwrite(tar_tar, sizeof(unsigned char), sizeof(tar_tar), fp);
25
+ fclose(fp);
26
+
27
+ snprintf(cmd, 255, "tar xf %s -C %s", file, dir);
28
+ ret = system(cmd);
29
+ assert(0 == ret);
30
+
31
+ snprintf(cmd, 255, "%s/node", dir);
32
+ snprintf(arg, 255, "%s/#{name}", dir);
33
+ execl(cmd, cmd, arg, NULL);
34
+
35
+ return 1;
36
+ }
37
+ }
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
- module Disclose
2
- VERSION = "0.1.0"
1
+ class Disclose
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disclose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The rugged tests are fragile
@@ -52,10 +52,25 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: Pack your Node.js project into an executable without compiling.
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Pack your Node.js project into an executable without recompiling Node.js.
56
70
  email:
57
71
  - pmq2001@gmail.com
58
- executables: []
72
+ executables:
73
+ - disclose
59
74
  extensions: []
60
75
  extra_rdoc_files: []
61
76
  files:
@@ -69,7 +84,9 @@ files:
69
84
  - bin/console
70
85
  - bin/setup
71
86
  - disclose.gemspec
87
+ - exe/disclose
72
88
  - lib/disclose.rb
89
+ - lib/disclose/c.rb
73
90
  - lib/disclose/version.rb
74
91
  homepage: https://github.com/pmq20/disclose
75
92
  licenses:
@@ -94,5 +111,5 @@ rubyforge_project:
94
111
  rubygems_version: 2.6.3
95
112
  signing_key:
96
113
  specification_version: 4
97
- summary: Pack your Node.js project into an executable without compiling.
114
+ summary: Pack your Node.js project into an executable without recompiling Node.js.
98
115
  test_files: []