-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Feat/openrpc describe #66
Changes from 52 commits
c0b3e99
e1e296f
2f27d7d
c4cdb5d
70606a3
b717463
3d135fb
f71a118
affbfe9
7cbfe11
7fe19af
12fcc73
97e4bbd
5174a59
480c0ff
9c1fd41
3655474
25ffa84
f8badf7
62e3a8e
ae7f91f
6b1733d
2d532e0
f7e35ee
122fc85
11bfcc0
452a4b9
d7021d2
e1354ed
e3ba54c
e634b09
4e0ebde
22f93fe
abd8920
9b77c07
6e89095
44f5bad
bfc4b52
a60324a
78899d8
ea7f356
8b0f697
8f8753c
cee881a
6295542
ca80acf
8c24416
4953b7c
e33b389
2ce5ce2
5761cf4
b9d9f0b
769edf9
38662b0
beba177
ed3ac24
d8028d7
f9a5859
295b2d8
5ccb751
253fa8d
5971264
274fac0
b720b7a
99d302e
a0c597d
cf1f0f5
bdc0bd8
c0917ff
3cf2d23
d24e681
8108b02
10b3f22
1d5def1
f85fd0e
1e06ba9
8fb93b5
c281025
010205a
b5505da
6abf651
d5c4aea
27de8aa
e2f26b6
76dc2b8
f36393a
044c8a2
532614c
7af048e
75e1cb0
8b73b9a
ccdf168
47f4b5a
b61bfa1
c1f79d7
9a1451c
3c2b9ac
1dd15d1
9127410
fb5b231
9568648
692713b
e4c4725
23bdc9c
600c206
49c45f3
5d263c2
5319e62
43180ab
8843b93
dfce94c
a4188bf
6aad7c6
fb5a231
7b72230
4af7b8b
492dae1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var schema_utils_js_1 = require("@open-rpc/schema-utils-js"); | ||
var program = require('commander').program; | ||
program.version("0.0.1"); | ||
program.option("-v, --verbose", "verbose logging"); | ||
program.parse(process.argv); | ||
// Get either stdin or first argument. | ||
// https://gist.github.com/ishu3101/9fa58ca1440f780d6288 | ||
var args = program.args; // process.argv.slice(2); | ||
var input = args[0]; | ||
var isTTY = process.stdin.isTTY; | ||
var stdin = process.stdin; | ||
var stdout = process.stdout; | ||
// If no STDIN and no arguments, display usage message | ||
if (isTTY && args.length === 0) { | ||
program.help(); | ||
} | ||
// If no STDIN but arguments given | ||
else if (isTTY && args.length !== 0) { | ||
handleShellArguments(); | ||
} | ||
// read from STDIN | ||
else { | ||
handlePipedContent(); | ||
} | ||
function handlePipedContent() { | ||
var data = ''; | ||
stdin.on('readable', function () { | ||
var chuck = stdin.read(); | ||
if (chuck !== null) { | ||
data += chuck; | ||
} | ||
}); | ||
stdin.on('end', function () { | ||
doValidate(data); | ||
}); | ||
} | ||
function handleShellArguments() { | ||
doValidate(input); | ||
} | ||
function doValidate(input) { | ||
if (input === "") { | ||
process.exit(2); | ||
} | ||
schema_utils_js_1.parseOpenRPCDocument(input).then(function (doc) { | ||
if (program.verbose) | ||
console.log(doc); | ||
console.log("OK"); | ||
}).catch(function (err) { | ||
console.log("PARSE FAIL", err); | ||
process.exit(1); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import SimpleHTTPServer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add the python dep? heres a popular one: https://www.npmjs.com/package/serve There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is here so I can serve the generated doc to a local Open-RPC playground for development visibility. I was getting CORS errors with the normal |
||
import sys | ||
|
||
# https://gist.github.com/enjalot/2904124 | ||
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | ||
def send_head(self): | ||
"""Common code for GET and HEAD commands. | ||
This sends the response code and MIME headers. | ||
Return value is either a file object (which has to be copied | ||
to the outputfile by the caller unless the command was HEAD, | ||
and must be closed by the caller under all circumstances), or | ||
None, in which case the caller has nothing further to do. | ||
""" | ||
path = self.translate_path(self.path) | ||
f = None | ||
if os.path.isdir(path): | ||
if not self.path.endswith('/'): | ||
# redirect browser - doing basically what apache does | ||
self.send_response(301) | ||
self.send_header("Location", self.path + "/") | ||
self.end_headers() | ||
return None | ||
for index in "index.html", "index.htm": | ||
index = os.path.join(path, index) | ||
if os.path.exists(index): | ||
path = index | ||
break | ||
else: | ||
return self.list_directory(path) | ||
ctype = self.guess_type(path) | ||
try: | ||
# Always read in binary mode. Opening files in text mode may cause | ||
# newline translations, making the actual size of the content | ||
# transmitted *less* than the content-length! | ||
f = open(path, 'rb') | ||
except IOError: | ||
self.send_error(404, "File not found") | ||
return None | ||
self.send_response(200) | ||
self.send_header("Content-type", ctype) | ||
fs = os.fstat(f.fileno()) | ||
self.send_header("Content-Length", str(fs[6])) | ||
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) | ||
self.send_header("Access-Control-Allow-Origin", "*") | ||
self.end_headers() | ||
return f | ||
|
||
|
||
if __name__ == "__main__": | ||
import os | ||
import SocketServer | ||
|
||
PORT = (len(sys.argv) > 1 and int(sys.argv[1])) or 31338 | ||
|
||
Handler = CORSHTTPRequestHandler | ||
#Handler = SimpleHTTPServer.SimpleHTTPRequestHandler | ||
|
||
httpd = SocketServer.TCPServer(("", PORT), Handler) | ||
|
||
print "serving at port", PORT | ||
httpd.serve_forever() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the result of running typescript compile?
If so, might I suggest that you include the src ts instead of the compiled result?
If this is meant to be maintained as JS, then lets ditch the export and clean this up a little.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. This is/was only in the PR as a shortcut/convenience for reproducing the document validation heuristic, and I've since made the script just demand that this tool is installed globally.