Example #1
0
module.exports = function(source) {
  this.cacheable();

  console.log('source', source);
  console.log('strippedSource', stripComments(source));

  return stripComments(source);
}
Example #2
0
// add base rules
function getConfig() {
  var configPath = path.join(__dirname, '..', '..', '.htmlhintrc');
  if (fs.existsSync(configPath)) {
    var config = fs.readFileSync(configPath, 'utf-8');
    return JSON.parse(stripJsonComments(config));
  }
}
Example #3
0
File: app.js Project: abbr/Unippear
var parseWhiteList = function () {
    try {
        validClients = JSON.parse(stripJsonComments(fs.readFileSync(clientWhiteList).toString())).map(function (v) {
            return new RegExp(v)
        })
    } catch (err) {}
}
Example #4
0
//************ Constructor **************//
function WatsonUtils(app,config) {

    // Load local config including credentials for running app locally (but services remotely)
    var configFPath = "./config/watson_config.json";
    if (fs.existsSync(configFPath)) {

        try {
            var data = fs.readFileSync(configFPath, "utf8");
            data = strip_json_comments(data);
            this.config = JSON.parse(data);
        } catch (err) {
            console.log("Unable to load local credentials.json:\n" + JSON.stringify(err));
        }
    }

    // Create Service utils classes
    this.conversationStore = new ConversationStore(this,config)
    this.nlcUtils = new NlcUtils(this)
    this.alchemyUtils = new AlchemyApiUtils(this)
    this.pipelines = new Pipelines()

    //************ Supported URL paths **************//
    var internalThis = this;
    app.post("/answerFactoid", function(req,res) {
        internalThis.answerFactoid(req,res);
    });
}
Example #5
0
  function find(start, rel) {
    var file = path.join(start, rel);

    if (opts.babelrc.indexOf(file) >= 0) {
      return;
    }

    if (exists(file)) {
      var content = fs.readFileSync(file, "utf8");
      var json;

      try {
        json = jsons[content] = jsons[content] || JSON.parse(stripJsonComments(content));
        normaliseOptions(json);
      } catch (err) {
        err.message = `${file}: ${err.message}`;
        throw err;
      }

      opts.babelrc.push(file);

      if (json.breakConfig) return;

      merge(opts, json);
    }

    var up = path.dirname(start);
    if (up !== start) { // root
      find(up, rel);
    }
  }
Example #6
0
      asyncUtil.eachLimit(namespaces, 40, function (namespace, callback) {
        var resourceFilePath = getResourceFilePath(lng, namespace);

        var fileExists = fs.existsSync(resourceFilePath);

        if (fileExists) {
          var namespaceFileContent = fs.readFileSync(resourceFilePath, 'utf8');

          //logger.info(typeof namespaceFileContent);
          //logger.info(namespaceFileContent);

          try {
            var namespaceJson = JSON.parse(strip(namespaceFileContent));

            //Merge the translations on top of any previous ones
            if (resStore[lng] && resStore[lng][namespace]) {
              _.mergeAll(resStore[lng][namespace], namespaceJson);
            } else {
              resStore[lng][namespace] = namespaceJson;
            }
          } catch (err) {
            resStore[lng][namespace] = {};
            logger.error('Error parsing locale file', resourceFilePath, err);
          }
          callback();
        } else {
          //No JSON exists for this namespace
          missingNameSpaces.push(namespace);
          callback();
        }
      }, function (err) {
Example #7
0
	var _parseConfig = function( path ) {
		return JSON.parse(
			stripJsonComments(
				fs.readFileSync( path, 'utf-8' )
			)
		)
	}
        fs.readFile(filename, function(err, raw) {
            if (!raw) {
                throw new Error("Missing translations [" + filename + "]!");
            }

            def.resolve(JSON.parse(stripJsonComments(raw.toString('utf8'))));
        });
Example #9
0
  sidekickAnalyser(function(setup) {
    var config;

    var conf = setup.configFiles || {};
    if(conf) {
      try {
        config = JSON.parse(stripJsonComments(conf));
      } catch(e) {
        // FIXME need some way of signalling
        console.error("can't parse config");
        console.error(e);
      }
    }

    if(!config) {
      config = {};
    }

    run(setup.content)
      .then((results) => {
        console.log(JSON.stringify({ meta: results }));
      }, (err) => {
        process.exit(1);
      })
  });
Example #10
0
function parse(contents, filename) {
    var data = stripComments(stripBom(contents));
    if (/^\s*$/.test(data)) {
        return {};
    }
    return JSON.parse(data);
}
Example #11
0
exports.getContent = function(config, directory) {
    if (!config) {
        return;
    }

    var configPath = path.resolve(directory, config);
    var ext;
    var content;

    config = path.basename(config);

    if (fs.existsSync(configPath)) {
        ext = path.extname(configPath);

        if (ext === '.js' || ext === '.json') {
            content = require(configPath);
        } else {
            content = JSON.parse(
                stripJSONComments(
                    fs.readFileSync(configPath, 'utf8')
                )
            );
        }

        // Adding property via Object.defineProperty makes it
        // non-enumerable and avoids warning for unsupported rules
        Object.defineProperty(content, 'configPath', {
            value: configPath
        });
    }

    return content && config === 'package.json' ? content.jscsConfig : content;
};
Example #12
0
  loadConfig: function(fp) {
    if (!fp) {
      return {};
    }

    if (!shjs.test("-e", fp)) {
      cli.error("Can't find config file: " + fp);
      exports.exit(1);
    }

    try {
      var config = JSON.parse(stripJsonComments(shjs.cat(fp)));
      config.dirname = path.dirname(fp);

      if (config['extends']) {
        var baseConfig = exports.loadConfig(path.resolve(config.dirname, config['extends']));
        config.globals = _.extend({}, baseConfig.globals, config.globals);
        _.defaults(config, baseConfig);
        delete config['extends'];
      }

      return config;
    } catch (err) {
      cli.error("Can't parse config file: " + fp + "\nError:" + err);
      exports.exit(1);
    }
  },
Example #13
0
  loadConfig: function(fp) {
    if (!fp) {
      return {};
    }

    if (!shjs.test("-e", fp)) {
      cli.error("Can't find config file: " + fp);
      exports.exit(1);
    }

    try {
      var config = JSON.parse(stripJsonComments(shjs.cat(fp)));
      config.dirname = path.dirname(fp);

      if (config['extends']) {
        var baseConfig = exports.loadConfig(path.resolve(config.dirname, config['extends']));
        config = _.merge({}, baseConfig, config, function(a, b) {
          if (_.isArray(a)) {
            return a.concat(b);
          }
        });
        delete config['extends'];
      }

      return config;
    } catch (err) {
      cli.error("Can't parse config file: " + fp + "\nError:" + err);
      exports.exit(1);
    }
  },
Example #14
0
module.exports.load = function (configFilePath, cwd, overrides) {
  if (configFilePath) {
    return override(
      JSON.parse(
        stripJSONComments(
          fs.readFileSync(configFilePath, 'utf-8').trim())), overrides)
  }

  var directory = cwd || process.cwd()
  config = loadConfig(directory)
  if (!config) {
    var evns = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME]
    for (var x = 0; x < evns.length; x++) {
      if (!evns[x]) {
        continue
      }
      config = loadConfig(evns[x])
      if (config) {
        break
      }
    }
  }

  if (config) {
    override(config, overrides)
  }
  return config
}
function parseContent(contents, filename) {
    var data = stripComments(stripBom(contents));
    if (/^\s*$/.test(data)) {
        return {};
    }
    return parseJson(data, null, filename);
}
Example #16
0
/**
 * Load and parse a YAML or JSON configuration object from a file.
 * @param {string} filePath the path to the YAML or JSON config file
 * @returns {Object} the parsed config object (empty object if there was a parse error)
 * @api private
 */
function load(filePath) {
	'use strict';

	var defaults = {
		server: {
			port: 8999,
			static: [{
				mountPath: '/',
				physicalDirectory: path.join(process.cwd(), 'static')
			}],
			requestLogging: true,
			oracleConnectionPool: true,
			oracleDebug: false
		},
		services: []
	};
	var config;

	// Load configuration
	debug('Load configuration file "' + filePath + '"...');
	if (filePath) {
		try {
			config = yaml.safeLoad(stripComments(fs.readFileSync(filePath, 'utf8')));
		} catch (e) {
			throw new TypeError('Could not parse file: ' + filePath + ' Error: ' + e.message);
		}
	}

	// Merge default options with the actual ones
	var extended = underscore.extend(defaults, config);

	return extended;
}
Example #17
0
function loadConfig (dir) {
  for (var x = 0; x < configSources.length; x++) {
    var found
    var source = configSources[x]
    try {
      found = findup.sync(dir, source)
    } catch (e) {
      continue
    }

    if (found) {
      var configFilePath = path.normalize(path.join(found, source))
      try {
        config = JSON.parse(
          stripJSONComments(
            fs.readFileSync(configFilePath, 'utf-8').trim()))
      } catch (e) {
        throw new Error(e + ' ' + configFilePath)
      }

      if (source === 'package.json') {
        config = config.rtlcssConfig
      }

      if (config) {
        return config
      }
    }
  }
}
Example #18
0
/*
 * Return an object from a JSON file containing comments
 */
function loadJson (path) {
    var json = fs.readFileSync(path, 'utf-8');
    json = stripJsonComments(json);
    json = JSON.parse(json);

    return json;
}
Example #19
0
exports.getContent = function (config, directory) {

  if (!config) {
    return
  }

  var configPath = path.resolve(directory, config)
    , ext
    , content

  config = path.basename(config)

  if (fs.existsSync(configPath)) {
    ext = path.extname(configPath)

    if (ext === '.js') {
      content = require(configPath)
    } else {
      content = JSON.parse(stripJSONComments(fs.readFileSync(configPath, 'utf8')))
    }

    content.configPath = configPath
  }

  return content && config === 'package.json' ? content.pugLintConfig || content.jadeLintConfig : content
}
Example #20
0
function init(grunt, options) {
    var _                   = require('underscore'),
        stripJsonComments   = require('strip-json-comments'),
        path                = require('path'),
        config,
        themes,
        file;

    config = grunt.file.read(__dirname + '/settings.json');
    config = stripJsonComments(config);
    config = JSON.parse(config);

    themes = require(path.resolve(process.cwd(), config.themes));

    if (options.theme) {
        themes = _.pick(themes, options.theme);
    }

    tasks = Object.keys(themes);

    config.themes = themes;

    file = grunt.option('file');

    if (file) {
        config.singleTest = file;
    }

    enableTasks(grunt, config);
}
Example #21
0
function loadAndParseConfig(file) {
  try {
    return JSON.parse(stripJsonComments(fs.readFileSync(file).toString()));
  } catch (ex) {
    console.error('Can\'t parse configuration file: "' + file + '"\nException: ' + ex.message);
    process.exit(1);
  }
}
fs.readdirSync(MOBILE_DIR).forEach(function(filename) {
    if (filename.match(/\.json$/) && BLACKLIST.indexOf(filename) === -1) {
        var language = filename.replace(/\.json$/, "");

        var raw = fs.readFileSync(MOBILE_DIR + "/" + filename);
        translations[language + "_mobile"] = JSON.parse(stripJsonComments(raw.toString('utf8')));
    }
});
function loadConfigIfValid(filename) {
  var strip = require("strip-json-comments");
  try {
    JSON.parse(strip(fs.readFileSync(filename, "utf8")));
    return cli.loadConfig(filename);
  } catch (e) {}
  return {};
}
Example #24
0
function loadJson(filepath, content) {
    try {
        return parseJson(stripJsonComments(content));
    } catch (err) {
        err.message = `JSON Error in ${filepath}:\n${err.message}`;
        throw err;
    }
}
var loadConfig = function (path) {
    var data = fs.readFileSync(path, 'utf8');

    data = stripJsonComments(data);
    data = stripBom(data);

    return JSON.parse(data);
};
Example #26
0
                ['./appconfig.json', './appconfig.default.json'].forEach(function (filename) {
                    var json = fs.readFileSync(filename);

                    if (json) {
                        var data = JSON.parse(stripJsonComments(json.toString('utf8')));
                        config = _.defaults(config, data);
                    }
                });
var loadConfig = function(filename){
    var data = fs.readFileSync(__dirname + filename);
    var defaults = {};
    if(data){
        defaults = JSON.parse(stripJsonComments(data.toString()));
    }
    return defaults;
};
var loadConfigIfValid = function loadConfigIfValid(filename) {
	var strip = require('strip-json-comments');
	try {
		JSON.parse(strip(_fs2['default'].readFileSync(filename, 'utf8')));
		return _jshintSrcCli2['default'].loadConfig(filename);
	} catch (e) {}
	return {};
};
Example #29
0
		grunt.file.expand({}, ["files/data/artists/*.json", "files/data/sites/"+grunt.config.get('site_name')+"/posts.json"]).forEach(function(f) {
			try {
				if (!grunt.file.exists(f)) {
					throw "JSON source file "+f+" not found.";
				} else {
					var fragment;

					try {
						var withComments = grunt.file.read(f),
						    without = stripJsonComments(withComments),
						    linted = jsonlint.parse(without);

						fragment = {
							dir: '',
							// Attach comment-less JSON
							json: linted
						};

						// Start a top level
						var currentDir = json;

						// Remove the path to the container, and the .json extension
						var path = f.replace(f.base + '/', '').replace('.json', '');

						var test = true;
						while (test) {
							var _path = path,
							    _currentDir = currentDir;

							if(!_currentDir['artists']) _currentDir['artists'] = {};
							if(!_currentDir['posts'])   _currentDir['posts'] = {};

							// If the is a slash, we have a parent folder
							var firstSlash = _path.lastIndexOf('/');
							if (firstSlash > -1) {
								path = _path.slice(firstSlash + 1);
								test = true;
								continue;
							}

							if(f.indexOf('artists') === -1) {
								//posts

								_currentDir[path] = fragment.json;
							} else {
								//artists
								_currentDir['artists'][path] = fragment.json;
							}
							test = false;
						}
					} catch (e)	{
						grunt.fail.warn(e);
					}
				}
			} catch (e)	{
				grunt.fail.warn(e);
			}
		});
Example #30
0
MavensMateUtil.prototype.getFileBody = function(path, parseJSON) {
  var fileBody = fs.readFileSync(path, 'utf8');
  if (parseJSON) {
    fileBody = stripJson(fileBody);
    return JSON.parse(fileBody);
  } else {
    return fileBody;
  }
};