diff --git a/index.js b/index.js index 9400ac6..282e281 100755 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ #!/usr/bin/env node import { logger, getSymbol } from './lib/logger.js' -import {options} from './lib/args.js' -if (!options) { +import { options, configValid } from './lib/args.js' +if (!configValid) { logger.end() process.exit(1) } diff --git a/lib/args.js b/lib/args.js index dd26671..c989d7e 100644 --- a/lib/args.js +++ b/lib/args.js @@ -3,16 +3,30 @@ import help_default from './help.js' help_default() import { Command, Option, InvalidOptionArgumentError } from 'commander' -const component = 'args' -const version = 'esm-1.0.0' import { readFileSync } from 'fs' import { logger, addConsoleTransport, addFileTransport } from './logger.js' -import { config } from 'dotenv' +import { config } from 'dotenv' import { resolve, sep, posix } from 'path' import promptSync from 'prompt-sync' -const prompt = promptSync({ sigint:true }) import { createPrivateKey } from 'crypto' +import { fileURLToPath } from 'url'; + +const prompt = promptSync({ sigint:true }) +const component = 'args' + +function getVersion() { + try { + const packageJsonPath = fileURLToPath(new URL('../package.json', import.meta.url)); + const packageJsonText = readFileSync(packageJsonPath, 'utf8'); + return JSON.parse(packageJsonText).version; + } catch (error) { + console.error('Error reading package.json:', error); + } +} + +let configValid = true +const version = getVersion(); // Use .env, if present, to setup the environment config() @@ -150,9 +164,7 @@ if (options.clientKey) { file: options.clientKey, error: e }) - // Bail with no export object - module.exports = false -// return + configValid = false } } else { @@ -167,9 +179,7 @@ else { component: component, message: 'Missing client secret' }) - // Bail with no export object - module.exports = false - // return + configValid = false } } @@ -204,5 +214,5 @@ function getPrivateKey( pemFile, passphrase, canPrompt) { } } -export { options } +export { options, configValid }