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

Support for Config files #12

Merged
merged 5 commits into from
Oct 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output = "./test"
stylesheet = "https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"
title = "Test"
lang = "fr"
17 changes: 13 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/arg-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export interface CLIArgument {
}

export const CLIArgumentMap: Array<CLIArgument> = [
{
name: "Configuration",
key: "config",
long_form: "config",
short_form: "c",
description: "Path to configuration file.",
value: "path",
default: "",
},
{
name: "Output",
key: "outputDirectory",
Expand Down
23 changes: 22 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,34 @@ import {
MarkdownProcessingStrategy,
} from "./utils/file-processor";
import { Command } from "./helpers";
import toml from "toml";

async function main() {
Command.parse(process.argv);
const options = Command.opts();
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 },
Expand Down Expand Up @@ -60,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) {
Expand Down