pulsar/script/utils/verify-requirements.js

118 lines
3.5 KiB
JavaScript
Raw Normal View History

2014-05-30 20:36:29 +04:00
var path = require('path');
var fs = require('fs');
2014-06-04 23:44:51 +04:00
var childProcess = require('child_process');
2014-06-04 22:09:50 +04:00
var pythonExecutable = process.env.PYTHON;
2014-05-30 20:36:29 +04:00
module.exports = function(cb) {
verifyNode(function(error, nodeSuccessMessage) {
if (error) {
cb(error);
return;
}
verifyNpm(function(error, npmSuccessMessage) {
if (error) {
cb(error);
return;
}
verifyPython27(function(error, pythonSuccessMessage) {
cb(error, (nodeSuccessMessage + "\n" + npmSuccessMessage + "\n" + pythonSuccessMessage).trim());
});
});
});
2014-05-30 20:21:26 +04:00
};
function verifyNode(cb) {
var nodeVersion = process.versions.node;
var versionArray = nodeVersion.split('.');
var nodeMajorVersion = +versionArray[0];
var nodeMinorVersion = +versionArray[1];
2014-05-30 20:21:26 +04:00
if (nodeMajorVersion === 0 && nodeMinorVersion < 10) {
error = "node v0.10 is required to build Atom.";
cb(error);
}
else {
cb(null, "Node: v" + nodeVersion);
2014-05-30 20:21:26 +04:00
}
}
function verifyNpm(cb) {
2014-06-10 22:45:11 +04:00
var localNpmPath = path.resolve(__dirname, '..', '..', 'build', 'node_modules', '.bin', 'npm');
if (process.platform === 'win32')
localNpmPath += ".cmd";
2014-06-10 22:45:11 +04:00
var npmCommand = fs.existsSync(localNpmPath) ? localNpmPath : 'npm';
if (npmCommand === 'npm' && process.platform === 'win32')
npmCommand += ".cmd";
2014-06-10 22:45:11 +04:00
childProcess.execFile(npmCommand, ['-v'], { env: process.env }, function(err, stdout) {
if (err)
return cb("npm 1.4 is required to build Atom. An error (" + err + ") occured when checking the version.");
var npmVersion = stdout ? stdout.trim() : '';
var versionArray = npmVersion.split('.');
var npmMajorVersion = +versionArray[0] || 0;
var npmMinorVersion = +versionArray[1] || 0;
if (npmMajorVersion === 1 && npmMinorVersion < 4)
cb("npm v1.4+ is required to build Atom.");
else
cb(null, "npm: v" + npmVersion);
});
}
function verifyPython27(cb) {
2014-06-05 01:07:59 +04:00
if (process.platform == 'win32') {
2014-06-04 22:09:50 +04:00
if (!pythonExecutable) {
2014-05-30 20:21:26 +04:00
var systemDrive = process.env.SystemDrive || 'C:\\';
pythonExecutable = path.join(systemDrive, 'Python27', 'python.exe');
if (!fs.existsSync(pythonExecutable)) {
pythonExecutable = 'python';
}
}
2014-05-30 20:21:26 +04:00
checkPythonVersion(pythonExecutable, cb);
}
2014-06-05 01:07:59 +04:00
else {
2014-06-05 19:53:02 +04:00
cb(null, '');
2014-06-05 01:07:59 +04:00
}
}
function checkPythonVersion (python, cb) {
2014-06-04 22:10:14 +04:00
var pythonHelpMessage = "Set the PYTHON env var to '/path/to/Python27/python.exe' if your python is installed in a non-default location.";
2014-06-04 23:44:51 +04:00
childProcess.execFile(python, ['-c', 'import platform; print(platform.python_version());'], { env: process.env }, function (err, stdout) {
if (err) {
2014-06-04 23:34:18 +04:00
error = "Python 2.7 is required to build Atom. An error (" + err + ") occured when checking the version of '" + python + "'. ";
error += pythonHelpMessage;
cb(error);
return;
2014-05-30 20:21:26 +04:00
}
2014-06-04 22:10:14 +04:00
var version = stdout.trim();
if (~version.indexOf('+')) {
2014-06-04 22:10:14 +04:00
version = version.replace(/\+/g, '');
}
if (~version.indexOf('rc')) {
2014-06-04 22:10:14 +04:00
version = version.replace(/rc(.*)$/ig, '');
}
2014-06-04 22:10:14 +04:00
// Atom requires python 2.7 or higher (but not python 3) for node-gyp
var versionArray = version.split('.').map(function(num) { return +num; });
2014-06-04 22:10:14 +04:00
var goodPythonVersion = (versionArray[0] === 2 && versionArray[1] >= 7);
if (!goodPythonVersion) {
error = "Python 2.7 is required to build Atom. '" + python + "' returns version " + version + ". ";
error += pythonHelpMessage;
cb(error);
return;
}
// Finally, if we've gotten this far, callback to resume the install process.
cb(null, "Python: v" + version);
});
2014-05-30 20:21:26 +04:00
}