diff --git a/index.js b/index.js index faf4467..79fc403 100644 --- a/index.js +++ b/index.js @@ -93,6 +93,8 @@ function removeComments(code) { return code; } +let parsedElements = 0; + /** * @param {string} code */ @@ -113,6 +115,7 @@ function parse(code) { let interfaceFreeCode = code; const interface = /interface (\w+)(?: extends (\w+))? ?{([^}]*)}/g; while ((match = interface.exec(code)) !== null) { + parsedElements++; interfaceFreeCode = interfaceFreeCode.replace(match[0], ''); elements.push(['interface', {name: match[1], extends: match[2], contents: parse(match[3])}]); } @@ -122,6 +125,7 @@ function parse(code) { let namespaceFreeCode = code; const namespace = /namespace (\w+) ?{([^}]*)}/g; while ((match = namespace.exec(code)) !== null) { + parsedElements++; namespaceFreeCode = namespaceFreeCode.replace(match[0], ''); elements.push(['namespace', {name: match[1], contents: parse(match[2])}]); } @@ -131,6 +135,7 @@ function parse(code) { let functionFreeCode = code; const functions = /(function)?\s(\w+)\s*\(([^;]*)\)(\s*:\s*([\w\[\]\s|<>,]+))?/g; // wow this sucks while ((match = functions.exec(code)) !== null) { + parsedElements++; functionFreeCode = functionFreeCode.replace(match[0], ''); let arguments = match[3].split(',').map(s => { const split = s.split(':').map(s => s.trim()); @@ -144,6 +149,7 @@ function parse(code) { let enumFreeCode = code; const enums = /enum (\w+) ?{([^}]*)}/g; while ((match = enums.exec(code)) !== null) { + parsedElements++; enumFreeCode = enumFreeCode.replace(match[0], ''); elements.push(['enum', {name: match[1], contents: match[2].split(',').filter(c => c.split('=').length === 2).map(c => {return {name: c.split('=')[0].trim(), value: c.split('=')[1].trim()}})}]); } @@ -153,6 +159,7 @@ function parse(code) { let constFreeCode = code; const consts = /(\w+)\s*:\s*(\w+)/g; while ((match = consts.exec(code)) !== null) { + parsedElements++; constFreeCode = constFreeCode.replace(match[0], ''); elements.push(['const', {name: match[1], type: match[2]}]); } @@ -181,6 +188,7 @@ function parse(code) { let errorReason = {}; const files = await fs.readdir(declarationsPath); + const filesAmt = files.length; let i = 0; for (const f of files) { i++; @@ -188,17 +196,22 @@ function parse(code) { const stat = await fs.lstat(filePath); if (stat.isFile()) { + console.log(` ${chalk.cyanBright(f)}`); const file = await fs.readFile(filePath, 'utf8'); let startParse = Date.now(); + parsedElements = 0; const parsed = parse(file); - console.log(` parsed ${chalk.magentaBright(parsed.length)} elements from ${chalk.cyanBright(f)}`); + console.log(` parsed ${chalk.magentaBright(parsedElements)} objects from ${chalk.cyanBright(f)}`); timeParsing += Date.now() - startParse; if (parsed.length === 0) { console.log(`${chalk.redBright('!')} no elements parsed, ${chalk.gray('not writing anything')}`); continue; } + if (parsed.length > 10) { + console.log(`${chalk.redBright('!')} over 10 top-level objects were parsed - this may be a bad idea`); + } let transpiled; try { @@ -238,6 +251,6 @@ function parse(code) { } } - console.log(`\nfinished transpiling 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')} ${chalk.gray(`(${Math.floor(timeParsing/timeTotal * 1000 + 0.5) / 10}% spent parsing)`)}`); console.log(`check ${chalk.cyanBright(outPath)}`); })(); \ No newline at end of file