diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..10b4c73 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +lib +tsconfig.json +package.json +.eslintrc.json +rollup.config.ts \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..10c0b36 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,121 @@ +{ + "env": { + "es6": true, + "node": true + }, + "extends": [ + "airbnb-typescript/base", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:json/recommended" + ], + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json", + "ecmaVersion": 2020, + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint", + "import" + ], + "rules": { + "@typescript-eslint/no-shadow": 0, + "guard-for-in": 0, + "multiline-ternary": [ + "error", + "always" + ], + "@typescript-eslint/indent": [ + "error", + "tab", + { + "SwitchCase": 1 + } + ], + "linebreak-style": [ + "error", + "unix" + ], + "@typescript-eslint/quotes": [ + "error", + "double", + { + "allowTemplateLiterals": true + } + ], + "eqeqeq": [ + "error", + "always" + ], + "no-else-return": [ + "error", + { + "allowElseIf": false + } + ], + "no-floating-decimal": "error", + "no-implicit-coercion": "error", + "no-multi-spaces": [ + "warn", + { + "ignoreEOLComments": true + } + ], + "yoda": "error", + "@typescript-eslint/no-unused-vars": [ + "error", + { + "args": "none" + } + ], + "no-tabs": "off", + "max-len": [ + "error", + { + "code": 120, + "ignoreComments": true + } + ], + "no-console": "off", + "consistent-return": "off", + "class-methods-use-this": "off", + "import/prefer-default-export": "off", + "no-plusplus": "off", + "no-nested-ternary": "error", + "no-return-assign": "off", + "no-restricted-syntax": "off", + "no-await-in-loop": "off", + "no-mixed-spaces-and-tabs": [ + "error", + "smart-tabs" + ], + "import/no-cycle": "off", + "@typescript-eslint/explicit-function-return-type": "warn", + "import/extensions": "off", + "no-underscore-dangle": [ + "error", + { + "allowAfterThis": true + } + ], + "no-continue": "off", + "no-empty": [ + "error", + { + "allowEmptyCatch": true + } + ], + "@typescript-eslint/explicit-module-boundary-types": "off", + "no-void": "off", + "curly": [ + "error", + "all" + ], + "no-return-await": "error" + } +} \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..0dd4407 --- /dev/null +++ b/makefile @@ -0,0 +1,33 @@ +.SILENT: + +PACKAGE_VERSION=$(shell cat package.json | grep -i version | sed -e "s/ //g" | cut -c 12- | sed -e "s/\",//g") + +.PHONY: install +install: + pnpm install + +.PHONY: build +build: + pnpm run build + +.PHONY: lint +lint: + pnpm run lint + +.PHONY: npmjs +npmjs: + echo "//registry.npmjs.org/:_authToken=$$NPM_TOKEN" >> .npmrc + echo "@hecht-a:registry=https://registry.npmjs.org/" >> .npmrc + +.PHONY: publish-npmjs +publish-npmjs: + yarn publish --access public --registry https://registry.npmjs.org/ --new-version $(PACKAGE_VERSION) --non-interactive + +.PHONY: github-tag +github-tag: + git tag -a v$(PACKAGE_VERSION) -m "update to v$(PACKAGE_VERSION)" + git push origin v$(PACKAGE_VERSION) + +.PHONY: types +types: + pnpm run types \ No newline at end of file diff --git a/package.json b/package.json index 5ba9c82..6fee67f 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,44 @@ { - "name": "form-validator", - "private": true, + "name": "@hecht-a/form-validator", "version": "1.0.0", + "description": "This is a package to validate forms in frontend.", + "private": false, "type": "module", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "files": [ + "lib" + ], + "author": { + "name": "Axel Hecht", + "url": "https://github.com/hecht-a" + }, + "bugs": { + "url": "https://github.com/hecht-a/form-validator/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/hecht-a/form-validator.git" + }, "scripts": { - "dev": "vite", - "build": "tsc && vite build", - "preview": "vite preview" + "build": "rollup --config rollup.config.ts", + "types": "tsc --declaration --emitDeclarationOnly --project tsconfig.types.json", + "lint": "eslint --ext .ts,.js ." }, "devDependencies": { - "typescript": "^4.6.4", - "vite": "^3.0.7" + "@rollup/plugin-typescript": "^8.4.0", + "@typescript-eslint/eslint-plugin": "^4.33.0", + "@typescript-eslint/parser": "^4.33.0", + "eslint": "^7.32.0", + "eslint-config-airbnb-base": "^14.2.1", + "eslint-config-airbnb-typescript": "^12.3.1", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-json": "^2.1.2", + "rollup": "^2.79.0", + "rollup-plugin-delete": "^2.0.0", + "rollup-plugin-terser": "^7.0.2", + "tslib": "^2.4.0", + "typescript": "^4.8.2", + "vite": "^3.1.0" } } \ No newline at end of file diff --git a/rollup.config.ts b/rollup.config.ts new file mode 100644 index 0000000..2f3df46 --- /dev/null +++ b/rollup.config.ts @@ -0,0 +1,43 @@ +import remove from "rollup-plugin-delete"; +import {resolve} from "node:path"; +import {terser} from "rollup-plugin-terser"; +import typescript from "@rollup/plugin-typescript"; + +export default [ + { + input: resolve("src", "Validator/index.ts"), + plugins: [ + remove({targets: resolve("lib", "*")}), + typescript(), + terser() + ], + output: { + file: resolve("lib", "Validator/index.js"), + format: "cjs" + } + }, + { + input: resolve("src", "Error/index.ts"), + plugins: [ + remove({targets: resolve("lib", "*")}), + typescript(), + terser() + ], + output: { + file: resolve("lib", "Error/index.js.js"), + format: "cjs" + } + }, + { + input: resolve("src", "index.ts"), + plugins: [ + remove({targets: resolve("lib", "*")}), + typescript(), + terser() + ], + output: { + file: resolve("lib", "index.js"), + format: "cjs" + } + } +]; \ No newline at end of file diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 0000000..686bc68 --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "files": ["src/index.ts"], + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "outDir": "./lib" + } +} \ No newline at end of file