Skip to content

Commit

Permalink
BE-821 Convert to TS : app/platfrom/... (#178)
Browse files Browse the repository at this point in the history
* BE-821 Convert to TS : app/platfrom/...

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>

* BE-821 Fix an error and warnings detected by Sonarcloud

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia authored Sep 17, 2020
1 parent 21d718a commit 63f77c1
Show file tree
Hide file tree
Showing 34 changed files with 299 additions and 256 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"import/no-extraneous-dependencies": ["off"],
"import/no-unresolved": ["off"],
"import/no-named-as-default": ["off"],
"import/extensions": ["off"],
"react/no-unused-state": ["off"],
"react/destructuring-assignment": ["off"],
"jsx-a11y/label-has-for": ["off"],
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN apk add --no-cache --virtual npm-deps python make g++ curl bash && \
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin

# install NPM dependencies
RUN npm install && npm prune --production
RUN npm install && npm run build && npm prune --production

# build explorer app
RUN cd client && npm install && npm prune --production && yarn build
Expand Down Expand Up @@ -58,11 +58,12 @@ ENV EXPLORER_APP_PATH $DEFAULT_WORKDIR/explorer
WORKDIR $EXPLORER_APP_PATH

COPY . .
COPY --from=BUILD_IMAGE $EXPLORER_APP_PATH/dist ./dist/
COPY --from=BUILD_IMAGE $EXPLORER_APP_PATH/client/build ./client/build/
COPY --from=BUILD_IMAGE $EXPLORER_APP_PATH/node_modules ./node_modules/

# expose default ports
EXPOSE 8080

# run blockchain explorer main app
CMD node $EXPLORER_APP_PATH/main.js && tail -f /dev/null
CMD npm run app-start && tail -f /dev/null
4 changes: 3 additions & 1 deletion app/Synchronizer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable import/extensions */
import { helper } from './common/helper';
/* eslint-enable import/extensions */

const syncconfig = require('./explorerconfig.json');
const helper = require('./common/helper');
const ExplorerError = require('./common/ExplorerError');

const logger = helper.getLogger('Synchronizer');
Expand Down
2 changes: 1 addition & 1 deletion app/common/commonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

const helper = require('./helper');
import { helper } from './helper';

const logger = helper.getLogger('ForkSenderHandler');

Expand Down
136 changes: 0 additions & 136 deletions app/common/helper.js

This file was deleted.

116 changes: 116 additions & 0 deletions app/common/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
*SPDX-License-Identifier: Apache-2.0
*/

/*
* Copyright ONECHAIN 2017 All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const log4js = require('log4js/lib/log4js');

const fs = require('fs-extra');
const yn = require('yn');

/*
* Please assign the logger with the file name for the application logging and assign the logger with "PgService"
* for database logging for any file name. Please find an example below.
*
* To stacktrace, please pass the error.stack object to the logger. If there is no error.stack object pass in a
* string with description.
*
* const helper = require("./app/helper");
* const logger = helper.getLogger("main");
* logger.setLevel('INFO');
*/

/**
*
* Returns Logger
* @param {*} moduleName
* @returns
*/
export class helper {

static getLogger(moduleName) : any {
const logger = log4js.getLogger(moduleName);

let appLog = 'logs/app/app.log';
let dbLog = 'logs/db/db.log';
let consoleLog = 'logs/console/console.log';

if (process.env.SYNC_LOG_PATH) {
appLog = `${process.env.SYNC_LOG_PATH}/app/app.log`;
dbLog = `${process.env.SYNC_LOG_PATH}/db/db.log`;
consoleLog = `${process.env.SYNC_LOG_PATH}/console/console.log`;
}

let appLevel = 'debug';
let dbLevel = 'debug';
let consoleLevel = 'info';

if (process.env.LOG_LEVEL_APP) {
appLevel = process.env.LOG_LEVEL_APP;
}
if (process.env.LOG_LEVEL_DB) {
dbLevel = process.env.LOG_LEVEL_DB;
}
if (process.env.LOG_LEVEL_CONSOLE) {
consoleLevel = process.env.LOG_LEVEL_CONSOLE;
}

const logConfig = {
appenders: {
app: {
type: 'dateFile',
filename: appLog,
maxLogSize: 8 * 1024 * 1024,
daysToKeep: 7
},
db: {
type: 'dateFile',
filename: dbLog,
maxLogSize: 8 * 1024 * 1024,
daysToKeep: 7
},
console: {
type: 'dateFile',
filename: consoleLog,
maxLogSize: 8 * 1024 * 1024,
daysToKeep: 7
},
consoleFilter: {
type: 'logLevelFilter',
appender: 'console',
level: consoleLevel
}
},
categories: {
default: { appenders: ['consoleFilter', 'app'], level: appLevel },
PgService: { appenders: ['consoleFilter', 'db'], level: dbLevel }
}
};

if (process.env.LOG_CONSOLE_STDOUT) {
if (yn(process.env.LOG_CONSOLE_STDOUT)) {
logConfig.appenders.console = { ...logConfig.appenders.console, type: 'console' };
}
}

log4js.configure(logConfig);

return logger;
}
}

4 changes: 1 addition & 3 deletions app/passport/local-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/
import { User } from '../platform/fabric/models/User';

const { promisify } = require('util');

const jwt = require('jsonwebtoken');

const PassportLocalStrategy = require('passport-local').Strategy;

const User = require('../platform/fabric/models/User');
// @ts-ignore
const config = require('../explorerconfig.json');
// @ts-check
Expand Down
2 changes: 1 addition & 1 deletion app/persistence/fabric/CRUDService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

const helper = require('../../common/helper');
import { helper } from '../../common/helper';

const logger = helper.getLogger('CRUDService');

Expand Down
2 changes: 1 addition & 1 deletion app/persistence/fabric/MetricService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

const helper = require('../../common/helper');
import { helper } from '../../common/helper';

const logger = helper.getLogger('MetricService');

Expand Down
4 changes: 1 addition & 3 deletions app/persistence/postgreSQL/PgService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { helper } from '../../common/helper';

const { Client } = require('pg');
const Sequelize = require('sequelize');

const fs = require('fs');

const helper = require('../../common/helper');

const logger = helper.getLogger('PgService');

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {helper} from '../../common/helper';

const includes = require('lodash/includes');
const ExplorerError = require('../../common/ExplorerError');
const FabricUtils = require('./utils/FabricUtils.js');
const FabricGateway = require('../../platform/fabric/gateway/FabricGateway');
const helper = require('../../common/helper');

const logger = helper.getLogger('FabricClient');

Expand All @@ -18,6 +19,13 @@ const explorer_mess = require('../../common/ExplorerMessage').explorer;
* @class FabricClient
*/
class FabricClient {
network_id : string;
fabricGateway : any;
channelsGenHash : Map<string, any>;
config : any;
status : boolean;
channels : string[];

/**
* Creates an instance of FabricClient.
* @param {FabricConfig} config
Expand Down
Loading

0 comments on commit 63f77c1

Please sign in to comment.