Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var spawn = require('child_process').spawn;
var chalk = require('chalk');
var vow = require('vow');
var vowFs = require('vow-fs');
var SOURCES = ['lib', 'test/specs'];
var MOCHA = 'node_modules/.bin/mocha';
/**
* Applying passed presets to JSCS sources and tests, then executing tests.
* So we can make sure nothing breaks during these reformatting actions.
*/
var presets = process.env.TEST_PRESET && vow.resolve(process.env.TEST_PRESET.split(','));
/**
* Or applying every available preset if nothing passed and do the same.
*/
presets = presets || vowFs.listDir('./presets')
.then(function(presetFilenames) {
var presets = presetFilenames.map(function(presetFilename) {
return presetFilename.replace('.json', '');
});
// List of rules that are not used in any of the default presets
presets.unshift('./test/scripts/forgotten-rules.json');
return presets;
});
initArchives: function (options) {
var _this = this;
return vow.all(options.languages
.filter(function (lang) {
return options.archive[lang];
})
.map(function (lang) {
var archive = new Archive(options, lang);
_this.archive[lang] = archive;
return archive.init();
}));
},
_readYmlFileAndReplacePlaceholders: function (output, suffix, contentWrapper) {
var path = output + suffix;
return Vow.all([this._getConfig(output), this._readFile(path)])
.spread(function (config, content) {
for (var key in config) {
if (config.hasOwnProperty(key)) {
content = content.replace(new RegExp('%' + key + '%', 'g'), config[key]);
}
}
return {
path: path.replace('yml', 'js'),
content: contentWrapper.call(this, yml.safeLoad(content))
};
}, this);
},
.spread(function(obj, docs, libraries, people) {
return vow
.all([
addDynamicNodes(obj.sitemap, obj.routes, docs, people),
addLibraryNodes(obj.sitemap, obj.routes, obj.libraryNodes, libraries)
]).spread(function(dynamic, libraries) {
return {
sitemap: removeCircularReferences(obj.sitemap),
routes: obj.routes,
docs: docs,
urls: dynamic,
people: people
};
});
})
.then(function(content) {
removeFiles: function() {
return vow.all([
providers.getProviderFile().exists({ path: dataTargetPath }),
providers.getProviderFile().exists({ path: sitemapTargetPath })
]).spread(function(dataExists, sitemapExists) {
var promises = [];
if(dataExists) {
promises.push(providers.getProviderFile().remove({ path: dataTargetPath }));
}
if(sitemapExists) {
promises.push(providers.getProviderFile().remove({ path: sitemapTargetPath }));
}
return vow.all(promises);
});
},
module.exports = function (targets, loadedConfig) {
var config = new Configuration(loadedConfig);
return vow.all([scan(targets, config), loadRules()])
.spread(function (entities, rules) {
return vow.all(Object.keys(rules).map(function (rule) {
return new rules[rule]().check(entities);
}));
})
.then(function (res) {
return _(res)
.flatten()
.sortBy('path')
.value();
});
};
return vow.all(langs.map(function (lang) {
return vow.all([
vowFs.read(path.join(errorBundlesPath, 'error-404', 'error-404.' + lang + '.html'), 'utf-8'),
vowFs.read(path.join(errorBundlesPath, 'error-500', 'error-500.' + lang + '.html'), 'utf-8')
]).spread(function (error404, error500) {
errorPages[lang] = {
error404: error404.replace(/\{STATICS_HOST\}/g, staticsUrl),
error500: error500.replace(/\{STATICS_HOST\}/g, staticsUrl)
};
});
}))
.then(function () {
ORM.prototype.getIssues = function (options) {
options.page = options.page || DEFAULT.page;
options.limit = options.per_page || DEFAULT.limit;
var def = vow.defer();
ORM.models.issue.find().paginate(options).exec(function(err, models) {
err ? def.reject() : def.resolve(models);
});
return def.promise();
};
load: function (options) {
logger.debug('read file %s from yandex disk', options.path);
var def = vow.defer();
disk.readFile(options.path, 'utf8', function (err, content) {
if (err || !content) {
def.reject(err);
}
def.resolve(options.archive ? util.unzip(content) : content);
});
return def.promise();
},
load: function (options) {
logger.debug(util.format('load file from %s', options.path), module);
var def = vow.defer();
this.disk.readFile(options.path, 'utf8', function (err, content) {
(err || !content) ? def.reject(err) : def.resolve(content);
});
return def.promise();
},