diff --git a/.eslintrc.js b/.eslintrc.js index b49a7fd..b4c95e6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,8 @@ module.exports = { "env": { "browser": true, "commonjs": true, - "es2021": true + "es2021": true, + "node": true }, "extends": [ "eslint:recommended", diff --git a/package-lock.json b/package-lock.json index 8240d50..c582995 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "yargs": "^17.7.2" }, "devDependencies": { + "assert": "^2.1.0", "eslint": "^8.52.0", "eslint-plugin-react": "^7.33.2", "mocha": "^10.2.0", @@ -347,6 +348,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/assert": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/assert/-/assert-2.1.0.tgz", + "integrity": "sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "is-nan": "^1.3.2", + "object-is": "^1.1.5", + "object.assign": "^4.1.4", + "util": "^0.12.5" + } + }, "node_modules/asynciterator.prototype": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/asynciterator.prototype/-/asynciterator.prototype-1.0.0.tgz", @@ -1395,6 +1409,22 @@ "node": ">= 0.4" } }, + "node_modules/is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-array-buffer": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.2.tgz", @@ -1568,6 +1598,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-nan": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz", + "integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", @@ -2112,6 +2158,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/object-is": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz", + "integrity": "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", @@ -2918,6 +2980,19 @@ "punycode": "^2.1.0" } }, + "node_modules/util": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", + "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "which-typed-array": "^1.1.2" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index bb5d57e..6754c14 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "yargs": "^17.7.2" }, "devDependencies": { + "assert": "^2.1.0", "eslint": "^8.52.0", "eslint-plugin-react": "^7.33.2", "mocha": "^10.2.0", diff --git a/src/index.js b/src/index.js index a5e31e3..bbb6900 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,12 @@ -const fs = require("fs"); -const path = require("path"); -const yargs = require("yargs"); -const toml = require("toml"); +const fs = require('fs'); +const path = require('path'); +const yargs = require('yargs'); +const toml = require('toml'); // Function to read the content of a file function readFile(filePath) { try { - return fs.readFileSync(filePath, "utf8"); + return fs.readFileSync(filePath, 'utf8'); } catch (error) { console.error(`Error reading file: ${error.message}`); process.exit(1); @@ -34,20 +34,30 @@ function processFile(inputFilePath, outputDir, lang) { console.log(`Converted ${inputFilePath} to HTML.`); } -module.exports = { - processFile // Ensure processFile is included in the exported object -}; + +// Function to process all .txt and .md files in a directory +function processDirectory(inputDir, outputDir, lang) { + const files = fs.readdirSync(inputDir); + + files.forEach((file) => { + const filePath = path.join(inputDir, file); + + if (fs.lstatSync(filePath).isFile() && file.match(/\.(txt|md)$/)) { + processFile(filePath, outputDir, lang); + } + }); +} function generateHTML(fileContent, lang) { const [title, ...paragraphs] = fileContent.split(/\n{1,}/); // Split by one or more newline characters - const titleHtml = title ? `
${paragraph}
`; }) - .join("\n"); + .join('\n'); return ` @@ -62,7 +72,6 @@ function generateHTML(fileContent, lang) { `; } - function processConfigFile(configPath) { const configContent = readFile(configPath); return toml.parse(configContent); @@ -71,37 +80,37 @@ function processConfigFile(configPath) { // Main command-line tool logic function main() { yargs - .scriptName("til") - .usage("$0