Skip to content

Commit

Permalink
fix(): init date plugin and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
horprogs committed Dec 30, 2021
0 parents commit 3efa491
Show file tree
Hide file tree
Showing 23 changed files with 9,046 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
extends: [
'prettier',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['prettier', 'jest', '@typescript-eslint'],
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-console': ['error', { allow: ['warn', 'error'] }],
},
};
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test and Release
on:
workflow_dispatch:
push:
jobs:
test:
name: Lint and Test
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run lint
run: yarn lint
- name: Run tests
run: yarn test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2

release:
name: Release
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.idea
.tmp
app.yaml
yarn-error.log
coverage
dist
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit ""
4 changes: 4 additions & 0 deletions .ncurc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"upgrade": true,
"reject": []
}
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80,
"arrowParens": "always"
}
25 changes: 25 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"dryRun": false,
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md",
"package.json"
],
"message": "chore(release): set `package.json` to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}
64 changes: 64 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Contributing

## Suggesting new features

If you are here to suggest a feature, first create an issue if it does not already exist. From there, we will discuss use-cases for the feature and then finally discuss how it could be implemented.

## Commit message conventions

`just-validate` is using [Angular Commit Message Conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines).

We have very precise rules over how our git commit messages can be formatted. This leads to **more readable messages** that are easy to follow when looking through the **project history**.

### Commit Message Format

Each commit message consists of a **type** and a **subject**:

```
<type>(): <subject>
```

### Type

Must be one of the following:

- **feat**: A new feature
- **fix**: A bug fix
- **docs**: Documentation only changes
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing
semi-colons, etc)
- **refactor**: A code change that neither fixes a bug nor adds a feature
- **perf**: A code change that improves performance
- **test**: Adding missing or correcting existing tests
- **chore**: Changes to the build process or auxiliary tools and libraries such as documentation
generation

### Subject

The subject contains succinct description of the change:

- use the imperative, present tense: "change" not "changed" nor "changes"
- don't capitalize first letter
- no dot (.) at the end

### Example

Here is an example of the release type that will be done based on a commit messages:

| Commit message | Release type |
|-----------------------------------------| -------------------------- |
| `fix(): fix validation for number rule` | Patch Release |
| `feat(): add onFail callback` | ~~Minor~~ Feature Release |


## Pull requests

Maintainers merge pull requests by squashing all commits and editing the commit message if necessary using the GitHub user interface.

Use an appropriate commit type.

## Releases

For each new commit added to `master` with `git push` or by merging a pull request or merging from another branch, a github action is triggered and runs the `semantic-release` command to make a release if there are codebase changes since the last release that affect the package functionalities.

After the release, the link to the CDN for the new version should be changed here `site/examples/index.html`, in `README.md` and in `site/index.html`.
22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#### Copyright (c) 2021 Horprogs
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# JustValidate plugin date

[![codecov](https://codecov.io/gh/horprogs/Just-validate-plugin-date/branch/master/graph/badge.svg?token=O6DXXL5TUU)](https://codecov.io/gh/horprogs/Just-validate)
<a href="https://bundlephobia.com/result?p=just-validate-plugin-date@latest" target="\_parent">
<img alt="" src="https://badgen.net/bundlephobia/minzip/just-validate-plugin-date@latest" />
</a>

[//]: # '[![Codacy Badge](https://app.codacy.com/project/badge/Grade/6c7a25cc9fdb4bf8869884339418352d)](https://www.codacy.com/gh/horprogs/Just-validate/dashboard?utm_source=github.com&utm_medium=referral&utm_content=horprogs/Just-validate&utm_campaign=Badge_Grade)'

[![Known Vulnerabilities](https://snyk.io/test/github/horprogs/Just-validate-plugin-date/badge.svg)](https://snyk.io/test/github/horprogs/Just-validate-plugin-date)
[![Release workflow](https://github.com/horprogs/Just-validate-plugin-date/workflows/Test%20and%20Release/badge.svg)](https://github.com/horprogs/Just-validate-plugin-date/actions)

Date validation plugin for JustValidate library

## Installation

### npm

```shell
npm install just-validate-plugin-date --save
```

### yarn

```shell
yarn add just-validate-plugin-date
```

And then use it as an imported module:

```js
import JustValidatePluginDate from 'just-validate-plugin-date';
```

Or if you don't use module bundlers, just include JustValidatePluginDate script on your page from CDN and call it as `window.JustValidatePluginDate`:

```html
<script src="https://unpkg.com/just-validate@latest/dist/just-validate-plugin-date.production.min.js"></script>
```

## Usage

This plugin is supposed to use together with JustValidate library. It takes 1 argument: function which returns the validation config.

Check more details and examples here: https://github.com/horprogs/Just-validate

```js
JustValidatePluginDate((fields) => ({
format: 'dd/MM/yyyy',
isAfter: fields['#date_after'].elem.value,
isBefore: fields['#date_before'].elem.value,
}));
```

```js
import JustValidatePluginDate from 'just-validate-plugin-date';

validator.addField('#date', [
{
plugin: JustValidatePluginDate((fields) => ({
format: 'dd/MM/yyyy',
isAfter: '',
})),
},
]);
```
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage:
status:
project:
default:
target: 85%
threshold: 1%
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['./jest.setup.ts'],
coveragePathIgnorePatterns: ['testingUtils.ts', 'interfaces.ts'],
};
1 change: 1 addition & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom';
89 changes: 89 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "just-validate-plugin-date",
"version": "0.0.1",
"description": "Date plugin for JustValidate",
"scripts": {
"semantic-release": "semantic-release",
"dev": "vite --port 3001",
"build:vite": "tsc && vite build",
"build:types": "tsc --project tsconfig.types.json",
"build": "yarn run build:vite && yarn run build:types",
"lint": "tsc && eslint . --ext .ts",
"test": "jest",
"test:coverage": "jest --coverage",
"upgrade-packages": "ncu --configFileName .ncurc.json"
},
"main": "./dist/just-validate-plugin-date.production.min.js",
"module": "./dist/just-validate-plugin-date.es.js",
"exports": {
".": {
"import": "./dist/just-validate-plugin-date.es.js",
"require": "./dist/just-validate-plugin-date.min.js"
}
},
"types": "./dist/main.d.ts",
"author": "Georgii Perepecho <horprogs@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/horprogs/Just-validate-plugin-date.git"
},
"keywords": [
"form",
"validation",
"form validation",
"just-validate"
],
"bugs": {
"url": "https://github.com/horprogs/Just-validate-plugin-date/issues"
},
"unpkg": "./dist/just-validate-plugin-date.production.min.js",
"files": [
"dist"
],
"homepage": "https://github.com/horprogs/Just-validate-plugin-date#readme",
"devDependencies": {
"@babel/core": "7.16.5",
"@babel/preset-env": "7.16.5",
"@babel/preset-typescript": "7.16.5",
"@commitlint/cli": "^16.0.0",
"@commitlint/config-conventional": "^16.0.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.2",
"@semantic-release/npm": "^8.0.3",
"@semantic-release/release-notes-generator": "^10.0.3",
"@testing-library/dom": "8.11.1",
"@testing-library/jest-dom": "5.16.1",
"@testing-library/user-event": "13.5.0",
"@types/jest": "27.0.3",
"@types/jsdom": "16.2.14",
"@types/vfile-message": "2.0.0",
"@typescript-eslint/eslint-plugin": "5.8.0",
"@typescript-eslint/parser": "5.8.0",
"babel-jest": "27.4.5",
"eslint": "8.5.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jest": "25.3.0",
"eslint-plugin-prettier": "4.0.0",
"husky": "^7.0.4",
"jest": "27.4.5",
"jsdom": "19.0.0",
"just-validate": "^3.1.2",
"path": "0.12.7",
"prettier": "2.5.1",
"semantic-release": "^18.0.1",
"ts-node": "10.4.0",
"typescript": "4.5.4",
"vite": "2.7.7"
},
"engines": {
"node": "16.x",
"yarn": "1.x"
},
"dependencies": {
"date-fns": "^2.28.0"
}
}

0 comments on commit 3efa491

Please sign in to comment.