Skip to content

Commit

Permalink
Merge pull request #1 from Eveble/develop
Browse files Browse the repository at this point in the history
feat: add helpers
  • Loading branch information
desivi authored Jun 27, 2020
2 parents 9bc79b6 + 1a78d0c commit b5c6484
Show file tree
Hide file tree
Showing 62 changed files with 2,192 additions and 154 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"max-classes-per-file": 0,
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"no-useless-constructor": 0,
"import/extensions": 0,
"no-unused-vars": [
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
This PR CHANGES.

## Todos

- [ ] Todo
This PR changes.

---

Expand Down
76 changes: 25 additions & 51 deletions .github/workflows/update-pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Update Pull Request"
name: 'Update Pull Request'

on:
pull_request:
Expand All @@ -14,62 +14,36 @@ jobs:
CONFIGURATION_PATH: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value
format_fix_pr_information:
runs-on: ubuntu-latest
name: Format fix pull request
name: Format fix Pull request
if: ${{ contains(github.event.pull_request.title, 'fix') }}
needs: [assign_labels]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read 'fix' body template
id: pull_request_body
uses: juliangruber/read-file-action@v1
with:
path: ./.github/ISSUE_TEMPLATE/fix_template.md
- name: Update Pull Request
uses: tzkhan/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
branch-regex: ${{ secrets.PROJECT_KEY_PATTERN }} # [a-zA-Z0-9_]{3}-[\d]+
lowercase-branch: true
title-template: '[%branch%]'
replace-title: false
title-prefix-space: true
uppercase-title: false
body-template: |
[Link to %branch%](${{ secrets.TICKET_URL }}%branch%)
---
${{ steps.pull_request_body.outputs.content }}
replace-body: false
body-prefix-newline-count: 2
uppercase-body: true
- uses: actions/checkout@v2
- name: Read 'fix' body template
id: pull_request_body
uses: juliangruber/read-file-action@v1
with:
path: ./.github/PULL_REQUEST_TEMPLATE/bug_fix.md
- name: Update Pull Request
uses: AsasInnab/pr-body-action@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
body: ${{ steps.pull_request_body.outputs.content }}
format_default_pr_information:
runs-on: ubuntu-latest
name: Format default pull request
name: Format default Pull request
if: >
github.actor != 'github-actions[bot]' && (! contains(github.event.pull_request.labels.*.name, 'bug') && ! contains(github.event.pull_request.labels.*.name, 'fix'))
needs: [assign_labels]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read 'default' body template
id: pull_request_body
uses: juliangruber/read-file-action@v1
with:
path: ./.github/ISSUE_TEMPLATE/pull_request_template.md
- name: Update Pull Request
uses: tzkhan/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
branch-regex: ${{ secrets.PROJECT_KEY_PATTERN }} # [a-zA-Z0-9_]{3}-[\d]+
lowercase-branch: true
title-template: '[%branch%]'
replace-title: false
title-prefix-space: true
uppercase-title: false
body-template: |
[Link to %branch%](${{ secrets.TICKET_URL }}%branch%)
---
${{ steps.pull_request_body.outputs.content }}
replace-body: false
body-prefix-newline-count: 2
uppercase-body: true
- uses: actions/checkout@v2
- name: Read 'default' body template
id: pull_request_body
uses: juliangruber/read-file-action@v1
with:
path: ./.github/pull_request_template.md
- name: Update Pull Request
uses: AsasInnab/pr-body-action@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
body: ${{ steps.pull_request_body.outputs.content }}
40 changes: 40 additions & 0 deletions .github/workflows/update-tracked-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Update tracked Pull Request'

on:
pull_request:
types: [opened]

jobs:
format:
name: Format tracked Pull Request
runs-on: ubuntu-latest
steps:
- name: Initialize workflow variables
id: vars
shell: bash
run: |
PROJECT_KEY=$PROJECT_KEY
echo ::set-output name=PROJECT_KEY::${PROJECT_KEY}
unset HAS_PROJECT_KEY
if [ -n $PROJECT_KEY ]; then HAS_PROJECT_KEY='true' ; fi
echo set-output name=HAS_PROJECT_KEY::${HAS_PROJECT_KEY}
echo ::set-output name=HAS_PROJECT_KEY::${HAS_PROJECT_KEY}
env:
PROJECT_KEY: '${{ secrets.PROJECT_KEY }}'
- name: Update Pull Request
if: ${{ steps.vars.outputs.HAS_PROJECT_KEY && contains(github.event.pull_request.title, steps.vars.outputs.PROJECT_KEY ) }}
uses: tzkhan/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
branch-regex: ${{ secrets.PROJECT_KEY_PATTERN }} # [a-zA-Z0-9_]{3}-[\d]+
lowercase-branch: true
title-template: '[%branch%]'
replace-title: false
title-prefix-space: true
uppercase-title: false
body-template: |
[Link to %branch%](${{ secrets.TICKET_URL }}%branch%)
---
replace-body: false
body-prefix-newline-count: 2
uppercase-body: true
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adam Desivi <[email protected]>
29 changes: 1 addition & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,13 @@ or
yarn add @eveble/helpers
```

You'll also need to [install Eveble][eveble-installation].

## Complementary Packages

Most likely, you'll also need [the Eveble testing framework][eveble-testing]:

```bash
npm install @eveble/eveble
npm install --save-dev @eveble/testing
```

## Create a Eveble App

The recommended way to start new apps with Eveble is by using the [official Eveble boilerplate][eveble-boilerplate]:

```bash
# Clone the repository
$ git clone https://github.com/eveble/eveble-boilerplate.git <YOUR_PROJECT_NAME>
# Go into the repository
$ cd <YOUR_PROJECT_NAME>
# Run setup
$ npm run setup
```

## Documentation

The <@eveble/helpers> docs are now published at **[https://eveble.github.io/helpers/][package-homepage]** .
The **@eveble/helpers** docs are published at **[https://eveble.github.io/helpers/][package-homepage]** .

## License

[MIT](LICENSE)

[package-homepage]: https://eveble.github.io/helpers/
[nodejs]: https://nodejs.org/
[eveble-installation]: https://eveble.github.com/docs/01-the-basics/02-installation
[eveble-boilerplate]: https://github.com/eveble/eveble-boilerplate
[eveble-testing]: https://github.com/eveble/testing
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
},
"repository": {
"type": "git",
"url": "git://github.com/eveble/eveble-boilerplate.git"
"url": "git://github.com/eveble/helpers.git"
},
"dependencies": {
"reflect-metadata": "^0.1.13",
"tsruntime": "^3.0.0-beta.1",
"ttypescript": "^1.5.10"
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@types/chai-as-promised": "^7.1.2",
Expand Down Expand Up @@ -88,19 +86,20 @@
"scripts": {
"explain": "./node_modules/.bin/npm-scripts-info",
"reset": "git clean -dfx && git reset --hard && npm i",
"test:integration:watch": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json TS_NODE_COMPILER=\"ttypescript\" ./node_modules/.bin/mocha --watch --config ./.mocharc.json ./test/integration",
"test:integration": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json TS_NODE_COMPILER=\"ttypescript\" ./node_modules/.bin/mocha --config ./.mocharc.json ./test/integration",
"test:unit:watch": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json TS_NODE_COMPILER=\"ttypescript\" ./node_modules/.bin/mocha --watch --config ./.mocharc.json ./test/unit",
"test:unit": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json TS_NODE_COMPILER=\"ttypescript\" ./node_modules/.bin/mocha --config ./.mocharc.json ./test/unit",
"test:integration:watch": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json ./node_modules/.bin/mocha --watch --config ./.mocharc.json ./test/integration",
"test:integration": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json ./node_modules/.bin/mocha --config ./.mocharc.json ./test/integration",
"test:unit:watch": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json ./node_modules/.bin/mocha --watch --config ./.mocharc.json ./test/unit",
"test:unit": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json ./node_modules/.bin/mocha --config ./.mocharc.json ./test/unit",
"test:watch": "npm test -- --watch",
"test": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json TS_NODE_COMPILER=\"ttypescript\" ./node_modules/.bin/mocha --config ./.mocharc.json",
"test": "./node_modules/.bin/cross-env NODE_ENV=test TS_NODE_PROJECT=./test/tsconfig.json ./node_modules/.bin/mocha --config ./.mocharc.json",
"cz": "node_modules/.bin/git-cz",
"commit": "npm run cz",
"build:cjs": "./node_modules/.bin/cross-env NODE_ENV=cjs rollup -c",
"build:es": "./node_modules/.bin/cross-env NODE_ENV=es rollup -c",
"build": "npm run clean && npm run build:es && npm run build:cjs",
"clean": "./node_modules/.bin/rimraf dist",
"lint": "./node_modules/.bin/eslint --fix 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
"test:lint": "./node_modules/.bin/eslint 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
"format": "node_modules/.bin/tsc --noEmit && ./node_modules/.bin/prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
"format:staged": "./node_modules/.bin/pretty-quick --staged --no-restage --bail",
"test:format": "./node_modules/.bin/prettier --check 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
Expand Down Expand Up @@ -129,6 +128,7 @@
"build": "Clean and build(bundle) the project with rollup",
"clean": "Clean dist folder",
"lint": "Try to automatically fix any linting problems",
"test:lint": "Validate linting",
"format": "Try to automatically fix any formatting problems",
"format:staged": "Try to automatically fix any formatting problems for staged files or throw error",
"test:format": "Validate formatting",
Expand All @@ -152,4 +152,4 @@
"isEvebleRequired": false,
"isTestingRequired": false,
"private": false
}
}
5 changes: 2 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import commonjs from 'rollup-plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import tsPlugin from 'rollup-plugin-typescript2';
import json from 'rollup-plugin-json';
import ttypescript from 'ttypescript';

import typescript from 'typescript';
import sourceMaps from 'rollup-plugin-sourcemaps';

const env = process.env.NODE_ENV;
Expand All @@ -29,7 +28,7 @@ export default {
commonjs(),
filesize(),
tsPlugin({
typescript: ttypescript,
typescript: typescript,
}),
sourceMaps(),
],
Expand Down
36 changes: 36 additions & 0 deletions src/constants/literal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export const NATIVE_ERROR_CLASSES = [
Error,
EvalError,
RangeError,
ReferenceError,
SyntaxError,
TypeError,
URIError,
];

export const NATIVE_TYPES = {
// Order is important!
string: String,
boolean: Boolean,
date: Date,
number: Number,
regexp: RegExp,
array: Array,
symbol: Symbol,
map: Map,
function: Function,
object: Object,
};

export const NATIVE_CONSTRUCTOR_NAMES = [
'String',
'Boolean',
'Date',
'Number',
'RegExp',
'Array',
'Symbol',
'Map',
'Function',
'Object',
];
1 change: 1 addition & 0 deletions src/constants/metadata-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TYPE_NAME_KEY = Symbol('eveble:typeName');
57 changes: 57 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Constants
import * as LITERAL from './constants/literal';
import * as METADATA_KEYS from './constants/metadata-keys';
// Types
import { types } from './types';
// Testing
import { isMocha } from './testing/is-mocha';
import { isMochaInWatchMode } from './testing/is-mocha-in-watch-mode';
import { isSinonClockDate } from './testing/is-sinon-clock-date';
// Types
import { getNativeType } from './types/get-native-type';
import { getScalarType } from './types/get-scalar-type';
import { getTypeName } from './types/get-type-name';
import { hasTypeName } from './types/has-type-name';
import { setTypeName } from './types/set-type-name';
import { isClassInstance } from './types/is-class-instance';
import { isClass } from './types/is-class';
import { isConstructor } from './types/is-constructor';
import { isErrorClass } from './types/is-error-class';
import { isErrorInstance } from './types/is-error-instance';
import { isMultidimensionalArray } from './types/is-multidimensional-array';
import { isNativeType } from './types/is-native-type';
import { isNativeTypeInstance } from './types/is-native-type-instance';
import { isScalarType } from './types/is-scalar-type';
import { isSubclassOf } from './types/is-subclass-of';
import { superClass } from './types/super-class';
import { superPrototype } from './types/super-prototype';

export {
// Constants
LITERAL,
METADATA_KEYS,
// Types
types,
// Testing
isMocha,
isMochaInWatchMode,
isSinonClockDate,
// Types
getNativeType,
getScalarType,
getTypeName,
hasTypeName,
setTypeName,
isClassInstance,
isClass,
isConstructor,
isErrorClass,
isErrorInstance,
isMultidimensionalArray,
isNativeType,
isNativeTypeInstance,
isScalarType,
isSubclassOf,
superClass,
superPrototype,
};
8 changes: 8 additions & 0 deletions src/testing/is-mocha-in-watch-mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Evaluates if Mocha is running in watch('--watch') mode.
* @param nodeProcess - Instance of `NodeJS.Process`.
* @returns Returns true if Mocha is running in watch mode, else false.
*/
export function isMochaInWatchMode(nodeProcess: NodeJS.Process): boolean {
return nodeProcess.argv.slice(2).includes('--watch');
}
12 changes: 12 additions & 0 deletions src/testing/is-mocha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Evaluates if Mocha is running on context(global/window) i.e. testing environment is present.
* @param context - Global context which is evaluated.
* @returns Returns true if Mocha is running on context, else false.
*/
export function isMocha(context: any): boolean {
return ['afterEach', 'after', 'beforeEach', 'before', 'describe', 'it'].every(
(fnName) => {
return context[fnName] instanceof Function;
}
);
}
Loading

0 comments on commit b5c6484

Please sign in to comment.