mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-01-25 05:58:29 -06:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import path from 'path'
|
|
import fse from 'fs-extra'
|
|
import { fileURLToPath } from 'url'
|
|
import { glob } from 'glob'
|
|
|
|
const sourceGlobs = [
|
|
'./internal/service/**/*.sql'
|
|
]
|
|
|
|
const outputFilePath = './internal/database/dbgen/queries.gen.sql'
|
|
|
|
// Obtains the project's root directory
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
const __dirname = path.dirname(__filename)
|
|
const rootDir = path.join(__dirname, '..')
|
|
const absoluteOutputFilePath = path.join(rootDir, outputFilePath)
|
|
|
|
try {
|
|
// Find all files that match the source globs
|
|
const files = []
|
|
for (const sourceGlob of sourceGlobs) {
|
|
const foundFiles = await glob(path.join(rootDir, sourceGlob))
|
|
files.push(...foundFiles)
|
|
}
|
|
|
|
// Read each file and concatenate them into a single string
|
|
let outFileContent = `-- This file is auto-generated by ${__filename}. DO NOT EDIT.\n\n`
|
|
for (const file of files) {
|
|
const content = await fse.readFile(file, 'utf-8')
|
|
outFileContent += `-- file: ${file}\n\n${content}\n\n`
|
|
}
|
|
|
|
await fse.ensureDir(path.dirname(absoluteOutputFilePath))
|
|
await fse.outputFile(absoluteOutputFilePath, outFileContent)
|
|
} catch (error) {
|
|
console.error('Error creating SQLC prebuild:', error)
|
|
}
|