disclose 0.4.0 → 0.5.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: 147ded056232e909f26a55163895b1fd1ef6f0d1
4
- data.tar.gz: 29572d9b133fab795a0ff679bedd26e5e783d169
3
+ metadata.gz: 12b6c9cb872ab8098620fb864c7a507cc1ffe53f
4
+ data.tar.gz: 521c3c4d2f170c39c58939f0d36ef5ec24e06a9c
5
5
  SHA512:
6
- metadata.gz: efd56b7015ed9c502bcf06891227d92163c4ff6f7707504a6fdaf1ba73482be893ad92deeb4484a91e8903d581c439072f614e76ad4936b6513de0f0af99a15d
7
- data.tar.gz: d5ca60829d3f3d7d4dc628349f682d11fa08d3d700524b96c10be903aa6ad271907e193df073c16fafc86209628479bad3155ee38f5342b5542e1a65df50b3ef
6
+ metadata.gz: ac677eb6eb07cc39cff5d09ee0699c04ba3dfea7f1e0244987bdb02a254e3b9da200d6b09dfa17db0ba015f6f0c4da174df4649867deab005bc743c704689a8a
7
+ data.tar.gz: 39cc60843db112afad3a2020c29cc3ae02547859565d08999acd9f068ee4b815e0ef7bbad3f15fc8688372047a06cc85e6ee958577a433222c395be084bbd85e
data/README.md CHANGED
@@ -12,12 +12,26 @@ Pack your Node.js project into an executable without recompiling Node.js.
12
12
 
13
13
  $ gem install disclose
14
14
 
15
+ ## Dependencies
16
+
17
+ Make sure that your system has the following components,
18
+
19
+ - tar
20
+ - xxd
21
+ - cc or cl.exe
22
+
15
23
  ## Usage
16
24
 
17
25
  $ disclose [node_path] [project_path]
18
26
 
19
27
  ## Example
20
28
 
29
+ On Windows,
30
+
31
+ > disclose "C:\Program Files\nodejs\node.exe" "Z:\node_modules\coffee-script"
32
+
33
+ On Unix,
34
+
21
35
  $ disclose /usr/local/bin/node /usr/local/lib/node_modules/coffee-script
22
36
 
23
37
  ## License
@@ -14,7 +14,26 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/pmq20/disclose"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.files = [
18
+ '.gitignore',
19
+ '.rspec',
20
+ '.travis.yml',
21
+ 'Gemfile',
22
+ 'LICENSE',
23
+ 'README.md',
24
+ 'Rakefile',
25
+ 'bin/console',
26
+ 'bin/setup',
27
+ 'disclose.gemspec',
28
+ 'exe/disclose',
29
+ 'lib/disclose.rb',
30
+ 'lib/disclose/c.rb',
31
+ 'lib/disclose/libiconv_2_dll.h',
32
+ 'lib/disclose/libintl_2_dll.h',
33
+ 'lib/disclose/tar_exe.h',
34
+ 'lib/disclose/version.rb',
35
+ 'lib/disclose/windows.rb',
36
+ ]
18
37
  spec.bindir = "exe"
19
38
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
39
  spec.require_paths = ["lib"]
@@ -42,9 +42,8 @@ Usage: disclose [node_path] [project_path]
42
42
  end
43
43
 
44
44
  def tar!
45
- chdir(@project_path) do
46
- @tar_path = "#{@working_dir}/tar.tar"
47
- exe("tar cf #{Shellwords.escape(@tar_path)} . -C #{Shellwords.escape File.dirname @node_path} #{Shellwords.escape File.basename @node_path}")
45
+ chdir(@working_dir) do
46
+ exe("tar cf tar.tar -C \"#{@project_path}\" . -C \"#{File.dirname @node_path}\" \"#{File.basename @node_path}\"")
48
47
  end
49
48
  end
50
49
 
@@ -62,7 +61,11 @@ Usage: disclose [node_path] [project_path]
62
61
  File.open("#{key}.c", "a") do |f|
63
62
  C.src(f, value, @md5)
64
63
  end
65
- exe("cc #{key}.c -o #{key}")
64
+ if Gem.win_platform?
65
+ exe("cl.exe #{key}.c")
66
+ else
67
+ exe("cc #{key}.c -o #{key}")
68
+ end
66
69
 
67
70
  puts "======= Success ======="
68
71
  puts File.join(@working_dir, key)
@@ -1,51 +1,107 @@
1
1
  class Disclose
2
2
  module C
3
3
  class << self
4
+ def unistd
5
+ if Gem.win_platform?
6
+ %q{
7
+ #include <stdlib.h>
8
+ #include <io.h>
9
+ #include <process.h> /* for getpid() and the exec..() family */
10
+ #include <direct.h> /* for _getcwd() and _chdir() */
11
+ }
12
+ else
13
+ %q{
14
+ #include <unistd.h>
15
+ }
16
+ end
17
+ end
18
+
19
+ def slash
20
+ Gem.win_platform? ? %q{\\\\} : '/'
21
+ end
22
+
4
23
  def src(f, name, md5)
5
24
  windows_prepare(f) if Gem.win_platform?
6
-
25
+ f.puts unistd
7
26
  f.puts %Q{
8
- #include <unistd.h>
9
27
  #include <stdio.h>
10
28
  #include <stdlib.h>
11
29
  #include <assert.h>
12
30
  #include <sys/types.h>
13
31
  #include <sys/stat.h>
14
32
 
33
+ char *tmp_prefix;
34
+ char md5_path[1024];
35
+ char cwd_path[1024];
36
+
37
+ void get_tmp_prefix() {
38
+ tmp_prefix = getenv("TMPDIR");
39
+ if (NULL != tmp_prefix) return;
40
+ tmp_prefix = getenv("TMP");
41
+ if (NULL != tmp_prefix) return;
42
+ tmp_prefix = getenv("TEMP");
43
+ if (NULL != tmp_prefix) return;
44
+ tmp_prefix = cwd_path;
45
+ }
46
+
15
47
  void untar() {
16
- char cmd[256] = {0};
17
- char file[] = "/tmp/disclose.file.XXXXXX";
18
- char dir[] = "/tmp/disclose.dir.XXXXXX";
48
+ char cmd[1024] = {0};
49
+ char file[1024] = {0};
50
+ char dir[1024] = {0};
19
51
  FILE *fp = NULL;
20
52
  int ret;
21
53
 
54
+ // Be careful about the number of XXXXXX
55
+ // Relate to the magical number 20 below.
56
+ snprintf(file, 1023, "%s#{slash}disclose.file.XXXXXX", tmp_prefix);
57
+ snprintf(dir, 1023, "%s#{slash}disclose.dir.XXXXXX", tmp_prefix);
58
+
22
59
  mktemp(file);
23
- mkdtemp(dir);
60
+ mktemp(dir);
61
+ mkdir(dir#{', 0777' unless Gem.win_platform?});
24
62
 
25
63
  fp = fopen(file, "wb");
26
64
  assert(fp);
27
65
  fwrite(tar_tar, sizeof(unsigned char), sizeof(tar_tar), fp);
28
66
  fclose(fp);
29
67
 
30
- #{Gem.win_platform? ? tar_windows : tar}
68
+ #{tar_windows if Gem.win_platform?}
31
69
 
32
- rename(dir, "/tmp/disclose.#{md5}");
70
+ chdir(tmp_prefix);
71
+
72
+ snprintf(cmd, 1023, "tar xf \\"%s\\" -C \\"%s\\"", file + strlen(file) - 20, dir + strlen(dir) - 20);
73
+ ret = system(cmd);
74
+ assert(0 == ret);
75
+
76
+ chdir(cwd_path);
77
+
78
+ rename(dir, md5_path);
33
79
  }
34
80
 
35
81
  int main(int argc, char const *argv[]) {
36
82
  char **argv2 = NULL;
37
83
  int i, index;
38
84
  struct stat info;
85
+ char arg0[1024] = {0};
86
+ char arg1[1024] = {0};
39
87
 
40
- if( stat( "/tmp/disclose.#{md5}", &info ) != 0 )
88
+ getcwd(cwd_path, sizeof(cwd_path));
89
+ get_tmp_prefix();
90
+ snprintf(md5_path, 1023, "%s#{slash}disclose.#{md5}", tmp_prefix);
91
+
92
+ if( stat( md5_path, &info ) != 0 )
41
93
  untar();
42
94
 
43
- assert(0 == stat( "/tmp/disclose.#{md5}", &info ) && info.st_mode & S_IFDIR);
95
+ assert(0 == stat( md5_path, &info ) && info.st_mode & S_IFDIR);
44
96
 
45
97
  argv2 = malloc(sizeof(char*) * (argc + 10));
46
98
  assert(argv2);
47
- argv2[0] = "/tmp/disclose.#{md5}/node";
48
- argv2[1] = "/tmp/disclose.#{md5}/#{name}";
99
+
100
+ snprintf(arg0, 1023, "%s#{slash}node", md5_path);
101
+ snprintf(arg1, 1023, "%s#{slash}#{name}", md5_path);
102
+
103
+ argv2[0] = arg0;
104
+ argv2[1] = arg1;
49
105
  index = 2;
50
106
  for (i = 1; i < argc; ++i) {
51
107
  argv2[index] = argv[i];
@@ -59,20 +115,14 @@ class Disclose
59
115
  }
60
116
  end
61
117
 
62
- def tar
63
- %Q{
64
- snprintf(cmd, 255, "tar xf %s -C %s", file, dir);
65
- ret = system(cmd);
66
- assert(0 == ret);
67
- }
68
- end
69
-
70
118
  def tar_windows
71
119
  %Q{
72
- char tardir[] = "/tmp/disclose.tardir.XXXXXX";
120
+ char tardir[1024];
121
+ snprintf(tardir, 1023, "%s#{slash}disclose.tardir.XXXXXX", tmp_prefix);
122
+ mktemp(tardir);
123
+ mkdir(tardir);
73
124
 
74
- ret = chdir(tardir);
75
- assert(0 == ret);
125
+ chdir(tardir);
76
126
 
77
127
  fp = fopen("libiconv_2.dll", "wb");
78
128
  assert(fp);
@@ -89,9 +139,7 @@ class Disclose
89
139
  fwrite(tar_exe, sizeof(unsigned char), sizeof(tar_exe), fp);
90
140
  fclose(fp);
91
141
 
92
- snprintf(cmd, 255, "tar xf %s -C %s", file, dir);
93
- ret = system(cmd);
94
- assert(0 == ret);
142
+ chdir(cwd_path);
95
143
  }
96
144
  end
97
145
 
@@ -1,3 +1,3 @@
1
1
  class Disclose
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disclose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The rugged tests are fragile
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler