From cd3018f25b23c09b27a4601ee96f1e7e6d5498d5 Mon Sep 17 00:00:00 2001 From: Todd Bluhm Date: Sat, 4 May 2019 05:45:52 -0500 Subject: [PATCH] Switch to dist folder and output typescript declaration files --- bin/env-cmd.js | 2 +- dist/env-cmd.d.ts | 21 +++++++++++++++++++++ {lib => dist}/env-cmd.js | 0 dist/get-env-vars.d.ts | 16 ++++++++++++++++ {lib => dist}/get-env-vars.js | 0 {lib => dist}/help.js | 0 dist/index.d.ts | 4 ++++ {lib => dist}/index.js | 0 dist/parse-args.d.ts | 5 +++++ {lib => dist}/parse-args.js | 0 dist/parse-env-file.d.ts | 26 ++++++++++++++++++++++++++ {lib => dist}/parse-env-file.js | 0 dist/parse-rc-file.d.ts | 15 +++++++++++++++ {lib => dist}/parse-rc-file.js | 0 dist/signal-termination.d.ts | 23 +++++++++++++++++++++++ {lib => dist}/signal-termination.js | 0 dist/spawn.d.ts | 2 ++ {lib => dist}/spawn.js | 0 dist/types.d.ts | 18 ++++++++++++++++++ {lib => dist}/types.js | 0 dist/utils.d.ts | 12 ++++++++++++ {lib => dist}/utils.js | 0 package.json | 9 +++++---- tsconfig.json | 3 ++- 24 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 dist/env-cmd.d.ts rename {lib => dist}/env-cmd.js (100%) create mode 100644 dist/get-env-vars.d.ts rename {lib => dist}/get-env-vars.js (100%) rename {lib => dist}/help.js (100%) create mode 100644 dist/index.d.ts rename {lib => dist}/index.js (100%) create mode 100644 dist/parse-args.d.ts rename {lib => dist}/parse-args.js (100%) create mode 100644 dist/parse-env-file.d.ts rename {lib => dist}/parse-env-file.js (100%) create mode 100644 dist/parse-rc-file.d.ts rename {lib => dist}/parse-rc-file.js (100%) create mode 100644 dist/signal-termination.d.ts rename {lib => dist}/signal-termination.js (100%) create mode 100644 dist/spawn.d.ts rename {lib => dist}/spawn.js (100%) create mode 100644 dist/types.d.ts rename {lib => dist}/types.js (100%) create mode 100644 dist/utils.d.ts rename {lib => dist}/utils.js (100%) diff --git a/bin/env-cmd.js b/bin/env-cmd.js index 67e901c..426bc39 100755 --- a/bin/env-cmd.js +++ b/bin/env-cmd.js @@ -1,2 +1,2 @@ #! /usr/bin/env node -require('../lib').CLI(process.argv.slice(2)) +require('../dist').CLI(process.argv.slice(2)) diff --git a/dist/env-cmd.d.ts b/dist/env-cmd.d.ts new file mode 100644 index 0000000..859a7da --- /dev/null +++ b/dist/env-cmd.d.ts @@ -0,0 +1,21 @@ +import { EnvCmdOptions } from './types'; +/** + * Executes env - cmd using command line arguments + * @export + * @param {string[]} args Command line argument to pass in ['-f', './.env'] + * @returns {Promise<{ [key: string]: any }>} + */ +export declare function CLI(args: string[]): Promise<{ + [key: string]: any; +}>; +/** + * The main env-cmd program. This will spawn a new process and run the given command using + * various environment file solutions. + * + * @export + * @param {EnvCmdOptions} { command, commandArgs, envFile, rc, options } + * @returns {Promise<{ [key: string]: any }>} Returns an object containing [environment variable name]: value + */ +export declare function EnvCmd({ command, commandArgs, envFile, rc, options }: EnvCmdOptions): Promise<{ + [key: string]: any; +}>; diff --git a/lib/env-cmd.js b/dist/env-cmd.js similarity index 100% rename from lib/env-cmd.js rename to dist/env-cmd.js diff --git a/dist/get-env-vars.d.ts b/dist/get-env-vars.d.ts new file mode 100644 index 0000000..d076d89 --- /dev/null +++ b/dist/get-env-vars.d.ts @@ -0,0 +1,16 @@ +import { GetEnvVarOptions } from './types'; +export declare function getEnvVars(options?: GetEnvVarOptions): Promise<{ + [key: string]: any; +}>; +export declare function getEnvFile({ filePath, fallback }: { + filePath?: string; + fallback?: boolean; +}): Promise<{ + [key: string]: any; +}>; +export declare function getRCFile({ environments, filePath }: { + environments: string[]; + filePath?: string; +}): Promise<{ + [key: string]: any; +}>; diff --git a/lib/get-env-vars.js b/dist/get-env-vars.js similarity index 100% rename from lib/get-env-vars.js rename to dist/get-env-vars.js diff --git a/lib/help.js b/dist/help.js similarity index 100% rename from lib/help.js rename to dist/help.js diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..39037f2 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,4 @@ +import { getEnvVars } from './get-env-vars'; +export * from './types'; +export * from './env-cmd'; +export declare const GetEnvVars: typeof getEnvVars; diff --git a/lib/index.js b/dist/index.js similarity index 100% rename from lib/index.js rename to dist/index.js diff --git a/dist/parse-args.d.ts b/dist/parse-args.d.ts new file mode 100644 index 0000000..fdad8c0 --- /dev/null +++ b/dist/parse-args.d.ts @@ -0,0 +1,5 @@ +import { EnvCmdOptions } from './types'; +/** +* Parses the arguments passed into the cli +*/ +export declare function parseArgs(args: string[]): EnvCmdOptions; diff --git a/lib/parse-args.js b/dist/parse-args.js similarity index 100% rename from lib/parse-args.js rename to dist/parse-args.js diff --git a/dist/parse-env-file.d.ts b/dist/parse-env-file.d.ts new file mode 100644 index 0000000..530f487 --- /dev/null +++ b/dist/parse-env-file.d.ts @@ -0,0 +1,26 @@ +/** + * Gets the environment vars from an env file + */ +export declare function getEnvFileVars(envFilePath: string): Promise<{ + [key: string]: any; +}>; +/** + * Parse out all env vars from a given env file string and return an object + */ +export declare function parseEnvString(envFileString: string): { + [key: string]: string; +}; +/** + * Parse out all env vars from an env file string + */ +export declare function parseEnvVars(envString: string): { + [key: string]: string; +}; +/** + * Strips out comments from env file string + */ +export declare function stripComments(envString: string): string; +/** + * Strips out newlines from env file string + */ +export declare function stripEmptyLines(envString: string): string; diff --git a/lib/parse-env-file.js b/dist/parse-env-file.js similarity index 100% rename from lib/parse-env-file.js rename to dist/parse-env-file.js diff --git a/dist/parse-rc-file.d.ts b/dist/parse-rc-file.d.ts new file mode 100644 index 0000000..1be55bd --- /dev/null +++ b/dist/parse-rc-file.d.ts @@ -0,0 +1,15 @@ +/** + * Gets the env vars from the rc file and rc environments + */ +export declare function getRCFileVars({ environments, filePath }: { + environments: string[]; + filePath: string; +}): Promise<{ + [key: string]: any; +}>; +/** + * Reads and parses the .rc file + */ +export declare function parseRCFile(fileData: string): { + [key: string]: any; +}; diff --git a/lib/parse-rc-file.js b/dist/parse-rc-file.js similarity index 100% rename from lib/parse-rc-file.js rename to dist/parse-rc-file.js diff --git a/dist/signal-termination.d.ts b/dist/signal-termination.d.ts new file mode 100644 index 0000000..e7d97fd --- /dev/null +++ b/dist/signal-termination.d.ts @@ -0,0 +1,23 @@ +/// +import { ChildProcess } from 'child_process'; +export declare class TermSignals { + private terminateSpawnedProcessFuncHandlers; + _exitCalled: boolean; + handleTermSignals(proc: ChildProcess): void; + /** + * Enables catching of unhandled exceptions + */ + handleUncaughtExceptions(): void; + /** + * Terminate parent process helper + */ + _terminateProcess(code?: number, signal?: string): void; + /** + * Exit event listener clean up helper + */ + _removeProcessListeners(): void; + /** + * General exception handler + */ + _uncaughtExceptionHandler(e: Error): void; +} diff --git a/lib/signal-termination.js b/dist/signal-termination.js similarity index 100% rename from lib/signal-termination.js rename to dist/signal-termination.js diff --git a/dist/spawn.d.ts b/dist/spawn.d.ts new file mode 100644 index 0000000..cabd0a7 --- /dev/null +++ b/dist/spawn.d.ts @@ -0,0 +1,2 @@ +import * as spawn from 'cross-spawn'; +export { spawn }; diff --git a/lib/spawn.js b/dist/spawn.js similarity index 100% rename from lib/spawn.js rename to dist/spawn.js diff --git a/dist/types.d.ts b/dist/types.d.ts new file mode 100644 index 0000000..ca1e952 --- /dev/null +++ b/dist/types.d.ts @@ -0,0 +1,18 @@ +export interface GetEnvVarOptions { + envFile?: { + filePath?: string; + fallback?: boolean; + }; + rc?: { + environments: string[]; + filePath?: string; + }; +} +export interface EnvCmdOptions extends GetEnvVarOptions { + command: string; + commandArgs: string[]; + options?: { + noOverride?: boolean; + useShell?: boolean; + }; +} diff --git a/lib/types.js b/dist/types.js similarity index 100% rename from lib/types.js rename to dist/types.js diff --git a/dist/utils.d.ts b/dist/utils.d.ts new file mode 100644 index 0000000..13e3d81 --- /dev/null +++ b/dist/utils.d.ts @@ -0,0 +1,12 @@ +/** + * A simple function for resolving the path the user entered + */ +export declare function resolveEnvFilePath(userPath: string): string; +/** + * A simple function that parses a comma separated string into an array of strings + */ +export declare function parseArgList(list: string): string[]; +/** + * A simple function to test if the value is a promise + */ +export declare function isPromise(value: any | PromiseLike): boolean; diff --git a/lib/utils.js b/dist/utils.js similarity index 100% rename from lib/utils.js rename to dist/utils.js diff --git a/package.json b/package.json index 6c2631b..55cc92c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "env-cmd", "version": "9.0.0", "description": "Executes a command using the envs in the provided env file", - "main": "lib/index.js", + "main": "dist/index.js", + "types": "dist/index.d.ts", "engines": { "node": ">=8.0.0" }, @@ -10,11 +11,11 @@ "env-cmd": "bin/env-cmd.js" }, "scripts": { - "test": "mocha -r ts-node/register ./**/*.ts", + "test": "mocha -r ts-node/register ./test/**/*.ts", "test-cover": "nyc --reporter=lcov --reporter=text npm test", - "test-lint": "eslint ./**/*.ts", + "test-lint": "eslint ./src/**/*.ts ./test/**/*.ts", "coveralls": "coveralls < coverage/lcov.info", - "lint": "eslint --fix ./**/*.ts", + "lint": "eslint --fix ./src/**/*.ts ./test/**/*.ts", "build": "tsc" }, "repository": { diff --git a/tsconfig.json b/tsconfig.json index 999f4cc..7ded638 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,10 @@ { "compilerOptions": { - "outDir": "./lib", + "outDir": "./dist", "target": "es2015", "module": "commonjs", "strict": true, + "declaration": true, "lib": [ "es2015", "es2016",