fix Node.js postinstall script on Windows

should now work on Windows XP and in shells without admin privileges
This commit is contained in:
Jeff Williams 2013-11-09 10:58:04 -08:00
parent ac88f30936
commit 8d36f92e7a

View File

@ -7,29 +7,31 @@ var jsdocPath = path.resolve( path.join(__dirname, '..') );
var symlinkSrc = path.join( jsdocPath, 'lib', 'jsdoc' );
var symlinkDest = path.join( jsdocPath, 'node_modules', 'jsdoc' );
fs.lstat(symlinkDest, function(err, stats) {
// if the path exists, make sure it looks okay
if (!err) {
if ( stats.isSymbolicLink() ) {
// this is what we want
fs.symlink(symlinkSrc, symlinkDest, 'dir', function(err) {
if (err) {
// On Windows, try to create a junction instead
if (process.platform.indexOf('win') === 0) {
fs.symlink(symlinkSrc, symlinkDest, 'junction', function(junctionErr) {
if (junctionErr) {
console.error('Unable to create a symbolic link or junction from %s to %s.\n' +
'Symbolic link result: %s\nJunction result: %s\n' +
'Make sure you have write privileges in the target directory. ' +
'You may need to run the Windows shell as an administrator.',
symlinkSrc, symlinkDest, err, junctionErr);
process.exit(1);
}
else {
process.exit(0);
}
});
}
else if ( stats.isDirectory() ) {
console.warn('The path %s should be a symbolic link to %s rather than a standalone ' +
'directory. You may need to resolve this issue so that JSDoc can work correctly.',
symlinkDest, symlinkSrc);
else {
console.error('Unable to create a symbolic link from %s to %s. %s\n',
symlinkSrc, symlinkDest, err);
process.exit(1);
}
process.exit(0);
}
else {
fs.symlink(symlinkSrc, symlinkDest, function(err) {
if (err) {
console.error('Unable to create a symbolic link from %s to %s: %s', symlinkSrc,
symlinkDest, err);
process.exit(1);
}
process.exit(0);
});
process.exit(0);
}
});