Skip to content

Commit

Permalink
revert(utils): Move boolean option parsing into its own util file
Browse files Browse the repository at this point in the history
  • Loading branch information
jcowman2 committed Feb 23, 2019
1 parent 36c6f58 commit e4591d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
Empty file modified bin/regal
100644 → 100755
Empty file.
39 changes: 9 additions & 30 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { Command } from "commander";
import { bundle, BundlerOptions, RecursivePartial } from "regal-bundler";
import { parseBoolean } from "./utils";
import { log } from "./wrappers";

export default (program: Command) =>
Expand Down Expand Up @@ -68,21 +69,10 @@ export default (program: Command) =>

// Handle --input-ts
if (args.inputTs !== undefined) {
let isTS = args.inputTs;

if (typeof isTS === "string") {
if (isTS === "true") {
isTS = true;
} else if (isTS === "false") {
isTS = false;
} else {
throw new Error(
"Illegal argument for --input-ts. Must be a boolean."
);
}
}

opts.bundler.input.ts = isTS;
opts.bundler.input.ts = parseBoolean(
"--input-ts",
args.inputTs
);
}

// Handle --output-file
Expand All @@ -102,21 +92,10 @@ export default (program: Command) =>

// Handle --minify
if (args.minify !== undefined) {
let min = args.minify;

if (typeof min === "string") {
if (min === "true") {
min = true;
} else if (min === "false") {
min = false;
} else {
throw new Error(
"Illegal argument for --minify. Must be a boolean."
);
}
}

opts.bundler.output.minify = min;
opts.bundler.output.minify = parseBoolean(
"--minify",
args.minify
);
}

bundle(opts);
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const parseBoolean = (argName: string, argValue: string) => {
if (typeof argValue === "boolean") {
return argValue;
} else if (typeof argValue === "string") {
if (argValue === "true") {
return true;
} else if (argValue === "false") {
return false;
}
}
throw new Error(`Illegal argument for ${argName}. Must be a boolean.`);
};

0 comments on commit e4591d7

Please sign in to comment.