Skip to content

Commit

Permalink
Merge pull request #1 from SecJS/feat/len-add-ci
Browse files Browse the repository at this point in the history
feat: Add CI
  • Loading branch information
jlenon7 authored Sep 21, 2021
2 parents ba10d6a + affce06 commit 70a687c
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 5,081 deletions.
Binary file removed .github/core.jpg
Binary file not shown.
Binary file added .github/core.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 3 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CD Core
name: CI Core

on:
push:
Expand All @@ -22,13 +22,10 @@ jobs:
registry-url: 'https://registry.npmjs.org'

- name: Download dependencies
run: yarn

- name: Run the tests inside project
run: yarn test
run: npm install

- name: Transpile typescript to javascript
run: yarn build
run: npm run build

- name: Automatic GitHub Release
uses: justincy/github-action-npm-release@2.0.1
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI Core

on:
pull_request:
branches:
- master

jobs:
build:

runs-on: ubuntu-18.04

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-node@v1
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'

- name: Download dependencies
run: npm install

- name: Verify project lint and try to fix it
run: npm run lint:fix

- name: Run the tests from project
run: npm run test
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@

The intention behind this repository is to concentrate all `SecJS` libraries to create an HTTP server to any NodeJS project.

<img src=".github/core.jpg" width="200px" align="right" hspace="30px" vspace="100px">
<img src=".github/core.png" width="200px" align="right" hspace="30px" vspace="100px">

## WARN 🛑⚠️

> This project is under `development` do not use it until releases v2.0.0.
## Installation

This project depends on [`@secjs/utils`]('https://github.com/SecJS/Utils')
> To use the high potential from this package you need to install first this other packages from SecJS,
> it keeps as dev dependency because one day `@secjs/core` will install everything once.
```bash
yarn add @secjs/utils
npm install @secjs/utils @secjs/exceptions
```

Then install the project
> Then you can install the package using:
```bash
yarn add @secjs/core
npm install @secjs/core
```

## Decorators
Expand Down Expand Up @@ -84,6 +85,4 @@ class TestController {

---

## License

Made with 🖤 by [jlenon7](https://github.com/jlenon7) :wave:
90 changes: 56 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
{
"name": "@secjs/core",
"version": "1.6.9",
"version": "1.7.0",
"license": "MIT",
"author": "João Lenon",
"repository": "https://github.com/SecJS/Core.git",
"bugs": "https://github.com/SecJS/Core/issues",
"homepage": "https://github.com/SecJS/Core#readme",
"scripts": {
"lint": "yarn eslint --fix",
"build": "tsc",
"test": "jest --verbose"
"test": "jest --verbose",
"test:debug": "DEBUG=* jest --verbose",
"lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix"
},
"devDependencies": {
"@secjs/utils": "^1.2.2",
"@types/jest": "26.0.22",
"@types/node": "^14.14.3",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^3.0.9",
"jest": "26.6.3",
"lint-staged": "^9.4.3",
"luxon": "^1.25.0",
"prettier": "^2.0.5",
"reflect-metadata": "^0.1.13",
"ts-jest": "26.5.4",
"ts-node": "^8.9.0",
"typescript": "^4.0.3"
"@secjs/exceptions": "1.0.1",
"@secjs/utils": "1.3.6",
"@types/jest": "27.0.1",
"@types/node": "14.17.0",
"@typescript-eslint/eslint-plugin": "4.31.0",
"@typescript-eslint/parser": "4.31.0",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",
"eslint-config-standard": "16.0.3",
"eslint-import-resolver-typescript": "2.4.0",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-standard": "5.0.0",
"husky": "3.0.9",
"jest": "27.1.0",
"lint-staged": "11.1.2",
"prettier": "2.3.2",
"reflect-metadata": "0.1.13",
"ts-jest": "27.0.5",
"ts-loader": "9.2.3",
"ts-node": "10.0.0",
"tsconfig-paths": "3.9.0",
"typescript": "4.3.5",
"uuid": "8.3.2"
},
"lint-staged": {
"*.js": [
Expand Down Expand Up @@ -93,31 +100,46 @@
},
"extends": [
"standard",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"globals": {
"use": true,
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"prettier"
],
"rules": {
"dot-notation": "off",
"camelcase": "off",
"no-undef": "off",
"@typescript-eslint/no-var-requires": "off",
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-explicit-any": "off",
"prettier/prettier": "error",
"camelcase": "off"
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "_"
}
]
}
},
"files": [
"base",
"utils",
"contracts",
"index.ts",
"index.d.ts",
"index.js"
],
"dependencies": {}
"src/**/*.js",
"src/**/*.d.ts",
"index.js",
"index.d.ts"
]
}
20 changes: 16 additions & 4 deletions src/Decorators/Http/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function Controller(path?: string | string[]): ClassDecorator {

path = pathPattern(path)

return (target: object) => {
return (target: any) => {
const routes: any[] = Reflect.getMetadata('controller:routes', target)

if (routes && routes.length) {
Expand All @@ -15,17 +15,29 @@ export function Controller(path?: string | string[]): ClassDecorator {
path.forEach(p => {
if (p === '/') return

routes.forEach(route => routesPrefixed.push({ path: `${p}${route.path}`, method: route.method }))
routes.forEach(route =>
routesPrefixed.push({
path: `${p}${route.path}`,
method: route.method,
}),
)
})

Reflect.defineMetadata('controller:routes', routesPrefixed, target)
} else {
const routesPrefixed = path === '/' ? routes : routes.filter(route => route.path = `${path}${route.path}`)
const routesPrefixed =
path === '/'
? routes
: routes.filter(route => (route.path = `${path}${route.path}`))

Reflect.defineMetadata('controller:routes', routesPrefixed, target)
}
}

Reflect.defineMetadata('controller:path', typeof path === 'string' ? [path] : path, target)
Reflect.defineMetadata(
'controller:path',
typeof path === 'string' ? [path] : path,
target,
)
}
}
23 changes: 17 additions & 6 deletions src/Decorators/Http/RequestMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,43 @@ export enum RequestMethod {
HEAD,
}

export function RequestMapper(path: string | string[] = '/', method: RequestMethod = RequestMethod.GET): MethodDecorator {
export function RequestMapper(
path: string | string[] = '/',
method: RequestMethod = RequestMethod.GET,
): MethodDecorator {
if (path.length && !path[0]) path = '/'

path = pathPattern(path)

return (
target: Object,
target: any,
key: string | symbol,
descriptor: TypedPropertyDescriptor<any>,
) => {
let routes = Reflect.getMetadata('controller:routes', target.constructor)

if (!routes) {
Reflect.defineMetadata('controller:routes', routes = [], target.constructor)
Reflect.defineMetadata(
'controller:routes',
(routes = []),
target.constructor,
)
}

typeof path === 'string' ? routes.push({ path, method }) : path.forEach(p => routes.push({ path: p, method }))
typeof path === 'string'
? routes.push({ path, method })
: path.forEach(p => routes.push({ path: p, method }))

Reflect.defineMetadata('controller:routes', routes, target.constructor)

return descriptor
}
}


export const createRequestDecorator = (method: RequestMethod) => (path?: string | string[]): MethodDecorator => RequestMapper(path, method)
export const createRequestDecorator =
(method: RequestMethod) =>
(path?: string | string[]): MethodDecorator =>
RequestMapper(path, method)

export const Get = createRequestDecorator(RequestMethod.GET)
export const Post = createRequestDecorator(RequestMethod.POST)
Expand Down
8 changes: 6 additions & 2 deletions tests/Decorators/Http/controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ describe('\n Controller Decorator', () => {
@Controller()
class TestController {}

expect(Reflect.getMetadata('controller:path', TestController)).toStrictEqual(['/'])
expect(
Reflect.getMetadata('controller:path', TestController),
).toStrictEqual(['/'])
})

it('should be able to add a path to the controller', async () => {
Expand All @@ -16,6 +18,8 @@ describe('\n Controller Decorator', () => {
@Controller(path)
class TestController {}

expect(Reflect.getMetadata('controller:path', TestController)).toStrictEqual([path])
expect(
Reflect.getMetadata('controller:path', TestController),
).toStrictEqual([path])
})
})
Loading

0 comments on commit 70a687c

Please sign in to comment.