mirror of
https://github.com/samsonjs/Mojo.Ext.git
synced 2026-03-25 09:25:46 +00:00
[CHANGED] added injection script and pretty printing.
This commit is contained in:
parent
7be7950555
commit
32f7a8ac7b
6 changed files with 98 additions and 0 deletions
62
inject.rb
Executable file
62
inject.rb
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rubygems'
|
||||
require 'json'
|
||||
require 'fileutils'
|
||||
|
||||
def inject
|
||||
FileUtils.cp_r(mojo_ext_path, target_mojo_ext_path)
|
||||
|
||||
mojo_ext_source_dict = {'source' => 'mojo-ext/ext.js'}
|
||||
unless sources.first == mojo_ext_source_dict
|
||||
sources.unshift(mojo_ext_source_dict)
|
||||
save_sources!
|
||||
end
|
||||
end
|
||||
|
||||
def extended?
|
||||
File.exists?(File.join(project_path, 'mojo-ext'))
|
||||
end
|
||||
|
||||
def sources
|
||||
$sources ||= JSON.parse(File.read(sources_file))
|
||||
end
|
||||
|
||||
def sources_file
|
||||
File.join(project_path, 'sources.json')
|
||||
end
|
||||
|
||||
def save_sources!
|
||||
FileUtils.mv(sources_file, File.join(project_path, 'sources.json-backup'))
|
||||
File.open(sources_file, 'w') {|f| f.puts(sources.to_json)}
|
||||
`./prettyprint.py "#{sources_file}" "#{sources_file}"`
|
||||
end
|
||||
|
||||
def project_path
|
||||
ARGV.first || Dir.pwd
|
||||
end
|
||||
|
||||
def main
|
||||
unless File.exists?(sources_file)
|
||||
raise "no Mojo project found at #{project_path}"
|
||||
end
|
||||
|
||||
if extended?
|
||||
puts "project already contains Mojo.Ext, bailing"
|
||||
else
|
||||
inject
|
||||
puts "injected Mojo.Ext"
|
||||
end
|
||||
end
|
||||
|
||||
def mojo_ext_path
|
||||
File.expand_path(File.join('..', 'src'), __FILE__)
|
||||
end
|
||||
|
||||
def target_mojo_ext_path
|
||||
File.join(project_path, 'mojo-ext')
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
main
|
||||
end
|
||||
36
prettyprint.py
Executable file
36
prettyprint.py
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/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