boojs 0.0.11 → 0.0.12
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 +4 -4
- data/README.md +13 -4
- data/bin/boojs +9 -3
- data/lib/boojs/version.rb +1 -1
- data/lib/boojs.rb +9 -3
- data/logo.png +0 -0
- data/spec/cli_spec.rb +40 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2816f9929db6f4b3a6ba72ec65c64decc07ab016
|
4
|
+
data.tar.gz: 1c843b29d1261e9ffcc08e460eb6a8247c3621ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 839246c16475ca0a1d4bed48163f9a39773a6aacd537a8927762a9bd67e3aa0d5c815321b11feeaad8e96df098f51a945eef29945b9306c502e7d81ad7193871
|
7
|
+
data.tar.gz: e1b8b16bc122526097f36ed8c62541b379538b47cfdb9fe0e545cbad4d6abc9f8fbbfe561d681f45031bee4219aa03d89624d5d8226e878ffd1d708d641cc9d9
|
data/README.md
CHANGED
@@ -10,9 +10,12 @@
|
|
10
10
|
</p>
|
11
11
|
|
12
12
|
# What is this?
|
13
|
-
A simple tool that allows you to execute javascript in the command line as if you were in a browser. Built on-top of [PhantomJS](phantomjs.org) and
|
14
|
-
|
13
|
+
A simple tool that allows you to execute javascript in the command line as if you were in a browser. Built on-top of [PhantomJS](http://phantomjs.org/) and
|
14
|
+
acts as a well-behaved unix tool.
|
15
15
|
|
16
|
+
**Wait, isn't this just NodeJS? No, they are for different things. BooJS gives you the full DOM, you can call `document` in BooJS and import arbitrary browser javascript libraries.**
|
17
|
+
|
18
|
+
# Setup
|
16
19
|
```sh
|
17
20
|
#Setup
|
18
21
|
gem install boojs
|
@@ -21,15 +24,16 @@ gem install boojs
|
|
21
24
|
# Usage
|
22
25
|
#### SYNOPSIS
|
23
26
|
```sh
|
24
|
-
boojs [-v file]
|
27
|
+
boojs [-e statement] [-v file] [file]
|
25
28
|
```
|
26
29
|
|
27
30
|
#### DESCRIPTION
|
28
31
|
The following options are available:
|
32
|
+
* `-e` - Pass a javascript statement to execute after the file (if a file is provided) and then immediately terminate.
|
29
33
|
* `-v` - Verify that a file contains no javascript syntax errors. Returns 0 if there are no errors.
|
30
34
|
|
31
35
|
#### EXAMPLES
|
32
|
-
Open a standard headless javascript browser REPL
|
36
|
+
Open a standard headless javascript browser 'REPL'
|
33
37
|
```sh
|
34
38
|
(sh)>boojs
|
35
39
|
```
|
@@ -39,6 +43,11 @@ Execute a file first, then enter pipe mode (repl like)
|
|
39
43
|
(sh)>boojs code.js
|
40
44
|
```
|
41
45
|
|
46
|
+
Execute a statement, and then immediately exit.
|
47
|
+
```sh
|
48
|
+
(sh)>boojs -e "console.log(document);"
|
49
|
+
```
|
50
|
+
|
42
51
|
Verify that a file contains no javascript errors
|
43
52
|
```sh
|
44
53
|
(sh)>boojs -v code.js
|
data/bin/boojs
CHANGED
@@ -6,11 +6,17 @@ require 'phantomjs'
|
|
6
6
|
#Parse
|
7
7
|
##########################################
|
8
8
|
parser = OptionParser.new do |opts|
|
9
|
-
opts.banner = "Usage: boojs [-v file] [file]"
|
9
|
+
opts.banner = "Usage: boojs [-v file] [-e command] [file]"
|
10
10
|
|
11
|
+
#Verify this file
|
11
12
|
opts.on "-v FILE" do |f|
|
12
13
|
@vfile = f
|
13
14
|
end
|
15
|
+
|
16
|
+
#One-shot command
|
17
|
+
opts.on "-e COMMAND" do |c|
|
18
|
+
@c = c
|
19
|
+
end
|
14
20
|
end
|
15
21
|
parser.parse!
|
16
22
|
file = ARGV.pop
|
@@ -22,8 +28,8 @@ if @vfile
|
|
22
28
|
BooJS.verify File.read(@file)
|
23
29
|
else
|
24
30
|
if file
|
25
|
-
BooJS.pipe File.read(file)
|
31
|
+
BooJS.pipe File.read(file), @c
|
26
32
|
else
|
27
|
-
BooJS.pipe
|
33
|
+
BooJS.pipe nil, @c
|
28
34
|
end
|
29
35
|
end
|
data/lib/boojs/version.rb
CHANGED
data/lib/boojs.rb
CHANGED
@@ -28,8 +28,9 @@ module BooJS
|
|
28
28
|
system("phantomjs #{tmp.path} 2>&1") or raise "Verifying failed"
|
29
29
|
end
|
30
30
|
|
31
|
-
#Optionally, accept code to inject
|
32
|
-
|
31
|
+
#Optionally, accept code to inject and a command to run
|
32
|
+
#If the command is nil, this is not executed as a oneshot
|
33
|
+
def self.pipe(str=nil, cmd=nil)
|
33
34
|
js = %{
|
34
35
|
var system = require('system');
|
35
36
|
function __spec_ping(str) {
|
@@ -53,7 +54,12 @@ module BooJS
|
|
53
54
|
js += "\n#{str}" if str
|
54
55
|
|
55
56
|
#Repl
|
56
|
-
|
57
|
+
if cmd
|
58
|
+
js += "\n#{cmd}"
|
59
|
+
js += "\nphantom.exit(1)"
|
60
|
+
else
|
61
|
+
js += "\nwhile (true) { var line = system.stdin.readLine(); eval(line); }"
|
62
|
+
end
|
57
63
|
|
58
64
|
phantom = Phantomjs.path
|
59
65
|
tmp = Tempfile.new(SecureRandom.hex)
|
data/logo.png
CHANGED
Binary file
|
data/spec/cli_spec.rb
CHANGED
@@ -3,12 +3,12 @@ require 'tempfile'
|
|
3
3
|
require 'securerandom'
|
4
4
|
|
5
5
|
describe "CLI" do
|
6
|
-
before(:
|
6
|
+
before(:each) do
|
7
7
|
#Laziness
|
8
8
|
`ps -ax | grep phantomjs | grep -v phantomjs | awk '{print $1}' | xargs kill -9`
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
it "Will not exit in pipe mode" do
|
12
12
|
@finished = false
|
13
13
|
Thread.new do
|
14
14
|
`ruby -I./lib ./bin/boojs`
|
@@ -91,4 +91,42 @@ describe "CLI" do
|
|
91
91
|
sleep 5
|
92
92
|
expect(@read).to eq("hello")
|
93
93
|
end
|
94
|
+
|
95
|
+
it "Can be passed a command as an argument with the -e flag for a one shot" do
|
96
|
+
Thread.new do
|
97
|
+
Open3.popen3(%{ruby -I./lib ./bin/boojs -e 'console.log("hello");'}) do |i, o, e, t|
|
98
|
+
@read = o.gets.chomp
|
99
|
+
@value = t.value
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
sleep 5
|
104
|
+
expect(@read).to eq("hello")
|
105
|
+
expect(@value).not_to eq(nil)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "Can be passed a command as an argument with the -e flag for a one shot and a file" do
|
109
|
+
#Write to a temporary file
|
110
|
+
function_name = SecureRandom.hex
|
111
|
+
value = SecureRandom.hex
|
112
|
+
jsc = %{
|
113
|
+
function a_#{function_name}() {
|
114
|
+
console.log("#{value}");
|
115
|
+
}
|
116
|
+
}
|
117
|
+
f = Tempfile.new(SecureRandom.hex)
|
118
|
+
f.puts jsc
|
119
|
+
f.close
|
120
|
+
|
121
|
+
Thread.new do
|
122
|
+
Open3.popen3(%{ruby -I./lib ./bin/boojs -e 'a_#{function_name}()' #{f.path}}) do |i, o, e, t|
|
123
|
+
@read = o.gets.chomp
|
124
|
+
@value = t.value
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
sleep 5
|
129
|
+
expect(@read).to eq(value)
|
130
|
+
expect(@value).not_to eq(nil)
|
131
|
+
end
|
94
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boojs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|