Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Help flag issue #608

Merged
merged 8 commits into from
Apr 11, 2024
2 changes: 1 addition & 1 deletion src/__tests__/unit/util/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('util/args: ', () => {
const result = parseArgs();

expect(info).toHaveBeenCalledWith(HELP);
expect(result).toEqual(undefined);
expect(result).toBeUndefined();
});

it('returns manifest and output path.', () => {
Expand Down
31 changes: 14 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,34 @@ import {load} from './lib/load';
import {parameterize} from './lib/parameterize';

import {parseArgs} from './util/args';
import {ERRORS} from './util/errors';
import {andHandle} from './util/helpers';
import {logger} from './util/logger';

import {STRINGS} from './config';

const packageJson = require('../package.json');

const {CliInputError} = ERRORS;

const {DISCLAIMER_MESSAGE, SOMETHING_WRONG} = STRINGS;
const {DISCLAIMER_MESSAGE} = STRINGS;

const impactEngine = async () => {
logger.info(DISCLAIMER_MESSAGE);
const options = parseArgs();

if (options) {
const {inputPath, outputPath, paramPath} = options;

const {tree, context, parameters} = await load(inputPath, paramPath);
parameterize.combine(context.params, parameters);
const pluginStorage = await initalize(context.initialize.plugins);
const computedTree = await compute(tree, {context, pluginStorage});
const aggregatedTree = aggregate(computedTree, context.aggregation);
context['if-version'] = packageJson.version;
exhaust(aggregatedTree, context, outputPath);

if (!options) {
return;
}

return Promise.reject(new CliInputError(SOMETHING_WRONG));
logger.info(DISCLAIMER_MESSAGE);
const {inputPath, outputPath, paramPath} = options;

const {tree, context, parameters} = await load(inputPath!, paramPath);
parameterize.combine(context.params, parameters);
const pluginStorage = await initalize(context.initialize.plugins);
const computedTree = await compute(tree, {context, pluginStorage});
const aggregatedTree = aggregate(computedTree, context.aggregation);
context['if-version'] = packageJson.version;
exhaust(aggregatedTree, context, outputPath);

return;
};

impactEngine().catch(andHandle);
6 changes: 6 additions & 0 deletions src/types/process-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ export interface ManifestProcessArgs {
'override-params'?: string;
help?: boolean;
}

export interface ProcessArgsOutputs {
inputPath?: string;
outputPath?: string;
paramPath?: string;
}
4 changes: 2 additions & 2 deletions src/util/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ERRORS} from './errors';

import {CONFIG, STRINGS} from '../config';

import {ManifestProcessArgs} from '../types/process-args';
import {ManifestProcessArgs, ProcessArgsOutputs} from '../types/process-args';

const {CliInputError} = ERRORS;

Expand Down Expand Up @@ -50,7 +50,7 @@ const prependFullFilePath = (filePath: string) => {
* If it is, then returns object containing full path.
* 4. If params are missing or invalid, then rejects with `CliInputError`.
*/
export const parseArgs = () => {
export const parseArgs = (): ProcessArgsOutputs | undefined => {
const {
manifest,
output,
Expand Down
Loading