From d4ac1033e96d54dc0ab45f0cc368fc581f9a4197 Mon Sep 17 00:00:00 2001 From: oof1lab Date: Mon, 6 Nov 2017 19:16:06 +0000 Subject: [PATCH] refactor : console prints --- bin/index.js | 12 ++++++------ index.js | 13 +++++++------ lib/util/cmd.helper.js | 2 +- lib/util/data.helper.js | 3 ++- lib/xapi.js | 18 +++++++++-------- package-lock.json | 43 +++++++++++++++++++++++++++++------------ package.json | 11 ++++++----- 7 files changed, 63 insertions(+), 39 deletions(-) diff --git a/bin/index.js b/bin/index.js index 079c8a9de9..c308cc7f10 100755 --- a/bin/index.js +++ b/bin/index.js @@ -30,9 +30,7 @@ let mysqlPool = mysql.createPool(sqlConfig); /**************** START : setup Xapi ****************/ console.log(''); -console.log(''); -console.log(' Generating APIs at speed of your thoughts.. '); -console.log(''); +console.log(' REST APIs at the speed of thought.. '); console.log(''); let t = process.hrtime(); @@ -44,10 +42,12 @@ moreApis.init((err, results) => { var t1 = process.hrtime(t); var t2 = t1[0]+t1[1]/1000000000 - console.log('| |'); - console.log("| xmysql took : %d seconds",dataHelp.round(t2,1)); - console.log('| |'); + console.log(' '); + console.log(" Xmysql took : %d seconds",dataHelp.round(t2,1)); + console.log(' '); console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); + + }) /**************** END : setup Xapi ****************/ diff --git a/index.js b/index.js index 93e8a942bb..f0453bf898 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ #! /usr/bin/env node + const morgan = require('morgan'); const bodyParser = require('body-parser'); const express = require('express'); @@ -30,9 +31,7 @@ let mysqlPool = mysql.createPool(sqlConfig); /**************** START : setup Xapi ****************/ console.log(''); -console.log(''); -console.log(' Generating APIs at speed of your thoughts.. '); -console.log(''); +console.log(' REST APIs at the speed of thought.. '); console.log(''); let t = process.hrtime(); @@ -44,10 +43,12 @@ moreApis.init((err, results) => { var t1 = process.hrtime(t); var t2 = t1[0]+t1[1]/1000000000 - console.log('| |'); - console.log("| xmysql took : %d seconds",dataHelp.round(t2,1)); - console.log('| |'); + console.log(' '); + console.log(" Xmysql took : %d seconds",dataHelp.round(t2,1)); + console.log(' '); console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); + + }) /**************** END : setup Xapi ****************/ diff --git a/lib/util/cmd.helper.js b/lib/util/cmd.helper.js index ab477c81bc..9dcd379c34 100644 --- a/lib/util/cmd.helper.js +++ b/lib/util/cmd.helper.js @@ -11,7 +11,7 @@ program.on('--help', () => { }) program - .version('0.1.8') + .version('0.1.9') .option('-h, --host ', 'hostname') .option('-d, --database ', 'database schema name') .option('-u, --user ', 'username of database / root by default') diff --git a/lib/util/data.helper.js b/lib/util/data.helper.js index 1fa0b84346..0f67979d36 100644 --- a/lib/util/data.helper.js +++ b/lib/util/data.helper.js @@ -1,5 +1,6 @@ 'use strict'; + exports.findOrInsertObjectArrayByKey = (obj, key, array) => { let found = 0; @@ -36,7 +37,7 @@ exports.findObjectInArrayByKey = (key, value, objArray) => { }; -exports.round = function(number, precision) { +exports.round = function (number, precision) { var factor = Math.pow(10, precision); var tempNumber = number * factor; var roundedTempNumber = Math.round(tempNumber); diff --git a/lib/xapi.js b/lib/xapi.js index d6c14b9372..6cb3912828 100644 --- a/lib/xapi.js +++ b/lib/xapi.js @@ -37,9 +37,9 @@ class Xapi { this.mysql.init((err, results) => { this.app.use(this.urlMiddleware) - this.setupRoutes() + let stat = this.setupRoutes() this.app.use(this.errorMiddleware) - cbk(err, results) + cbk(err, stat) }) @@ -210,12 +210,14 @@ class Xapi { let statStr = ' Generated: ' + stat.apis + ' REST APIs for ' + stat.tables + ' tables ' console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); - console.log('| |'); - console.log('| |'); - console.log('| ' + statStr); - console.log('| |'); - console.log('| |'); - console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); + console.log(' '); + console.log(' Database : %s',this.config.database); + console.log(' Number of resources : %s',stat.tables); + console.log(' '); + console.log(' REST APIs Generated : %s'.green.bold,stat.apis ); + console.log(' '); + + return stat } async create(req, res) { diff --git a/package-lock.json b/package-lock.json index b0ba96ed90..02acd8d88f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "xmysql", - "version": "0.1.0", + "version": "0.1.8", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -40,7 +40,8 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true }, "basic-auth": { "version": "2.0.0", @@ -76,6 +77,7 @@ "version": "1.1.8", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "dev": true, "requires": { "balanced-match": "1.0.0", "concat-map": "0.0.1" @@ -84,7 +86,8 @@ "browser-stdout": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz", - "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=" + "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=", + "dev": true }, "busboy": { "version": "0.2.14", @@ -151,7 +154,8 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true }, "concat-stream": { "version": "1.6.0", @@ -253,7 +257,8 @@ "diff": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz", - "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==" + "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==", + "dev": true }, "ee-first": { "version": "1.1.1", @@ -273,7 +278,8 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true }, "etag": { "version": "1.8.1", @@ -367,12 +373,14 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, "requires": { "fs.realpath": "1.0.0", "inflight": "1.0.6", @@ -385,17 +393,20 @@ "growl": { "version": "1.10.3", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", - "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==" + "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==", + "dev": true }, "has-flag": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", - "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", + "dev": true }, "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", - "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true }, "http-errors": { "version": "1.6.2", @@ -424,6 +435,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, "requires": { "once": "1.4.0", "wrappy": "1.0.2" @@ -481,6 +493,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, "requires": { "brace-expansion": "1.1.8" } @@ -502,6 +515,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/mocha/-/mocha-4.0.1.tgz", "integrity": "sha512-evDmhkoA+cBNiQQQdSKZa2b9+W2mpLoj50367lhy+Klnx9OV8XlCIhigUnn1gaTFLQCa0kdNhEGDr0hCXOQFDw==", + "dev": true, "requires": { "browser-stdout": "1.3.0", "commander": "2.11.0", @@ -519,6 +533,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, "requires": { "ms": "2.0.0" } @@ -601,6 +616,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, "requires": { "wrappy": "1.0.2" } @@ -613,7 +629,8 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true }, "path-to-regexp": { "version": "0.1.7", @@ -851,6 +868,7 @@ "version": "4.4.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "dev": true, "requires": { "has-flag": "2.0.0" } @@ -907,7 +925,8 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true }, "xtend": { "version": "4.0.1", diff --git a/package.json b/package.json index 9a84a1a9eb..42353e68b0 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,17 @@ { "name": "xmysql", - "version": "0.1.8", + "version": "0.1.9", "description": "One command to generate REST APIs for any MySql database", "main": "index.js", "scripts": { "test": "./node_modules/.bin/mocha tests/*.js --exit" }, "keywords": [ - "mysql rest api generator", - "mysql rest api json", - "create rest api for sql database", - "node mysql rest api" + "mysql-rest-api-generator", + "node-mysql-rest-api", + "rest", + "restful", + "rest-apis" ], "engines": { "node": ">= 7.6.0"