Skip to content

Commit

Permalink
Fix extracting CLI args when running as script
Browse files Browse the repository at this point in the history
  • Loading branch information
juusaw committed Oct 6, 2019
1 parent f4d77dd commit 856a9c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cli.js
Expand Up @@ -2,4 +2,4 @@

var tsToIo = require("./build/index.js");

console.log(tsToIo.getValidatorsFromFileNames([process.argv[2]]));
console.log(tsToIo.getValidatorsFromFileNames());
19 changes: 5 additions & 14 deletions src/index.ts
Expand Up @@ -215,7 +215,11 @@ export function getValidatorsFromString(
return result.join("\n\n");
}

export function getValidatorsFromFileNames(config: TsToIoConfig) {
export function getValidatorsFromFileNames() {
const config = getCliConfig();
if (!config.fileNames.length) {
return displayHelp();
}
const program = ts.createProgram(config.fileNames, compilerOptions);
const checker = program.getTypeChecker();
const result = config.includeHeader ? [getImports()] : [];
Expand All @@ -226,16 +230,3 @@ export function getValidatorsFromFileNames(config: TsToIoConfig) {
}
return result.join("\n\n");
}

function isEntryPoint() {
return require.main === module;
}

if (isEntryPoint()) {
const config = getCliConfig();
if (!config.fileNames.length) {
displayHelp();
} else {
console.log(getValidatorsFromFileNames(config));
}
}

0 comments on commit 856a9c3

Please sign in to comment.