Allow reformat to accept diff src/target
This commit is contained in:
+27
-5
@@ -8,14 +8,36 @@ RecipeBookParser = require '../src/scripts/models/recipe_book_parser'
|
|||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
if process.argv.length isnt 3
|
if process.argv.length is 3
|
||||||
throw new Error "Expected a file name as an argument"
|
sourceFileName = process.argv[2]
|
||||||
|
targetFileName = process.argv[2]
|
||||||
|
else if process.argv.length is 4
|
||||||
|
sourceFileName = process.argv[2]
|
||||||
|
targetFileName = process.argv[3]
|
||||||
|
else
|
||||||
|
console.error """
|
||||||
|
|
||||||
fileName = process.argv[2]
|
USAGE: reformat <source> (<target>)
|
||||||
text = fs.readFileSync fileName, 'UTF-8'
|
|
||||||
|
Reformats a given recipe book into the latest version of the recipe book
|
||||||
|
format. This includes alphabetizing entries, simplifying item lists, and
|
||||||
|
upgrading to the latest version.
|
||||||
|
|
||||||
|
If given a single argument, the named file will be replaced with the
|
||||||
|
reformatted version. If two arguments are given, then the output will be
|
||||||
|
written to the second file. If a "-" is given as the second file, the
|
||||||
|
output will be written to stdout.
|
||||||
|
|
||||||
|
"""
|
||||||
|
process.exit -1
|
||||||
|
|
||||||
|
text = fs.readFileSync sourceFileName, 'UTF-8'
|
||||||
data = JSON.parse text
|
data = JSON.parse text
|
||||||
parser = new RecipeBookParser
|
parser = new RecipeBookParser
|
||||||
recipeBook = parser.parse data
|
recipeBook = parser.parse data
|
||||||
text = parser.unparse recipeBook
|
text = parser.unparse recipeBook
|
||||||
|
|
||||||
fs.writeFileSync fileName, text, encoding:'UTF-8'
|
if targetFileName is '-'
|
||||||
|
console.log text
|
||||||
|
else
|
||||||
|
fs.writeFileSync targetFileName, text, encoding:'UTF-8'
|
||||||
|
|||||||
Reference in New Issue
Block a user