Skip to content

Commit

Permalink
Merge fe40e81 into 9dd3de6
Browse files Browse the repository at this point in the history
  • Loading branch information
homer0 committed May 21, 2022
2 parents 9dd3de6 + fe40e81 commit 88fa5bb
Show file tree
Hide file tree
Showing 32 changed files with 5,393 additions and 4,771 deletions.
9 changes: 0 additions & 9 deletions .esdoc.json

This file was deleted.

7 changes: 5 additions & 2 deletions .eslintrc
@@ -1,5 +1,8 @@
{
"root": true,
"plugins": ["homer0"],
"extends": ["plugin:homer0/node"]
"plugins": ["@homer0"],
"extends": [
"plugin:@homer0/node-with-prettier",
"plugin:@homer0/jsdoc"
]
}
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,34 @@
name: Release NPM package

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "::set-output name=NVMRC::$(cat .nvmrc)"
id: nvm
- uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: Install dependencies
env:
HUSKY: 0
run: yarn --frozen-lockfile
- run: yarn semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Generate documentation
run: yarn docs
- name: Deploy documentation
uses: JamesIves/github-pages-deploy-action@4.1.1
with:
BRANCH: gh-pages
FOLDER: docs
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,24 @@
name: Test

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '16' ]
name: Run jest and ESLint (Node ${{ matrix.node }})
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn --frozen-lockfile
- run: yarn lint:all
- run: yarn test
- name: Coveralls
if: ${{ matrix.node == '14' }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ npm-debug.log
yarn-error.log
dist
docs/
.vscode
1 change: 1 addition & 0 deletions .husky/.gitignore
@@ -0,0 +1 @@
_
9 changes: 9 additions & 0 deletions .husky/commit-msg
@@ -0,0 +1,9 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if hash yarn 2>/dev/null; then
yarn commitlint --edit $1
else
npx commitlint --edit $1
fi

4 changes: 3 additions & 1 deletion utils/hooks/post-merge → .husky/post-merge
@@ -1,7 +1,9 @@
#!/bin/bash -ex
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if hash yarn 2>/dev/null; then
yarn
else
npm install
fi

5 changes: 2 additions & 3 deletions utils/hooks/pre-commit → .husky/pre-commit
@@ -1,9 +1,8 @@
#!/bin/bash -e
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if hash yarn 2>/dev/null; then
yarn run lint
yarn test
else
npm run lint
npm test
fi
8 changes: 8 additions & 0 deletions .husky/pre-push
@@ -0,0 +1,8 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if hash yarn 2>/dev/null; then
yarn test
else
npm test
fi
7 changes: 7 additions & 0 deletions .jestrc.js
@@ -0,0 +1,7 @@
module.exports = {
automock: true,
collectCoverage: true,
testPathIgnorePatterns: ['/node_modules/', '/utils/scripts/'],
unmockedModulePathPatterns: ['/node_modules/', '/mocks/'],
testEnvironment: 'node',
};
7 changes: 0 additions & 7 deletions .jestrc.json

This file was deleted.

46 changes: 46 additions & 0 deletions .jsdoc.js
@@ -0,0 +1,46 @@
const packageJson = require('./package.json');

module.exports = {
source: {
include: ['./src'],
includePattern: '.js$',
},
plugins: ['docdash/nativeTypesPlugin', 'jsdoc-ts-utils', 'plugins/markdown'],
templates: {
cleverLinks: true,
default: {
includeDate: false,
},
},
opts: {
recurse: true,
destination: './docs',
readme: 'README.md',
template: 'node_modules/docdash',
},
docdash: {
title: packageJson.name,
meta: {
title: `${packageJson.name} docs`,
},
sectionOrder: [],
collapse: true,
refLinks: [
{
title: 'View the package on Yarn',
url: `https://yarnpkg.com/package/${packageJson.name}`,
type: 'yarn',
},
{
title: 'Go to the GitHub repository',
url: `https://github.com/${packageJson.repository}`,
type: 'github',
},
{
title: 'View the package on NPM',
url: `https://www.npmjs.com/package/${packageJson.name}`,
type: 'npm',
},
],
},
};
2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
10
14
1 change: 1 addition & 0 deletions .prettierrc
@@ -0,0 +1 @@
"@homer0/prettier-config"
12 changes: 12 additions & 0 deletions .releaserc
@@ -0,0 +1,12 @@
{
"tagFormat": "${version}",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
"@semantic-release/github"
],
"branches": ["main"]
}
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

44 changes: 33 additions & 11 deletions README.md
Expand Up @@ -81,25 +81,47 @@ This only works on classes and regular functions (no arrow). The idea was for it

### NPM/Yarn Tasks

| Task | Description |
|-----------------|-------------------------------------|
| `test` | Run the project unit tests. |
| `run lint` | Lint the modified files. |
| `run lint:full` | Lint the project code. |
| `run docs` | Generate the project documentation. |
| `run todo` | List all the pending to-do's. |
| Task | Description |
|----------------|-------------------------------------|
| `test` | Run the project unit tests. |
| `run lint` | Lint the modified files. |
| `run lint:all` | Lint the project code. |
| `run docs` | Generate the project documentation. |
| `run todo` | List all the pending to-do's. |

### Repository hooks

I use [`husky`](https://yarnpkg.com/package/husky) to automatically install the repository hooks so the code will be tested and linted before any commit, and the dependencies updated after every merge.

#### Commits convention

I use [conventional commits](https://www.conventionalcommits.org) with [`commitlint`](https://commitlint.js.org) in order to support semantic releases. The one that sets it up is actually husky, that installs a script that runs `commitlint` on the `git commit` command.

The configuration is on the `commitlint` property of the `package.json`.

### Releases

I use [`semantic-release`](https://yarnpkg.com/package/semantic-release) and a GitHub action to automatically release on NPM everything that gets merged to main.

The configuration for `semantic-release` is on `./releaserc` and the workflow for the release is on `./.github/workflow/release.yml`.

### Testing

I use [Jest](https://facebook.github.io/jest/) with [Jest-Ex](https://yarnpkg.com/en/package/jest-ex) to test the project. The configuration file is on `./.jestrc`, the tests and mocks are on `./tests` and the script that runs it is on `./utils/scripts/test`.
I use [Jest](https://facebook.github.io/jest/) to test the project.

The configuration file is on `./.jestrc.js`, the tests are on `./tests` and the script that runs it is on `./utils/scripts/test`.

### Linting
### Linting && Formatting

I use [ESlint](http://eslint.org) with [my own custom configuration](http://yarnpkg.com/en/package/eslint-plugin-homer0) to validate all the JS code. The configuration file for the project code is on `./.eslintrc` and the one for the tests is on `./tests/.eslintrc`. There's also an `./.eslintignore` to exclude some files on the process. The script that runs it is on `./utils/scripts/lint`.
I use [ESlint](https://eslint.org) with [my own custom configuration](https://yarnpkg.com/en/package/@homer0/eslint-plugin) to validate all the JS code. The configuration file for the project code is on `./.eslintrc` and the one for the tests is on `./tests/.eslintrc`. There's also an `./.eslintignore` to exclude some files on the process. The script that runs it is on `./utils/scripts/lint-all`.

For formatting I use [Prettier](https://prettier.io) with [my custom configuration](https://yarnpkg.com/en/package/@homer0/prettier-config). The configuration file for the project code is on `./.prettierrc`.

### Documentation

I use [ESDoc](http://esdoc.org) to generate HTML documentation for the project. The configuration file is on `./.esdocrc` and the script that runs it is on `./utils/scripts/docs`.
I use [JSDoc](https://jsdoc.app) to generate an HTML documentation site for the project.

The configuration file is on `./.jsdoc.js` and the script that runs it is on `./utils/scripts/docs`.

### To-Dos

Expand Down
52 changes: 32 additions & 20 deletions package.json
Expand Up @@ -7,37 +7,49 @@
"author": "Leonardo Apiwan (@homer0) <me@homer0.com>",
"license": "MIT",
"dependencies": {
"@babel/types": "7.9.5"
"@babel/types": "7.18.0"
},
"devDependencies": {
"wootils": "^3.0.3",
"eslint": "^6.8.0",
"eslint-plugin-homer0": "^3.0.3",
"jest-ex": "^8.0.1",
"jest-cli": "^25.3.0",
"jasmine-expect": "^4.0.3",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "^1.0.0",
"esdoc-node": "1.0.4",
"leasot": "^10.2.0",
"coveralls": "^3.0.11",
"husky": "^4.2.5"
"@commitlint/cli": "^17.0.0",
"@commitlint/config-conventional": "^17.0.0",
"@homer0/eslint-plugin": "^9.0.2",
"@homer0/prettier-config": "^1.1.1",
"@homer0/prettier-plugin-jsdoc": "^5.1.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"eslint": "^8.16.0",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"jest": "^28.1.0",
"jsdoc": "^3.6.10",
"jsdoc-ts-utils": "^3.0.0",
"docdash": "homer0/docdash#semver:^2.1.0",
"leasot": "^13.1.0",
"lint-staged": "^12.4.1",
"prettier": "^2.6.2",
"semantic-release": "^19.0.2"
},
"engine-strict": true,
"engines": {
"node": ">=10.0.0"
"node": ">=14"
},
"main": "src/index.js",
"husky": {
"hooks": {
"pre-commit": "./utils/hooks/pre-commit",
"post-merge": "./utils/hooks/post-merge"
}
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"lint-staged": {
"*.js": [
"eslint",
"prettier --write"
]
},
"scripts": {
"prepare": "./utils/scripts/prepare",
"test": "./utils/scripts/test",
"lint": "./utils/scripts/lint",
"lint:full": "./utils/scripts/lint-full",
"lint:all": "./utils/scripts/lint-all",
"docs": "./utils/scripts/docs",
"todo": "./utils/scripts/todo"
}
Expand Down
19 changes: 12 additions & 7 deletions src/index.js
@@ -1,8 +1,9 @@
const InjectDirectiveParser = require('./injectDirectiveParser');
/**
* Generates the object that Babel will load in order to hook the parser for every functions and
* methods are being processed.
* @return {BabelPluginTransformClassInjectDirective}
* Generates the object that Babel will load in order to hook the parser for every
* functions and methods are being processed.
*
* @returns {BabelPluginTransformClassInjectDirective}
*/
const plugin = () => {
let parser;
Expand All @@ -13,7 +14,7 @@ const plugin = () => {
if (parser) {
parser.parseClassMethod(path);
} else {
throw new Error('`ClassMethod.enter` can\'t be called before `Program.enter`');
throw new Error("`ClassMethod.enter` can't be called before `Program.enter`");
}
},
},
Expand All @@ -22,7 +23,9 @@ const plugin = () => {
if (path) {
parser.parseFunction(path);
} else {
throw new Error('`FunctionDeclaration.enter` can\'t be called before `Program.enter`');
throw new Error(
"`FunctionDeclaration.enter` can't be called before `Program.enter`",
);
}
},
},
Expand All @@ -31,7 +34,9 @@ const plugin = () => {
if (path) {
parser.parseFunction(path);
} else {
throw new Error('`FunctionExpression.enter` can\'t be called before `Program.enter`');
throw new Error(
"`FunctionExpression.enter` can't be called before `Program.enter`",
);
}
},
},
Expand All @@ -43,7 +48,7 @@ const plugin = () => {
if (parser) {
parser.transform();
} else {
throw new Error('`Program.exit` can\'t be called before `Program.enter`');
throw new Error("`Program.exit` can't be called before `Program.enter`");
}
},
},
Expand Down

0 comments on commit 88fa5bb

Please sign in to comment.