"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/season/lib/csonc.js" (11 Apr 2017, 2901 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var CSON, fs, optimist, path;
    3 
    4   fs = require('fs');
    5 
    6   path = require('path');
    7 
    8   optimist = require('optimist');
    9 
   10   CSON = require('cson-parser');
   11 
   12   module.exports = function(argv) {
   13     var data, error, inputFile, options, parseData, version, _ref;
   14     if (argv == null) {
   15       argv = [];
   16     }
   17     options = optimist(argv);
   18     options.usage("Usage: csonc [options] cson_file --output json_file\n       csonc [options] < cson_file [> json_file]\n\nCompiles CSON to JSON.\n\nIf no input file is specified then the CSON is read from standard in.\n\nIf no output file is specified then the JSON is written to standard out.");
   19     options.alias('h', 'help').describe('help', 'Print this help message');
   20     options.alias('r', 'root').boolean('root').describe('root', 'Require that the input file contain an object at the root')["default"]('root', false);
   21     options.alias('o', 'output').string('output').describe('output', 'File path to write the JSON output to');
   22     options.alias('v', 'version').describe('version', 'Print the version');
   23     argv = options.argv;
   24     inputFile = argv._[0];
   25     if (inputFile) {
   26       inputFile = path.resolve(inputFile);
   27     }
   28     if (argv.version) {
   29       version = require('../package.json').version;
   30       console.log(version);
   31       return;
   32     }
   33     if (argv.help) {
   34       options.showHelp();
   35       return;
   36     }
   37     parseData = function(data) {
   38       var error, json, object, outputFile, _ref;
   39       try {
   40         object = CSON.parse(data);
   41         if (argv.r && (!_.isObject(object) || _.isArray(object))) {
   42           console.error("CSON data does not contain a root object");
   43           process.exit(1);
   44           return;
   45         }
   46       } catch (_error) {
   47         error = _error;
   48         console.error("Parsing data failed: " + error.message);
   49         process.exit(1);
   50       }
   51       json = JSON.stringify(object, void 0, 2) + "\n";
   52       if (argv.output) {
   53         outputFile = path.resolve(argv.output);
   54         try {
   55           return fs.writeFileSync(outputFile, json);
   56         } catch (_error) {
   57           error = _error;
   58           return console.error("Writing " + outputFile + " failed: " + ((_ref = error.code) != null ? _ref : error));
   59         }
   60       } else {
   61         return process.stdout.write(json);
   62       }
   63     };
   64     if (inputFile) {
   65       try {
   66         return parseData(fs.readFileSync(inputFile, 'utf8'));
   67       } catch (_error) {
   68         error = _error;
   69         console.error("Reading " + inputFile + " failed: " + ((_ref = error.code) != null ? _ref : error));
   70         return process.exit(1);
   71       }
   72     } else {
   73       process.stdin.resume();
   74       process.stdin.setEncoding('utf8');
   75       data = '';
   76       process.stdin.on('data', function(chunk) {
   77         return data += chunk.toString();
   78       });
   79       return process.stdin.on('end', function() {
   80         return parseData(data);
   81       });
   82     }
   83   };
   84 
   85 }).call(this);