Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return cb(err);
try {
pkg = JSON.parse(data);
if(!pkg || !pkg.version) {
throw new Error("Bad package.json");
}
} catch (e) {
return cb(e);
}
// get version from package.json
state.setVersion(pkg.version);
var mainFile = pkg.main;
if(mainFile) {
var mainFilePath = path.normalize(path.join(cwd, mainFile));
path.exists(mainFilePath, function(exists) {
if(exists) {
if(mainFilePath.match(/\.js$/)) {
// Main file must be .js file
state.setMainFilePath(mainFilePath);
}
} else {
// mainFilePath is directory
var tmp = path.join(mainFilePath, 'index.js');
path.exists(tmp, function(exists) {
if(exists) {
state.setMainFilePath(tmp);
}
});
}
});
} else {
// If no gameId is specified, return all the games from the lobby
// server.
if (!gameId) {
games = [];
for (gameId in gameIdMap)
for (var i = 0, game; game = gameIdMap[gameId][i++];)
games.push(game);
}
response.end(JSON.stringify({'games': games}));
} else {
if (requestPath == '/')
requestPath = '/' + defaultHtml;
var filePath = www + requestPath.replace('../', './');
path.exists(filePath, function(exists) {
if (!exists) {
response.writeHead(404);
response.end();
return;
}
fs.readFile(filePath, function(error, content) {
if (error) {
response.writeHead(500);
response.end();
return;
}
response.writeHead(200, {'Content-Type': getContentType(filePath)});
response.end(content);
});
});
exports.createSymlinkIfPathExists = function(symlinkPath, filePath) {
path.exists(symlinkPath, function(exists) {
if (!exists) {
console.log(' ' + symlinkPath + ' -> ' + filePath)
fs.symlinkSync(filePath, symlinkPath)
}
else {
console.log(' Skipped ' + filePath + ': already exists.')
}
})
}
function scp(local, remote, callback, exitCallback) {
if (!local) {
throw new Error(this.address + ': No local file path');
}
if (!remote) {
throw new Error(this.address + ': No remote file path');
}
var controller = this,
user = this.user,
options = this.scpOptions,
address = this.address;
path.exists(local, function (exists) {
if (exists) {
var reference = user + '@' + address + ':' + remote,
args = ['-r', local, reference],
child;
if (options) {
args = options.concat(args);
}
controller.log(user + ':scp: ' + local + ' ' + reference);
child = spawn('scp', args);
controller.listen(child, callback, exitCallback);
} else {
throw new Error('Local: ' + local + ' does not exist');
}
});
var mkdirs = module.exports.mkdirs = function(dirpath, mode, callback) {
path.exists(dirpath, function(exists) {
if(exists) {
callback(dirpath);
} else {
//尝试创建父目录,然后再创建当前目录
mkdirs(path.dirname(dirpath), mode, function(){
fs.mkdir(dirpath, mode, callback);
});
}
});
};
var makePath = function(callback) {
var self = this;
var randomString = 'alfred_sync_' + createRandomString(64) + '_' + Date.now();
var file_path= '/tmp/' + randomString;
path.exists(file_path, function(exists) {
if (exists) {
makePath(callback);
} else {
callback(file_path);
}
});
};
BundleManager.prototype.bundleExists = function(name, version, callback) {
path.exists(this.getBundleFilePath(name, version), callback);
};
break;
case '.css':
contentType = 'text/css';
break;
case '.jpg':
contentType = 'image/jpeg';
break;
case '.png':
contentType = 'image/png';
break;
case '.gif':
contentType = 'image/gif';
break;
}
path.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
}
});
}
else {
response.writeHead(404);
response.end();
function checkIfBundleExistsLocally(callback) {
var bundlePath = path.join(applicationPath, '.cast-project/tmp',
tarballName);
path.exists(bundlePath, async.apply(callback, null));
},