Skip to content

Commit

Permalink
Adding prettier/fixing format
Browse files Browse the repository at this point in the history
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
Ririio committed Oct 30, 2022
1 parent 1ed7f26 commit c423283
Show file tree
Hide file tree
Showing 13 changed files with 3,136 additions and 380 deletions.
12 changes: 7 additions & 5 deletions .eslintrc.js
@@ -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,
},
};
}
6 changes: 5 additions & 1 deletion .prettierignore
@@ -1 +1,5 @@
/text-files/**
/text-files
/dist
*.md
.eslintrc.js

5 changes: 5 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"arrowParens": "always"
}
8 changes: 6 additions & 2 deletions .vscode/settings.json
@@ -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"
}
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
@@ -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
57 changes: 7 additions & 50 deletions README.md
Expand Up @@ -2,59 +2,16 @@

The project allows for the converstion of .txt and .md files to a formatted HTML5

### Built With

- [Express](https://expressjs.com/)
- [Commander](https://www.npmjs.com/package/commander)
- [Dotenv](https://www.npmjs.com/package/dotenv)

## Getting Started

### 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

### Commands

Write "my-ssg" before using any commands or it will not work

**Input** (--input, -I)
<br />
&nbsp;&nbsp;This command will allow the user to be able to convert a .txt or .md file to that of an HTML5.
<br />
**Command Structure**: "my-ssg --input [fileName/directoryName]"
<br />
<br />
**Config** (--config, -C)
<br />
&nbsp;&nbsp;This command will allow the user to be able to pass a .json file with supported configuration keys such as input, output, and lang. The command will then be able to convert .txt or .md files specified in the input property to that of an HTML5. The output directory by default is dist, but if output key is defined in config file, the command will replace the default directory with the value of output key.
<br />
**Command Structure**: "my-ssg --config [fileName]"
<br />
**Output** (--output, -O)
<br />
&nbsp;&nbsp;This command will allow the user to change to create their own default folder for all the HTML5 that they convert.
<br />
**Command Structure**: my-ssg --output [directoryName] | my-ssg --output [directoryName] --input [filename]
<br />
<br />
**Help** (--help, -H)
<br />
&nbsp;&nbsp;This command will display the description of the program and all its available command and their respective descriptions
<br />
**Command Structure**: "my-ssg --help"
<br />
<br />
**Version** (--version, -V)
<br />
&nbsp;&nbsp;This command displays the current version of the program
<br />
**Command Structure**: "my-ssg --version"
<br />
| Command Name | Command Line | Description | Command Structure |
|---|---|---|---|
| **Input** | (--input, -I) | This command will allow the user to be able to convert a .txt or .md file to that of an HTML5. | my-ssg --input [fileName/directoryName] |
| Config | (--config, -C) | This command will allow the user to be able to pass a .json file with supported configuration keys such as input, output, and lang. The command will then be able to convert .txt or .md files specified in the input property to that of an HTML5. The output directory by default is dist, but if output key is defined in config file, the command will replace the default directory with the value of output key | my-ssg --config [fileName] |
| Output | (--output, -O) | This command will allow the user to change to create their own default folder for all the HTML5 that they convert | my-ssg --output [directoryName] | my-ssg --output [directoryName] --input [filename] |
| Help | (--help, -H) | This command will display the description of the program and all its available command and their respective descriptions | my-ssg --help
| Version | (--version, -V) | This command displays the current version of the program | my-ssg --version |

## Roadmap

Expand Down
154 changes: 82 additions & 72 deletions main.js
@@ -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)
}

0 comments on commit c423283

Please sign in to comment.