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,6 +97,12 @@ function afterBuild(options) { ...@@ -53,6 +97,12 @@ function afterBuild(options) {
*/ */
function build(options) { function build(options) {
installGitDependencies(function(err) {
if (err) {
console.error(err.message);
process.exit(1);
}
var args = [path.join('node_modules', 'pangyp', 'bin', 'node-gyp'), 'rebuild'].concat( var args = [path.join('node_modules', 'pangyp', 'bin', 'node-gyp'), 'rebuild'].concat(
['libsass_ext', 'libsass_cflags', 'libsass_ldflags', 'libsass_library'].map(function(subject) { ['libsass_ext', 'libsass_cflags', 'libsass_ldflags', 'libsass_library'].map(function(subject) {
return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join(''); return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join('');
...@@ -72,6 +122,8 @@ function build(options) { ...@@ -72,6 +122,8 @@ function build(options) {
} }
console.error(errorCode === 127 ? 'node-gyp not found!' : 'Build failed'); 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