commit 0ca414b48c9a2dcbc756ce4ce36e474fe5917ad6 Author: danbulant Date: Sat Sep 28 13:41:01 2019 +0200 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed0d3c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,88 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..716202a --- /dev/null +++ b/config.yml @@ -0,0 +1,8 @@ +showNames: true #show names of columns in first row, defaults to false +crlf: true #use windows crlf instead of linux lf, defaults to false + +# Connection: +host: database-1.cjbcrihhq2n4.us-east-2.rds.amazonaws.com #defaults to "localhost" +port: 3306 #defaults to 3306 +username: user #defaults to "root" +password: password #defaults to ""(nothing) diff --git a/index.js b/index.js new file mode 100644 index 0000000..f42010f --- /dev/null +++ b/index.js @@ -0,0 +1,71 @@ +const fs = require("fs"); +const configLoc = "config.yml"; +var config = {}; + +function log(str){ + if(str == undefined){ + console.log(); + return; + } + if(typeof str != "string"){ + console.log(str); + return; + } + console.log("[LOG] \x1b[2m" + str + "\x1b[0m"); +} +function success(str){ + console.log("[LOG] \x1b[32m" + str + "\x1b[0m"); +} +function warn(str){ + console.warn("[WARN] \x1b[33m" + str + "\x1b[0m"); +} +function error(str){ + console.error("[ERROR] \x1b[41m" + str + "\x1b[0m"); +} +log("Starting..."); +var today = new Date(); +var dateTime = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " " + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); +log("Current time and date: " + dateTime); +log(); +//read and check config +var configFile = fs.readFileSync(configLoc); +if(Buffer.isBuffer(configFile)){ + configFile = configFile.toString(); +} +configFile = configFile.split("\n"); +configFile.forEach((line) => { + line = line.trim(); //trim line + if(line.indexOf("#") != -1) line = line.substr(0, line.indexOf("#")); + if(line.indexOf(":") == -1) return; + var value = line.substr(line.indexOf(":") + 1, line.length - line.indexOf(":")).trim(); + if(value == "true") value = true;//string "true" save as literal true + if(value == "false") value = false;//same for false + if(value == parseInt(value)) value = parseInt(value);//save numbers as integers instead of strings + config[line.substr(0, line.indexOf(":")).trim()] = value; +}); +//check config +if(config.showNames == undefined){ + warn("Undefined showNames, using false"); + config.showNames = false; +} +if(config.crlf == undefined){ + warn("Undefined crlf, using false"); + config.crlf = false; +} +if(config.host == undefined){ + warn("Undefined crlf, using false"); + config.host = false; +} +if(config.port == undefined){ + warn("Undefined crlf, using false"); + config.port = false; +} +if(config.username == undefined){ + warn("Undefined crlf, using false"); + config.username = false; +} + +if(config.password == undefined){ + warn("Undefined crlf, using false"); + config.password = false; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..8935a0a --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "sql2csv", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node index.js" + }, + "author": "", + "license": "ISC" +}