diff --git a/core/lib/isNodeModule.js b/core/lib/isNodeModule.js new file mode 100644 index 0000000..c379aff --- /dev/null +++ b/core/lib/isNodeModule.js @@ -0,0 +1,13 @@ +'use strict'; + +var path = require('path'); +var fs = require('fs-extra'); + +module.exports = function(customPathToApp) { + var pathToApp = customPathToApp || global.pathToApp; + var grantParentPath = path.join(pathToApp, '../../'); + var relativePathToApp = path.relative(grantParentPath, pathToApp); + var assumedSourceNpmPath = path.join('node_modules', fs.readJsonSync(path.join(pathToApp, 'package.json')).name); + + return relativePathToApp === assumedSourceNpmPath; +}; \ No newline at end of file diff --git a/core/postInstall.js b/core/postInstall.js index 60ecb6f..3a77d05 100644 --- a/core/postInstall.js +++ b/core/postInstall.js @@ -3,6 +3,7 @@ var path = require('path'); var fs = require('fs-extra'); var link = require('./lib/createLink'); +var isNodeModule = require('./lib/isNodeModule'); var currentDir = process.env.PWD || __dirname; var pathToApp = currentDir.replace(/^\w:\\/, function (match) { @@ -12,10 +13,9 @@ var pathToApp = currentDir.replace(/^\w:\\/, function (match) { var userPath = path.join(pathToApp, '../../'); var internalUserPath = path.join(pathToApp, 'user'); -var parentNodeModules = path.join(pathToApp, '../'); // check if sourcejs is installed as a node_package -if (path.relative(parentNodeModules, pathToApp) === 'sourcejs') { +if (isNodeModule(pathToApp)) { fs.removeSync(internalUserPath); link(userPath, internalUserPath, 'dir'); console.log('SourceJS User folder symlink created.');