From 8e49fec80fda70e64a719d99fda3388161686f11 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 17 Aug 2018 16:42:59 -0700 Subject: [PATCH] Move perform build to tsc instead of tsbuild --- src/compiler/tsbuild.ts | 122 ---------------------------------------- src/tsc/tsc.ts | 122 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 122 deletions(-) diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index 60f1d843e78..87dcb0e2b57 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -385,128 +385,6 @@ namespace ts { }; } - const buildOpts: CommandLineOption[] = [ - { - name: "verbose", - shortName: "v", - category: Diagnostics.Command_line_Options, - description: Diagnostics.Enable_verbose_logging, - type: "boolean" - }, - { - name: "dry", - shortName: "d", - category: Diagnostics.Command_line_Options, - description: Diagnostics.Show_what_would_be_built_or_deleted_if_specified_with_clean, - type: "boolean" - }, - { - name: "force", - shortName: "f", - category: Diagnostics.Command_line_Options, - description: Diagnostics.Build_all_projects_including_those_that_appear_to_be_up_to_date, - type: "boolean" - }, - { - name: "clean", - category: Diagnostics.Command_line_Options, - description: Diagnostics.Delete_the_outputs_of_all_projects, - type: "boolean" - }, - { - name: "watch", - category: Diagnostics.Command_line_Options, - description: Diagnostics.Watch_input_files, - type: "boolean" - } - ]; - - export function performBuild(args: string[], compilerHost: CompilerHost, buildHost: BuildHost, system?: System): number | undefined { - let verbose = false; - let dry = false; - let force = false; - let clean = false; - let watch = false; - - const projects: string[] = []; - for (const arg of args) { - switch (arg.toLowerCase()) { - case "-v": - case "--verbose": - verbose = true; - continue; - case "-d": - case "--dry": - dry = true; - continue; - case "-f": - case "--force": - force = true; - continue; - case "--clean": - clean = true; - continue; - case "--watch": - case "-w": - watch = true; - continue; - - case "--?": - case "-?": - case "--help": - printHelp(buildOpts, "--build "); - return ExitStatus.Success; - } - // Not a flag, parse as filename - addProject(arg); - } - - // Nonsensical combinations - if (clean && force) { - buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force"); - return ExitStatus.DiagnosticsPresent_OutputsSkipped; - } - if (clean && verbose) { - buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose"); - return ExitStatus.DiagnosticsPresent_OutputsSkipped; - } - if (clean && watch) { - buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch"); - return ExitStatus.DiagnosticsPresent_OutputsSkipped; - } - if (watch && dry) { - buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry"); - return ExitStatus.DiagnosticsPresent_OutputsSkipped; - } - - if (projects.length === 0) { - // tsc -b invoked with no extra arguments; act as if invoked with "tsc -b ." - addProject("."); - } - - const builder = createSolutionBuilder(compilerHost, buildHost, projects, { dry, force, verbose }, system); - if (clean) { - return builder.cleanAllProjects(); - } - - if (watch) { - builder.buildAllProjects(); - builder.startWatching(); - return undefined; - } - - return builder.buildAllProjects(); - - function addProject(projectSpecification: string) { - const fileName = resolvePath(compilerHost.getCurrentDirectory(), projectSpecification); - const refPath = resolveProjectReferencePath(compilerHost, { path: fileName }); - if (!compilerHost.fileExists(refPath)) { - return buildHost.error(Diagnostics.File_0_does_not_exist, fileName); - } - projects.push(refPath); - } - } - /** * A SolutionBuilder has an immutable set of rootNames that are the "entry point" projects, but * can dynamically add/remove other projects based on changes on the rootNames' references diff --git a/src/tsc/tsc.ts b/src/tsc/tsc.ts index 97e239c8bca..f6f0db6e9aa 100644 --- a/src/tsc/tsc.ts +++ b/src/tsc/tsc.ts @@ -172,6 +172,128 @@ namespace ts { } } + const buildOpts: CommandLineOption[] = [ + { + name: "verbose", + shortName: "v", + category: Diagnostics.Command_line_Options, + description: Diagnostics.Enable_verbose_logging, + type: "boolean" + }, + { + name: "dry", + shortName: "d", + category: Diagnostics.Command_line_Options, + description: Diagnostics.Show_what_would_be_built_or_deleted_if_specified_with_clean, + type: "boolean" + }, + { + name: "force", + shortName: "f", + category: Diagnostics.Command_line_Options, + description: Diagnostics.Build_all_projects_including_those_that_appear_to_be_up_to_date, + type: "boolean" + }, + { + name: "clean", + category: Diagnostics.Command_line_Options, + description: Diagnostics.Delete_the_outputs_of_all_projects, + type: "boolean" + }, + { + name: "watch", + category: Diagnostics.Command_line_Options, + description: Diagnostics.Watch_input_files, + type: "boolean" + } + ]; + + function performBuild(args: string[], compilerHost: CompilerHost, buildHost: BuildHost, system?: System): number | undefined { + let verbose = false; + let dry = false; + let force = false; + let clean = false; + let watch = false; + + const projects: string[] = []; + for (const arg of args) { + switch (arg.toLowerCase()) { + case "-v": + case "--verbose": + verbose = true; + continue; + case "-d": + case "--dry": + dry = true; + continue; + case "-f": + case "--force": + force = true; + continue; + case "--clean": + clean = true; + continue; + case "--watch": + case "-w": + watch = true; + continue; + + case "--?": + case "-?": + case "--help": + printHelp(buildOpts, "--build "); + return ExitStatus.Success; + } + // Not a flag, parse as filename + addProject(arg); + } + + // Nonsensical combinations + if (clean && force) { + buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force"); + return ExitStatus.DiagnosticsPresent_OutputsSkipped; + } + if (clean && verbose) { + buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose"); + return ExitStatus.DiagnosticsPresent_OutputsSkipped; + } + if (clean && watch) { + buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch"); + return ExitStatus.DiagnosticsPresent_OutputsSkipped; + } + if (watch && dry) { + buildHost.error(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry"); + return ExitStatus.DiagnosticsPresent_OutputsSkipped; + } + + if (projects.length === 0) { + // tsc -b invoked with no extra arguments; act as if invoked with "tsc -b ." + addProject("."); + } + + const builder = createSolutionBuilder(compilerHost, buildHost, projects, { dry, force, verbose }, system); + if (clean) { + return builder.cleanAllProjects(); + } + + if (watch) { + builder.buildAllProjects(); + builder.startWatching(); + return undefined; + } + + return builder.buildAllProjects(); + + function addProject(projectSpecification: string) { + const fileName = resolvePath(compilerHost.getCurrentDirectory(), projectSpecification); + const refPath = resolveProjectReferencePath(compilerHost, { path: fileName }); + if (!compilerHost.fileExists(refPath)) { + return buildHost.error(Diagnostics.File_0_does_not_exist, fileName); + } + projects.push(refPath); + } + } + function performCompilation(rootNames: string[], projectReferences: ReadonlyArray | undefined, options: CompilerOptions, configFileParsingDiagnostics?: ReadonlyArray) { const host = createCompilerHost(options); enableStatistics(options);