var fs = require('fs'); var cp = require('child_process'); var glob = require('glob'); var ini = require('ini'); /** * Load a JSON file * * @param filePath The path of the json file * @return Promise */ exports.loadJSONFile = function(filePath) { return new Promise(function(resolve, reject) { fs.readFile(filePath, 'utf8', function(err, fileContent) { if(err) return reject(err); try { var json = JSON.parse(fileContent); return resolve(json); } catch(err) { return reject(err); } }); }); }; /** * Load a INI file * * @param filePath The path of the json file * @return Promise */ exports.loadINIFile = function(filePath) { return new Promise(function(resolve, reject) { fs.readFile(filePath, 'utf8', function(err, content) { if(err) return reject(err); try { var decoded = ini.decode(content); return resolve(decoded); } catch(err) { return reject(err); } }); }); }; exports.runApp = function(execPath) { return new Promise(function(resolve, reject) { cp.exec(execPath, function(err) { if(err) return reject(err); return resolve(); }); }); }; var _globCache = { statCache: {}, cache: {}, realpathCache: {}, symlinks: {} }; exports.findFiles = function(pattern, opts) { return new Promise(function(resolve, reject) { opts = opts || {}; opts.cache = _globCache.cache; opts.statCache = _globCache.statCache; opts.realpathCache = _globCache.realpathCache; opts.symlinks = _globCache.symlinks; glob(pattern, opts, function(err, files) { if(err) return reject(err); return resolve(files); }); }); }; exports.exists = function(filePath) { return new Promise(function(resolve) { fs.exists(filePath, resolve); }); };