From 937409fc48446aefa42e2feb857060f59bc71ca6 Mon Sep 17 00:00:00 2001 From: alexsam29 <69481177+alexsam29@users.noreply.github.com> Date: Mon, 3 Oct 2022 00:10:33 -0400 Subject: [PATCH 1/4] Added inital config option. --- main.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 2d0ede3..40eeb24 100644 --- a/main.js +++ b/main.js @@ -5,7 +5,8 @@ import { program } from 'commander'; program .option('-v, --version', 'displays the tool name and version') .option('-i, --input ', 'gets input from a file or folder') -.option('-l, --lang ', 'specifies language to use'); +.option('-l, --lang ', 'specifies language to use') +.option('-c, --config ', 'Add a JSON config file to specify options'); program.parse(process.argv); @@ -15,6 +16,10 @@ if (program.opts().version) console.log("version: 0.2"); } +if(program.opts().config) +{ + +} if (program.opts().input) { if (program.opts().lang) From 903d640ce0268769ddac7b9619823757053f5a35 Mon Sep 17 00:00:00 2001 From: alexsam29 <69481177+alexsam29@users.noreply.github.com> Date: Mon, 3 Oct 2022 02:50:23 -0400 Subject: [PATCH 2/4] Added ability to read from config file. --- main.js | 26 +++++++++++++++++++++++++- ssg-config.json | 5 +++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ssg-config.json diff --git a/main.js b/main.js index 40eeb24..1427f46 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ #! /usr/bin/env node import { generateHTML } from './generateHTML.js'; import { program } from 'commander'; +import fs, { read } from 'fs'; program .option('-v, --version', 'displays the tool name and version') @@ -18,7 +19,13 @@ if (program.opts().version) if(program.opts().config) { - + readConfigFile(program.opts().config).then(function(configFile) + { + generateHTML(configFile.input, configFile.lang); + }).catch(function (rej) + { + console.log(rej) + }) } if (program.opts().input) { @@ -33,3 +40,20 @@ if (program.opts().input) } } +//this function will read a JSON config file +function readConfigFile(config) +{ + return new Promise(function(res, rej) + { + if(fs.existsSync(config)) + { + const theFile = fs.readFileSync(config, "utf-8"); + const JSONfile = JSON.parse(theFile); + res(JSONfile); + } + else + { + rej("Error: Config file does not exist.") + } + }) +} diff --git a/ssg-config.json b/ssg-config.json new file mode 100644 index 0000000..96b2d87 --- /dev/null +++ b/ssg-config.json @@ -0,0 +1,5 @@ +{ + "input": "Sherlock-Holmes-Selected-Stories", + "output": "./build", + "stylesheet": "https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" +} \ No newline at end of file From bf1524c232c5f55e1592106d7617306f8866dd12 Mon Sep 17 00:00:00 2001 From: alexsam29 <69481177+alexsam29@users.noreply.github.com> Date: Mon, 3 Oct 2022 02:53:47 -0400 Subject: [PATCH 3/4] Code formatting. --- main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 1427f46..d7a7976 100644 --- a/main.js +++ b/main.js @@ -22,9 +22,10 @@ if(program.opts().config) readConfigFile(program.opts().config).then(function(configFile) { generateHTML(configFile.input, configFile.lang); - }).catch(function (rej) + }) + .catch(function (rej) { - console.log(rej) + console.log(rej); }) } if (program.opts().input) @@ -53,7 +54,7 @@ function readConfigFile(config) } else { - rej("Error: Config file does not exist.") + rej("Error: Config file does not exist."); } }) } From 29cdeba080ca83086ff65bed52164a649245a67d Mon Sep 17 00:00:00 2001 From: Alexander Samaniego <69481177+alexsam29@users.noreply.github.com> Date: Mon, 3 Oct 2022 03:04:43 -0400 Subject: [PATCH 4/4] Update README.md --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28f3311..6fdf90b 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,9 @@ nan1-ssg [-option] | -h, --help | Will display a help message, showing options and usage. | | -i , --input | Gives the tool a filename to generate HTML files with. The filename can be a file or a directory. | | -l , --lang | Specifies a language to generate the HTML from. | +| -c , --config | Add a JSON config file to specify options. Omit other options when using this option. | -The hello.txt file, markdownTest.md file, and Sherlock-Holmes-Selected-Stories directory are provided for testing purposes. +The hello.txt file, markdownTest.md file, ssg-config.json file and Sherlock-Holmes-Selected-Stories directory are provided for testing purposes. ## Examples @@ -73,6 +74,11 @@ nan1-ssg -i "./Sherlock-Holmes-Selected-Stories/Silver Blaze.txt" nan1-ssg -i "file with spaces.txt" ``` +**Using a configuration JSON file:** +``` +nan1-ssg -c ./ssg-config.json +``` + ## Features - Generating valid HTML5 files from .txt and .md files and placed in the dist directory @@ -80,3 +86,11 @@ nan1-ssg -i "file with spaces.txt" - Each HTML file uses a default stylesheet to improve beauty and readability - Can specify language to HTML file to use - Horizontal rules are translated from Markdown files +- A configuration JSON file can be used to specify all options + - Example file format: + ```json + { + "input": "./ssg-config.json", + "lang": "fr" + } + ```