Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Now using YAML for all configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
dschissler committed Nov 29, 2014
1 parent 73cd291 commit eebe9f9
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 163 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
8 changes: 0 additions & 8 deletions app/locale/config.json

This file was deleted.

7 changes: 7 additions & 0 deletions app/locale/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
default: en_US
map:
en: en_US
ru: ru_RU
de: de_DE
...
5 changes: 2 additions & 3 deletions app/phalcon/config/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
use Phalcon\Config,
Phalcon\Config\Adapter\Json as AdapterJson;
use Phalcon\Config;

$tmpDir = '/tmp/webird-' . md5(__DIR__) . '-' . posix_geteuid() . '/';

Expand All @@ -11,7 +10,7 @@
$cacheDir = $appDir . 'cache-static/';
$composerDir = $appDir . 'vendor';
// Load the configurable json config file
$config = new AdapterJson("{$appDir}/etc/config.json");
$config = new Config(yaml_parse_file("{$appDir}/etc/config.yaml"));
break;
case DEV_ENV:
$config = require_once(__DIR__ . '/config_dev.php');
Expand Down
9 changes: 4 additions & 5 deletions app/phalcon/config/config_dev.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
use Phalcon\Config,
Phalcon\Config\Adapter\Json as AdapterJson;
use Phalcon\Config;

$projectDir = realpath(__DIR__ . '/../../..') . '/';
$appDir = $projectDir . 'app/';
Expand All @@ -17,8 +16,8 @@
exec("mkdir -p " . escapeshellarg($cacheDir . 'volt/'));
exec("mkdir -p " . escapeshellarg($cacheDir . 'locale/'));

$config = new AdapterJson("{$etcDir}/dev_defaults.json");
$config2 = new AdapterJson("{$etcDir}/dev.json");
$config = new Config(yaml_parse_file("{$etcDir}/dev_defaults.yaml"));
$config2 = new Config(yaml_parse_file("{$etcDir}/dev.yaml"));
$config3 = new Config([
DEV_ENV => [
'path' => [
Expand All @@ -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")
]);


Expand Down
24 changes: 17 additions & 7 deletions app/phalcon/modules/cli/tasks/BuildTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function mainAction(array $params)
$this->buildPhalconDir();
$this->makeEntryPoints();
$this->copyFiles();
$this->buildConf();
$this->installPackages();
$this->compileLocales();
$this->buildWebpack();
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -276,16 +288,14 @@ 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);
}







private function installPackages()
{
$distDir = $this->config->dev->path->distDir;
Expand Down
14 changes: 10 additions & 4 deletions dev/gulpfile.webpack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

path = require 'path'
fs = require 'fs'
yaml = require 'js-yaml'
crypto = require 'crypto'
# Gulp
gulp = require 'gulp'
Expand Down Expand Up @@ -66,7 +67,7 @@ wpConf =
""
".js", ".coffee"
".html", ".hbs"
".css", ".scss", ".less", ".styl"
".css", ".scss", ".less"
]

resolveLoader:
Expand All @@ -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

Expand Down Expand Up @@ -129,6 +130,11 @@ wpConf =
test: /\.json$/
loader: "json"
}
{
# YAML Loader
test: /\.yaml$/
loader: "json!yaml"
}
{
# PO translation messages Loader
test: /\.po$/
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"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",
"coffee-script": "~1.8.0",
"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",
Expand Down
4 changes: 2 additions & 2 deletions etc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dev.json
dist.json
dev.yaml
dist.yaml
27 changes: 0 additions & 27 deletions etc/dev_defaults.json

This file was deleted.

21 changes: 21 additions & 0 deletions etc/dev_defaults.yaml
Original file line number Diff line number Diff line change
@@ -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
...
14 changes: 0 additions & 14 deletions etc/dist_defaults.json

This file was deleted.

12 changes: 12 additions & 0 deletions etc/dist_defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
app:
httpPort: 443
wsPort: 8192
zmqPort: 5500
security:
https: true
hsts: 31536000
preventClickjack: true
preventReplay: false
nonceExpire: 900
...
47 changes: 0 additions & 47 deletions etc/templates/dev_config.json

This file was deleted.

36 changes: 36 additions & 0 deletions etc/templates/dev_config.yaml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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: ""
...
Loading

0 comments on commit eebe9f9

Please sign in to comment.