Skip to content

Commit

Permalink
performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Dingsel committed Jun 14, 2024
1 parent 6abf91b commit d822c14
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 79 deletions.
30 changes: 11 additions & 19 deletions cmca-build-src/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { readFileSync, readdirSync } from "fs"
import { rm } from "fs/promises"
import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "fs"
import { mkdir, writeFile } from "fs/promises"
import { createRequire } from "module"
import { join } from "path"

Expand Down Expand Up @@ -37,9 +37,9 @@ switch (bundlerType) {
const options = JSON.parse(readFileSync(join(root, "/tsconfig.json")).toString())

const program = tsModule.createProgram([tsEntry], options)
delOldFiles()
const emitResult = program.emit();

//Handle diagnostics
const allDiagnostics = tsModule
.getPreEmitDiagnostics(program)
.concat(emitResult.diagnostics);
Expand All @@ -53,16 +53,15 @@ switch (bundlerType) {
console.log(tsModule.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
}
});

delTsFiles()
break
};
case "esbuild": {
const { build } = await import("esbuild")
await build({
const { outputFiles } = await build({
bundle: true,
format: "esm",
outfile: "./BP/scripts/main.js",
write: false,
entryPoints: {
in: ts ? tsEntry : "./BP/scripts/main.js"
},
Expand All @@ -81,22 +80,15 @@ switch (bundlerType) {
]
})
delOldFiles()
await Promise.all(
outputFiles.map(x =>
writeFile(x.path, x.contents)
)
)
break;
}
}

function delOldFiles() {
readdirSync("./BP/scripts/", { recursive: true }).map((/** @type {import("fs").PathLike} */ x) => {
const asStr = x.toString()
if (asStr.endsWith("main.js") || asStr.endsWith(".map")) return
rm("./BP/scripts/" + x, { force: true, recursive: true })
})
}

function delTsFiles() {
readdirSync("./BP/scripts/", { recursive: true }).map((/** @type {import("fs").PathLike} */ x) => {
const asStr = x.toString()
if (asStr.endsWith(".js")) return
rm("./BP/scripts/" + x, { force: true, recursive: true })
})
rmSync("./BP/scripts/", { force: true, recursive: true })
}
58 changes: 2 additions & 56 deletions cmca-build-src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmca-build-src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cmca-build",
"version": "0.1.2",
"version": "0.2.0",
"type": "module",
"keywords": [
"Minecraft",
Expand Down
4 changes: 2 additions & 2 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-mca",
"version": "0.1.2",
"version": "0.2.0",
"type": "module",
"keywords": [
"Minecraft",
Expand Down

0 comments on commit d822c14

Please sign in to comment.