Skip to content

Commit 7c1cb0e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into transformation-pipeline-refactor
2 parents 2f7ee83 + 1b580b4 commit 7c1cb0e

File tree

15 files changed

+400
-241
lines changed

15 files changed

+400
-241
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v1
1414
- uses: actions/setup-node@v1
15+
with:
16+
registry-url: "https://registry.npmjs.org"
1517
- run: npm install --global npm@6
1618
- run: npm ci
1719
- run: npm run build

package-lock.json

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-to-lua",
3-
"version": "0.28.0",
3+
"version": "0.28.1",
44
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
55
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
66
"license": "MIT",
@@ -44,11 +44,13 @@
4444
"typescript": "^3.6.2"
4545
},
4646
"devDependencies": {
47+
"@types/fs-extra": "^8.0.1",
4748
"@types/glob": "^7.1.1",
4849
"@types/jest": "^24.0.15",
4950
"@types/node": "^11.13.14",
5051
"@types/resolve": "0.0.8",
5152
"fengari": "^0.1.4",
53+
"fs-extra": "^8.1.0",
5254
"javascript-stringify": "^2.0.0",
5355
"jest": "^24.8.0",
5456
"jest-circus": "^24.8.0",

src/TSTransformers.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path";
22
import * as resolve from "resolve";
33
import * as ts from "typescript";
4+
import * as cliDiagnostics from "./cli/diagnostics";
45
import { CompilerOptions, TransformerImport } from "./CompilerOptions";
56
import * as diagnosticFactories from "./diagnostics";
67
import { noImplicitSelfTransformer } from "./NoImplicitSelfTransformer";
@@ -111,7 +112,7 @@ function resolveTransformerFactory(
111112
): { error?: ts.Diagnostic; factory?: TransformerFactory } {
112113
if (typeof transform !== "string") {
113114
const optionName = `${transformerOptionPath}.transform`;
114-
return { error: diagnosticFactories.compilerOptionRequiresAValueOfType(optionName, "string") };
115+
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "string") };
115116
}
116117

117118
let resolved: string;
@@ -167,18 +168,18 @@ function loadTransformer(
167168
break;
168169
default: {
169170
const optionName = `--${transformerOptionPath}.type`;
170-
return { error: diagnosticFactories.argumentForOptionMustBe(optionName, "program") };
171+
return { error: cliDiagnostics.argumentForOptionMustBe(optionName, "program") };
171172
}
172173
}
173174

174175
if (typeof after !== "boolean") {
175176
const optionName = `${transformerOptionPath}.after`;
176-
return { error: diagnosticFactories.compilerOptionRequiresAValueOfType(optionName, "boolean") };
177+
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "boolean") };
177178
}
178179

179180
if (typeof afterDeclarations !== "boolean") {
180181
const optionName = `${transformerOptionPath}.afterDeclarations`;
181-
return { error: diagnosticFactories.compilerOptionRequiresAValueOfType(optionName, "boolean") };
182+
return { error: cliDiagnostics.compilerOptionRequiresAValueOfType(optionName, "boolean") };
182183
}
183184

184185
if (typeof transformer === "function") {

src/cli/diagnostics.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
);

src/cli/information.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { optionDeclarations } from "./parse";
2+
3+
export const { version } = require("../../package.json");
4+
export const versionString = `Version ${version}`;
5+
6+
const helpString = `
7+
Syntax: tstl [options] [files...]
8+
9+
Examples: tstl path/to/file.ts [...]
10+
tstl -p path/to/tsconfig.json
11+
12+
In addition to the options listed below you can also pass options
13+
for the typescript compiler (For a list of options use tsc -h).
14+
Some tsc options might have no effect.
15+
`.trim();
16+
17+
export function getHelpString(): string {
18+
let result = helpString + "\n\n";
19+
20+
result += "Options:\n";
21+
for (const option of optionDeclarations) {
22+
const aliasStrings = (option.aliases || []).map(a => "-" + a);
23+
const optionString = aliasStrings.concat(["--" + option.name]).join("|");
24+
25+
const valuesHint = option.type === "enum" ? option.choices.join("|") : option.type;
26+
const spacing = " ".repeat(Math.max(1, 45 - optionString.length - valuesHint.length));
27+
28+
result += `\n ${optionString} <${valuesHint}>${spacing}${option.description}\n`;
29+
}
30+
31+
return result;
32+
}

0 commit comments

Comments
 (0)