Compare commits
3 Commits
6e281c40aa
...
738bbdafb9
Author | SHA1 | Date |
---|---|---|
Jill | 738bbdafb9 | |
Jill | 7a20cabad7 | |
Jill | 84a233c022 |
18
index.js
18
index.js
|
@ -5,6 +5,7 @@ const chalk = require('chalk');
|
|||
|
||||
const declarationsPath = path.resolve(__dirname, './isaac-typescript-definitions/typings/');
|
||||
const outPath = path.resolve(__dirname, './out/');
|
||||
const overridePath = path.resolve(__dirname, './override/');
|
||||
|
||||
let classes = {};
|
||||
|
||||
|
@ -79,7 +80,7 @@ function transpile(parsed, indent, prefix) {
|
|||
}
|
||||
|
||||
classes[d.name] = contents;
|
||||
return `---@class ${d.name}${n}${contents.filter(e => e[0] === 'const').map(c => `---@field public ${c[1].name} ${transpileType(c[1].type)}${n}`).join('')}${global ? '' : '__class_'}${d.name} = {}${n}${contents.filter(e => e[0] !== 'const').map(c => transpile(c, indent, `${global ? '' : '__class_'}${d.name}`)).join(n)}\n`;
|
||||
return `---@class ${d.name}${d.extends ? ' : ' + d.extends : ''}${n}${contents.filter(e => e[0] === 'const').map(c => `---@field public ${c[1].name} ${transpileType(c[1].type)}${n}`).join('')}${global ? '' : '__class_'}${d.name} = {}${n}${contents.filter(e => e[0] !== 'const').map(c => transpile(c, indent, `${global ? '' : '__class_'}${d.name}`)).join(n)}\n`;
|
||||
case 'function':
|
||||
return `${d.arguments.map(p => `---@param ${p.name.replace('?', '')} ${transpileType(p.type)}${n}`).join('')}---@return ${transpileType(d.returns)}${n}function ${prefix ? prefix + ':' : ''}${d.name}(${d.arguments.map(a => a.name.replace('?', '')).join(', ')}) end`;
|
||||
case 'const':
|
||||
|
@ -218,6 +219,17 @@ async function recursiveReaddir(rpath, p, fileNames) {
|
|||
const filePath = path.resolve(declarationsPath, f);
|
||||
|
||||
console.log(` ${chalk.cyanBright(f)}`);
|
||||
|
||||
const override = path.resolve(overridePath, f.replace('.d.ts', '.lua'));
|
||||
const luaFilename = f.replace('.d.ts', '.lua').split('/').join('_');
|
||||
try {
|
||||
if (await fs.stat(override)) {
|
||||
console.log(' file exists in override/, ignoring');
|
||||
await fs.copyFile(override, path.resolve(outPath, luaFilename));
|
||||
continue;
|
||||
}
|
||||
} catch(err) {}
|
||||
|
||||
const file = await fs.readFile(filePath, 'utf8');
|
||||
|
||||
let startParse = Date.now();
|
||||
|
@ -267,11 +279,11 @@ async function recursiveReaddir(rpath, p, fileNames) {
|
|||
}
|
||||
|
||||
//console.log(inspect(parsed, false, 10));
|
||||
const luaFilename = f.replace('.d.ts', '.lua').split('/').pop();
|
||||
await fs.writeFile(path.resolve(outPath, luaFilename), transpiled);
|
||||
//console.log(` wrote ${chalk.cyanBright(luaFilename)}`);
|
||||
}
|
||||
|
||||
console.log(`\nfinished transpiling ${chalk.magentaBright(filesAmt)} ${chalk.gray(`+ ${files.length - filesAmt}`)} files in ${chalk.magentaBright(timeTotal + 'ms')} ${chalk.gray(`(${Math.floor(timeParsing/timeTotal * 1000 + 0.5) / 10}% spent parsing)`)}`);
|
||||
console.log(`\nfinished transpiling ${chalk.magentaBright(filesAmt)} ${chalk.gray(`+ ${files.length - filesAmt}`)} files in ${chalk.magentaBright(timeTotal + 'ms')} avg ${chalk.magentaBright((Math.floor(timeTotal / filesAmt * 100) / 100) + 'ms')} ${chalk.gray(`(${Math.floor(timeParsing/timeTotal * 1000 + 0.5) / 10}% spent parsing)`)}`);
|
||||
console.log(`total class cache size: ${chalk.magentaBright(Object.keys(classes).length + ' classes')}`)
|
||||
console.log(`check ${chalk.cyanBright(outPath)}`);
|
||||
})();
|
|
@ -0,0 +1,21 @@
|
|||
---@class Mod
|
||||
---@field Name string
|
||||
__class_Mod = {}
|
||||
|
||||
---@param modCallback ModCallbacks
|
||||
---@param callback fun(): void
|
||||
---@vararg any
|
||||
---@return void
|
||||
function __class_Mod:AddCallback(modCallback, callback, ...) end
|
||||
---@return boolean
|
||||
function __class_Mod:HasData() end
|
||||
---@return string
|
||||
function __class_Mod:LoadData() end
|
||||
---@param callbackID ModCallbacks
|
||||
---@param callback fun(): void
|
||||
---@return void
|
||||
function __class_Mod:RemoveCallback(callbackID, callback) end
|
||||
---@return void
|
||||
function __class_Mod:RemoveData() end
|
||||
---@param data string
|
||||
function __class_Mod:SaveData(data) end
|
Loading…
Reference in New Issue