-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add eslint, change to travis and add some sample files
- Loading branch information
hirsch
committed
Apr 9, 2020
1 parent
14c6c71
commit d5dea06
Showing
24 changed files
with
2,906 additions
and
2,851 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-unused-vars': 'off', | ||
'@typescript-eslint/no-use-before-define': 'off', | ||
'@typescript-eslint/no-var-requires': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ lib | |
es | ||
coverage | ||
.rpt2_cache | ||
test.db | ||
|
||
### node ### | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
language: node_js | ||
node_js: | ||
- 10 | ||
before_install: # if "install" is overridden | ||
# Repo for Yarn | ||
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg | ||
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list | ||
- sudo apt-get update -qq | ||
- sudo apt-get install -y -qq yarn | ||
cache: | ||
yarn: true | ||
install: | ||
- yarn install | ||
script: | ||
- yarn install | ||
- yarn run lint | ||
- yarn run test | ||
- yarn run build | ||
- yarn run semantic-release || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require('path') | ||
|
||
module.exports = { | ||
type: 'sqlite', | ||
database: './test.db', | ||
entities: ['sample/entities/**/*{.ts,.js}'], | ||
factories: ['sample/factories/**/*{.ts,.js}'], | ||
seeds: ['sample/seeds/**/*{.ts,.js}'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
{ | ||
"name": "typeorm-seeding", | ||
"version": "0.0.0-development", | ||
"version": "1.3.0", | ||
"description": "TypeORM seeding", | ||
"main": "dist/typeorm-seeding.js", | ||
"module": "dist/typeorm-seeding.es.js", | ||
"types": "dist/typeorm-seeding.d.ts", | ||
"bin": { | ||
"typeorm-seeding": "dist/cli.js" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"types": "dist/typeorm-seeding.d.ts", | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "tslint -p tsconfig.json -c tslint.json", | ||
"build": "npm run clean && rollup -c", | ||
"lint": "eslint \"src/**/*.ts\" --fix", | ||
"build": "tsc --project ./tsconfig.build.json", | ||
"watch": "rollup -cw", | ||
"clean": "rimraf dist", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage", | ||
"semantic-release": "semantic-release" | ||
"semantic-release": "semantic-release", | ||
"schema:drop": "ts-node ./node_modules/typeorm/cli.js schema:drop", | ||
"schema:sync": "ts-node ./node_modules/typeorm/cli.js schema:sync", | ||
"schema:log": "ts-node ./node_modules/typeorm/cli.js schema:log", | ||
"seed:run": "ts-node ./src/cli.ts seed", | ||
"seed:config": "ts-node ./src/cli.ts config" | ||
}, | ||
"license": "MIT", | ||
"author": "w3tec.ch <[email protected]>", | ||
|
@@ -32,40 +36,38 @@ | |
} | ||
], | ||
"devDependencies": { | ||
"@types/faker": "^4.1.4", | ||
"@types/jest": "^24.0.13", | ||
"@types/yargs": "^13.0.0", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.17.1", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.66.2", | ||
"rollup-plugin-cli": "^0.1.5", | ||
"rollup-plugin-commonjs": "^9.1.8", | ||
"rollup-plugin-hashbang": "^2.2.2", | ||
"rollup-plugin-json": "^4.0.0", | ||
"rollup-plugin-node-builtins": "^2.1.2", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-typescript2": "^0.21.1", | ||
"semantic-release": "^15.13.27", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "^5.11.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"tslint-plugin-prettier": "^2.0.1", | ||
"typescript": "^3.0.3" | ||
"@types/chalk": "^2.2.0", | ||
"@types/faker": "^4.1.11", | ||
"@types/glob": "7.1.1", | ||
"@types/jest": "^25.1.4", | ||
"@types/node": "13.9.8", | ||
"@types/yargs": "^15.0.4", | ||
"@typescript-eslint/eslint-plugin": "^2.26.0", | ||
"@typescript-eslint/parser": "^2.26.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-plugin-import": "^2.20.2", | ||
"jest": "^25.2.6", | ||
"prettier": "^2.0.2", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^17.0.4", | ||
"sqlite": "^3.0.6", | ||
"ts-jest": "^25.3.0", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"@types/glob": "7.1.1", | ||
"@types/node": "12.0.4", | ||
"chalk": "2.4.2", | ||
"chalk": "^4.0.0", | ||
"faker": "4.1.0", | ||
"glob": "7.1.3", | ||
"ora": "3.4.0", | ||
"glob": "7.1.6", | ||
"ora": "4.0.3", | ||
"reflect-metadata": "0.1.13", | ||
"yargs": "13.2.4" | ||
"yargs": "15.3.1" | ||
}, | ||
"peerDependencies": { | ||
"typeorm": "^0.2.20" | ||
"typeorm": "^0.2.24" | ||
}, | ||
"resolutions": { | ||
"mem": ">=4.0.0" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm' | ||
import { User } from './User.entity' | ||
|
||
@Entity() | ||
export class Pet { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string | ||
|
||
@Column() | ||
name: string | ||
|
||
@Column() | ||
age: number | ||
|
||
@ManyToOne((type) => User, (user) => user.pets) | ||
@JoinColumn({ name: 'user_id' }) | ||
user: User | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm' | ||
import { Pet } from './Pet.entity' | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string | ||
|
||
@Column() | ||
firstName: string | ||
|
||
@Column() | ||
lastName: string | ||
|
||
@Column() | ||
email: string | ||
|
||
@OneToMany((type) => Pet, (pet) => pet.user) | ||
pets: Pet[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Faker from 'faker' | ||
import { define, factory } from '../../dist/typeorm-seeding' | ||
import { Pet } from '../entities/Pet.entity' | ||
import { User } from '../entities/User.entity' | ||
|
||
define(Pet, (faker: typeof Faker) => { | ||
const gender = faker.random.number(1) | ||
const name = faker.name.firstName(gender) | ||
|
||
const pet = new Pet() | ||
pet.name = name | ||
pet.age = faker.random.number() | ||
// pet.user = factory(User)({ roles: ['admin'] }) | ||
return pet | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as Faker from 'faker' | ||
import { define } from '../../dist/typeorm-seeding' | ||
import { User } from '../entities/User.entity' | ||
|
||
define(User, (faker: typeof Faker) => { | ||
const gender = faker.random.number(1) | ||
const firstName = faker.name.firstName(gender) | ||
const lastName = faker.name.lastName(gender) | ||
const email = faker.internet.email(firstName, lastName) | ||
|
||
const user = new User() | ||
user.firstName = firstName | ||
user.lastName = lastName | ||
user.email = email | ||
return user | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Connection } from 'typeorm' | ||
import { Seeder, Factory } from '../../src/types' | ||
import { times } from '../../src/typeorm-seeding' | ||
import { Pet } from '../entities/Pet.entity' | ||
import { User } from '../entities/User.entity' | ||
|
||
export default class CreatePets implements Seeder { | ||
public async run(factory: Factory, connection: Connection): Promise<any> { | ||
const em = connection.createEntityManager() | ||
|
||
await times(10, async (n) => { | ||
// This creates a pet in the database | ||
const pet = await factory(Pet)().seed() | ||
// This only returns a entity with fake data | ||
const user = await factory(User)().make() | ||
user.pets = [pet] | ||
await em.save(user) | ||
}) | ||
} | ||
} |
Oops, something went wrong.