Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Configure typed/untyped converstion from the CLI and default to typed #157

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import * as tsickle from './tsickle';
interface Settings {
/** If provided, path to save externs to. */
externsPath?: string;

/** If provided, convert every type to the Closure {?} type */
isUntyped: boolean;
}

function usage() {
Expand All @@ -22,6 +25,7 @@ example:

tsickle flags are:
--externs=PATH save generated Closure externs.js to PATH
--untyped convert every type in TypeScript to the Closure {?} type
`);
}

Expand All @@ -30,7 +34,7 @@ tsickle flags are:
* the arguments to pass on to tsc.
*/
function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: string[]} {
let settings: Settings = {};
let settings: Settings = {isUntyped: false};
let parsedArgs = minimist(args);
for (let flag of Object.keys(parsedArgs)) {
switch (flag) {
Expand All @@ -42,6 +46,9 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
case 'externs':
settings.externsPath = parsedArgs[flag];
break;
case 'untyped':
settings.isUntyped = true;
break;
case '_':
// This is part of the minimist API, and holds args after the '--'.
break;
Expand Down Expand Up @@ -129,7 +136,7 @@ function createSourceReplacingCompilerHost(
* Compiles TypeScript code into Closure-compiler-ready JS.
* Doesn't write any files to disk; all JS content is returned in a map.
*/
function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
function toClosureJS(options: ts.CompilerOptions, fileNames: string[], isUntyped: boolean):
{jsFiles?: {[fileName: string]: string}, externs?: string, errors?: ts.Diagnostic[]} {
// Parse and load the program without tsickle processing.
// This is so:
Expand All @@ -141,10 +148,8 @@ function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
return {errors};
}

// TODO(evanm): let the user configure tsickle options via the command line.
// Or, better, just make tsickle always work without needing any options.
const tsickleOptions: tsickle.Options = {
untyped: true,
untyped: isUntyped,
};

// Process each input file with tsickle and save the output.
Expand Down Expand Up @@ -201,7 +206,7 @@ function main(args: string[]) {
// Run tsickle+TSC to convert inputs to Closure JS files.
let jsFiles: {[fileName: string]: string};
let externs: string;
({jsFiles, externs, errors} = toClosureJS(options, fileNames));
({jsFiles, externs, errors} = toClosureJS(options, fileNames, settings.isUntyped));
if (errors && errors.length > 0) {
console.error(tsickle.formatDiagnostics(errors));
process.exit(1);
Expand Down