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

feat: add version command #99

Open
erhant opened this issue Oct 15, 2024 · 2 comments
Open

feat: add version command #99

erhant opened this issue Oct 15, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@erhant
Copy link
Owner

erhant commented Oct 15, 2024

This can be used at the top:

import {version, name} from '../package.json';

Then, at the bottom:

  new Command()
    .name(name)
    .version(version)
// ...

Not sure if that package.json can cause any trouble though, mixed comments on the web.

@erhant erhant added enhancement New feature or request good first issue Good for newcomers labels Oct 15, 2024
@numtel
Copy link
Contributor

numtel commented Oct 15, 2024

I don't know if the typescript compiler handles importing jsons differently than normal node.js but I did this on the circuitscan cli:

import {readFileSync} from 'node:fs';
import {dirname, join} from 'node:path';
import {fileURLToPath} from 'node:url';

// Recreate old common.js __dirname global
const __dirname = dirname(fileURLToPath(import.meta.url));

function getPackageJson() {
  return JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
}

program
  .version(getPackageJson().version);

@erhant
Copy link
Owner Author

erhant commented Oct 16, 2024

hmm, also people on the web (stackoverflow) advise against this (i.e. readFile to JSON.parse), thanks for the suggestion though! I will try a few things 🙏🏻

@erhant erhant mentioned this issue Jan 28, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants