Commit 3733adb2 by xzyfer

Init libSass submodule when npm installing via git url

parent c06ff0f2
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
*/ */
var eol = require('os').EOL, var eol = require('os').EOL,
pkg = require('../package.json'),
fs = require('fs'), fs = require('fs'),
mkdir = require('mkdirp'), mkdir = require('mkdirp'),
path = require('path'), path = require('path'),
...@@ -46,6 +47,49 @@ function afterBuild(options) { ...@@ -46,6 +47,49 @@ function afterBuild(options) {
} }
/** /**
* initSubmodules
*
* @param {Function} cb
* @api private
*/
function initSubmodules(cb) {
var errorMsg = '';
var git = spawn(['LIBSASS_GIT_VERSION=', pkg.libsass, ' ./scripts/git.sh'].join());
git.stderr.on('data', function(data) {
errorMsg += data.toString();
});
git.on('close', function(code) {
var error;
if (code !== 0) {
error = { message: errorMsg + 'Unable to checkout the libSass submodule' };
}
cb(error);
});
}
/**
* installGitDependencies
*
* @param {Function} cb
* @api private
*/
function installGitDependencies(cb) {
var libsassPath = './src/libsass';
if (fs.access) { // node 0.12+, iojs 1.0.0+
fs.access(libsassPath, fs.R_OK, function(err) {
err && err.code === 'ENOENT' ? initSubmodules(cb) : cb();
});
} else { // node < 0.12
fs.exists(libsassPath, function(exists) {
exists ? cb() : initSubmodules(cb);
});
}
}
/**
* Build * Build
* *
* @param {Object} options * @param {Object} options
...@@ -53,25 +97,33 @@ function afterBuild(options) { ...@@ -53,25 +97,33 @@ function afterBuild(options) {
*/ */
function build(options) { function build(options) {
var args = [path.join('node_modules', 'pangyp', 'bin', 'node-gyp'), 'rebuild'].concat( installGitDependencies(function(err) {
['libsass_ext', 'libsass_cflags', 'libsass_ldflags', 'libsass_library'].map(function(subject) { if (err) {
return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join(''); console.error(err.message);
})).concat(options.args); process.exit(1);
}
console.log(['Building:', process.sass.runtime.execPath].concat(args).join(' ')); var args = [path.join('node_modules', 'pangyp', 'bin', 'node-gyp'), 'rebuild'].concat(
['libsass_ext', 'libsass_cflags', 'libsass_ldflags', 'libsass_library'].map(function(subject) {
return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join('');
})).concat(options.args);
var proc = spawn(process.sass.runtime.execPath, args, { console.log(['Building:', process.sass.runtime.execPath].concat(args).join(' '));
stdio: [0, 1, 2]
});
proc.on('exit', function(errorCode) { var proc = spawn(process.sass.runtime.execPath, args, {
if (!errorCode) { stdio: [0, 1, 2]
afterBuild(options); });
return; proc.on('exit', function(errorCode) {
} if (!errorCode) {
afterBuild(options);
console.error(errorCode === 127 ? 'node-gyp not found!' : 'Build failed'); return;
}
console.error(errorCode === 127 ? 'node-gyp not found!' : 'Build failed');
process.exit(1);
});
}); });
} }
......
#!/bin/sh
git clone --depth=1 git@github.com:sass/libsass.git ./src/libsass
cd ./src/libsass
git checkout $LIBSASS_GIT_VERSION
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