Skip to content

Commit

Permalink
handle server start error, defer testing to another time, delete old …
Browse files Browse the repository at this point in the history
…dist folder
  • Loading branch information
ezzabuzaid committed Jun 4, 2019
1 parent 5f5f0df commit c60d772
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
14 changes: 8 additions & 6 deletions build.js
@@ -1,4 +1,4 @@
const { spawnSync } = require('child_process');
const child_process = require('child_process');
const path = require('path');
const fs = require('fs');
const pwd = process.cwd();
Expand Down Expand Up @@ -27,8 +27,10 @@ const { env } = argv;

// TODO setup delete folder functions
// make sure that all of them pass in pipeline
spawnSync('tsc', { shell: true })
fs.copyFileSync(path.join(pwd, `src/environment/.env.${env}`), './dist/environment/.env', (err) => {
// TODO use pipline to move files instead of sync way
console.log('Succesfully copied');
});
const DIST = path.join(pwd, 'dist');
const ENV = 'environment/.env';
const ENV_DIST = path.join(DIST, ENV);
const ENV_SRC = path.join(pwd, 'src', `${ENV}.${env}`);
del.sync(DIST);
child_process.spawnSync('tsc', { shell: true });
fs.copyFileSync(ENV_SRC, ENV_DIST);
1 change: 1 addition & 0 deletions src/app/core/database/database.ts
Expand Up @@ -51,6 +51,7 @@ export class Database {

public static load(option: IMongooseURI, options: ConnectionOptions = {}) {
const { URI } = new MongooseURI(option);
log.info(URI);
return connect(URI, {
useNewUrlParser: true,
autoIndex: false,
Expand Down
22 changes: 14 additions & 8 deletions src/app/server.ts
Expand Up @@ -43,11 +43,6 @@ export class Server extends Application {
super();
this.path = new URL(`http://${this.host}:${this.port}`);
log.info(`The env => ${stage.LEVEL}`);
// try {
// this.init();
// } catch (error) {
// throw new Error(`Faild to init the server ${error}`);
// }
}

/**
Expand Down Expand Up @@ -78,9 +73,20 @@ export class Server extends Application {
MONGO_PASSWORD: password,
MONGO_PATH: path,
MONGO_HOST: host } = envirnoment.env;
return Promise.all([
Database.load({ user, password, path, host, atlas: false }),
this.populateRoutes()]);

let atlas = false;
if (stage.production) {
atlas = true;
}

try {
return Promise.all([
Database.load({ user, password, path, host, atlas }),
this.populateRoutes()]);
} catch (error) {
throw new Error(`Faild to init the server ${error}`);
}


}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mongoose/field.ts
Expand Up @@ -3,8 +3,8 @@ import 'reflect-metadata';
import { MongooseTypes } from './types';

export function Field<T = any>(options: Exclude<MongooseTypes.FieldOptions, 'type'> = {}) {
return (instance: MongooseTypes.FieldAttr & T, propertyKey: string) => {
if (instance && !instance.fiIFieldAttr
return (instance: MongooseTypes.IFieldAttr & T, propertyKey: string) => {
if (instance && !instance.fields) {
AppUtils.defineProperty(instance, 'fields', { value: {} });
}
const fields = instance.fields;
Expand Down

0 comments on commit c60d772

Please sign in to comment.