From e703e51c9c09b22e3bcda9a1faf1e05897f60616 Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 21 Dec 2021 15:25:09 +0100 Subject: Initial commit --- _mint/index.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 _mint/index.js (limited to '_mint/index.js') diff --git a/_mint/index.js b/_mint/index.js new file mode 100644 index 0000000..fabe9ff --- /dev/null +++ b/_mint/index.js @@ -0,0 +1,81 @@ +const fs = require('fs'); +const path = require('path'); +const beautify = require('js-beautify').js; + +global.root = __dirname; +global.constructed = "'use strict';\n\nglobal.MintExceptionManagerError = require('../_mint/internal/_exceptionManager');\n\ntry {\n\n"; + +class MintcImportError extends Error { + constructor(props) { + super(props); + this.name = "MintcImportError"; + } +} + +if (fs.existsSync(root + "/temp")) { + fs.rmSync(root + "/temp", { recursive: true }); +} +fs.mkdirSync(root + "/temp"); + +if (fs.existsSync(root + "/../_build")) { + fs.rmSync(root + "/../_build", { recursive: true }); +} +fs.mkdirSync(root + "/../_build"); + +let file = ""; + +if (typeof process.argv[2] !== "undefined") { + if (fs.existsSync(process.argv[2])) { + file = fs.readFileSync(process.argv[2]).toString(); + } else { + throw new MintcImportError("File not found") + } +} + +const MintParser = require('./parser/base'); +const MintParserComments = require('./parser/comments'); +const MintParserModules = require('./parser/modules'); +const MintParserVariables = require('./parser/variables'); +const MintParserFunctions = require('./parser/functions'); +const MintParserThrows = require('./parser/throws'); +const MintParserConditions = require('./parser/conditions'); +const MintParserStrings = require('./parser/strings'); + +file = new MintParserComments().parse(file); +console.log(file); +console.log("-------------------"); + +file = new MintParserModules().parse(file); +console.log(file); +console.log("-------------------"); + +file = new MintParserVariables().parse(file); +console.log(file); +console.log("-------------------"); + +file = new MintParserFunctions().parse(file); +console.log(file); +console.log("-------------------"); + +file = new MintParserThrows().parse(file); +console.log(file); +console.log("-------------------"); + +file = new MintParserConditions().parse(file); +console.log(file); +console.log("-------------------"); + +file = new MintParserStrings().parse(file); +console.log(file); +console.log("-------------------"); + +constructed += file; +constructed += "\n\n} catch (e) { throw new MintExceptionManagerError(e.name, e.message, e.stack); }"; + +fs.writeFileSync(root + "/../_build/" + (path.basename(process.argv[2], process.argv[2].split(".")[process.argv[2].split(".").length - 1]).substr(0, path.basename(process.argv[2], process.argv[2].split(".")[process.argv[2].split(".").length - 1]).length - 1)) + ".js", beautify(constructed, { + indent_size: 4, + space_in_empty_paren: true, + no_preserve_newlines: true, + max_preserve_newlines: 1, + jslint_happy: true +})); \ No newline at end of file -- cgit