Skip to content

Commit cd6b775

Browse files
author
Mubarak Imam
committed
chore(backend): refactor backend for ci
- add gulp task to copy assets to build directory - refactor ormconfig - add pre and post build tasks - improve restrictions on tsconfig - exclude migrations folder from tslint - move migrations under src directory - fix environment issues in config - update add-typescript-to-cypress to a better version - add gulp to package.json
1 parent fb46d49 commit cd6b775

File tree

13 files changed

+2059
-963
lines changed

13 files changed

+2059
-963
lines changed

nestpoc-api/gulpfile.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as gulp from 'gulp';
2+
3+
export default () => {
4+
return gulp.src(['./src/**/*', '!./**/*.ts'])
5+
.pipe(gulp.dest('dist'));
6+
};

nestpoc-api/ormconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
"username": "postgres",
66
"password": "",
77
"database": "nestpoc",
8-
"synchronize": true,
8+
"synchronize": false,
99
"logging": false,
1010
"entities": [
11-
"./**/models/*.model.ts"
11+
"./src/modules/**/models/*.model.ts"
1212
],
1313
"migrations": [
14-
"./migrations/*.ts"
14+
"./src/migrations/*.ts"
1515
],
1616
"subscribers": [
17-
"src/**/subscribers/*.ts"
17+
"./src/**/subscribers/*.ts"
1818
],
1919
"cli": {
20-
"migrationsDir": "./migrations"
20+
"migrationsDir": "./src/migrations"
2121
}
2222
}

nestpoc-api/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"prebuild": "rimraf dist",
99
"tsc": "ts-node -r tsconfig-paths/register",
1010
"build": "tsc -b tsconfig.build.json",
11+
"postbuild": "tscpaths -p tsconfig.json -s ./src -o ./dist && $(npm bin)/gulp",
1112
"format": "prettier --write \"src/**/*.ts\"",
1213
"start": "yarn tsc src/main.ts",
1314
"start:dev": "nodemon",
1415
"start:debug": "nodemon --config nodemon-debug.json",
1516
"prestart:prod": "yarn run build",
16-
"start:prod": "node dist/main.js",
17+
"start:p": "node dist/main.js",
18+
"start:prod": "yarn start:p",
1719
"lint": "tslint -p tsconfig.json -c tslint.json",
1820
"test:unit": "jest --config ./test/jest-unit.json",
1921
"test:unit:watch": "yarn test:unit:cov --watch",
@@ -46,6 +48,7 @@
4648
"dotenv": "^7.0.0",
4749
"graphql": "^14.2.1",
4850
"graphql-tools": "^4.0.4",
51+
"gulp": "^4.0.2",
4952
"install": "^0.12.2",
5053
"nest-router": "^1.0.9",
5154
"passport": "^0.4.0",
@@ -73,6 +76,7 @@
7376
"ts-jest": "^23.10.5",
7477
"ts-node": "^7.0.1",
7578
"tsconfig-paths": "^3.7.0",
79+
"tscpaths": "^0.0.9",
7680
"tslint": "5.14.0",
7781
"tslint-config-airbnb": "^5.11.1",
7882
"typescript": "^3.4.1",

nestpoc-api/migrations/1555134026445-add necessary schemas.ts renamed to nestpoc-api/src/migrations/1555134026445-add necessary schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {MigrationInterface, QueryRunner} from 'typeorm';
2-
import { services } from '../src/modules/common/config/constants';
2+
import { services } from '../modules/common/config/constants';
33

44
export class addNecessarySchemas1555134026445 implements MigrationInterface {
55

nestpoc-api/src/modules/common/config/config.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ export class ConfigService implements JwtOptionsFactory, GqlOptionsFactory {
9393
}
9494

9595
public createDatabaseOpts(): any {
96-
const entitiesPath = path.join(process.cwd(), 'src/**/models/*.model.ts');
97-
const migrationsPath = path.join(process.cwd(), 'src/../migrations/*.ts');
96+
const fileExt = this.isDevelopment ? 'ts' : 'js';
97+
const entitiesPath = `./**/modules/**/models/*.model.${fileExt}`;
98+
const migrationsPath = `./**/migrations/*.${fileExt}`;
9899
return {
99100
type: this.envConfig.NESTPOC_DB_TYPE,
100101
host: this.envConfig.NESTPOC_DB_HOST,
@@ -119,13 +120,13 @@ export class ConfigService implements JwtOptionsFactory, GqlOptionsFactory {
119120

120121
public createGqlOptions(): GqlModuleOptions {
121122
return {
122-
typePaths: [path.join(process.cwd(), 'src/**/*.graphql')],
123+
typePaths: ['./**/*.graphql'],
123124
context: ({ req, res, connection, payload }) => {
124125
if (req) {
125126
return { headers: req.headers };
126127
}
127128
},
128-
// installSubscriptionHandlers: true,
129+
introspection: true,
129130
definitions: {
130131
path: path.join(process.cwd(), 'src/graphql.schema.ts'),
131132
outputAs: 'class',

nestpoc-api/src/modules/common/config/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const getModelRepository = (model: ModelRepository): {
77
} => {
88
return {
99
provide: model.key,
10-
useFactory: (connection: Connection) => connection.getRepository(model.schema),
10+
useFactory: (conn: Connection) => conn.getRepository(model.schema),
1111
inject: [databaseProviderKey],
1212
};
1313
};

nestpoc-api/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["node_modules", "test", "**/*spec.ts"]
3+
"exclude": ["node_modules", "test", "**/*spec.ts", "!src/**/*.ts"]
44
}

nestpoc-api/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"experimentalDecorators": true,
99
"target": "es6",
1010
"sourceMap": true,
11+
"moduleResolution": "node",
1112
"outDir": "./dist",
1213
"baseUrl": "./src",
1314
"paths": {
1415
"@nestpoc/*": ["./modules/*"]
1516
},
1617
"lib": ["dom", "es2018", "esnext"]
1718
},
18-
"exclude": ["node_modules", "dist" ]
19+
"include": ["src/**/*.ts"],
20+
"exclude": ["node_modules"]
1921
}

nestpoc-api/tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"max-file-line-count": [true, 250]
1515
},
1616
"linterOptions": {
17-
"exclude": ["./migrations/*.ts"]
17+
"exclude": ["./src/migrations/*.ts"]
1818
},
1919
"rulesDirectory": []
2020
}

0 commit comments

Comments
 (0)