Skip to content

Commit

Permalink
Merge branch 'main' into nextjs-blog
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 authored Nov 28, 2023
2 parents 692415b + 6e67120 commit e9c4d19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
dist/
markdown.db
*.tgz
.markdowndb/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# mddb

## 0.6.0

### Minor Changes

- [#73](https://github.com/datopian/markdowndb/pull/73) [`aedd641`](https://github.com/datopian/markdowndb/commit/aedd6413a7eee41a0d710c477ba55996c43b3e0f) Thanks [@mohamedsalem401](https://github.com/mohamedsalem401)! - [ #53 , JSON output option ] Implemented functionality to write file JSON output to disk

## 0.5.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mddb",
"version": "0.5.0",
"version": "0.6.0",
"description": "Parse markdown files and store them in an SQL database.",
"bin": {
"mddb": "./dist/src/bin/index.js"
Expand Down
16 changes: 16 additions & 0 deletions src/lib/markdowndb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
mapFileTagsToInsert,
getUniqueValues,
} from "./databaseUtils.js";
import fs from "fs";

const defaultFilePathToUrl = (filePath: string) => {
let url = filePath
Expand Down Expand Up @@ -76,6 +77,7 @@ export class MarkdownDB {
.filter(isLinkToDefined);
const fileTagsToInsert = fileObjects.flatMap(mapFileTagsToInsert);

writeJsonToFile(".markdowndb/files.json", fileObjects);
await MddbFile.batchInsert(this.db, filesToInsert);
await MddbTag.batchInsert(this.db, tagsToInsert);
await MddbFileTag.batchInsert(this.db, fileTagsToInsert);
Expand Down Expand Up @@ -191,3 +193,17 @@ export class MarkdownDB {
this.db.destroy();
}
}

function writeJsonToFile(filePath: string, jsonData: any[]) {

Check warning on line 197 in src/lib/markdowndb.ts

View workflow job for this annotation

GitHub Actions / Lint & format check

Unexpected any. Specify a different type
try {
const directory = path.dirname(filePath);
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory, { recursive: true });
}

const jsonString = JSON.stringify(jsonData, null, 2);
fs.writeFileSync(filePath, jsonString);
} catch (error: any) {

Check warning on line 206 in src/lib/markdowndb.ts

View workflow job for this annotation

GitHub Actions / Lint & format check

Unexpected any. Specify a different type
console.error(`Error writing data to ${filePath}: ${error}`);
}
}

0 comments on commit e9c4d19

Please sign in to comment.