Skip to content

Commit

Permalink
Merge pull request #1197 from DarkFlorist/build-script-fix
Browse files Browse the repository at this point in the history
Fixed build error when app/js folder does not exist
  • Loading branch information
KillariDev authored Nov 28, 2024
2 parents 34b2b23 + e7e4e11 commit 078d851
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions build/bundler.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path'
import * as url from 'url'
import { promises as fs } from 'fs'
import * as path from 'node:path'
import * as url from 'node:url'
import { promises as fs } from 'node:fs'

const directoryOfThisFile = path.dirname(url.fileURLToPath(import.meta.url))

Expand Down Expand Up @@ -62,12 +62,21 @@ async function* getFiles(topDir: string): AsyncGenerator<string, any, undefined>
}
}

async function ensureDirectoryExists(dir: string) {
try {
await fs.access(dir)
} catch {
await fs.mkdir(dir)
}
}

async function replaceImportsInJSFiles() {
const folders = [
path.join(directoryOfThisFile, '..', 'app', 'js'),
path.join(directoryOfThisFile, '..', 'app', 'vendor')
]
for (const folder of folders) {
await ensureDirectoryExists(folder)
for await (const filePath of getFiles(folder)) {
if (path.extname(filePath) !== '.js' && path.extname(filePath) !== '.mjs') continue
const replaced = replaceImport(filePath, await fs.readFile(filePath, 'utf8'))
Expand Down
8 changes: 4 additions & 4 deletions build/vendor.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'
import * as url from 'url'
import { promises as fs } from 'fs'
import { FileType, recursiveDirectoryCopy } from '@zoltu/file-copier'
import * as path from 'node:path'
import * as url from 'node:url'
import { promises as fs } from 'node:fs'
import { type FileType, recursiveDirectoryCopy } from '@zoltu/file-copier'
import { createHash } from 'node:crypto'

const directoryOfThisFile = path.dirname(url.fileURLToPath(import.meta.url))
Expand Down

0 comments on commit 078d851

Please sign in to comment.