Skip to content

Commit

Permalink
Refactoring config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyfox committed Jul 29, 2017
1 parent ddff597 commit 0a966bb
Show file tree
Hide file tree
Showing 2,940 changed files with 420,904 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vault.js filter=git-crypt diff=git-crypt
*vault* filter=git-crypt diff=git-crypt
*.tex filter=git-crypt diff=git-crypt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.DS_Store
/bower_components
/app/bower_components
/www/bower_components
21 changes: 2 additions & 19 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

process.env.NODE_ENV = "development";

const env = process.env.NODE_ENV || "development";
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
Expand All @@ -10,22 +9,6 @@ const bodyParser = require('body-parser');

console.log("ENV: " + process.env.NODE_ENV);

const rebuildDatabase = true;

if(rebuildDatabase){
const dictionary = require('./eanaEltuMigration/dictionary');

dictionary.buildDictionary(function(){
// We have a full Dictionary now to do things with :)
//console.log(dictionary.missingEntryTranslations);
//console.log(dictionary.entries);
dictionary.export(function(){
console.log("Export Complete!!!");
//process.exit(0);
});
});
}

const app = express();

const apiV1 = require('./routes/apiV1');
Expand All @@ -42,7 +25,7 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use('/api/v1', apiV1);
app.use('/', express.static(path.join(__dirname, 'app')));
app.use('/', express.static(path.join(__dirname, 'www')));

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
43 changes: 0 additions & 43 deletions app/index.html

This file was deleted.

17 changes: 17 additions & 0 deletions bin/rebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const config = require("../config");
const debug = require('debug')('Naranawm:rebuild');

const Dictionary = require('../eanaEltuMigration/dictionary');
const dictionary = new Dictionary(config);

debug("Starting Database Rebuild");
dictionary.buildDictionary(function(){
// We have a full Dictionary now to do things with :)

dictionary.export(function(){
debug("Export Complete!!!");
process.exit(0);
});
});
5 changes: 3 additions & 2 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/

const app = require('../app');
const debug = require('debug')('mobiledatabase:server');
const debug = require('debug')('naranawm:server');
const http = require('http');
const config = require("../config");

/**
* Get port from environment and store in Express.
*/

const port = normalizePort(process.env.PORT || '3000');
const port = normalizePort(config.port);
app.set('port', port);

/**
Expand Down
10 changes: 5 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"license": "MIT",
"private": true,
"dependencies": {
"angular": "~1.5.0",
"angular-route": "~1.5.0",
"angular-loader": "~1.5.0",
"angular-mocks": "~1.5.0",
"html5-boilerplate": "^5.3.0"
"angular": "~1.6.5",
"angular-route": "~1.6.5",
"angular-loader": "~1.6.5",
"angular-mocks": "~1.6.5",
"bootstrap": "^3.3.7"
}
}
5 changes: 5 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
const env = process.env.NODE_ENV || "development";

// If running in development mode, use the local config properties, otherwise pull in that environments config
module.exports = (env !== "development") ? require(`./${env}.vault`) : require('./local');
Binary file added config/kelutral.vault.js
Binary file not shown.
Binary file added config/kenten.vault.js
Binary file not shown.
27 changes: 27 additions & 0 deletions config/local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {

port: 3000,

databases: {
naranawm: {
host: "127.0.0.1",
database: "naranawm",
username: "mobile",
password: "mobile",
dialect: "mysql"
},
eanaEltu: {
host: '127.0.0.1',
database: 'eanaeltu',
username: 'mobile',
password: 'mobile'
},
sqlite: {
host: "127.0.0.1",
dialect: "sqlite",
storage: "database.sqlite",
benchmark: false
}
}

};
43 changes: 16 additions & 27 deletions eanaEltuMigration/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const Lemma = require('./lemma');
const EanaEltu = require('./eanaEltu');
const models = require('../models');
const Promise = require('bluebird');
const debug = require('debug')('Naranawm:server');

/*
* This Module / Section is to export data from Eana Eltu
* and convert it into a format that we can insert into
* the new database schema */

function Dictionary () {
this.debug = false;
function Dictionary (config) {
this.eanaEltu = new EanaEltu();
this.languages = {
en: {
Expand All @@ -38,9 +38,7 @@ function Dictionary () {
}

Dictionary.prototype.buildDictionary = function (callback) {
if(this.debug){
console.log("Building Dictionary...");
}
debug("Building Dictionary...");
const self = this;
this.eanaEltu.fetchData(function(rawEEdata){
self.eanaEltu = rawEEdata;
Expand All @@ -49,9 +47,7 @@ Dictionary.prototype.buildDictionary = function (callback) {
buildDictionaryMetadata(self);
buildDictionaryTemplates(self);
buildDictionaryLemmas(self);
if(self.debug){
console.log("Complete");
}
debug("Complete");
callback();
});
};
Expand Down Expand Up @@ -1132,7 +1128,7 @@ Dictionary.prototype.exportPhonemes = function(){
Dictionary.prototype.exportGraphemePhonemeCorrespondence = function(){
"use strict";
const graphemeMap = {};

const self = this;
return models.Grapheme.findAll().then(function(graphemes){
for(let i = 0; i < graphemes.length; i++){
graphemeMap[graphemes[i].id] = graphemes[i];
Expand All @@ -1151,9 +1147,7 @@ Dictionary.prototype.exportGraphemePhonemeCorrespondence = function(){
};

Dictionary.prototype.export = function (callback) {
if(this.debug){
console.log("Exporting Dictionary to new Database...");
}
debug("Exporting Dictionary to new Database...");
const self = this;

// Using force: true to drop all tables first
Expand Down Expand Up @@ -1220,7 +1214,7 @@ function getDictionaryBuildTemplate(data){
case "\\end{hangparas}}\\end{multicols}+\\newpage":
return "end_hangparas_multicols_newpage";
default:
console.log(723, data);
debug(723, data);
return;
}
}
Expand Down Expand Up @@ -1357,9 +1351,8 @@ function buildDictionaryMetadata(self) {
const localization = self.eanaEltu.dictLoc[index];
for(let lc in localization){
if(localization[lc].value === '' || localization[lc].value === null || localization[lc].value === undefined){
if(self.debug){
console.log("Missing " + lc + " translation for [" + index + "]");
}
debug("Missing " + lc + " translation for [" + index + "]");

if(self.missingMetadataTranslations[lc.toLowerCase()] === undefined){
self.missingMetadataTranslations[lc.toLowerCase()] = [];
}
Expand Down Expand Up @@ -1604,7 +1597,7 @@ function buildDictionaryTemplates(self) {
const meta = self.metadata[result[1]];
if(meta[lc] === undefined){
if(self.languages[lc].active){
console.log("MISSING TRANSLATION FOR [" + result[1] + "] in " + lc);
debug("MISSING TRANSLATION FOR [" + result[1] + "] in " + lc);
}
continue;
}
Expand All @@ -1626,7 +1619,7 @@ function buildDictionaryTemplates(self) {


if(metadata === ""){
console.log(1129, lc, index, result[1], metadata, meta[lc].value);
debug(1129, lc, index, result[1], metadata, meta[lc].value);
}

if(index === "cww" || index === "derives"){
Expand Down Expand Up @@ -1670,7 +1663,7 @@ function buildDictionaryTemplates(self) {
// sub_entry_lemma_def exists in the localized layout but not in the main layout
// we need to pull this out and move it to the main...

console.log(1173, index, layout, localizedFormat);
debug(1173, index, layout, localizedFormat);

}

Expand Down Expand Up @@ -1736,9 +1729,7 @@ function buildDictionaryLemmas(self) {
self.sources[lemma.source] = lemma.source;

if(lemma.source === "") {
if(self.debug){
console.log("Missing Source: " + lemma.lemma, lemma.type, lemma.id);
}
debug("Missing Source: " + lemma.lemma, lemma.type, lemma.id);
self.missingSources.push({id: lemma.id, lemma: lemma.lemma});
}

Expand Down Expand Up @@ -1778,9 +1769,7 @@ function buildDictionaryLemmas(self) {
}

if(definition === undefined){
if(self.debug){
console.log("<" + lemma.lemma + "> Missing [" + lc + "] Localization for " + id);
}
debug("<" + lemma.lemma + "> Missing [" + lc + "] Localization for " + id);
if(self.missingDefinitionTranslations[lc] === undefined){
self.missingDefinitionTranslations[lc] = [];
}
Expand Down Expand Up @@ -1875,8 +1864,8 @@ function processTemplate(template) {
audio: primaryLemma.audio
*/

const dictionary = new Dictionary();
//const dictionary = new Dictionary();

module.exports = dictionary;
module.exports = Dictionary;


14 changes: 5 additions & 9 deletions eanaEltuMigration/eanaEltu.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

const mysql = require('mysql');

// vault.js is an encrypted module that contains connection info for the db.
const env = process.env.NODE_ENV || "development";
const vault = require('../vault');

const config = require("../config");
function EanaEltu() {
this.debug = false;
this.rawEEdata = {};
this.dbConnection = mysql.createConnection({
host: vault[env].eanaEltu.host,
user: vault[env].eanaEltu.username,
password: vault[env].eanaEltu.password,
database: vault[env].eanaEltu.database
host: config.databases.eanaEltu.host,
user: config.databases.eanaEltu.username,
password: config.databases.eanaEltu.password,
database: config.databases.eanaEltu.database
});
}

Expand Down
47 changes: 47 additions & 0 deletions ecosystem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"apps": [
{
"name": "Naranawm",
"script": "bin/www",
"env_production": {
"NODE_ENV": "production"
}
},
{
"name": "Naranawm-RebuildDB",
"script": "bin/rebuild",
"autorestart": false
}
],
"deploy": {
"production": {
"user": "node",
"host": [
"192.168.137.95"
],
"ref": "origin/master",
"repo": "git@github.com:LearnNavi/Naranawm.git",
"path": "/opt/Naranawm",
"ssh_options": "StrictHostKeyChecking=no",
"post-deploy": "npm install && pm2 startOrRestart ecosystem.json --env production",
"env": {
"NODE_ENV": "production"
}
},
"kenten": {
"user": "root",
"host": [
"192.168.137.95"
],
"ref": "origin/master",
"repo": "https://github.com/LearnNavi/Naranawm.git",
"path": "/opt/Naranawm",
"ssh_options": "StrictHostKeyChecking=no",
"post-setup": "git-crypt unlock ~/Naranawm.key",
"post-deploy": "npm install && pm2 startOrRestart ecosystem.json --env kenten",
"env": {
"NODE_ENV": "kenten"
}
}
}
}
Loading

0 comments on commit 0a966bb

Please sign in to comment.