Skip to content

Commit cd7375b

Browse files
author
Gery Hirschfeld
authored
Merge pull request #42 from w3tecch/update
refactor: add eslint, change to travis and add some sample files
2 parents 14c6c71 + f244c65 commit cd7375b

29 files changed

+3073
-2931
lines changed

.circleci/config.yml

-35
This file was deleted.

.eslintrc.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin'],
8+
extends: [
9+
'plugin:@typescript-eslint/eslint-recommended',
10+
'plugin:@typescript-eslint/recommended',
11+
'prettier',
12+
'prettier/@typescript-eslint',
13+
],
14+
root: true,
15+
env: {
16+
node: true,
17+
jest: true,
18+
},
19+
rules: {
20+
'@typescript-eslint/interface-name-prefix': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
'@typescript-eslint/no-unused-vars': 'off',
24+
'@typescript-eslint/no-use-before-define': 'off',
25+
'@typescript-eslint/no-var-requires': 'off',
26+
},
27+
};

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ lib
44
es
55
coverage
66
.rpt2_cache
7+
test.db
78

89
### node ###
910
logs

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"singleQuote": true,
3-
"trailingComma": "all",
43
"semi": false,
4+
"trailingComma": "all",
55
"tabWidth": 2,
66
"jsxBracketSameLine": true,
77
"printWidth": 120

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
node_js:
3+
- 10
4+
before_install: # if "install" is overridden
5+
# Repo for Yarn
6+
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
7+
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
8+
- sudo apt-get update -qq
9+
- sudo apt-get install -y -qq yarn
10+
cache:
11+
yarn: true
12+
install:
13+
- yarn install
14+
- yarn add -P typeorm
15+
script:
16+
- yarn run lint
17+
- yarn run test
18+
- yarn run build
19+
- yarn run semantic-release || true

README.md

+27-15
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ yarn add typeorm-seeding
4949
```
5050

5151
Optional, for `Faker` types
52+
5253
```bash
5354
npm install -D @types/faker
5455
```
@@ -60,11 +61,18 @@ To configure the path to your seeds and factories change the TypeORM config file
6061
```JavaScript
6162
module.exports = {
6263
...
63-
seeds: ['src/seeds/**/*.seed.ts'],
64-
factories: ['src/factories/**/*.factory.ts'],
64+
seeds: ['src/seeds/**/*{.ts,.js}'],
65+
factories: ['src/factories/**/*{.ts,.js}'],
6566
}
6667
```
6768

69+
or add the following variables to your `.env` file.
70+
71+
```
72+
TYPEORM_SEEDING_FACTORIES=src/seeds/**/*{.ts,.js}
73+
TYPEORM_SEEDING_SEEDS=src/factories/**/*{.ts,.js}
74+
```
75+
6876
![divider](./w3tec-divider.png)
6977

7078
## ❯ Writing Seeders
@@ -82,7 +90,10 @@ export default class CreateUsers implements Seeder {
8290
.createQueryBuilder()
8391
.insert()
8492
.into(User)
85-
.values([{ firstName: 'Timber', lastName: 'Saw' }, { firstName: 'Phantom', lastName: 'Lancer' }])
93+
.values([
94+
{ firstName: 'Timber', lastName: 'Saw' },
95+
{ firstName: 'Phantom', lastName: 'Lancer' },
96+
])
8697
.execute()
8798
}
8899
}
@@ -99,7 +110,7 @@ Once you have written your seeder, you can add this script to your `package.json
99110
}
100111
```
101112

102-
And then
113+
And then
103114

104115
```bash
105116
npm run seed
@@ -112,8 +123,8 @@ For all entities we want to seed, we need to define a factory. To do so we give
112123
Settings can be used to pass some static value into the factory.
113124

114125
```typescript
115-
import Faker from 'faker';
116-
import { define } from "typeorm-seeding";
126+
import Faker from 'faker'
127+
import { define } from 'typeorm-seeding'
117128
import { User } from '../entities'
118129

119130
define(User, (faker: typeof Faker, settings: { roles: string[] }) => {
@@ -134,8 +145,8 @@ define(User, (faker: typeof Faker, settings: { roles: string[] }) => {
134145
Handle relation in the entity factory like this.
135146

136147
```typescript
137-
import Faker from 'faker';
138-
import { define } from 'typeorm-seeding';
148+
import Faker from 'faker'
149+
import { define } from 'typeorm-seeding'
139150
import { Pet } from '../entities'
140151

141152
define(Pet, (faker: typeof Faker, settings: undefined) => {
@@ -145,7 +156,7 @@ define(Pet, (faker: typeof Faker, settings: undefined) => {
145156
const pet = new Pet()
146157
pet.name = name
147158
pet.age = faker.random.number()
148-
pet.user = factory(User)({ roles: ['admin'] })
159+
pet.user = factory(User)({ roles: ['admin'] }) as any
149160
return pet
150161
})
151162
```
@@ -198,7 +209,7 @@ export default class CreatePets implements Seeder {
198209
public async run(factory: Factory, connection: Connection): Promise<any> {
199210
const em = connection.createEntityManager()
200211

201-
await times(10, async n => {
212+
await times(10, async (n) => {
202213
// This creates a pet in the database
203214
const pet = await factory(Pet)().seed()
204215
// This only returns a entity with fake data
@@ -216,11 +227,12 @@ Now you are able to execute your seeds with this command `npm run seed`.
216227

217228
### CLI Options
218229

219-
| Option | Default | Description |
220-
| ------------------ | -------------- | ------------------------------------------------------------- |
221-
| `--class` or `--c` | null | Option to specify a specific seeder class to run individually |
222-
| `--config` | `ormconfig.js` | Path to the typeorm config file (json or js). |
223-
230+
| Option | Default | Description |
231+
| ---------------------- | --------------- | --------------------------------------------------------------------------- |
232+
| `--seed` or `-s` | null | Option to specify a specific seeder class to run individually. |
233+
| `--connection` or `-c` | null | Name of the typeorm connection. Required if there are multiple connections. |
234+
| `--configName` or `-n` | `ormconfig.js` | Name to the typeorm config file. |
235+
| `--root` or `-r` | `process.cwd()` | Path to the typeorm config file. |
224236

225237
## ❯ License
226238

ormconfig.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path')
2+
3+
module.exports = [
4+
{
5+
name: 'sample',
6+
type: 'sqlite',
7+
database: 'test.db',
8+
entities: ['sample/entities/**/*{.ts,.js}'],
9+
factories: ['sample/factories/**/*{.ts,.js}'],
10+
seeds: ['sample/seeds/**/*{.ts,.js}'],
11+
},
12+
{
13+
name: 'other',
14+
type: 'sqlite',
15+
database: 'test.db',
16+
entities: ['sample/entities/**/*{.ts,.js}'],
17+
factories: ['sample/factories/**/*{.ts,.js}'],
18+
seeds: ['sample/seeds/**/*{.ts,.js}'],
19+
}
20+
]

package.json

+37-35
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
{
22
"name": "typeorm-seeding",
3-
"version": "0.0.0-development",
3+
"version": "1.3.0",
44
"description": "TypeORM seeding",
55
"main": "dist/typeorm-seeding.js",
6-
"module": "dist/typeorm-seeding.es.js",
6+
"types": "dist/typeorm-seeding.d.ts",
77
"bin": {
88
"typeorm-seeding": "dist/cli.js"
99
},
1010
"files": [
1111
"dist"
1212
],
13-
"types": "dist/typeorm-seeding.d.ts",
1413
"scripts": {
14+
"prebuild": "rimraf dist",
1515
"format": "prettier --write \"src/**/*.ts\"",
16-
"lint": "tslint -p tsconfig.json -c tslint.json",
17-
"build": "npm run clean && rollup -c",
16+
"lint": "eslint \"src/**/*.ts\" --fix",
17+
"build": "tsc --project ./tsconfig.build.json",
1818
"watch": "rollup -cw",
19-
"clean": "rimraf dist",
2019
"test": "jest",
2120
"test:watch": "jest --watch",
2221
"test:cov": "jest --coverage",
23-
"semantic-release": "semantic-release"
22+
"semantic-release": "semantic-release",
23+
"schema:drop": "ts-node ./node_modules/typeorm/cli.js schema:drop -c sample",
24+
"schema:sync": "ts-node ./node_modules/typeorm/cli.js schema:sync -c sample",
25+
"schema:log": "ts-node ./node_modules/typeorm/cli.js schema:log -c sample",
26+
"seed:run": "ts-node ./src/cli.ts seed -c sample",
27+
"seed:config": "ts-node ./src/cli.ts config -c sample"
2428
},
2529
"license": "MIT",
2630
"author": "w3tec.ch <[email protected]>",
@@ -32,40 +36,38 @@
3236
}
3337
],
3438
"devDependencies": {
35-
"@types/faker": "^4.1.4",
36-
"@types/jest": "^24.0.13",
37-
"@types/yargs": "^13.0.0",
38-
"jest": "^24.8.0",
39-
"prettier": "^1.17.1",
40-
"rimraf": "^2.6.2",
41-
"rollup": "^0.66.2",
42-
"rollup-plugin-cli": "^0.1.5",
43-
"rollup-plugin-commonjs": "^9.1.8",
44-
"rollup-plugin-hashbang": "^2.2.2",
45-
"rollup-plugin-json": "^4.0.0",
46-
"rollup-plugin-node-builtins": "^2.1.2",
47-
"rollup-plugin-node-globals": "^1.4.0",
48-
"rollup-plugin-node-resolve": "^3.4.0",
49-
"rollup-plugin-typescript2": "^0.21.1",
50-
"semantic-release": "^15.13.27",
51-
"ts-jest": "^24.0.2",
52-
"tslint": "^5.11.0",
53-
"tslint-config-prettier": "^1.18.0",
54-
"tslint-plugin-prettier": "^2.0.1",
55-
"typescript": "^3.0.3"
39+
"@types/chalk": "^2.2.0",
40+
"@types/faker": "^4.1.11",
41+
"@types/glob": "7.1.1",
42+
"@types/jest": "^25.1.4",
43+
"@types/node": "13.9.8",
44+
"@types/yargs": "^15.0.4",
45+
"@typescript-eslint/eslint-plugin": "^2.26.0",
46+
"@typescript-eslint/parser": "^2.26.0",
47+
"eslint": "^6.8.0",
48+
"eslint-config-prettier": "^6.10.1",
49+
"eslint-plugin-import": "^2.20.2",
50+
"jest": "^25.2.6",
51+
"prettier": "^2.0.2",
52+
"rimraf": "^3.0.2",
53+
"semantic-release": "^17.0.4",
54+
"sqlite": "^3.0.6",
55+
"ts-jest": "^25.3.0",
56+
"typescript": "^3.8.3"
5657
},
5758
"dependencies": {
58-
"@types/glob": "7.1.1",
59-
"@types/node": "12.0.4",
60-
"chalk": "2.4.2",
59+
"chalk": "^4.0.0",
6160
"faker": "4.1.0",
62-
"glob": "7.1.3",
63-
"ora": "3.4.0",
61+
"glob": "7.1.6",
62+
"ora": "4.0.3",
6463
"reflect-metadata": "0.1.13",
65-
"yargs": "13.2.4"
64+
"yargs": "15.3.1"
6665
},
6766
"peerDependencies": {
68-
"typeorm": "^0.2.20"
67+
"typeorm": "^0.2.24"
68+
},
69+
"resolutions": {
70+
"mem": ">=4.0.0"
6971
},
7072
"jest": {
7173
"moduleFileExtensions": [

0 commit comments

Comments
 (0)