Skip to content

Commit

Permalink
refactor(globals, utils): removes globals; keep environmentals and mo…
Browse files Browse the repository at this point in the history
…ves it to utils
  • Loading branch information
rafamel committed May 7, 2019
1 parent 5a421ee commit 5fc902e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 205 deletions.
36 changes: 0 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"@types/pify": "^3.0.2",
"@types/prompts": "^2.4.0",
"@types/ps-tree": "^1.1.0",
"@types/read-pkg-up": "^3.0.1",
"@types/semver": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^1.7.0",
"@typescript-eslint/parser": "^1.7.0",
Expand Down Expand Up @@ -132,7 +131,6 @@
"promist": "^0.5.3",
"prompts": "^2.0.4",
"ps-tree": "^1.2.0",
"read-pkg-up": "^5.0.0",
"semver": "^6.0.0",
"slimconf": "^0.9.0",
"string-argv": "^0.3.0"
Expand Down
10 changes: 4 additions & 6 deletions src/bin/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import { flags, safePairs, splitBy } from 'cli-belt';
import { loadPackage, flags, safePairs, splitBy } from 'cli-belt';
import { stripIndent as indent } from 'common-tags';
import arg from 'arg';
import chalk from 'chalk';
Expand All @@ -14,14 +14,12 @@ import list from './list';
import raise from './raise';
import stream from './stream';
import logger from '~/utils/logger';
import { pkg } from '~/globals';

export default async function main(argv: string[]): Promise<void> {
// Set process title
if (pkg().name) process.title = pkg().name;
const pkg = await loadPackage(__dirname, { title: true });

const help = indent`
${pkg().description ? chalk.bold.yellow(pkg().description) : ''}
${pkg.description ? chalk.bold.yellow(pkg.description) : ''}
Usage:
$ kpo [options] [@scope] [tasks] -- [streamArgs]
Expand Down Expand Up @@ -66,7 +64,7 @@ export default async function main(argv: string[]): Promise<void> {
const cmd = arg(types, { argv, permissive: false, stopAtPositional: true });

if (cmd['--help']) return console.log(help);
if (cmd['--version']) return console.log(pkg().version || 'Unknown');
if (cmd['--version']) return console.log(pkg.version || 'Unknown');
if (!cmd._.length) {
console.log(help + '\n');
throw Error(`A command is required`);
Expand Down
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ export const CONCURRENTLY_PATH = require.resolve(
);
/* Shared between instances: changes might imply a major version release */
export const OWNED_ENV_KEY = 'kpo_owned';
export const GLOBALS_KEY = 'kpo_globals';
export type TEnvironmental = 'kpo_log';
export type TGlobal = 'version';
2 changes: 1 addition & 1 deletion src/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ICliOptions, IScopeOptions, TCoreOptions, IOfType } from '~/types';
import { DEFAULT_LOG_LEVEL } from '~/constants';
import { setLevel } from '~/utils/logger';
import { environmentals } from '~/globals';
import environmentals from '~/utils/environmentals';
import initialize from './initialize';

export const state = {
Expand Down
70 changes: 0 additions & 70 deletions src/globals.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/utils/environmentals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { TEnvironmental, OWNED_ENV_KEY } from '~/constants';
import { IOfType } from '~/types';

const locals = {} as IOfType<string>;

/**
* Used for state preservation for different kpo instances AND children
* processes. Will only pollute `process.env` if the process is kpo owned,
* that is, if `process.env[OWNED_ENV_KEY]` is set.
*/
export default function environmentals(key: TEnvironmental) {
const vars = process.env[OWNED_ENV_KEY] ? process.env : locals;

return {
get(): string | void {
return vars[key] || undefined;
},
set(value?: string): void {
vars[key] = value || undefined;
}
};
}
27 changes: 0 additions & 27 deletions src/utils/version-range.ts

This file was deleted.

61 changes: 0 additions & 61 deletions test/utils/version-range.test.ts

This file was deleted.

0 comments on commit 5fc902e

Please sign in to comment.