erhant / circomkit

A testing & development environment for Circom.
https://www.npmjs.com/package/circomkit
MIT License
100 stars 6 forks source link

feat: add `version` command #99

Open erhant opened 1 week ago

erhant commented 1 week ago

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.

numtel commented 1 week ago

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 commented 1 week ago

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 🙏🏻