Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing error referred from ESLint Updating CONTRIBUTING.md | ignore all .md files Integrated ESLint to VS code Adding pre commit hook Adding Standard Linter & Pre-commit hook fixing standard script
- Loading branch information
Showing
13 changed files
with
3,136 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
module.exports = { | ||
extends: ["airbnb-base", "prettier"], | ||
extends: ['airbnb-base', 'prettier'], | ||
plugins: [], | ||
parserOptions: { | ||
ecmaVersion: 2021, | ||
}, | ||
rules: { | ||
"no-plusplus": ["off"], | ||
"arrow-body-style": ["off"], | ||
"no-console": ["off"], | ||
'no-plusplus': ['off'], | ||
'arrow-body-style': ['off'], | ||
'no-console': ['off'], | ||
'semi': [2, 'never'], | ||
'curly': [2, 'all'] | ||
}, | ||
env: { | ||
es2021: true, | ||
node: true, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
/text-files/** | ||
/text-files | ||
/dist | ||
*.md | ||
.eslintrc.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
"eslint.format.enable": true, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## Built With | ||
|
||
- [Express](https://expressjs.com/) | ||
- [Commander](https://www.npmjs.com/package/commander) | ||
- [Dotenv](https://www.npmjs.com/package/dotenv) | ||
|
||
## Editor Used | ||
|
||
| Formatter | Command Line | ||
|---|---| | ||
| [Eslint](https://eslint.org/) | npm run <check-format/write-format> | ||
| [Prettier](https://prettier.io/) | npm run lint | | ||
|
||
## Installation | ||
|
||
1. Change the current directory to "release 0.1" | ||
2. Type "npm install" in the command line to download all necessary libraries | ||
3. Type "npm link" to allow for "my-ssg" to function | ||
|
||
The program should now allow you to use all commands without any problems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,164 +1,174 @@ | ||
#!/usr/bin/env node | ||
|
||
require("dotenv").config(); | ||
const { program } = require("commander"); | ||
const fs = require("fs"); | ||
const sr = require("./service"); | ||
const pjson = require("./package.json"); | ||
require('dotenv').config() | ||
const { program } = require('commander') | ||
const fs = require('fs') | ||
const sr = require('./service') | ||
const pjson = require('./package.json') | ||
const { | ||
textConverter, | ||
createIndexFile, | ||
convertExtension, | ||
} = require("./src/text-converter"); | ||
} = require('./src/text-converter') | ||
|
||
// For adding custom flags into the command line | ||
|
||
program.version(`${pjson.name}: version-${pjson.version}`); | ||
program.version(`${pjson.name}: version-${pjson.version}`) | ||
|
||
const outputFolder = process.env.OUTPUT_DIRECTORY; | ||
const outputFolder = process.env.OUTPUT_DIRECTORY | ||
|
||
program | ||
.description("Program Custom Flags") | ||
.option("-H, --help") | ||
.option(`-I, --input <type>`, "Input to the dist folder") | ||
.description('Program Custom Flags') | ||
.option('-H, --help') | ||
.option('-I, --input <type>', 'Input to the dist folder') | ||
.option( | ||
`-C, --config <type>`, | ||
"Output to the folder specified in config file" | ||
'-C, --config <type>', | ||
'Output to the folder specified in config file' | ||
) | ||
.option(`-O, --output <type>`, "Output to a custom folder") | ||
.option('-O, --output <type>', 'Output to a custom folder') | ||
.option( | ||
`-L, --lang <type>`, | ||
"Changes generated lang attributes on the html root" | ||
); | ||
'-L, --lang <type>', | ||
'Changes generated lang attributes on the html root' | ||
) | ||
|
||
program.parse(); | ||
program.parse() | ||
|
||
const options = program.opts(); | ||
const options = program.opts() | ||
|
||
if (options.help) { | ||
console.log( | ||
"\n--Commands--\nVersion: -V, --version\nInput: -I, --input\nOutput: -O, --output" | ||
); | ||
'\n--Commands--\nVersion: -V, --version\nInput: -I, --input\nOutput: -O, --output' | ||
) | ||
console.log( | ||
"\n--Help--\nDescription: The program is used to display the content of a .txt file into that of an .html" | ||
); | ||
'\n--Help--\nDescription: The program is used to display the content of a .txt file into that of an .html' | ||
) | ||
console.log( | ||
"Output: Typing 'my-ssg --output(or)-O <directory_name> in the command line will generate a new directory where the HTML5 files will be added to" | ||
); | ||
) | ||
console.log( | ||
"Input: By typing 'my-ssg --input(or)-I file.txt' the program will generate a valid HTML5 file\n" | ||
); | ||
) | ||
console.log( | ||
"Config: By typing 'my-ssg --config(or)-C file.json' the program will generate a valid HTML5 file based on configuration specified\n" | ||
); | ||
) | ||
console.log( | ||
"Lang: By typing 'my-ssg --lang(or)-L <language> the program will add a 'lang' attribute on the root html" | ||
); | ||
) | ||
} | ||
try { | ||
if (options.input) { | ||
fs.rmSync(outputFolder, { recursive: true, force: true }); | ||
sr.createFolder(outputFolder); | ||
fs.rmSync(outputFolder, { recursive: true, force: true }) | ||
sr.createFolder(outputFolder) | ||
|
||
const stats = fs.statSync(program.opts().input); | ||
const stats = fs.statSync(program.opts().input) | ||
|
||
// Determines whether the value that was given is a directory or a file | ||
if (stats.isDirectory()) { | ||
const directoryName = program.opts().input; | ||
const directoryName = program.opts().input | ||
|
||
// read the directory, and go through each individual file name using forEach | ||
fs.readdir(directoryName, (err, files) => { | ||
let navLinks; | ||
let navLinks | ||
|
||
files.forEach((file) => { | ||
const outputFileName = convertExtension(file); | ||
const outputFileName = convertExtension(file) | ||
|
||
if (navLinks) navLinks += "," + outputFileName; | ||
else navLinks = outputFileName; | ||
}); | ||
if (navLinks) { | ||
navLinks += `,${outputFileName}` | ||
} else { | ||
navLinks = outputFileName | ||
} | ||
}) | ||
|
||
files.forEach((file) => { | ||
const filename = `${directoryName}/${file}`; | ||
const filename = `${directoryName}/${file}` | ||
|
||
textConverter(filename, navLinks); | ||
}); | ||
textConverter(filename, navLinks) | ||
}) | ||
|
||
createIndexFile(outputFolder, navLinks); | ||
}); | ||
createIndexFile(outputFolder, navLinks) | ||
}) | ||
} else if (stats.isFile()) { | ||
const filename = program.opts().input; | ||
textConverter(filename); | ||
const filename = program.opts().input | ||
textConverter(filename) | ||
} | ||
} | ||
if (options.output) { | ||
// Prevents the user from creating a directory that currently exists within the program | ||
// Resets the value of the directory to 'dist' | ||
if (fs.existsSync(options.output)) { | ||
console.log( | ||
"The name given already exists as a directory or file", | ||
'The name given already exists as a directory or file', | ||
"\nSet directory to default: 'dist'" | ||
); | ||
sr.replaceDirectory("dist"); | ||
} else sr.replaceDirectory(options.output); | ||
) | ||
sr.replaceDirectory('dist') | ||
} else { | ||
sr.replaceDirectory(options.output) | ||
} | ||
} | ||
if (options.lang) { | ||
sr.changeLanguage(options.lang); | ||
sr.changeLanguage(options.lang) | ||
} | ||
if (options.config) { | ||
const lines = fs.readFileSync(options.config, "utf8"); | ||
const parsedObj = JSON.parse(lines); | ||
const lines = fs.readFileSync(options.config, 'utf8') | ||
const parsedObj = JSON.parse(lines) | ||
|
||
if (parsedObj.lang) { | ||
sr.changeLanguage(parsedObj.lang); | ||
sr.changeLanguage(parsedObj.lang) | ||
} | ||
|
||
if (parsedObj.output) { | ||
// Prevents the user from creating a directory that currently exists within the program | ||
// Resets the value of the directory to 'dist' | ||
if (fs.existsSync(parsedObj.output)) { | ||
console.log( | ||
"The name given already exists as a directory or file", | ||
'The name given already exists as a directory or file', | ||
"\nSet directory to default: 'dist'" | ||
); | ||
sr.replaceDirectory("dist"); | ||
} else sr.replaceDirectory(parsedObj.output); | ||
) | ||
sr.replaceDirectory('dist') | ||
} else { | ||
sr.replaceDirectory(parsedObj.output) | ||
} | ||
} | ||
|
||
if (parsedObj.input) { | ||
fs.rmSync(outputFolder, { recursive: true, force: true }); | ||
sr.createFolder(outputFolder); | ||
fs.rmSync(outputFolder, { recursive: true, force: true }) | ||
sr.createFolder(outputFolder) | ||
|
||
const stats = fs.statSync(parsedObj.input); | ||
const stats = fs.statSync(parsedObj.input) | ||
|
||
// Determines whether the value that was given is a directory or a file | ||
if (stats.isDirectory()) { | ||
const directoryName = parsedObj.input; | ||
const directoryName = parsedObj.input | ||
|
||
// read the directory, and go through each individual file name using forEach | ||
fs.readdir(directoryName, (err, files) => { | ||
let navLinks; | ||
let navLinks | ||
|
||
files.forEach((file) => { | ||
const outputFileName = convertExtension(file); | ||
const outputFileName = convertExtension(file) | ||
|
||
if (navLinks) navLinks += "," + outputFileName; | ||
else navLinks = outputFileName; | ||
}); | ||
if (navLinks) { | ||
navLinks += `,${outputFileName}` | ||
} else { | ||
navLinks = outputFileName | ||
} | ||
}) | ||
|
||
files.forEach((file) => { | ||
const filename = `${directoryName}/${file}`; | ||
const filename = `${directoryName}/${file}` | ||
|
||
textConverter(filename, navLinks); | ||
}); | ||
textConverter(filename, navLinks) | ||
}) | ||
|
||
createIndexFile(outputFolder, navLinks); | ||
}); | ||
createIndexFile(outputFolder, navLinks) | ||
}) | ||
} else if (stats.isFile()) { | ||
const filename = parsedObj.input; | ||
textConverter(filename); | ||
const filename = parsedObj.input | ||
textConverter(filename) | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
console.error(err.message); | ||
console.error(err.message) | ||
} |
Oops, something went wrong.