const fs = require("fs-promise");
const path = require("path");

const codeFilePaths = [
	"Validators/DomainName/DomainNameValidatorException.js",
	"Validators/DomainName/DomainNameValidator.js"
];

const outputCodeFileName = "node.js";

/**
 * Main function.
 */
(
	async() =>
	{
		const workspaceFolder = path.dirname(path.dirname(__filename));
		const outputFilePath = path.join(workspaceFolder, outputCodeFileName);
		await fs.writeFile(outputFilePath, "", {flag: "w"});
		await fs.writeFile(outputFilePath, "/* eslint-disable */ \n", {flag: "a", encoding: "utf8"});
		await fs.writeFile(outputFilePath, "if (!module) { module = {}; } \n", {flag: "a", encoding: "utf8"});
		for(let i = 0; i < codeFilePaths.length; i++)
		{
			const readFilePath = path.join(workspaceFolder, codeFilePaths[i]);
			const fileContent = await fs.readFile(readFilePath, {flag: "r", encoding: "utf8"});
			await fs.writeFile(outputFilePath, fileContent, {flag: "a", encoding: "utf8"});
		}
		await fs.writeFile(outputFilePath, "module.exports = DomainNameValidator;\n", {flag: "a", encoding: "utf8"});
		console.log("Done.");
	}
)();
