diff options
| author | rr- <rr-@sakuya.pl> | 2016-04-06 20:38:45 +0200 |
|---|---|---|
| committer | rr- <rr-@sakuya.pl> | 2016-04-06 22:36:04 +0200 |
| commit | 55cc7b59e4a9c23810371fa3fa3895ec8c3a7bf8 (patch) | |
| tree | ba6fb29e9adc2919dc5f7f470a2e1fb739d868a9 /client | |
| parent | 19a357611bd667e2f443595bb536cda4150c19a8 (diff) | |
client+server: switch to yaml config
Diffstat (limited to 'client')
| -rw-r--r-- | client/build.js | 37 | ||||
| -rw-r--r-- | client/js/api.js | 6 | ||||
| -rw-r--r-- | client/js/views/help_view.js | 2 | ||||
| -rw-r--r-- | client/js/views/home_view.js | 2 | ||||
| -rw-r--r-- | client/js/views/login_view.js | 4 | ||||
| -rw-r--r-- | client/js/views/registration_view.js | 4 | ||||
| -rw-r--r-- | client/package.json | 4 |
7 files changed, 33 insertions, 26 deletions
diff --git a/client/build.js b/client/build.js index eb32e9b..70e63e5 100644 --- a/client/build.js +++ b/client/build.js @@ -5,40 +5,47 @@ const glob = require('glob'); const path = require('path'); const util = require('util'); const execSync = require('child_process').execSync; +const camelcase = require('camelcase'); + +function convertKeysToCamelCase(input) { + let result = {}; + Object.keys(input).map((key, _) => { + const value = input[key]; + if (value !== null && value.constructor == Object) { + result[camelcase(key)] = convertKeysToCamelCase(value); + } else { + result[camelcase(key)] = value; + } + }); + return result; +} function getVersion() { return execSync('git describe --always --dirty --long --tags').toString(); } function getConfig() { - const ini = require('ini'); + const yaml = require('js-yaml'); const merge = require('merge'); const camelcaseKeys = require('camelcase-keys'); - function parseIniFile(path) { - let result = ini.parse(fs.readFileSync(path, 'utf-8') - .replace(/#.+$/gm, '') - .replace(/\s+$/gm, '')); - Object.keys(result).map((key, _) => { - result[key] = camelcaseKeys(result[key]); - }); - return result; + function parseConfigFile(path) { + let result = yaml.load(fs.readFileSync(path, 'utf-8')); + return convertKeysToCamelCase(result); } - let config = parseIniFile('../config.ini.dist'); + let config = parseConfigFile('../config.yaml.dist'); try { - const localConfig = parseIniFile('../config.ini'); + const localConfig = parseConfigFile('../config.yaml'); config = merge.recursive(config, localConfig); } catch (e) { console.warn('Local config does not exist, ignoring'); } - delete config.basic.secret; + delete config.secret; delete config.smtp; delete config.database; - config.service.userRanks = config.service.userRanks.split(/,\s*/); - config.service.tagCategories = config.service.tagCategories.split(/,\s*/); config.meta = { version: getVersion(), buildDate: new Date().toUTCString(), @@ -63,7 +70,7 @@ function bundleHtml(config) { .replace(/(<\/head>)/, templatesHtml + '$1') .replace( /(<title>)(.*)(<\/title>)/, - util.format('$1%s$3', config.basic.name)); + util.format('$1%s$3', config.name)); fs.writeFileSync( './public/index.htm', diff --git a/client/js/api.js b/client/js/api.js index a881b56..497525e 100644 --- a/client/js/api.js +++ b/client/js/api.js @@ -48,7 +48,7 @@ class Api { continue; } const rankName = config.privileges[privilege]; - const rankIndex = config.service.userRanks.indexOf(rankName); + const rankIndex = config.ranks.indexOf(rankName); if (minViableRank === null || rankIndex < minViableRank) { minViableRank = rankIndex; } @@ -57,7 +57,7 @@ class Api { console.error('Bad privilege name: ' + lookup); } let myRank = this.user !== null ? - config.service.userRanks.indexOf(this.user.accessRank) : + config.ranks.indexOf(this.user.rank) : 0; return myRank >= minViableRank; } @@ -91,7 +91,7 @@ class Api { } getFullUrl(url) { - return (config.basic.apiUrl + '/' + url).replace(/([^:])\/+/g, '$1/'); + return (config.apiUrl + '/' + url).replace(/([^:])\/+/g, '$1/'); } } diff --git a/client/js/views/help_view.js b/client/js/views/help_view.js index 4f68a7d..eaf6c14 100644 --- a/client/js/views/help_view.js +++ b/client/js/views/help_view.js @@ -25,7 +25,7 @@ class HelpView extends BaseView { } const content = this.sectionTemplates[section]({ - 'name': config.basic.name, + 'name': config.name, }); this.showView(this.template({'content': content})); diff --git a/client/js/views/home_view.js b/client/js/views/home_view.js index 1f1f0f4..9a8603d 100644 --- a/client/js/views/home_view.js +++ b/client/js/views/home_view.js @@ -11,7 +11,7 @@ class HomeView extends BaseView { render(section) { this.showView(this.template({ - name: config.basic.name, + name: config.name, version: config.meta.version, buildDate: config.meta.buildDate, })); diff --git a/client/js/views/login_view.js b/client/js/views/login_view.js index 2f24053..3708e65 100644 --- a/client/js/views/login_view.js +++ b/client/js/views/login_view.js @@ -17,8 +17,8 @@ class LoginView extends BaseView { const userNameField = document.getElementById('user-name'); const passwordField = document.getElementById('user-password'); const rememberUserField = document.getElementById('remember-user'); - userNameField.setAttribute('pattern', config.service.userNameRegex); - passwordField.setAttribute('pattern', config.service.passwordRegex); + userNameField.setAttribute('pattern', config.userNameRegex); + passwordField.setAttribute('pattern', config.passwordRegex); form.addEventListener('submit', e => { e.preventDefault(); diff --git a/client/js/views/registration_view.js b/client/js/views/registration_view.js index 7e1ee85..1a1583e 100644 --- a/client/js/views/registration_view.js +++ b/client/js/views/registration_view.js @@ -17,8 +17,8 @@ class RegistrationView extends BaseView { const userNameField = document.getElementById('user-name'); const passwordField = document.getElementById('user-password'); const emailField = document.getElementById('user-email'); - userNameField.setAttribute('pattern', config.service.userNameRegex); - passwordField.setAttribute('pattern', config.service.passwordRegex); + userNameField.setAttribute('pattern', config.userNameRegex); + passwordField.setAttribute('pattern', config.passwordRegex); form.addEventListener('submit', e => { e.preventDefault(); diff --git a/client/package.json b/client/package.json index da59222..8f8fca2 100644 --- a/client/package.json +++ b/client/package.json @@ -7,13 +7,13 @@ }, "dependencies": { "browserify": "^13.0.0", - "camelcase-keys": "^2.1.0", + "camelcase": "^2.1.1", "csso": "^1.8.0", "glob": "^7.0.3", "handlebars": "^4.0.5", "html-minifier": "^1.3.1", - "ini": "^1.3.4", "js-cookie": "^2.1.0", + "js-yaml": "^3.5.5", "merge": "^1.2.0", "page": "^1.7.1", "superagent": "^1.8.3", |