-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.ts
23 lines (17 loc) · 1.05 KB
/
compiler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import * as chalk from "chalk";
import * as path from "path";
import * as fs from "fs";
import { compile, recursiveReadDirectoryWithContents } from "./compileClient";
export class Compiler {
compile(project: string, to: string): { luaPrimaryFile: string, files: Record<string, string> } {
const primaryFile = JSON.parse(fs.readFileSync(path.join(require.resolve(project), "../package.json"), "utf-8")).main;
let split = primaryFile.split(".");
split.pop();
split = split.join(".").split("/");
const luaPrimaryFile = split.join(".");
console.log(`${chalk.grey("[")}${chalk.green("Compiler")}${chalk.grey("]")} compiling ${chalk.cyan(project)} ${chalk.grey("[")}${chalk.blue(primaryFile)}${chalk.grey("]")} ${chalk.grey("(")}${chalk.blue(path.join(require.resolve(project), ".."))}${chalk.grey(")")}`)
compile(project, to);
fs.writeFileSync(path.join(to, "package.json"), fs.readFileSync(path.join(require.resolve(project), "..", "package.json")));
return { luaPrimaryFile, files: recursiveReadDirectoryWithContents(to) };
}
}