From eebe9f90c375c53881853c418144ec0a3bcfa6ec Mon Sep 17 00:00:00 2001 From: David Schissler Date: Sat, 29 Nov 2014 06:51:55 +0200 Subject: [PATCH] Now using YAML for all configurations --- .gitignore | 4 +- app/locale/config.json | 8 ---- app/locale/config.yaml | 7 +++ app/phalcon/config/config.php | 5 +-- app/phalcon/config/config_dev.php | 9 ++-- app/phalcon/modules/cli/tasks/BuildTask.php | 24 ++++++++--- dev/gulpfile.webpack.coffee | 14 ++++-- dev/package.json | 2 + etc/.gitignore | 4 +- etc/dev_defaults.json | 27 ------------ etc/dev_defaults.yaml | 21 +++++++++ etc/dist_defaults.json | 14 ------ etc/dist_defaults.yaml | 12 ++++++ etc/templates/dev_config.json | 47 --------------------- etc/templates/dev_config.yaml | 36 ++++++++++++++++ etc/templates/dist_config.json | 44 ------------------- etc/templates/dist_config.yaml | 34 +++++++++++++++ setup/distro/ubuntu1404/lists/package | 1 + setup/distro/ubuntu1404/lists/pecl | 1 + 19 files changed, 151 insertions(+), 163 deletions(-) delete mode 100644 app/locale/config.json create mode 100644 app/locale/config.yaml delete mode 100644 etc/dev_defaults.json create mode 100644 etc/dev_defaults.yaml delete mode 100644 etc/dist_defaults.json create mode 100644 etc/dist_defaults.yaml delete mode 100644 etc/templates/dev_config.json create mode 100644 etc/templates/dev_config.yaml delete mode 100644 etc/templates/dist_config.json create mode 100644 etc/templates/dist_config.yaml diff --git a/.gitignore b/.gitignore index 6311b7b..96ef269 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ app/locale/*/LC_MESSAGES/messages.mo -etc/dev.json -etc/dist.json +etc/dev.yaml +etc/dist.yaml dist/ dev/node_modules/ dev/bower_components/ diff --git a/app/locale/config.json b/app/locale/config.json deleted file mode 100644 index 3ef9dd0..0000000 --- a/app/locale/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "default": "en_US", - "map": { - "en": "en_US", - "ru": "ru_RU", - "de": "de_DE" - } -} diff --git a/app/locale/config.yaml b/app/locale/config.yaml new file mode 100644 index 0000000..6540d2c --- /dev/null +++ b/app/locale/config.yaml @@ -0,0 +1,7 @@ +--- +default: en_US +map: + en: en_US + ru: ru_RU + de: de_DE +... diff --git a/app/phalcon/config/config.php b/app/phalcon/config/config.php index 0f81b53..fb1e7bf 100644 --- a/app/phalcon/config/config.php +++ b/app/phalcon/config/config.php @@ -1,6 +1,5 @@ [ 'path' => [ @@ -30,7 +29,7 @@ ] ]); $config4 = new Config([ - 'locale' => json_decode(file_get_contents("$appDir/locale/config.json"), true) + 'locale' => yaml_parse_file("$appDir/locale/config.yaml") ]); diff --git a/app/phalcon/modules/cli/tasks/BuildTask.php b/app/phalcon/modules/cli/tasks/BuildTask.php index 768e123..af1c0e0 100644 --- a/app/phalcon/modules/cli/tasks/BuildTask.php +++ b/app/phalcon/modules/cli/tasks/BuildTask.php @@ -30,6 +30,7 @@ public function mainAction(array $params) $this->buildPhalconDir(); $this->makeEntryPoints(); $this->copyFiles(); + $this->buildConf(); $this->installPackages(); $this->compileLocales(); $this->buildWebpack(); @@ -239,7 +240,6 @@ private function copyFiles() { $projectDir = $this->config->dev->path->projectDir; $appDir = $this->config->path->appDir; - $localeDir = $this->config->path->localeDir; $etcDir = $this->config->dev->path->etcDir; $devDir = $this->config->dev->path->devDir; $distDir = $this->config->dev->path->distDir; @@ -262,11 +262,23 @@ private function copyFiles() copy("$etcDir/schema.sql", "$distDir/etc/schema.sql"); // Move the CLI startup program to the root dist directory chmod("$distDir/webird.php", 0775); + } + + - $config1 = json_decode(file_get_contents("$etcDir/dist_defaults.json"), true); - $config2 = json_decode(file_get_contents("$etcDir/dist.json"), true); - $localeConfig = json_decode(file_get_contents("$localeDir/config.json"), true); + + private function buildConf() + { + $etcDir = $this->config->dev->path->etcDir; + $localeDir = $this->config->path->localeDir; + $devDir = $this->config->dev->path->devDir; + $distDir = $this->config->dev->path->distDir; + + $config1 = yaml_parse_file("$etcDir/dist_defaults.yaml"); + $config2 = yaml_parse_file("$etcDir/dist.yaml"); + + $localeConfig = yaml_parse_file("$localeDir/config.yaml"); $localeConfig['supported'] = $this->getDI()->getLocale()->getSupportedLocales(); $config3 = [ 'locale' => $localeConfig @@ -276,8 +288,7 @@ private function copyFiles() $configMerged = array_replace_recursive($config1, $config2, $config3); // Write the merged settings to the dist directory - $jsonConfigMerged = json_encode($configMerged, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - file_put_contents("$distDir/etc/config.json", $jsonConfigMerged); + yaml_emit_file("$distDir/etc/config.yaml", $configMerged); } @@ -285,7 +296,6 @@ private function copyFiles() - private function installPackages() { $distDir = $this->config->dev->path->distDir; diff --git a/dev/gulpfile.webpack.coffee b/dev/gulpfile.webpack.coffee index 83825e1..36beea3 100644 --- a/dev/gulpfile.webpack.coffee +++ b/dev/gulpfile.webpack.coffee @@ -2,6 +2,7 @@ path = require 'path' fs = require 'fs' +yaml = require 'js-yaml' crypto = require 'crypto' # Gulp gulp = require 'gulp' @@ -66,7 +67,7 @@ wpConf = "" ".js", ".coffee" ".html", ".hbs" - ".css", ".scss", ".less", ".styl" + ".css", ".scss", ".less" ] resolveLoader: @@ -78,7 +79,7 @@ wpConf = VERSION: JSON.stringify require("#{devRoot}/package.json").version THEME_ROOT: JSON.stringify "#{appRoot}/theme" LOCALE_ROOT: JSON.stringify "#{appRoot}/locale" - LOCALE_CONFIG: fs.readFileSync "#{appRoot}/locale/config.json", 'utf8' + LOCALE_CONFIG: JSON.stringify yaml.load(fs.readFileSync "#{appRoot}/locale/config.yaml", 'utf8') new ExtractTextPlugin 'css/[name].css', allChunks: false @@ -129,6 +130,11 @@ wpConf = test: /\.json$/ loader: "json" } + { + # YAML Loader + test: /\.yaml$/ + loader: "json!yaml" + } { # PO translation messages Loader test: /\.po$/ @@ -232,8 +238,8 @@ for common, entryList of appConfig.commons # Dev Server Build - uses websockets for live reloading ############################################################ gulp.task 'webpack:dev-server', (callback) -> - config = JSON.parse fs.readFileSync "#{etcRoot}/dev_defaults.json", 'utf8' - configCustom = JSON.parse fs.readFileSync "#{etcRoot}/dev.json", 'utf8' + config = yaml.load fs.readFileSync "#{etcRoot}/dev_defaults.yaml", 'utf8' + configCustom = yaml.load fs.readFileSync "#{etcRoot}/dev.yaml", 'utf8' _.merge config, configCustom webpackPort = config.dev.webpackPort diff --git a/dev/package.json b/dev/package.json index 5f7ac04..49eafa9 100644 --- a/dev/package.json +++ b/dev/package.json @@ -5,6 +5,7 @@ "devDependencies": { "gulp": "~3.8.10", "gulp-util": "~3.0.1", + "js-yaml": "~3.2.3", "webpack": "~1.4.13", "webpack-dev-server": "~1.6.5", "extract-text-webpack-plugin": "~0.3.4", @@ -12,6 +13,7 @@ "coffee-loader": "~0.7.2", "bundle-loader": "~0.5.2", "json-loader": "~0.5.1", + "yaml-loader": "~0.1.0", "po-loader": "~0.1.1", "style-loader": "~0.8.2", "less-loader": "~0.7.7", diff --git a/etc/.gitignore b/etc/.gitignore index 9a22058..0d9c627 100644 --- a/etc/.gitignore +++ b/etc/.gitignore @@ -1,2 +1,2 @@ -dev.json -dist.json +dev.yaml +dist.yaml diff --git a/etc/dev_defaults.json b/etc/dev_defaults.json deleted file mode 100644 index 0909a38..0000000 --- a/etc/dev_defaults.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "dev": { - "webpackPort": 8091, - "webpackLiveReload": true, - "path": { - "debugLog": "/var/log/nginx/{{name}}-debug.log" - }, - "phpEncode": false, - "phpEncoders": { - "ioncube": { - "path": "/usr/local/bin/ioncube_encoder" - } - } - }, - "app": { - "httpPort": 80, - "wsPort": 8092, - "zmqPort": 5500 - }, - "security": { - "https": false, - "hsts": 0, - "preventClickjack": true, - "preventReplay": false, - "nonceExpire": 900 - } -} diff --git a/etc/dev_defaults.yaml b/etc/dev_defaults.yaml new file mode 100644 index 0000000..bbd3c06 --- /dev/null +++ b/etc/dev_defaults.yaml @@ -0,0 +1,21 @@ +--- +dev: + webpackPort: 8091 + webpackLiveReload: true + path: + debugLog: /var/log/nginx/{{name}}-debug.log + phpEncode: false + phpEncoders: + ioncube: + path: /usr/local/bin/ioncube_encoder +app: + httpPort: 80 + wsPort: 8092 + zmqPort: 5500 +security: + https: false + hsts: 0 + preventClickjack: true + preventReplay: false + nonceExpire: 900 +... diff --git a/etc/dist_defaults.json b/etc/dist_defaults.json deleted file mode 100644 index c802573..0000000 --- a/etc/dist_defaults.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "app": { - "httpPort": 443, - "wsPort": 8192, - "zmqPort": 5500 - }, - "security": { - "https": true, - "hsts": 31536000, - "preventClickjack": true, - "preventReplay": false, - "nonceExpire": 900 - } -} diff --git a/etc/dist_defaults.yaml b/etc/dist_defaults.yaml new file mode 100644 index 0000000..f2ad6d3 --- /dev/null +++ b/etc/dist_defaults.yaml @@ -0,0 +1,12 @@ +--- +app: + httpPort: 443 + wsPort: 8192 + zmqPort: 5500 +security: + https: true + hsts: 31536000 + preventClickjack: true + preventReplay: false + nonceExpire: 900 +... diff --git a/etc/templates/dev_config.json b/etc/templates/dev_config.json deleted file mode 100644 index f876bde..0000000 --- a/etc/templates/dev_config.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "dev": { - "phpEncode": false - }, - "app": { - "webUser": "www-data", - "webGroup": "www-data" - }, - "site": { - "domain": [ - "dev.webird.io", - "www.dev.webird.io" - ], - "mail": { - "name": "Webird Development", - "email": "notification-noreply@webird.io" - } - }, - "database": { - "host": "localhost", - "dbname": "webird", - "username": "root", - "password": "root" - }, - "security": { - "salt": "CHANGE ME!!!", - "cryptKey": "CHANGE ME!!!" - }, - "services": { - "google": { - "clientId": "", - "clientSecret": "" - }, - "microsoft": { - "clientId": "", - "clientSecret": "" - } - }, - "mailer": { - "driver": "smtp", - "host": "smtp.gmail.com", - "port": "587", - "encryption": "tls", - "username": "", - "password": "" - } -} diff --git a/etc/templates/dev_config.yaml b/etc/templates/dev_config.yaml new file mode 100644 index 0000000..15225b1 --- /dev/null +++ b/etc/templates/dev_config.yaml @@ -0,0 +1,36 @@ +--- +dev: + phpEncode: false +app: + webUser: www-data + webGroup: www-data +site: + domain: + - dev.webird.io + - www.dev.webird.io + mail: + name: Webird Development + email: notification-noreply@webird.io +database: + host: localhost + dbname: webird + username: root + password: root +security: + salt: CHANGE ME!!! + cryptKey: CHANGE ME!!! +services: + google: + clientId: "" + clientSecret: "" + microsoft: + clientId: "" + clientSecret: "" +mailer: + driver: smtp + host: smtp.gmail.com + port: "587" + encryption: tls + username: "" + password: "" +... diff --git a/etc/templates/dist_config.json b/etc/templates/dist_config.json deleted file mode 100644 index e9ca736..0000000 --- a/etc/templates/dist_config.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "app": { - "webUser": "www-data", - "webGroup": "www-data" - }, - "site": { - "domains": [ - "dist.webird.io", - "www.dist.webird.io" - ], - "mail": { - "name": "Webird", - "email": "notification-noreply@webird.io" - } - }, - "database": { - "host": "localhost", - "dbname": "webird", - "username": "root", - "password": "root" - }, - "security": { - "salt": "CHANGE ME!!!", - "cryptKey": "CHANGE ME!!!" - }, - "services": { - "google": { - "clientId": "", - "clientSecret": "" - }, - "microsoft": { - "clientId": "", - "clientSecret": "" - } - }, - "mailer": { - "driver": "smtp", - "host": "smtp.gmail.com", - "port": "587", - "encryption": "tls", - "username": "", - "password": "" - } -} diff --git a/etc/templates/dist_config.yaml b/etc/templates/dist_config.yaml new file mode 100644 index 0000000..727b8c9 --- /dev/null +++ b/etc/templates/dist_config.yaml @@ -0,0 +1,34 @@ +--- +app: + webUser: www-data + webGroup: www-data +site: + domains: + - dist.webird.io + - www.dist.webird.io + mail: + name: Webird + email: notification-noreply@webird.io +database: + host: localhost + dbname: webird + username: root + password: root +security: + salt: CHANGE ME!!! + cryptKey: CHANGE ME!!! +services: + google: + clientId: "" + clientSecret: "" + microsoft: + clientId: "" + clientSecret: "" +mailer: + driver: smtp + host: smtp.gmail.com + port: "587" + encryption: tls + username: "" + password: "" +... diff --git a/setup/distro/ubuntu1404/lists/package b/setup/distro/ubuntu1404/lists/package index 6b62dd2..1214a97 100644 --- a/setup/distro/ubuntu1404/lists/package +++ b/setup/distro/ubuntu1404/lists/package @@ -32,3 +32,4 @@ libpcre3-dev libzmq3 libzmq3-dev libevent-dev +libyaml-dev diff --git a/setup/distro/ubuntu1404/lists/pecl b/setup/distro/ubuntu1404/lists/pecl index 6f43f70..ef9e8b2 100644 --- a/setup/distro/ubuntu1404/lists/pecl +++ b/setup/distro/ubuntu1404/lists/pecl @@ -1,5 +1,6 @@ # You must add -alpha or -beta if the package is not yet stable mailparse +yaml zmq-beta libevent-beta msgpack-beta