Skip to content

Commit

Permalink
refactor: use single source for constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 3, 2021
1 parent 165233b commit 1d6ebe6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { formatMessage } from '../helpers/format-message';
import { run } from '../utils/run';
import { log } from '../tasks/stdio/log';
import { constants } from '../constants';
import main from './main';
import { NullaryFn } from 'type-core';
import { loadPackage } from 'cli-belt';
import { attach, options as _options, resolver, add } from 'exits';

export interface BinOptions {
Expand All @@ -22,16 +22,16 @@ export interface BinOptions {
*/
export async function bin(options?: BinOptions): Promise<void> {
try {
const pkg = await loadPackage(__dirname, { title: false });
const opts = Object.assign(
{
bin: 'kpo',
file: 'kpo.tasks.js',
description: pkg.description || '',
version: pkg.version || 'Unknown'
bin: constants.bin,
file: constants.file,
description: constants.description,
version: constants.version
},
options
);

const task = await main({ argv: process.argv.slice(2) }, opts);

const cbs: NullaryFn[] = [];
Expand Down
8 changes: 8 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pkg from '../package.json';

export const constants = {
bin: 'kpo',
file: 'kpo.tasks.js',
description: pkg.description || '',
version: pkg.version || 'Unknown'
};
3 changes: 2 additions & 1 deletion src/tasks/reflection/lift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parseToRecord } from '../../helpers/parse';
import { getAbsolutePath } from '../../helpers/paths';
import { isCancelled } from '../../utils/is-cancelled';
import { run } from '../../utils/run';
import { constants } from '../../constants';
import { select } from '../transform/select';
import { write } from '../filesystem/write';
import { print } from '../stdio/print';
Expand Down Expand Up @@ -38,7 +39,7 @@ export interface LiftOptions {
export function lift(tasks: Task.Record, options?: LiftOptions): Task.Async {
return async (ctx: Context): Promise<void> => {
const opts = Object.assign(
{ purge: false, mode: 'default', bin: 'kpo' },
{ purge: false, mode: 'default', bin: constants.bin },
options
);

Expand Down
3 changes: 2 additions & 1 deletion src/tasks/reflection/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Task, Context } from '../../definitions';
import { parseToArray } from '../../helpers/parse';
import { constants } from '../../constants';
import { print } from '../stdio/print';
import { Empty } from 'type-core';
import { into } from 'pipettes';
Expand All @@ -24,7 +25,7 @@ export function list(
map?: (name: string, route: string[]) => string[]
): Task.Sync {
return (ctx: Context): void => {
const opts = Object.assign({ bin: 'kpo' }, options);
const opts = Object.assign({ bin: constants.bin }, options);
const items = parseToArray(tasks);
const maxRouteLength = items.reduce(
(acc, item) => (acc > item.route.length ? acc : item.route.length),
Expand Down

0 comments on commit 1d6ebe6

Please sign in to comment.