diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..b7425b9 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +enable-pre-post-scripts=true \ No newline at end of file diff --git a/package.json b/package.json index 89ca9d2..428ec4a 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "build:kill-dist": "rimraf ./dist", "build:code": "tsc && tscpaths -p tsconfig.json -s ./src -o ./dist", "build": "pnpm run build:kill-dist && pnpm run build:code", + "postbuild": "node postbuild.mjs", "db:explorer": "drizzle-kit studio", "db:migrate-generate": "drizzle-kit generate:pg", "db:migrate-run": "tsx ./migrator.ts" diff --git a/postbuild.mjs b/postbuild.mjs new file mode 100644 index 0000000..70fbaaa --- /dev/null +++ b/postbuild.mjs @@ -0,0 +1,21 @@ +import { join } from "node:path"; +import { cpSync, mkdirSync, existsSync } from "node:fs"; + +const srcDocs = join(process.cwd(), "src", "docs"); +const outDocs = join(process.cwd(), "dist", "docs"); + +if (!existsSync(outDocs)) { + mkdirSync(outDocs, { recursive: true }, (err) => { + if (err) { + console.error(err); + } + }); +} + +cpSync(srcDocs, outDocs, { recursive: true }, (err) => { + if (err) { + console.error(err); + } +}); + +console.log("↻ Copied /src/docs to /dist/docs."); diff --git a/src/utils/openapi-docs.ts b/src/utils/openapi-docs.ts index c14f808..c9bbe09 100644 --- a/src/utils/openapi-docs.ts +++ b/src/utils/openapi-docs.ts @@ -1,5 +1,5 @@ import { join } from "node:path"; -import { readFileSync, writeFileSync } from "node:fs"; +import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs"; type OpenApiDocTransformer = (filename: string, source_path: string, dirVersion: string, doc: string) => string; @@ -10,7 +10,8 @@ export function transformOpenapiYmlDoc(dir_version: string, transformers: OpenAp const openapiFilename = `openapi.${dir_version}.yaml`; const openapiYmlSourcePath = join(__dirname, "..", "docs", openapiFilename); - const openapiYmlOutPath = join(__dirname, "..", "..", "public", "static", openapiFilename); + const outDir = join(__dirname, "..", "..", "public", "static"); + const openapiYmlOutPath = join(outDir, openapiFilename); const openapiYmlInputDoc = readFileSync(openapiYmlSourcePath, "utf-8").toString(); @@ -22,6 +23,10 @@ export function transformOpenapiYmlDoc(dir_version: string, transformers: OpenAp newOpenapiYmlDoc = transformer(openapiFilename, openapiYmlSourcePath, dir_version, newOpenapiYmlDoc); } + if (!existsSync(outDir)) { + mkdirSync(outDir, { recursive: true }); + } + writeFileSync(openapiYmlOutPath, newOpenapiYmlDoc); console.log(`📖 Finishing updating /static/${openapiFilename}`);