Skip to content
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

Take -version from package.json #48

Closed
youurayy opened this issue Feb 5, 2012 · 5 comments
Closed

Take -version from package.json #48

youurayy opened this issue Feb 5, 2012 · 5 comments

Comments

@youurayy
Copy link

youurayy commented Feb 5, 2012

E.g.

program.version(JSON.parse(require('fs').readFileSync(
     require.main.filename.match(/^(.+)\/.+$/)[1] + '/../package.json')).version)

But a test is needed for the existence of package.json, I think the 2 most used locations are and /.

So 1, check for main_module_dir/package.json and 2, check for main_module_dir/../package.json.

@jprichardson
Copy link

Agreed, I'd love this.

@jgallen23
Copy link

+1

sebastiendb added a commit to sebastiendb/commander.js that referenced this issue May 4, 2012
sebastiendb added a commit to sebastiendb/commander.js that referenced this issue May 4, 2012
tj added a commit that referenced this issue Jul 3, 2012
Issue #48 : Take -version from package.json
@tj
Copy link
Owner

tj commented Aug 30, 2012

just realized this is implemented wrong, you'll get commander's version every time

@tj
Copy link
Owner

tj commented Aug 30, 2012

your require() is always relative to commander's ./lib

@kimmobrunfeldt
Copy link

For others finding this issue: you know where the package.json is in your project, so you can just do:

program
    .version(require('./package.json').version)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants