Skip to content

Commit f006542

Browse files
Wojciech KrysiakWojciech Krysiak
authored andcommitted
feat: migrate to typescript
1 parent 367524e commit f006542

22 files changed

+1374
-917
lines changed

.env-example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NODE_ENV=test
2+
POSTGRES_USER="adminbro"
3+
POSTGRES_PASSWORD="adminbro"
4+
POSTGRES_DATABASE="adminbro-sequelize-test"
5+
POSTGRES_HOST
6+
POSTGRES_PORT

.eslintrc.js

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,59 @@
11
module.exports = {
2-
'env': {
3-
'es6': true,
4-
'node': true,
5-
'mocha': true
2+
env: {
3+
browser: true,
4+
es2020: true,
5+
},
6+
extends: [
7+
'airbnb',
8+
'plugin:react/recommended',
9+
'plugin:@typescript-eslint/recommended',
10+
],
11+
ignorePatterns: [
12+
'*/build/**/*',
13+
'*.json',
14+
'*.txt',
15+
'yarn.lock',
16+
'*.yaml',
17+
],
18+
parser: '@typescript-eslint/parser',
19+
parserOptions: {
20+
ecmaFeatures: {
21+
jsx: true,
622
},
7-
'extends': 'airbnb-base',
8-
'parserOptions': {
9-
'ecmaVersion': 2018,
10-
'sourceType': 'module'
23+
ecmaVersion: 11,
24+
sourceType: 'module',
25+
},
26+
plugins: [
27+
'react',
28+
'@typescript-eslint',
29+
],
30+
rules: {
31+
semi: ['error', 'never'],
32+
'no-unused-vars': 'off',
33+
'import/extensions': 'off',
34+
'import/no-unresolved': 'off',
35+
'react/jsx-filename-extension': 'off',
36+
indent: [
37+
'error',
38+
2,
39+
],
40+
'linebreak-style': ['error', 'unix'],
41+
'object-curly-newline': 'off',
42+
'@typescript-eslint/no-explicit-any': 'off',
43+
},
44+
overrides: [{
45+
files: ['*.tsx'],
46+
rules: {
47+
'react/prop-types': 'off',
48+
'react/jsx-props-no-spreading': 'off',
49+
'import/no-extraneous-dependencies': 'off',
1150
},
12-
'rules': {
13-
'indent': [
14-
'error',
15-
2
16-
],
17-
'linebreak-style': [
18-
'error',
19-
'unix'
20-
],
21-
'quotes': [
22-
'error',
23-
'single'
24-
],
25-
'semi': [
26-
'error',
27-
'never'
28-
],
29-
'import/no-unresolved': 'off',
30-
'no-underscore-dangle': 'off',
31-
'guard-for-in': 'off',
32-
'no-restricted-syntax': 'off',
33-
'no-await-in-loop': 'off',
51+
}, {
52+
files: ['./src/**/*.spec.ts', 'spec/*.ts'],
53+
rules: {
54+
'no-unused-expressions': 'off',
55+
'func-names': 'off',
56+
'import/no-extraneous-dependencies': 'off',
3457
},
35-
overrides: [
36-
{
37-
files: ['*-test.js', '*.spec.js'],
38-
rules: {
39-
'no-unused-expressions': 'off',
40-
'func-names': 'off',
41-
'prefer-arrow-callback': 'off'
42-
}
43-
}
44-
],
45-
globals: {
46-
'expect': true,
47-
'factory': true,
48-
'sandbox': true,
49-
'User': true
50-
}
51-
}
58+
}],
59+
}

.github/workflows/push.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: CI/CD
2-
on: push
2+
on: [push, pull_request]
33
jobs:
44
setup:
55
name: setup
@@ -97,6 +97,7 @@ jobs:
9797
name: Publish
9898
needs: test
9999
runs-on: ubuntu-latest
100+
if: github.event_name == 'push'
100101
steps:
101102
- name: Checkout
102103
uses: actions/checkout@v2

.gitignore

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,119 @@
1-
node_modules
2-
.nyc_output
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
322
coverage
4-
.DS_store
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# Snowpack dependency directory (https://snowpack.dev/)
45+
web_modules/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
.parcel-cache
78+
79+
# Next.js build output
80+
.next
81+
out
82+
83+
# Nuxt.js build / generate output
84+
.nuxt
85+
dist
86+
87+
# Gatsby files
88+
.cache/
89+
# Comment in the public line in if your project uses Gatsby and not Next.js
90+
# https://nextjs.org/blog/next-9-1#public-directory-support
91+
# public
92+
93+
# vuepress build output
94+
.vuepress/dist
95+
96+
# Serverless directories
97+
.serverless/
98+
99+
# FuseBox cache
100+
.fusebox/
101+
102+
# DynamoDB Local files
103+
.dynamodb/
104+
105+
# TernJS port file
106+
.tern-port
107+
108+
# Stores VSCode versions used for testing VSCode extensions
109+
.vscode-test
110+
111+
# yarn v2
112+
.yarn/cache
113+
.yarn/unplugged
114+
.yarn/build-state.yml
115+
.yarn/install-state.gz
116+
.pnp.*
117+
118+
build
119+
types

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
12
/**
23
* @module @admin-bro/sequelize
34
*
@@ -76,7 +77,7 @@
7677
* @type {typeof BaseDatabase}
7778
* @static
7879
*/
79-
const Database = require('./src/database')
80+
const Database = require('./build/database').default
8081

8182
/**
8283
* Implementation of {@link BaseResource} for Sequelize Adapter
@@ -85,6 +86,6 @@ const Database = require('./src/database')
8586
* @type {typeof BaseResource}
8687
* @static
8788
*/
88-
const Resource = require('./src/resource')
89+
const Resource = require('./build/resource').default
8990

9091
module.exports = { Database, Resource }

migrations/20181211174223-create-user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GENDER_CHOICES = {
1+
const GENDER_CHOICES = {
22
MALE: "male",
33
FEMALE: "female",
44
}

models/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ fs
2121
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
2222
})
2323
.forEach(file => {
24-
const model = sequelize['import'](path.join(__dirname, file))
24+
// const model = sequelize['import'](path.join(__dirname, file))
25+
const model = require(path.join(__dirname, file))(sequelize, Sequelize)
2526
db[model.name] = model
2627
})
2728

package.json

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"name": "@admin-bro/sequelize",
33
"version": "1.0.0-beta.3",
44
"description": "Sequelize adapter for AdminBro",
5-
"main": "index.js",
5+
"main": "build/index.js",
6+
"types": "types/index.d.ts",
67
"scripts": {
7-
"test": "./node_modules/mocha/bin/mocha spec/index.js",
8+
"build": "tsc",
9+
"test": "mocha -r ts-node/register src/*.spec.ts",
810
"cover": "NODE_ENV=test ./node_modules/nyc/bin/nyc.js --reporter=html -x=spec -x=coverage --all=true npm test",
9-
"sequelize": "./node_modules/.bin/sequelize",
10-
"lint": "./node_modules/eslint/bin/eslint.js './spec/**/*.js' './src/**/*.js'",
11+
"sequelize": "sequelize",
12+
"lint": "eslint './spec/**/*.ts' './src/**/*.ts'",
1113
"release": "semantic-release"
1214
},
1315
"repository": {
@@ -29,26 +31,32 @@
2931
"@commitlint/cli": "^8.3.5",
3032
"@commitlint/config-conventional": "^8.3.4",
3133
"@semantic-release/git": "^9.0.0",
32-
"@types/mocha": "^7.0.2",
33-
"admin-bro": "^3.0.0",
34+
"@types/chai": "^4.2.12",
35+
"@types/mocha": "^8.0.3",
36+
"@types/sinon": "^9.0.5",
37+
"@types/sinon-chai": "^3.2.4",
38+
"@typescript-eslint/eslint-plugin": "^3.7.0",
39+
"@typescript-eslint/parser": "^3.7.0",
40+
"admin-bro": "^3.2.3",
3441
"chai": "^4.2.0",
35-
"eslint": "^5.10.0",
36-
"eslint-config-airbnb-base": "^13.1.0",
37-
"eslint-plugin-import": "^2.14.0",
38-
"factory-girl": "^5.0.4",
42+
"eslint": "^7.5.0",
43+
"eslint-config-airbnb": "^18.2.0",
44+
"eslint-plugin-import": "^2.22.0",
45+
"eslint-plugin-jsx-a11y": "^6.3.1",
46+
"eslint-plugin-react": "^7.20.3",
47+
"eslint-plugin-react-hooks": "^4.0.8",
3948
"husky": "^4.2.5",
40-
"lodash": "^4.17.11",
4149
"mocha": "^5.2.0",
42-
"mongoose": "^5.3.15",
4350
"nyc": "^12.0.2",
4451
"pg": "^7.7.1",
4552
"semantic-release": "^17.0.7",
46-
"semantic-release-jira-releases-sb": "^0.7.2",
4753
"semantic-release-slack-bot": "^1.6.2",
48-
"sequelize": "^4.42.0",
49-
"sequelize-cli": "^5.4.0",
54+
"sequelize": ">4.42.0",
55+
"sequelize-cli": "^6.2.0",
5056
"sinon": "^7.1.1",
51-
"sinon-chai": "^3.3.0"
57+
"sinon-chai": "^3.3.0",
58+
"ts-node": "^9.0.0",
59+
"typescript": "^4.0.2"
5260
},
5361
"dependencies": {
5462
"escape-regexp": "0.0.1",

spec/index.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)