Skip to content

Commit

Permalink
feat: add base repository structure (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaz authored Jul 15, 2020
1 parent 70a9a36 commit 62a2c31
Show file tree
Hide file tree
Showing 26 changed files with 5,234 additions and 951 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*.ts]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/coverage/**
**/node_modules/**
packages/*/dist/**
!.eslintrc.js
77 changes: 77 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = {
extends: ['plugin:import/errors', 'plugin:import/typescript', 'prettier', 'plugin:eslint-comments/recommended'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint/eslint-plugin'],
rules: {
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@typescript-eslint/ban-types': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/prefer-ts-expect-error': 'error',
'import/default': 'off',
'import/order': 'error',
'no-dupe-class-members': 'off',
'@typescript-eslint/explicit-module-boundary-types': 2,
'no-unused-vars': 'off'
}
},
{
files: ['*.md'],
rules: {
'arrow-body-style': 0,
'consistent-return': 0,
'import/no-extraneous-dependencies': 0,
'import/no-unresolved': 0,
'jest/no-focused-tests': 0,
'jest/no-identical-title': 0,
'jest/valid-expect': 0,
'no-undef': 0,
'no-unused-vars': 0,
'prettier/prettier': 0,
'sort-keys': 0
}
},
{
files: ['**/__tests__/**', '**/__mocks__/**'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 0
}
}
],
// parser: 'babel-eslint',
parser: '@typescript-eslint/parser',
plugins: ['markdown', 'import', 'prettier', 'eslint-comments'],
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
rules: {
'arrow-body-style': 2,
'eslint-comments/no-unused-disable': 2,
'import/no-duplicates': 2,
'import/no-extraneous-dependencies': [
2,
{
devDependencies: ['**/__tests__/**']
}
],
'import/no-unresolved': [2, { ignore: ['fsevents'] }],
'import/order': 2,
'no-console': 2,
'no-restricted-imports': [
2,
{
message: 'Please use graceful-fs instead.',
name: 'fs'
}
],
'no-unused-vars': 2,
'prettier/prettier': 2,
'sort-imports': [2, { ignoreDeclarationSort: true }]
}
}
50 changes: 50 additions & 0 deletions .github/workflows/pr-create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Pull Request

on:
pull_request:
branches:
- master
types: [opened, reopened, synchronize]

jobs:
create-pr:
runs-on: ubuntu-latest
timeout-minutes: 4

steps:
- uses: actions/checkout@v2

# todo: run with matrix of supported versions
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: get yarn cache
timeout-minutes: 1
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashfiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: install dependencies
run: yarn install --frozen-lockfile

- name: check format
run: yarn prettify

- name: check lint
run: yarn lint

- name: build packages
run: yarn build

- name: test
run: yarn test
env:
CI: true
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
node_modules
dist

*.tsbuildinfo

logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

coverage/

node_modules/

.DS_Store

.idea/

.eslintcache
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.json
*.md

dist/
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"printWidth": 120,
"semi": false,
"trailingComma": "none",
"arrowParens": "avoid"
"arrowParens": "avoid",
"useTabs": false
}
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


A sketch of domain langauage

```ts
Expand Down Expand Up @@ -39,8 +37,8 @@ export const handler = serverlessPipe({config: {}})
})
// what if you have dependencies dependent on dependencies ?
// do we run them in order and pass dependencies so they can create dependencies
// this start what application needs to run
// .global
// this start what application needs to run
// .global
// {depedendencies: {commercetoolsClient, awsClient}}
.singleton(commercetoolClient)
// todoRepositoryClient(awsClient) - level of abstraction is left to developer
Expand All @@ -59,13 +57,13 @@ export const handler = serverlessPipe({config: {}})
// SSM - not important (concept)
.refresh(() => {
return {
factory: () => {},
factory: () => {},
interval: 1000
}
})
// this is very specific to the environment and converts AWS events or google or azure to the typed object representation
// order does not matter
//
// order does not matter
//
.payload((event, context) => {
event.pathVariables
event.queryParams
Expand Down
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
threshold: 95%
patch:
default:
target: 95%

comment: off
19 changes: 19 additions & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { defaults } = require('jest-config')

module.exports = {
testEnvironment: 'node',
preset: 'ts-jest',
testMatch: null,
testRegex: '/__tests__/.*\\.test\\.ts$',
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
setupFilesAfterEnv: ['jest-extended'],
moduleNameMapper: {},
clearMocks: true,
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.json'
}
}
}
9 changes: 9 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"packages": ["packages/*"],
"version": "independent",
"command": {
"version": {
"includeMergedTags": true
}
}
}
41 changes: 35 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
{
"engines": {
"node": "0.12"
"node": ">=0.10"
},
"private": true,
"scripts": {
"clean": "git clean -dfqX -- ./node_modules **/{dist,node_modules}/ ./packages/*/tsconfig*tsbuildinfo ./coverage .eslintcache",
"build": "tsc --build tsconfig.build.json",
"build:clean": "tsc --build tsconfig.build.json --clean",
"watch": "tsc --build tsconfig.build.json --watch",
"postinstall": "lerna run prepare && npm run build",
"test": "jest --verbose",
"test:clean": "jest --clearCache",
"test:watch": "jest --verbose --watchAll",
"coverage": "npm test -- --coverage",
"lint": "eslint . --cache --ext js,jsx,ts,tsx,md",
"lint:prettier": "prettier '**/*.{md,yml,yaml}' --write --ignore-path .gitignore",
"commit": "git-cz",
"pretty-quick": "pretty-quick",
"prettify:fix": "prettier --write 'packages/**/*.{js,ts}'",
Expand All @@ -13,12 +24,30 @@
"packages/*"
],
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/preset-typescript": "^7.9.0",
"babel-jest": "^26.0.1",
"@types/jest": "^26.0.4",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"codecov": "^3.7.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.18.0",
"eslint-plugin-markdown": "^1.0.2",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.0.1",
"jest-config": "^26.1.0",
"jest-extended": "^0.11.5",
"lerna": "^3.22.1",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1"
"pretty-quick": "^2.0.1",
"ts-jest": "^26.1.2",
"typescript": "^3.9.6"
},
"jest": {
"projects": [
"<rootDir>/packages/*"
]
}
}
8 changes: 3 additions & 5 deletions packages/sls-app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFilesAfterEnv: ['jest-extended']
}
const config = require('../../jest.config.base')

module.exports = config
20 changes: 9 additions & 11 deletions packages/sls-app/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "@cabiri-io/sls-app",
"version": "1.0.0",
"main": "index.js",
"version": "0.0.1",
"author": "Cabiri <[email protected]>",
"license": "MIT",
"scripts": {
"test": "jest"
"repository": {
"type": "git",
"url": "https://github.com/cabiri-io/sls-pipe",
"directory": "packages/sls-app"
},
"devDependencies": {
"@types/jest": "^26.0.0",
"jest": "^26.0.1",
"jest-extended": "^0.11.5",
"ts-jest": "^26.1.0",
"typescript": "^3.9.5"
}
"homepage": "https://github.com/cabiri-io/sls-pipe#readme",
"main": "dist/index.js",
"types": "dist/index.d.ts"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { application, ApplicationError } from '../src'
import { ApplicationError, application } from '..'

describe('application flow', () => {
describe('action', () => {
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('application flow', () => {
.then(() => {
expect(preAction).toHaveBeenCalledWith({ payload: 'hello', dependencies: { appendString: 'world' } })
expect(action).toHaveBeenCalledWith('hello', { appendString: 'world' })
//@ts-ignore
//@ts-expect-error
expect(preAction).toHaveBeenCalledBefore(action)
})
})
Expand All @@ -50,9 +50,9 @@ describe('application flow', () => {
expect(preAction1).toHaveBeenCalledWith({ payload: 'hello', dependencies: { appendString: 'world' } })
expect(preAction2).toHaveBeenCalledWith({ payload: 'hello', dependencies: { appendString: 'world' } })
expect(action).toHaveBeenCalledWith('hello', { appendString: 'world' })
//@ts-ignore
//@ts-expect-error
expect(preAction1).toHaveBeenCalledBefore(preAction2)
//@ts-ignore
//@ts-expect-error
expect(preAction2).toHaveBeenCalledBefore(action)
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/sls-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function application<P, D, R>(): Application<P, D, R> {
},

action(actionFunction) {
//@ts-ignore
//@ts-expect-error
if (mainAction) throw new ApplicationError('you can only have a single action')
mainAction = actionFunction
return this
Expand Down
Loading

0 comments on commit 62a2c31

Please sign in to comment.