From 8f7c6fb6390ee94e371f93b6721fe9f481a49cd5 Mon Sep 17 00:00:00 2001 From: Yousef Date: Wed, 4 Oct 2023 13:51:57 -0400 Subject: [PATCH 1/5] add 'toml' packages as a dependency --- package-lock.json | 17 +++++++++++++---- package.json | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 52334f1..3d977b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,24 @@ { "name": "tilvert", - "version": "0.1.1", + "version": "0.1.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tilvert", - "version": "0.1.1", + "version": "0.1.5", "license": "MIT", + "dependencies": { + "commander": "^11.0.0" + }, "bin": { - "tilvert": "dist/src/main.js" + "tilvert": "dist/main.js" }, "devDependencies": { "@types/node": "^20.5.9", "gh-pages": "^6.0.0", "prettier": "^3.0.3", + "toml": "^3.0.0", "typescript": "^5.2.2" } }, @@ -71,7 +75,6 @@ "version": "11.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz", "integrity": "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==", - "dev": true, "engines": { "node": ">=16" } @@ -460,6 +463,12 @@ "node": ">=0.10.0" } }, + "node_modules/toml": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", + "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==", + "dev": true + }, "node_modules/trim-repeated": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", diff --git a/package.json b/package.json index cf7ce2b..abba661 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@types/node": "^20.5.9", "gh-pages": "^6.0.0", "prettier": "^3.0.3", + "toml": "^3.0.0", "typescript": "^5.2.2" }, "dependencies": { From 7e0eee70514624d789bf14fafb14f0d91f26a082 Mon Sep 17 00:00:00 2001 From: Yousef Date: Wed, 4 Oct 2023 13:53:14 -0400 Subject: [PATCH 2/5] add the new config option to the arguments map --- src/helpers/arg-map.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/helpers/arg-map.ts b/src/helpers/arg-map.ts index b70ebaf..cb6e4ae 100644 --- a/src/helpers/arg-map.ts +++ b/src/helpers/arg-map.ts @@ -9,6 +9,15 @@ export interface CLIArgument { } export const CLIArgumentMap: Array = [ + { + name: "Configuration", + key: "config", + long_form: "config", + short_form: "c", + description: "Path to configuration file.", + value: "path", + default: "", + }, { name: "Output", key: "outputDirectory", From 7b6434f989e951035e0caac869882efff9a7db20 Mon Sep 17 00:00:00 2001 From: Yousef Date: Wed, 4 Oct 2023 13:54:48 -0400 Subject: [PATCH 3/5] add logic to read and parse config files --- src/main.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.ts b/src/main.ts index cc087e1..2ca7ed8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import { MarkdownProcessingStrategy, } from "./utils/file-processor"; import { Command } from "./helpers"; +import toml from "toml"; async function main() { Command.parse(process.argv); @@ -13,6 +14,26 @@ async function main() { const inputList = Command.args; const processor = new FileProcessor(); + // check if config flag is used + if (options.config) { + // Read the configuration file + const configData = await FileIO.readFile(options.config); + if (!configData) { + console.error("Error: Unable to read configuration file."); + process.exit(1); + } + + // parse the configuration file + const config = toml.parse(configData); + + // override the options with the configuration file + Object.keys(config).forEach((key) => { + if (key in options) { + options[key] = config[key]; + } + }); + } + const meta = [ { key: "author", value: options.author }, { key: "description", value: options.description }, From 801b139d297befd3e94466fac57c0db25d047551 Mon Sep 17 00:00:00 2001 From: Yousef Date: Wed, 4 Oct 2023 13:55:22 -0400 Subject: [PATCH 4/5] add example config file --- config.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 config.toml diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..7dc83f6 --- /dev/null +++ b/config.toml @@ -0,0 +1,4 @@ +output = "./test" +stylesheet = "https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" +title = "Test" +lang = "fr" \ No newline at end of file From b9051ccd2b81f6ab151888cd3688dd6af77ad6d1 Mon Sep 17 00:00:00 2001 From: Yousef Date: Wed, 4 Oct 2023 23:10:45 -0400 Subject: [PATCH 5/5] fix a bug that was causing the language attribute of the HTML to not set correctly --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 2ca7ed8..8fbd00d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -81,7 +81,7 @@ async function main() { for (let i = 0; i < files.length; ++i) { const htmlDoc = new TILvertHTMLDocument(); htmlDoc.setTitle(options.title); - htmlDoc.setLanguage(options.language); + htmlDoc.setLanguage(options.lang); htmlDoc.addStylesheet(options.stylesheet); meta.forEach((tag) => { if (tag.value) {