Move perform build to tsc instead of tsbuild
This commit is contained in:
parent
d2240a40e1
commit
8e49fec80f
2 changed files with 122 additions and 122 deletions
|
@ -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
|
||||
|
|
122
src/tsc/tsc.ts
122
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<ProjectReference> | undefined, options: CompilerOptions, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>) {
|
||||
const host = createCompilerHost(options);
|
||||
enableStatistics(options);
|
||||
|
|
Loading…
Reference in a new issue