Initial commit

This commit is contained in:
danbulant 2019-09-28 13:41:01 +02:00
commit 0ca414b48c
5 changed files with 180 additions and 0 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

88
.gitignore vendored Normal file
View file

@ -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/

8
config.yml Normal file
View file

@ -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)

71
index.js Normal file
View file

@ -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;
}

11
package.json Normal file
View file

@ -0,0 +1,11 @@
{
"name": "sql2csv",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC"
}