Skip to content

Commit

Permalink
Added static analysis tools
Browse files Browse the repository at this point in the history
- Added CONTRIBUTING.md

- Added Prettier packages.

- Formatted files using Prettier.

- Added ESLInt.

- Added ESLint and Prettier config module.

- Fixed linter errors.

- Added blank Prettier config file.

- Added Git hooks.

- Adjusted fomatting for MD files.

- Added to CONTRIBUTING.md

- Added Prettier config rules.
  • Loading branch information
alexsam29 committed Nov 3, 2022
1 parent 64d95e8 commit bcde670
Show file tree
Hide file tree
Showing 17 changed files with 5,537 additions and 419 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": ["standard", "prettier"],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ dist
.pnp.*
.DS_Store
src/.DS_Store

# Ignore artifacts:
build
coverage
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore artifacts:
build
coverage

# Ignore MD files
#*.md
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"endOfLine": "lf",
"useTabs": false,
"semi": true,
"singleQuote": false
}
75 changes: 75 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Development Setup

To contribute to this project, setup your development environment according to these steps and use the code formatter and linter described below.

## Fork Repository and Install Packages

1. Download and install a recent version of [Node.js](https://nodejs.org/en/) (8.0 or higher).
2. Fork the project repository and clone the forked repository on to your local machine.
3. Open the repository in your editor/IDE of choice.
4. Open a terminal or command window and move to the directory where the repository was cloned to.
5. Run the command `npm install` followed by `npm install -g` to install packages and install the tool globally.

## Source Code Formatter

This project uses [Prettier](https://prettier.io/) to format the source code.

### Using the Command Line

Once all packages are installed you can format all files using the terminal/CLI with the command:

```
npx prettier --write .
```

You can use `prettier --write .` to format everything, but it's not recommended. It's recommended only to format the source code that you have written/changed.

To format a certain directory use:

```
npx prettier --write directory_name/
```

To format a certain file use:

```
npx prettier --write filepath/filename.js
```

To check whether files have been formatted using Prettier but without overwriting anything, run the command:

```
npx prettier --check .
```

### Editor/IDE Integration

Formatting from the command line is a good way to format the source code and should be done at the minimum. But it can be annoying to run the command(s) every time. Depending on your editor/IDE, you can integrate Prettier so that code formats automatically as it's being written.

[Click here](https://prettier.io/docs/en/editors.html) to find out how to integrate Prettier in your editor/IDE.

## Linter

This project uses [ESLint](https://eslint.org/) as the linter of choice to help make the source code more consistent and to avoid potential bugs.

### Using the Command Line

Once all packages are installed you can use ESLint to check files for coding errors/mistakes with this command:

```
npx eslint yourfile.js
```

You can also do this for multiple files at once, just keep adding filenames to the end like so:

```
npx eslint yourfile.js yourfile_2.js yourfile_3.js
```

It's recommended to do this on all files that have been added or changed.

### Editor/IDE Integration

Much like code formatting, using the command line to check for coding errors should be done at the minimum. However, you can integrate ESLint into your editor/IDE of choice to make the process much easier.

[Click here](https://eslint.org/docs/latest/user-guide/integrations) to find out how to integrate ESLint in your editor/IDE.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ ssg -i file_path
```
ssg -i file_path -o directoryPath
```

NOTE: This will <b>DELETE the specified directory</b> and create a new one with the same name. <b>DO NOT SPECIFY A DIRECTORY WITH IMPORTANT FILES</b>.

7. [OPTIONAL] Indicate the language to use when generating the lang attribute on the root <html> element in the resulting HTML file(s). Default language is `en-CA`.

```
ssg -i testFiles -o randomFolder -l fr
```

8. [OPTIONAL] Specify a JSON configuration file to use instead of inputting options manually in the command line.

```
ssg --config .\testFiles\ssg-config.json
```
Expand All @@ -43,14 +46,14 @@ Language codes must be ISO 639-1 standard language codes. Which can be found [he

### List of Options

| Option | Description | Type |
| ------------- | ---------------------------------------------------------------------------------------------------- | ------------------- |
| -h, --help | Show help | [boolean] |
| -v, --version | Show version number | [boolean] |
| -i, --input | File or folder to generate HTML files from | [string] |
| -o, --output | Specify a different output directory (any existing contents in the directory will be <b>DELETED</b>) | [string] |
| -l, --lang | HTML language code for resulting HTML file(s) | [string] |
| -c, --config | Specify a JSON configuration file to use | [string] |
| Option | Description | Type |
| ------------- | ---------------------------------------------------------------------------------------------------- | --------- |
| -h, --help | Show help | [boolean] |
| -v, --version | Show version number | [boolean] |
| -i, --input | File or folder to generate HTML files from | [string] |
| -o, --output | Specify a different output directory (any existing contents in the directory will be <b>DELETED</b>) | [string] |
| -l, --lang | HTML language code for resulting HTML file(s) | [string] |
| -c, --config | Specify a JSON configuration file to use | [string] |

## Examples

Expand Down Expand Up @@ -97,23 +100,26 @@ ssg -i ".\testFiles\Silver Blaze.txt" -o .\anotherFolder
```
ssg -i .\testFiles -o .\anotherFolder
```

### Specify a HTML `lang` attribute for resulting HTML files

```
ssg --input testFiles --lang en-GB
```

### Specify a JSON config file

```
ssg --config .\testFiles\configFile.json
```

## Optional Features Implemented

- Title parsed from text and markdown files. It will populate the `<title>` tag and add a `<h1>` tag to the top of the body.
- Allow the user to specify a different output directory using --output or -o. If not specified, dist will be used, but if the user specifies a different output path, it will use that. If the directory does not exist, a new directory will be created.
- If the user specifies a folder for the input, it will automatically generate an index.html file, which has relative links to each of the generated HTML files.
- Italicized text parsed from markdown files. It will add a `<i>` tag to any italicized text.
- Bold text parsed from markdown files. It will add a `<strong>` tag to any bold text.
- Language code added to generated HTML files using input from the `-l`/`--lang` argument.
- Inline code blocks parsed from markdown files. It will add a `<code>` tag to any inline code block.
- Allows the user to use a JSON formatted configuration file to specify all of their SSG options.
- Title parsed from text and markdown files. It will populate the `<title>` tag and add a `<h1>` tag to the top of the body.
- Allow the user to specify a different output directory using --output or -o. If not specified, dist will be used, but if the user specifies a different output path, it will use that. If the directory does not exist, a new directory will be created.
- If the user specifies a folder for the input, it will automatically generate an index.html file, which has relative links to each of the generated HTML files.
- Italicized text parsed from markdown files. It will add a `<i>` tag to any italicized text.
- Bold text parsed from markdown files. It will add a `<strong>` tag to any bold text.
- Language code added to generated HTML files using input from the `-l`/`--lang` argument.
- Inline code blocks parsed from markdown files. It will add a `<code>` tag to any inline code block.
- Allows the user to use a JSON formatted configuration file to specify all of their SSG options.
60 changes: 32 additions & 28 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en-CA" dir="ltr">
<head>
<title>index</title>
<meta charset="utf-8">




</head>
<body>
<ul>

<li><a href=".\dist\input MD.html">input MD</a></li>

<li><a href=".\dist\inputTXT.html">inputTXT</a></li>

<li><a href=".\dist\Silver Blaze.html">Silver Blaze</a></li>

<li><a href=".\dist\THE ADVENTURE OF THE SIX NAPOLEONS.html">THE ADVENTURE OF THE SIX NAPOLEONS</a></li>

<li><a href=".\dist\THE ADVENTURE OF THE SPECKLED BAND.html">THE ADVENTURE OF THE SPECKLED BAND</a></li>

<li><a href=".\dist\The Naval Treaty.html">The Naval Treaty</a></li>

<li><a href=".\dist\The Red Headed League.html">The Red Headed League</a></li>
</ul>

</body>
<head>
<title>index</title>
<meta charset="utf-8" />
</head>
<body>
<ul>
<li><a href=".\dist\input MD.html">input MD</a></li>

<li><a href=".\dist\inputTXT.html">inputTXT</a></li>

<li><a href=".\dist\Silver Blaze.html">Silver Blaze</a></li>

<li>
<a href=".\dist\THE ADVENTURE OF THE SIX NAPOLEONS.html"
>THE ADVENTURE OF THE SIX NAPOLEONS</a
>
</li>

<li>
<a href=".\dist\THE ADVENTURE OF THE SPECKLED BAND.html"
>THE ADVENTURE OF THE SPECKLED BAND</a
>
</li>

<li><a href=".\dist\The Naval Treaty.html">The Naval Treaty</a></li>

<li>
<a href=".\dist\The Red Headed League.html">The Red Headed League</a>
</li>
</ul>
</body>
</html>
Loading

0 comments on commit bcde670

Please sign in to comment.