circomkit icon indicating copy to clipboard operation
circomkit copied to clipboard

feat: add `version` command

Open erhant opened this issue 1 year ago • 2 comments

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 avatar Oct 15 '24 21:10 erhant

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);

numtel avatar Oct 15 '24 23:10 numtel

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 avatar Oct 16 '24 07:10 erhant