|
| 1 | +import * as ts from "typescript"; |
| 2 | + |
| 3 | +export const tstlOptionsAreMovingToTheTstlObject = (tstl: Record<string, any>): ts.Diagnostic => ({ |
| 4 | + file: undefined, |
| 5 | + start: undefined, |
| 6 | + length: undefined, |
| 7 | + category: ts.DiagnosticCategory.Warning, |
| 8 | + code: 0, |
| 9 | + source: "typescript-to-lua", |
| 10 | + messageText: |
| 11 | + 'TSTL options are moving to the "tstl" object. Adjust your tsconfig to look like\n' + |
| 12 | + `"tstl": ${JSON.stringify(tstl, undefined, 4)}`, |
| 13 | +}); |
| 14 | + |
| 15 | +export const watchErrorSummary = (errorCount: number): ts.Diagnostic => ({ |
| 16 | + file: undefined, |
| 17 | + start: undefined, |
| 18 | + length: undefined, |
| 19 | + category: ts.DiagnosticCategory.Message, |
| 20 | + code: errorCount === 1 ? 6193 : 6194, |
| 21 | + messageText: |
| 22 | + errorCount === 1 |
| 23 | + ? "Found 1 error. Watching for file changes." |
| 24 | + : `Found ${errorCount} errors. Watching for file changes.`, |
| 25 | +}); |
| 26 | + |
| 27 | +const createCommandLineError = <Args extends any[]>(code: number, getMessage: (...args: Args) => string) => ( |
| 28 | + ...args: Args |
| 29 | +): ts.Diagnostic => ({ |
| 30 | + file: undefined, |
| 31 | + start: undefined, |
| 32 | + length: undefined, |
| 33 | + category: ts.DiagnosticCategory.Error, |
| 34 | + code, |
| 35 | + messageText: getMessage(...args), |
| 36 | +}); |
| 37 | + |
| 38 | +export const unknownCompilerOption = createCommandLineError( |
| 39 | + 5023, |
| 40 | + (name: string) => `Unknown compiler option '${name}'.` |
| 41 | +); |
| 42 | + |
| 43 | +export const compilerOptionRequiresAValueOfType = createCommandLineError( |
| 44 | + 5024, |
| 45 | + (name: string, type: string) => `Compiler option '${name}' requires a value of type ${type}.` |
| 46 | +); |
| 47 | + |
| 48 | +export const optionProjectCannotBeMixedWithSourceFilesOnACommandLine = createCommandLineError( |
| 49 | + 5042, |
| 50 | + () => "Option 'project' cannot be mixed with source files on a command line." |
| 51 | +); |
| 52 | + |
| 53 | +export const cannotFindATsconfigJsonAtTheSpecifiedDirectory = createCommandLineError( |
| 54 | + 5057, |
| 55 | + (dir: string) => `Cannot find a tsconfig.json file at the specified directory: '${dir}'.` |
| 56 | +); |
| 57 | + |
| 58 | +export const theSpecifiedPathDoesNotExist = createCommandLineError( |
| 59 | + 5058, |
| 60 | + (dir: string) => `The specified path does not exist: '${dir}'.` |
| 61 | +); |
| 62 | + |
| 63 | +export const compilerOptionExpectsAnArgument = createCommandLineError( |
| 64 | + 6044, |
| 65 | + (name: string) => `Compiler option '${name}' expects an argument.` |
| 66 | +); |
| 67 | + |
| 68 | +export const argumentForOptionMustBe = createCommandLineError( |
| 69 | + 6046, |
| 70 | + (name: string, values: string) => `Argument for '${name}' option must be: ${values}.` |
| 71 | +); |
| 72 | + |
| 73 | +export const optionCanOnlyBeSpecifiedInTsconfigJsonFile = createCommandLineError( |
| 74 | + 6064, |
| 75 | + (name: string) => `Option '${name}' can only be specified in 'tsconfig.json' file.` |
| 76 | +); |
| 77 | + |
| 78 | +export const optionBuildMustBeFirstCommandLineArgument = createCommandLineError( |
| 79 | + 6369, |
| 80 | + () => "Option '--build' must be the first command line argument." |
| 81 | +); |
0 commit comments