Commit 4c72885a by Adeel

Build: Use node-gyp from dependencies.

Code: Minor refactoring.
parent fe1d59f5
......@@ -10,19 +10,22 @@ var semver = require('semver'),
function getRuntimeName() {
return process.execPath
.split(/[\\/]+/).pop()
.split('.')[0];
.split('.').shift();
}
/**
* Get unique name of binary for current platform
*
* @api public
* @api private
*/
module.exports.getBinaryIdentifiableName = function() {
return process.platform + '-' +
process.arch + '-' +
getRuntimeName() + '-' +
runtimeVersion.major + '.' +
runtimeVersion.minor;
};
function getBinaryIdentifiableName() {
return [process.platform, '-',
process.arch, '-',
getRuntimeName(), '-',
runtimeVersion.major, '.',
runtimeVersion.minor].join('');
}
process.runtime = getRuntimeName();
process.sassBinaryName = getBinaryIdentifiableName();
var fs = require('fs'),
path = require('path'),
utils = require('./utils');
path = require('path');
require('./extensions');
/**
* Get binding
......@@ -12,10 +13,10 @@ function getBinding() {
var candidates = [
path.join(__dirname, '..', 'build', 'Debug', 'binding.node'),
path.join(__dirname, '..', 'build', 'Release', 'binding.node'),
path.join(__dirname, '..', 'vendor', utils.getBinaryIdentifiableName(), 'binding.node')
path.join(__dirname, '..', 'vendor', process.sassBinaryName, 'binding.node')
];
var candidate = candidates.filter(fs.existsSync)[0];
var candidate = candidates.filter(fs.existsSync).shift();
if (!candidate) {
throw new Error('`libsass` bindings not found. Try reinstalling `node-sass`?');
......@@ -146,12 +147,7 @@ function getOptions(options) {
var success = options.success;
options.error = function(err, code) {
try {
err = JSON.parse(err);
} catch (e) {
err = { message: err };
}
err = JSON.parse(err);
err.code = code;
if (error) {
......
......@@ -2,8 +2,9 @@ var fs = require('fs'),
path = require('path'),
spawn = require('child_process').spawn,
mkdir = require('mkdirp'),
Mocha = require('mocha'),
utils = require('../lib/utils');
Mocha = require('mocha');
require('../lib/extensions');
/**
* After build
......@@ -15,9 +16,9 @@ var fs = require('fs'),
function afterBuild(options) {
var folder = options.debug ? 'Debug' : 'Release';
var target = path.join(__dirname, '..', 'build', folder, 'binding.node');
var install = path.join(__dirname, '..', 'vendor', options.bin, 'binding.node');
var install = path.join(__dirname, '..', 'vendor', process.sassBinaryName, 'binding.node');
mkdir(path.join(__dirname, '..', 'vendor', options.bin), function (err) {
mkdir(path.join(__dirname, '..', 'vendor', process.sassBinaryName), function (err) {
if (err && err.code !== 'EEXIST') {
console.error(err.message);
return;
......@@ -49,9 +50,8 @@ function afterBuild(options) {
*/
function build(options) {
var bin = options.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp';
var proc = spawn(bin, ['rebuild'].concat(options.args), {
customFds: [0, 1, 2]
var proc = spawn(process.execPath, ['node_modules/pangyp/bin/node-gyp', 'rebuild'].concat(options.args), {
stdio: [0, 1, 2]
});
proc.on('exit', function(code) {
......@@ -92,7 +92,7 @@ function parseArgs(args) {
return false;
} else if (arg.substring(0, 13) === '--target_arch') {
options.arch = arg.substring(14);
} else if (arg === '--debug') {
} else if (arg === '-d' || arg === '--debug') {
options.debug = true;
}
......@@ -110,18 +110,16 @@ function parseArgs(args) {
*/
function testBinary(options) {
options.bin = utils.getBinaryIdentifiableName();
if (options.force || process.env.SASS_FORCE_BUILD) {
return build(options);
}
fs.stat(path.join(__dirname, '..', 'vendor', options.bin, 'binding.node'), function (err) {
fs.stat(path.join(__dirname, '..', 'vendor', process.sassBinaryName, 'binding.node'), function (err) {
if (err) {
return build(options);
}
console.log('`' + options.bin + '` exists; testing');
console.log('`' + process.sassBinaryName + '` exists; testing');
var mocha = new Mocha({
ui: 'bdd',
......
......@@ -2,8 +2,9 @@ var fs = require('fs'),
path = require('path'),
request = require('request'),
mkdirp = require('mkdirp'),
exec = require('shelljs').exec,
utils = require('../lib/utils');
exec = require('shelljs').exec;
require('../lib/extensions');
/**
* Download file, if succeeds save, if not delete
......@@ -77,31 +78,28 @@ function applyProxy(options, cb) {
*/
function exists() {
var name = utils.getBinaryIdentifiableName();
fs.exists(path.join(__dirname, '..', 'vendor', name), function (exists) {
fs.exists(path.join(__dirname, '..', 'vendor', process.sassBinaryName), function (exists) {
if (exists) {
return;
}
fetch(name);
fetch();
});
}
/**
* Fetch binaries
*
* @param {String} name
* @api private
*/
function fetch(name) {
function fetch() {
var url = [
'https://raw.githubusercontent.com/sass/node-sass-binaries/v',
require('../package.json').version, '/', name,
require('../package.json').version, '/', process.sassBinaryName,
'/binding.node'
].join('');
var dir = path.join(__dirname, '..', 'vendor', name);
var dir = path.join(__dirname, '..', 'vendor', process.sassBinaryName);
var dest = path.join(dir, 'binding.node');
mkdirp(dir, function(err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment