Skip to content

Commit

Permalink
add npx markdowndb init CLI script that will bootstrap the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Dec 5, 2023
1 parent 7f95118 commit 7e42ae2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 2 additions & 3 deletions mddb.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export default {
customFields: [
]
}
customFields: []
};
20 changes: 19 additions & 1 deletion src/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import * as path from 'path';
import { promises as fs } from 'fs';
import { MarkdownDB } from "../lib/markdowndb.js";

async function loadConfig(configFilePath) {
Expand All @@ -15,10 +16,27 @@ async function loadConfig(configFilePath) {
}
}

async function initConfigFile(configFilePath = "mddb.config.js") {
const normalizedPath = path.resolve(configFilePath);
const configFileContent = `export default {\n customFields: []\n};\n`;

try {
await fs.writeFile(normalizedPath, configFileContent);
console.log(`Configuration file created at ${normalizedPath}`);
} catch (error) {
throw new Error(`Error creating configuration file at ${normalizedPath}: ${error.message}`);
}
}

// TODO get these from markdowndb.config.js or something
const dbPath = "markdown.db";
const ignorePatterns = [/Excalidraw/, /\.obsidian/, /DS_Store/];
const [contentPath, configFilePath] = process.argv.slice(2);
const [command, contentPath, configFilePath] = process.argv.slice(2);

if (command === 'init') {
await initConfigFile(configFilePath);
process.exit();
}

if (!contentPath) {
throw new Error("Invalid/Missing path to markdown content folder");
Expand Down

0 comments on commit 7e42ae2

Please sign in to comment.