Created
August 22, 2015 11:48
-
-
Save dmail/d6b2c0b688614a6f6907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var meta = JSON.parse(fs.readFileSync('./package.json')); | |
var ignored = String(fs.readFileSync('./.gitignore')).split('\n'); | |
function ignore(entry){ | |
if( ignored.indexOf(entry) === -1 ){ | |
fs.appendFileSync('./.gitignore', '\n' + entry); | |
ignored.push(entry); | |
} | |
} | |
if( meta.dependencies ){ | |
ignore('node_modules/'); | |
Object.keys(meta.dependencies).forEach(function(dependency){ | |
var dependencyLocation = 'node_modules/' + dependency; | |
var dependencySymlink = 'lib'; | |
if( dependency[0] === '@' ){ | |
dependencySymlink+= dependency.slice(dependency.indexOf('/')); | |
} | |
else{ | |
dependencySymlink+= '/' + dependency; | |
} | |
if( false === fs.existsSync(dependencySymlink) ){ | |
ignore(dependencySymlink); | |
fs.symlinkSync(dependencyLocation, dependencySymlink, 'junction'); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment