| 61 | } |
| 62 | |
| 63 | func ParseBuildCommandLine( |
| 64 | commandLine []string, |
| 65 | host ParseConfigHost, |
| 66 | ) *ParsedBuildCommandLine { |
| 67 | if commandLine == nil { |
| 68 | commandLine = []string{} |
| 69 | } |
| 70 | parser := parseCommandLineWorker(buildOptionsDidYouMeanDiagnostics, commandLine, host.FS(), host.GetCurrentDirectory()) |
| 71 | compilerOptions := &core.CompilerOptions{} |
| 72 | for key, value := range parser.options.Entries() { |
| 73 | buildOption := BuildNameMap.Get(key) |
| 74 | if buildOption == &TscBuildOption || buildOption == CompilerNameMap.Get(key) { |
| 75 | ParseCompilerOptions(key, value, compilerOptions) |
| 76 | } |
| 77 | } |
| 78 | result := &ParsedBuildCommandLine{ |
| 79 | BuildOptions: convertMapToOptions(parser.options, &buildOptionsParser{&core.BuildOptions{}}).BuildOptions, |
| 80 | CompilerOptions: compilerOptions, |
| 81 | WatchOptions: convertMapToOptions(parser.options, &watchOptionsParser{&core.WatchOptions{}}).WatchOptions, |
| 82 | Projects: parser.fileNames, |
| 83 | Errors: parser.errors, |
| 84 | Raw: parser.options, |
| 85 | |
| 86 | comparePathsOptions: tspath.ComparePathsOptions{ |
| 87 | UseCaseSensitiveFileNames: host.FS().UseCaseSensitiveFileNames(), |
| 88 | CurrentDirectory: host.GetCurrentDirectory(), |
| 89 | }, |
| 90 | } |
| 91 | |
| 92 | if len(result.Projects) == 0 { |
| 93 | // tsc -b invoked with no extra arguments; act as if invoked with "tsc -b ." |
| 94 | result.Projects = append(result.Projects, ".") |
| 95 | } |
| 96 | |
| 97 | // Nonsensical combinations |
| 98 | if result.BuildOptions.Clean.IsTrue() && result.BuildOptions.Force.IsTrue() { |
| 99 | result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "clean", "force")) |
| 100 | } |
| 101 | if result.BuildOptions.Clean.IsTrue() && result.BuildOptions.Verbose.IsTrue() { |
| 102 | result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "clean", "verbose")) |
| 103 | } |
| 104 | if result.BuildOptions.Clean.IsTrue() && result.CompilerOptions.Watch.IsTrue() { |
| 105 | result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "clean", "watch")) |
| 106 | } |
| 107 | if result.CompilerOptions.Watch.IsTrue() && result.BuildOptions.Dry.IsTrue() { |
| 108 | result.Errors = append(result.Errors, ast.NewCompilerDiagnostic(diagnostics.Options_0_and_1_cannot_be_combined, "watch", "dry")) |
| 109 | } |
| 110 | |
| 111 | return result |
| 112 | } |
| 113 | |
| 114 | func parseCommandLineWorker( |
| 115 | parseCommandLineWithDiagnostics *ParseCommandLineWorkerDiagnostics, |