@token-dashboard/codex-usage-uploader 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@token-dashboard/codex-usage-uploader",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Codex 用量上报 CLI",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import { CodexUsageUploader } from './collector.js';
4
4
  import { identityIsBound, promptConfirm } from './auth.js';
5
5
  import { CLI_NAME, DEFAULT_BACKEND_URL, DEFAULT_CONFIG_FILE, PRODUCT_NAME } from './constants.js';
6
- import { ensurePathInShellConfigs, findPackageRoot, installCurrentPackage, removePathFromShellConfigs } from './install.js';
6
+ import { ensurePathInShellConfigs, findPackageRoot, getPackageVersion, installCurrentPackage, removePathFromShellConfigs } from './install.js';
7
7
  import { LaunchdServiceManager } from './launchd.js';
8
8
  import { collectLocalUsage, getLocalTimeZone } from './local-usage.js';
9
9
  import { formatStatusOutput, mergeRuntimeConfig, saveRuntimeConfig } from './runtime-config.js';
@@ -41,6 +41,7 @@ Common options:
41
41
  --yes Skip interactive prompts
42
42
  --package-spec <spec> npm install spec used by init
43
43
  --lines <n> Number of log lines for service logs
44
+ -v, --version Show version
44
45
  -h, --help Show help
45
46
  `;
46
47
 
@@ -93,6 +94,10 @@ export function parseCliArgs(argv) {
93
94
  options.help = true;
94
95
  continue;
95
96
  }
97
+ if (token === '-v' || token === '--version') {
98
+ options.version = true;
99
+ continue;
100
+ }
96
101
  if (token === '--yes') {
97
102
  options.yes = true;
98
103
  continue;
@@ -347,7 +352,13 @@ async function runInit(options) {
347
352
 
348
353
  const uploader = cliDeps.createUploader(runtime);
349
354
  try {
350
- const identity = await bindIdentity(uploader, options);
355
+ const hasIdentityOverrides = Object.values(identityOverrides(options)).some(v => v !== undefined);
356
+ let identity;
357
+ if (!hasIdentityOverrides && identityIsBound(uploader.identity)) {
358
+ identity = uploader.identity;
359
+ } else {
360
+ identity = await bindIdentity(uploader, options);
361
+ }
351
362
  console.log(`${PRODUCT_NAME} install is ready.`);
352
363
  console.log(`Backend: ${runtime.backendUrl}`);
353
364
  console.log(`Install root: ${runtime.installRoot}`);
@@ -685,6 +696,10 @@ function runLifecycleCommand(action, options) {
685
696
  export async function main(argv = process.argv.slice(2)) {
686
697
  try {
687
698
  const { command, subcommand, extraPositionals, options } = parseCliArgs(argv);
699
+ if (options.version) {
700
+ console.log(getPackageVersion());
701
+ return 0;
702
+ }
688
703
  if (!command || options.help) {
689
704
  printUsage();
690
705
  return 0;
package/src/install.js CHANGED
@@ -12,6 +12,12 @@ const SHELL_CONFIG_FILES = [
12
12
  path.join(os.homedir(), '.bash_profile'),
13
13
  ];
14
14
 
15
+ export function getPackageVersion(startUrl = import.meta.url) {
16
+ const root = findPackageRoot(startUrl);
17
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
18
+ return pkg.version ?? 'unknown';
19
+ }
20
+
15
21
  export function findPackageRoot(startUrl = import.meta.url) {
16
22
  let current = path.dirname(fileURLToPath(startUrl));
17
23
  while (true) {