Skip to content

Commit

Permalink
Make sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Jul 29, 2024
1 parent d2a0a4a commit 9a47c0e
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions docs/core_docs/scripts/validate_notebook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as fs from "node:fs/promises";
import * as fs from "node:fs";
import * as ts from "typescript";
import { v4 as uuidv4 } from "uuid";

export async function extract(filepath: string) {
const cells = JSON.parse((await fs.readFile(filepath)).toString()).cells;
export function extract(filepath: string) {
const cells = JSON.parse((fs.readFileSync(filepath)).toString()).cells;
const code = cells
.map((cell: Record<string, any>) => {
if (cell.cell_type === "code") {
Expand Down Expand Up @@ -35,11 +34,11 @@ const run = async () => {
try {
const typescriptSource = await extract(pathname);
try {
await fs.access("./tmp", fs.constants.F_OK);
await fs.existsSync("./tmp");
} catch (err) {
await fs.mkdir("./tmp");
await fs.mkdirSync("./tmp");
}
await fs.writeFile(tempFilepath, typescriptSource);
await fs.writeFileSync(tempFilepath, typescriptSource);
const program = ts.createProgram([tempFilepath], {
module: ts.ModuleKind.NodeNext,
moduleResolution: ts.ModuleResolutionKind.NodeNext,
Expand Down Expand Up @@ -73,14 +72,11 @@ const run = async () => {
}
} finally {
try {
await fs.rm(tempFilepath);
await fs.rmSync(tempFilepath);
} catch (e) {
// Do nothing
}
}
};

run().catch((e) => {
console.error(e);
process.exit(1);
});
run();

0 comments on commit 9a47c0e

Please sign in to comment.