Skip to content

Commit

Permalink
refactored for version command and validating token
Browse files Browse the repository at this point in the history
  • Loading branch information
Matte22 committed Jan 31, 2024
1 parent 73ca68e commit 9b5f500
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
32 changes: 21 additions & 11 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -150,9 +164,7 @@ if (options.clientKey) {
file: options.clientKey,
error: e
})
// Bail with no export object
module.exports = false
// return
configValid = false
}
}
else {
Expand All @@ -167,9 +179,7 @@ else {
component: component,
message: 'Missing client secret'
})
// Bail with no export object
module.exports = false
// return
configValid = false
}
}

Expand Down Expand Up @@ -204,5 +214,5 @@ function getPrivateKey( pemFile, passphrase, canPrompt) {
}
}

export { options }
export { options, configValid }

0 comments on commit 9b5f500

Please sign in to comment.