From 24249229e3694fd2e82886e64da7029aedaa41ce Mon Sep 17 00:00:00 2001 From: Ritik Bheda Date: Thu, 7 Oct 2021 15:56:03 -0400 Subject: [PATCH 1/4] added functionality for config file --- bin/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/index.js b/bin/index.js index 9f1ea47..396be82 100755 --- a/bin/index.js +++ b/bin/index.js @@ -19,7 +19,9 @@ let outputFolder = "./dist"; //commander const { program } = require("commander"); +const { option } = require("yargs"); program.version("0.1"); +program.option("-c, --config", "enter the config.json file with options to be added here") program.option("-v, --version", "version 0.1"); program.option("-h, --help", "help for cmd-svg"); program.option("-i, --input ", "specify input file or folder"); @@ -349,6 +351,7 @@ function checkInput(input) { program.parse(process.argv); //console.log(`argv 0 ${process.argv[0]} \n argv 1 ${process.argv[1]} \n argv 2 ${process.argv[2]} \n argv 3 ${process.argv[3]} \n outputFolder \n\n`); const options = program.opts(); +const configFile = require("../config.json"); if (options.version) { console.log(verMsg); //exit @@ -360,6 +363,13 @@ if (options.version) { } else { //yargs //check if input is file or folder and if it exists + + if(options.config){ + configFile.input ? options.input = configFile.input : process.exit(1); + configFile.stylesheet ? options.stylesheet = configFile.stylesheet : options.stylesheet = undefined; + } + + let files = []; if (process.argv[5] != undefined){ @@ -375,7 +385,7 @@ if (options.version) { //do the magic of converting txt to html console.log(` running >>>`); - convertToHtml(process.argv[3], options.stylesheet, outputFolder, isFile); + convertToHtml(options.input, options.stylesheet, outputFolder, isFile); } else { //no input given console.log(errorCode1); From e7437fff8d58352d0fa818efd3dd82360f88b988 Mon Sep 17 00:00:00 2001 From: Ritik Bheda Date: Fri, 8 Oct 2021 17:09:48 -0400 Subject: [PATCH 2/4] now accepts any file json file --- bin/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/index.js b/bin/index.js index 396be82..e8e9de4 100755 --- a/bin/index.js +++ b/bin/index.js @@ -21,7 +21,7 @@ let outputFolder = "./dist"; const { program } = require("commander"); const { option } = require("yargs"); program.version("0.1"); -program.option("-c, --config", "enter the config.json file with options to be added here") +program.option("-c, --config ", "enter the config.json file with options to be added here") program.option("-v, --version", "version 0.1"); program.option("-h, --help", "help for cmd-svg"); program.option("-i, --input ", "specify input file or folder"); @@ -351,7 +351,7 @@ function checkInput(input) { program.parse(process.argv); //console.log(`argv 0 ${process.argv[0]} \n argv 1 ${process.argv[1]} \n argv 2 ${process.argv[2]} \n argv 3 ${process.argv[3]} \n outputFolder \n\n`); const options = program.opts(); -const configFile = require("../config.json"); +const configFile = require("../"+options.config); if (options.version) { console.log(verMsg); //exit @@ -363,7 +363,6 @@ if (options.version) { } else { //yargs //check if input is file or folder and if it exists - if(options.config){ configFile.input ? options.input = configFile.input : process.exit(1); configFile.stylesheet ? options.stylesheet = configFile.stylesheet : options.stylesheet = undefined; From 0813fd62a9e514438e3aca81c8db7c797277192c Mon Sep 17 00:00:00 2001 From: Ritik Bheda Date: Fri, 8 Oct 2021 17:11:34 -0400 Subject: [PATCH 3/4] updates README.md file --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2890bcd..3327012 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ ssgy -i examples 14. adding -s stylesheet option 15. making it easy on the eyes =) checkout my cmd-ssg -h 16. proper error message if incorrect file/folder inputs +17. accept a json file to pass options from the file ``` Special Thanks : Kevan Yang From 745fe12e94836acf9ef7bc237cc2bf50af699896 Mon Sep 17 00:00:00 2001 From: Ritik Bheda Date: Fri, 8 Oct 2021 17:15:02 -0400 Subject: [PATCH 4/4] minor fix for calling file --- bin/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/index.js b/bin/index.js index e8e9de4..cae9a1f 100755 --- a/bin/index.js +++ b/bin/index.js @@ -351,7 +351,6 @@ function checkInput(input) { program.parse(process.argv); //console.log(`argv 0 ${process.argv[0]} \n argv 1 ${process.argv[1]} \n argv 2 ${process.argv[2]} \n argv 3 ${process.argv[3]} \n outputFolder \n\n`); const options = program.opts(); -const configFile = require("../"+options.config); if (options.version) { console.log(verMsg); //exit @@ -364,6 +363,7 @@ if (options.version) { //yargs //check if input is file or folder and if it exists if(options.config){ + const configFile = require("../"+options.config); configFile.input ? options.input = configFile.input : process.exit(1); configFile.stylesheet ? options.stylesheet = configFile.stylesheet : options.stylesheet = undefined; }