Skip to content

Commit

Permalink
#190: add node module check lib
Browse files Browse the repository at this point in the history
  • Loading branch information
robhrt7 committed Oct 22, 2015
1 parent 6481b9d commit 597132b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions core/lib/isNodeModule.js
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions core/postInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.');
Expand Down

0 comments on commit 597132b

Please sign in to comment.