Skip to content

Add getProjectPath() to compute path to parent project #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 1, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ends-with dependency to make it work on node 0.12
  • Loading branch information
Alexander Lisianoi committed Oct 1, 2017
commit 67f5ab1df48fd423ce0c0f1cba24d0bb2d5de535
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path')
var chalk = require('chalk')
var Git = require('git-tools')

var endsWith = require('ends-with')
var objectAssign = require('object-assign')

var validate = require('./lib/validate')
Expand All @@ -12,18 +13,21 @@ var defaults = require('./lib/defaults')

// Need to find the path to the project that is installing
// commitplease. Previously, process.cwd() made the job easy but its
// output changed with node v8.1.2
// output changed with node v8.1.2 (at least compared to 7.10.0)
function getProjectPath () {
// Use the fact that npm will inject a path that ends with
// commitplease/node_modules/.bin into PATH
// commitplease/node_modules/.bin into process.env.PATH
var p = process.env.PATH.split(':').filter(
function (p) {
return p.endsWith(path.join('commitplease', 'node_modules', '.bin'))
return endsWith(p, path.join('commitplease', 'node_modules', '.bin'))
}
)

if (p.length !== 1) {
console.error(chalk.red('Failed to find project path\n'))

// Just leave with zero so as not to interrupt install
process.exit(0)
}

// Removing suffix node_modules/commitplease/node_modules/.bin will
Expand All @@ -37,8 +41,6 @@ function getProjectPath () {
function getOptions () {
var projectPath = getProjectPath()

console.log(projectPath)

var pkg = path.join(projectPath, 'package.json')
var npm = path.join(projectPath, '.npmrc')

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"dependencies": {
"chalk": "^1.1.1",
"ends-with": "^1.0.1",
"git-tools": "^0.2.1",
"ini": "^1.3.4",
"object-assign": "^4.1.0",
Expand Down