'use strict';var_fs=require('fs');var_fs2=_interopRequireDefault(_fs);var_path=require('path');var_path2=_interopRequireDefault(_path);var_minimist=require('minimist');var_minimist2=_interopRequireDefault(_minimist);var_package=require('../package.json');var_package2=_interopRequireDefault(_package);var_=require('./');var_2=_interopRequireDefault(_);function_interopRequireDefault(obj){returnobj&&obj.__esModule?obj:{default:obj}}varargv=(0,_minimist2.default)(process.argv.slice(2),{alias:{'convert':'c','space':'s','validate':'v','out-file':'o','version':'V','help':'h'},boolean:['convert','validate','version','help'],string:['space','out-file']});if(argv.version){version()}elseif(argv.help){usage()}else{varinFilename=argv._[0];varreadStream=void0;if(inFilename){readStream=_fs2.default.createReadStream(inFilename)}else{readStream=process.stdin}varjson5='';readStream.on('data',function(data){json5+=data});readStream.on('end',function(){varspace=void0;if(argv.space==='t'||argv.space==='tab'){space='\t'}else{space=Number(argv.space)}varvalue=void0;try{value=_2.default.parse(json5);if(!argv.validate){varjson=JSON.stringify(value,null,space);varwriteStream=void0;if(argv.convert&&inFilename&&!argv.o){varparsedFilename=_path2.default.parse(inFilename);varoutFilename=_path2.default.format(Object.assign(parsedFilename,{base:_path2.default.basename(parsedFilename.base,parsedFilename.ext)+'.json'}));writeStream=_fs2.default.createWriteStream(outFilename)}elseif(argv.o){writeStream=_fs2.default.createWriteStream(argv.o)}else{writeStream=process.stdout}writeStream.write(json)}}catch(err){console.error(err.message);process.exit(1)}})}functionversion(){console.log(_package2.default.version)}functionusage(){console.log('\n Usage: json5 [options] <file>\n\n If <file> is not provided, then STDIN is used.\n\n Options:\n\n -s, --space The number of spaces to indent or \'t\' for tabs\n -o, --out-file [file] Output to the specified file, otherwise STDOUT\n -v, --validate Validate JSON5 but do not output JSON\n -V, --version Output the version number\n -h, --help Output usage information')}