Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 29 #30

Merged
merged 3 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { name, version } = require('../SSGNode/package.json')
let sourcePath = "./Sherlock Holmes Selected Stories/The Adventure of the Six Napoleans.txt"
let endPath = "./dist"
let lang = "en"
let config = ""

function run() {
let texts = "";
Expand Down Expand Up @@ -176,6 +177,29 @@ function generateFile(html) {
}
}

function configReader(){
try {
//parse the file and check for the arguments.
const configJSON = JSON.parse(fs.readFileSync(config, 'utf8'));
if(configJSON.lang !== "" && configJSON.lang !== undefined){
lang = configJSON.lang;
}

//validate the input for a file/folder else throws an error and close to program.
if(fs.lstatSync(configJSON.input).isDirectory() || fs.lstatSync(configJSON.input).isFile()){
sourcePath = configJSON.input;
}

//Output folder else default to ./dist
if(configJSON.output !== "" && configJSON.output !== undefined){
endPath = configJSON.output;
}
} catch (error) {
console.log(`ERROR: ${error}`);
exit(-1);
}
}

function genCss(dir) {
mkExist(dir);
mkExist(`${dir}/styles.css`, false);
Expand All @@ -195,6 +219,7 @@ const defaultFolder = "Sherlock Holmes Selected Stories";
//check if the argument corresponds with anything we can use
let pathchanged = false;
let langchanged = false;
let configchanged = false;

process.argv.forEach(function (val, index, array) {
//if path isn't the default one, change it for this next value
Expand All @@ -214,6 +239,15 @@ process.argv.forEach(function (val, index, array) {
}
}

if (configchanged) {
if(!val.match("^-")) {
//means this might be the config
config = val;
console.log(`Config file is now ${config}`);
configReader();
}
}

switch(val) {
case "--version":
case "-v":
Expand Down Expand Up @@ -244,6 +278,10 @@ process.argv.forEach(function (val, index, array) {
case "-l":
langchanged = true;
break;
case "--config":
case "-c":
configchanged = true;
break;
}
});

Expand Down
5 changes: 5 additions & 0 deletions ssg-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"input": "./text.txt",
"output": "folder",
"lang": "fr"
}