Files
website/scripts/reformat
T
Andrew Miner e612cedf8d Fix scripts and tests
* Fix the reformat script to work with recent changes
* Fix the convert-nei-dump script to remove leading and trailing '_'
* Fix various broken tests
2015-01-21 15:05:19 -08:00

52 lines
1.7 KiB
CoffeeScript
Executable File

#!/usr/bin/env coffee
global._ = require 'underscore'
global.Backbone = require 'backbone'
fs = require 'fs'
Logger = require '../src/scripts/logger'
ModVersion = require '../src/scripts/models/mod_version'
ModVersionParser = require '../src/scripts/models/mod_version_parser'
require '../src/scripts/underscore_mixins'
########################################################################################################################
if process.argv.length is 3
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 """
USAGE: reformat <source> (<target>)
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
global.logger = new Logger level:Logger.WARNING
try
text = fs.readFileSync sourceFileName, 'UTF-8'
parser = new ModVersionParser model:new ModVersion modSlug:'', version:''
modVersion = parser.parse text
text = parser.unparse modVersion
if targetFileName is '-'
console.log text
else
fs.writeFileSync targetFileName, text, encoding:'UTF-8'
catch e
console.error e.stack