Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return when.promise(function(resolve,reject) {
var promises = [];
whenNode.call(fs.readdir,dir).done(function(files) {
files = files.sort();
files.forEach(function(fn) {
var stats = fs.statSync(path.join(dir,fn));
if (stats.isFile()) {
if (/\.js$/.test(fn)) {
promises.push(when.promise(function(resolve,reject) {
loadNode(dir,fn).then(resolve, function(err) {
resolve({'fn':fn,err:err});
});
}));
}
} else if (stats.isDirectory()) {
// Ignore /.dirs/, /lib/ /node_modules/
if (!/^(\..*|lib|icons|node_modules|test)$/.test(fn)) {
promises.push(when.promise(function(resolve,reject) {
loadNodes(path.join(dir,fn)).then(function(errs) {
const tpl = this.opts[k].template
const root = compiler.options.context
// If the template option doesn't exist or is malformed, we return or error.
if (!tpl) { return _data }
if (!tpl.path) { throw new Error('missing template.path') }
if (!tpl.output) { throw new Error('missing template.output') }
// If there is also a template transform function, we run that here
const data = tpl.transform ? tpl.transform(_data) : _data
// We must ensure that template data is an array to render each item
if (!Array.isArray(data)) { throw new Error('template data is not an array') }
// First we read the template file
const tplPath = path.join(root, tpl.path)
return node.call(fs.readFile.bind(fs), tplPath, 'utf8')
.then((template) => {
// Now we go through each item in the data array to render a template
return W.map(data, (item) => {
// The template gets all the default locals as well as an "item" prop
// that contains the data specific to the template, and a filename
const newLocals = Object.assign({}, this.opts.addDataTo, {
item,
filename: path.join(root, tpl.path)
})
// We need to precisely replicate the way reshape is set up internally
// in order to render the template correctly, so we run the reshape
// loader's options parsing with the real loader context and the user's
// reshape options from the config
const options = loader.parseOptions.call(this.loaderContext, this.util.getSpikeOptions().reshape, {})
function getXpiInfoFromInstallRdf(installRdf) {
var parser = new xml2js.Parser();
return nodefn.call(parser.parseString, installRdf)
.catch(function(parseError) {
parseError.message = "install.rdf: " + parseError.message;
throw parseError;
})
.then(function(result) {
var info = {
manifest: null,
};
// RDF is one of those sick and twisted XML variants.
var root = result.RDF || result["RDF:RDF"];
if (!root) {
throw new Error("Could not find root RDF element in install.rdf");
}
var descriptions = root.Description || root["RDF:Description"];
if (!descriptions) {
sem.take(function() {
return nodefn.call(fs.readFile, file.abs).then(function(data) {
var filePath = file.rel.split("/").map(function(segment) {
return encodeURIComponent(segment);
}).join("/");
return self.client.request({
url: "/deploys/" + self.id + "/files/" + filePath,
type: "put",
body: data,
contentType: "application/octet-stream",
ignoreResponse: true
}).then(function(response) {
progress && progress("upload", {file: file, total: files.length});
sem.leave();
return file;
}).catch(function(response) {
progress && progress("uploadError", {file:file, message: response.data});
gulp.task('mktmp', function () {
return nodefn.call(exec, 'mkdir -p "' + paths.tmp + '"');
});
return when.promise(function(resolve,reject) {
whenNode.call(fs.readFile,templateFilename,'utf8').done(function(content) {
try {
registerConfig(content);
} catch(err) {
reject("invalid template file: "+err.message);
}
resolve();
}, function(err) {
reject("missing template file");
});
});
}
return when.map(Object.keys(patternObj), patternBase => when.map(patternObj[patternBase], pattern => fn.call(glob, pattern, {cwd: patternBase})
.then(matches => when.map(matches, match => {
const src = path.resolve(patternBase, match);
return fn.call(fs.stat, src).then(stat => {
const dst = path.resolve(target, match);
if(stat.isDirectory()) {
return mkdirAsync(dst);
} else {
return copyAsync(src, dst);
}
});
}))
));
function mkdirAsync(path) {
return dirCache[path] || (dirCache[path] = fn.call(mkdirp, path));
}
return when.all(deployment.stylesheets.map(function (filePath) {
var fileName = path.basename(filePath);
var source = path.resolve(__dirname, '..', filePath);
var target = path.resolve(__dirname, writeFilesProcessor.outputFolder, fileName);
stylesheets.push(fileName);
return nodefn.call(fs.copy, source, target);
}));
}