Skip to content

Add luaLibDir compiler option and in operator, fix template strings#60

Merged
Perryvw merged 8 commits intoTypeScriptToLua:masterfrom
zapp-brannigan-dota:patch-branch
Mar 6, 2018
Merged

Add luaLibDir compiler option and in operator, fix template strings#60
Perryvw merged 8 commits intoTypeScriptToLua:masterfrom
zapp-brannigan-dota:patch-branch

Conversation

@zapp-brannigan-dota
Copy link
Copy Markdown
Contributor

luaLibDir is a new compiler option that specifies the save location for typescript_lualib.lua relative to outDir.

Typescript template strings now cast all expressions to string.

src/Compiler.ts Outdated
var argv = minimist(args, {
const argv = minimist(args, {
string: ['l'],
alias: { h: 'help', v: 'version', l: 'luaTarget' },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add CLI options for addHeader and lualiboutdir. Don't forget to update help text and readme.

src/Compiler.ts Outdated
options.luaLibDir = path.join(options.outDir, options.luaLibDir);
}
if (!fs.existsSync(options.luaLibDir)){
fs.mkdirSync(options.luaLibDir);
Copy link
Copy Markdown
Member

@lolleko lolleko Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure mkdir sync is not recursive. In this case this will error on a longer path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript has a function to recursively create files / directories. not sure If that function is exposed tho.

src/Compiler.ts Outdated
options.luaLibDir = options.outDir;
}
else {
options.luaLibDir = path.join(options.outDir, options.luaLibDir);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be path.resolve, just to be sure.

interface CompilerOptions extends ts.CompilerOptions {
addHeader?: boolean;
luaLibDir?: string;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add luaTarget: string aswell

src/Compiler.ts Outdated
// Copy lualib to target dir
// This isnt run in sync because copyFileSync wont report errors.
fs.copyFile(path.resolve(__dirname, "../dist/lualib/typescript.lua"), path.join(options.outDir, "typescript_lualib.lua"), (err: NodeJS.ErrnoException) => {
fs.copyFile(path.resolve(__dirname, "../dist/lualib/typescript.lua"), path.join(options.luaLibDir, "typescript_lualib.lua"), (err: NodeJS.ErrnoException) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you change options.luaLibDir the require call should be resolved, in order to point to that new path, https://github.com/Perryvw/TypescriptToLua/blob/master/src/Transpiler.ts#L36

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment below.

@lolleko lolleko self-assigned this Mar 2, 2018
process.exit(1);
if (invalidErrorCount != commandLine.errors.length) {
process.exit(1);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of logError looks pretty dodgy. Improve or add some comments that explain what/why this function does.

@Perryvw
Copy link
Copy Markdown
Member

Perryvw commented Mar 2, 2018

Not sure if we want to support luaLibDir in the first place, sounds like a lot of hacky stuff for little gain.

@Perryvw
Copy link
Copy Markdown
Member

Perryvw commented Mar 5, 2018

After some discussion we decided not to want the lualibdir stuff in the main branch. Like I said in the previous comment it seems like asking for trouble with limited pay-off. The rest of the pull request looks good and I'd be happy to merge if you remove the lualibdir part.

@zapp-brannigan-dota
Copy link
Copy Markdown
Contributor Author

luaLibDir solves the problem of a directory structure like this:

src/
- game/
  - tsconfig.json
  - scripts/
    - vscripts/
      - ...

There is no additional resolving needed. It can only be used to specify the correct subfolder, nothing else.

@lolleko
Copy link
Copy Markdown
Member

lolleko commented Mar 5, 2018

Did you try setting rootDir to ./scripts/vscripts/

@zapp-brannigan-dota
Copy link
Copy Markdown
Contributor Author

rootDir solves the problem, so I removed luaLibDir. It was broken on Windows but is fixed now. I can't tell if it works on other platforms tho.

@zapp-brannigan-dota
Copy link
Copy Markdown
Contributor Author

There should tests for compiling different types of skeleton projects. I might make them at some point but I've never done that so some examples would be very helpful.

@Perryvw Perryvw merged commit 3f8923d into TypeScriptToLua:master Mar 6, 2018
@zapp-brannigan-dota zapp-brannigan-dota deleted the patch-branch branch March 7, 2018 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants