Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/actions/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getAllFiles from "../utils/getAllFiles.js"
import buildSource from "./processes/buildSource.js"
import buildDefinitions from "./processes/buildDefinitions.js"

const build = () => {
const build = async () => {
if (fs.existsSync("dist")) {
console.log("Removing old build...")
fs.rmSync("dist", { recursive: true })
Expand All @@ -12,7 +12,7 @@ const build = () => {

const files = getAllFiles("src")

buildSource(files, false)
await buildSource(files, false)
buildDefinitions()
}

Expand Down
8 changes: 4 additions & 4 deletions src/actions/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const send = async (config: Config, dayNum: number, part: 1 | 2) => {
return false
}

const dev = (dayRaw: string | undefined) => {
const dev = async (dayRaw: string | undefined) => {
const day = dayRaw && (dayRaw.match(/\d+/) ?? [])[0]
const config = readConfig()

Expand Down Expand Up @@ -184,20 +184,20 @@ const dev = (dayRaw: string | undefined) => {
const files = getAllFiles("src")

if (config.language === "ts") {
buildSource(files)
await buildSource(files)
}

runSolution(dayNum, indexFile)

const reload = (file: string) => {
const reload = async (file: string) => {
if (![".js", ".ts", ".mjs"].includes(path.parse(file).ext)) {
return
}

console.clear()

if (config.language === "ts") {
buildSource(file)
await buildSource(file)
}

runSolution(dayNum, indexFile)
Expand Down
33 changes: 18 additions & 15 deletions src/actions/processes/buildSource.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { spawnSync } from "child_process"
import * as esbuild from "esbuild"
import path from "path"

const buildSource = (input: string | string[], sourcemap: boolean = true) => {
const buildSource = async (
input: string | string[],
sourcemap: boolean = true,
) => {
const files = Array.isArray(input) ? input : [input]
const outDir = Array.isArray(input)
? "dist"
: path.parse(input).dir.replace(/^src/, "dist")

console.log("Transpiling...\n")

spawnSync(
"npx",
[
"esbuild",
...files,
"--format=esm",
`--outdir=${outDir}`,
"--platform=node",
"--target=node16",
...(sourcemap ? ["--sourcemap"] : []),
],
{ stdio: "inherit", shell: true },
)
try {
await esbuild.build({
entryPoints: files,
format: "esm",
outdir: outDir,
platform: "node",
target: "node16",
sourcemap: sourcemap,
})
} catch (error) {
console.error("Build failed:", error)
process.exit(1)
}
}

export default buildSource
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ switch (String(command || "").toLowerCase()) {
break
}
case "day": {
dev(args[0])
await dev(args[0])
break
}
case "build": {
build()
await build()
break
}
case "update:readme": {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2020",
"module": "es2020",
"target": "es2022",
"module": "es2022",
"removeComments": true,
"declaration": true,
"outDir": "node_modules/aocrunner/lib",
Expand Down