mirror of
https://github.com/samsonjs/Mojo.Ext.git
synced 2026-04-27 15:07:46 +00:00
[CHANGED] removed python program to pretty print JSON, used jj in Ruby instead.
This commit is contained in:
parent
32f7a8ac7b
commit
157503c13c
2 changed files with 9 additions and 38 deletions
11
inject.rb
11
inject.rb
|
|
@ -3,6 +3,7 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'stringio'
|
||||||
|
|
||||||
def inject
|
def inject
|
||||||
FileUtils.cp_r(mojo_ext_path, target_mojo_ext_path)
|
FileUtils.cp_r(mojo_ext_path, target_mojo_ext_path)
|
||||||
|
|
@ -27,9 +28,15 @@ def sources_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_sources!
|
def save_sources!
|
||||||
|
# capture pretty-print output to string
|
||||||
|
pretty_json = StringIO.new
|
||||||
|
orig_stdout = $stdout
|
||||||
|
$stdout = pretty_json
|
||||||
|
jj sources
|
||||||
|
$stdout = orig_stdout
|
||||||
|
pretty_json.rewind()
|
||||||
FileUtils.mv(sources_file, File.join(project_path, 'sources.json-backup'))
|
FileUtils.mv(sources_file, File.join(project_path, 'sources.json-backup'))
|
||||||
File.open(sources_file, 'w') {|f| f.puts(sources.to_json)}
|
File.open(sources_file, 'w') {|f| f.puts(pretty_json.read)}
|
||||||
`./prettyprint.py "#{sources_file}" "#{sources_file}"`
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_path
|
def project_path
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
"""
|
|
||||||
Convert JSON data to human-readable form.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
prettyJSON.py inputFile [outputFile]
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import simplejson as json
|
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
|
||||||
try:
|
|
||||||
inputFile = open(args[1])
|
|
||||||
input = json.load(inputFile)
|
|
||||||
inputFile.close()
|
|
||||||
except IndexError:
|
|
||||||
usage()
|
|
||||||
return False
|
|
||||||
if len(args) < 3:
|
|
||||||
print json.dumps(input, sort_keys = False, indent = 4)
|
|
||||||
else:
|
|
||||||
outputFile = open(args[2], "w")
|
|
||||||
json.dump(input, outputFile, sort_keys = False, indent = 4)
|
|
||||||
outputFile.close()
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
|
||||||
print __doc__
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(not main(sys.argv))
|
|
||||||
Loading…
Reference in a new issue