Skip to content

Commit

Permalink
chore: Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
cmath10 committed Feb 12, 2024
0 parents commit 7e509fb
Show file tree
Hide file tree
Showing 24 changed files with 5,194 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["@commitlint/config-conventional"],
"rules": {
"body-max-line-length": [2, "always", 200],
"footer-max-line-length": [2, "always", 200],
"header-max-length": [2, "always", 200],
"subject-case": [2, "never"]
}
}
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
root: true,
parserOptions: {
parser: '@typescript-eslint/parser',
},
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
'comma-dangle': ['error', {
arrays: 'always-multiline',
exports: 'always-multiline',
functions: 'never',
imports: 'always-multiline',
objects: 'always-multiline',
}],
'no-debugger': 'error',
'object-curly-spacing': ['error', 'always'],
'quotes': ['error', 'single'],
},
}
88 changes: 88 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
eslint:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 18.x, 20.x ]

steps:
- name: Using branch ${{ github.ref }} for repository ${{ github.repository }}.
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Cache dependencies
id: cache-deps
uses: actions/cache@v4
with:
path: .yarn
key: ${{ runner.OS }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-node-${{ matrix.node-version }}-yarn-
- name: Install dependencies
run: |
yarn install
- name: Run lint
run: |
yarn lint
tests:
needs: eslint

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- name: Using branch ${{ github.ref }} for repository ${{ github.repository }}.
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Cache dependencies
id: cache-deps
uses: actions/cache@v4
with:
path: .yarn
key: ${{ runner.OS }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-node-${{ matrix.node-version }}-yarn-
- name: Install dependencies
run: |
yarn install
- name: Run tests
run: |
yarn test:coverage
- name: Upload coverage to GitHub Artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.node-version }}
path: coverage/

# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: ./coverage/lcov.info
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea

coverage/
dist/
node_modules/

.npmrc
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
20 changes: 20 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.github
.husky
.idea
coverage
/node_modules
src
tests

.commitlintrc.json
.eslintrc.js
.gitignore
.npmrc
.versionrc.json
docker-compose.yml
jest.config.ts
rollup.config.ts
tsconfig.json
yarn.lock

Makefile
12 changes: 12 additions & 0 deletions .versionrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"types": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Fixes" },
{ "type": "chore", "hidden": true },
{ "type": "docs", "hidden": true },
{ "type": "style", "hidden": true },
{ "type": "refactor", "hidden": true },
{ "type": "perf", "hidden": true },
{ "type": "test", "hidden": true }
]
}
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
TARGET_HEADER=@echo -e '===== \e[34m' $@ '\e[0m'
YARN=@docker-compose run --rm node yarn

.PHONY: node_modules
node_modules: package.json yarn.lock ## Installs dependencies
$(TARGET_HEADER)
$(YARN) install --silent
@touch node_modules || true

.PHONY: build
build: node_modules ## Creates a dist catalogue with library build
$(TARGET_HEADER)
$(YARN) build

.PHONY: husky
husky: node_modules ## Adds husky git hooks with commit content checks
@docker-compose run --rm node npx husky init

.PHONY: eslint
eslint: node_modules ## Runs eslint
$(TARGET_HEADER)
$(YARN) lint

.PHONY: test
test: node_modules ## Runs autotests
$(TARGET_HEADER)
$(YARN) test

.PHONY: test-coverage
test-coverage: node_modules ## Runs autotests with --coverage
$(TARGET_HEADER)
ifdef reporter
$(YARN) test --coverage --coverageReporters=$(reporter)
else
$(YARN) test --coverage --coverageReporters=text
endif

.PHONY: release
release: ## Bumps version and creates tag
$(TARGET_HEADER)
ifdef as
$(YARN) release:$(as)
else
$(YARN) release
endif

.PHONY: help
help: ## Calls recipes list
@cat $(MAKEFILE_LIST) | grep -e "^[a-zA-Z_\-]*: *.*## *" | awk '\
BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

# Colors
$(call computable,CC_BLACK,$(shell tput -Txterm setaf 0 2>/dev/null))
$(call computable,CC_RED,$(shell tput -Txterm setaf 1 2>/dev/null))
$(call computable,CC_GREEN,$(shell tput -Txterm setaf 2 2>/dev/null))
$(call computable,CC_YELLOW,$(shell tput -Txterm setaf 3 2>/dev/null))
$(call computable,CC_BLUE,$(shell tput -Txterm setaf 4 2>/dev/null))
$(call computable,CC_MAGENTA,$(shell tput -Txterm setaf 5 2>/dev/null))
$(call computable,CC_CYAN,$(shell tput -Txterm setaf 6 2>/dev/null))
$(call computable,CC_WHITE,$(shell tput -Txterm setaf 7 2>/dev/null))
$(call computable,CC_END,$(shell tput -Txterm sgr0 2>/dev/null))
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.8'

services:
node:
image: node:20
user: node
volumes:
- ./:/project
working_dir: /project

9 changes: 9 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Config } from '@jest/types'

export default {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
} as Config.InitialOptions
61 changes: 61 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@modulify/morph",
"description": "Mapping util",
"license": "MIT",
"version": "0.0.0",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "types/index.d.ts",
"scripts": {
"build": "rollup --config rollup.config.ts --configPlugin typescript",
"lint": "eslint --ext .js,.mjs,.ts src tests types",
"prepare": "husky",
"release": "standard-version",
"release:minor": "standard-version --release-as minor",
"release:patch": "standard-version --release-as patch",
"release:major": "standard-version --release-as major",
"stats": "gzip -c ./dist/index.mjs | wc -c",
"test": "jest --config jest.config.ts",
"test:coverage": "jest --config jest.config.ts --coverage --coverageReporters=lcov"
},
"devDependencies": {
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@jest/types": "^29.6.3",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^18.15 || ^20.11",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"eslint": "^8.56.0",
"husky": "^9.0.10",
"jest": "^29.7.0",
"rollup": "^4.9.6",
"rollup-plugin-delete": "^2.0.0",
"standard-version": "^9.5.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"mapper",
"mapping"
],
"contributors": [
"Zaitsev Kirill <[email protected]>"
],
"homepage": "https://github.com/modulify/morph",
"repository": {
"type": "git",
"url": "https://github.com/modulify/morph.git"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
48 changes: 48 additions & 0 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type {
InputPluginOption,
OutputOptions,
RollupOptions,
} from 'rollup'

import path from 'node:path'
import url from 'node:url'

import clean from 'rollup-plugin-delete'
import typescript from '@rollup/plugin-typescript'

const __dirname = path.dirname(url.fileURLToPath(import.meta.url))

const input = path.join(__dirname, '/src/index.ts')

const output: OutputOptions = {
exports: 'named',
dir: path.join(__dirname, '/dist'),
globals: {
vue: 'Vue',
},
}

const plugins: InputPluginOption = [
typescript(),
]

export default [{
input,
output: {
...output,
format: 'cjs',
entryFileNames: 'index.cjs',
},
plugins: [
clean({ targets: 'dist/*' }),
...plugins,
],
}, {
input,
output: {
...output,
format: 'esm',
entryFileNames: 'index.mjs',
},
plugins,
}] as RollupOptions[]
13 changes: 13 additions & 0 deletions src/MorphEach.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import MorphOne from '@/MorphOne'

export default class MorphEach {
private readonly _morph: MorphOne

constructor (morph: MorphOne) {
this._morph = morph
}

apply (source: unknown[]): unknown[] {
return source.map(v => this._morph.apply(v))
}
}
Loading

0 comments on commit 7e509fb

Please sign in to comment.