Skip to content

Commit

Permalink
Merge pull request #3 from AikidoSec/read-package-json
Browse files Browse the repository at this point in the history
Don't read package name, description, version from package.json to prevent PATH issues on Windows
  • Loading branch information
willem-delbare authored Jul 13, 2023
2 parents 6fcc6e3 + d349601 commit fe31743
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/commands/scan.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import chalk from 'chalk';
import { Argument, InvalidArgumentError, Option } from 'commander';
import { pollScanStatus, startScan, } from '../aikidoApi.js';
import { getApiKey } from '../configuration.js';
import { outputError, outputHttpError, outputLog, startSpinner, } from '../output.js';
import chalk from 'chalk';
async function cli(repoId, baseCommitId, headCommitId, branchName, options, command) {
const apiKey = getApiKey();
if (!apiKey) {
Expand Down
1 change: 0 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node
import { Command } from 'commander';
export declare const pkgJson: any;
export declare const program: Command;
declare global {
namespace NodeJS {
Expand Down
14 changes: 3 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@
import chalk from 'chalk';
import { Command } from 'commander';
import dotenv from 'dotenv';
import { readFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import apiKey from './commands/apiKey.js';
import scan from './commands/scan.js';
import upload from './commands/upload.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const __rootdirname = dirname(__dirname);
dotenv.config(process.env.NODE_ENV ? { path: `.env.${process.env.NODE_ENV}` } : {});
const pkgJsonPath = join('/', __rootdirname, 'package.json');
export const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
export const program = new Command();
program
.name(pkgJson.name)
.description(pkgJson.description)
.version(pkgJson.version);
.name('Aikido API Client')
.description('CLI api client to easily integrate the Aikido public CI API into custom deploy scripts')
.version('1.0.1');
apiKey.cliSetup(program);
scan.cliSetup(program);
upload.cliSetup(program);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aikidosec/ci-api-client",
"version": "1.0.0",
"version": "1.0.1",
"description": "CLI api client to easily integrate the Aikido public CI API into custom deploy scripts",
"license": "MIT",
"author": "Bert Devriese <bert@builtinbruges.com>",
Expand Down
7 changes: 3 additions & 4 deletions src/commands/scan.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import chalk from 'chalk';
import { Argument, Command, InvalidArgumentError, Option } from 'commander';
import { Ora } from 'ora';
import {
TStartScanResult,
TPollIsScanningResult,
TPollScanCompletedDefaultBranchResult,
TPollScanFeatureBranchCompletedResult,
TScanApiOptions,
TStartScanResult,
pollScanStatus,
startScan,
} from '../aikidoApi.js';
Expand All @@ -15,9 +17,6 @@ import {
outputLog,
startSpinner,
} from '../output.js';
import chalk from 'chalk';
import { Ora } from 'ora';
import { pkgJson } from '../index.js';

type TScanArguments = {
repoId: string | number;
Expand Down
20 changes: 5 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,24 @@
import chalk from 'chalk';
import { Command } from 'commander';
import dotenv from 'dotenv';
import { readFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import apiKey from './commands/apiKey.js';
import scan from './commands/scan.js';
import upload from './commands/upload.js';

// Determine current file location and path to
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const __rootdirname = dirname(__dirname);

// Load all .env configuration variables and auto-inject them into process.env
dotenv.config(
process.env.NODE_ENV ? { path: `.env.${process.env.NODE_ENV}` } : {}
);

// Set commander instance info from package.json
const pkgJsonPath = join('/', __rootdirname, 'package.json');
export const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));

// Start up commander.js Command instance
export const program = new Command();

program
.name(pkgJson.name)
.description(pkgJson.description)
.version(pkgJson.version);
.name('Aikido API Client')
.description(
'CLI api client to easily integrate the Aikido public CI API into custom deploy scripts'
)
.version('1.0.1');

// Load in all app commands and set them up in the `program` instance
apiKey.cliSetup(program);
Expand Down

0 comments on commit fe31743

Please sign in to comment.