Skip to content

Commit

Permalink
feat: handle dirs not existing
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Jun 23, 2024
1 parent 9ad8227 commit 6772b0f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-pre-post-scripts=true
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions postbuild.mjs
Original file line number Diff line number Diff line change
@@ -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.");
9 changes: 7 additions & 2 deletions src/utils/openapi-docs.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();

Expand All @@ -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}`);
Expand Down

0 comments on commit 6772b0f

Please sign in to comment.