Merge pull request #13 from mducharme/master
Change project-x to www, Add PHP scripts, charcoal-legacy as dependency.
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
project-x/modules/boilerplate/node_modules/
|
||||
vendor
|
||||
composer.lock
|
||||
www/charcoal
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
{
|
||||
"minimum-stability":"stable",
|
||||
"require": {
|
||||
"league/climate": "~3.0"
|
||||
}
|
||||
"league/climate": "~3.0",
|
||||
"locomotivemtl/charcoal-composer-installer":"@dev",
|
||||
"locomotivemtl/charcoal-legacy": "@dev"
|
||||
},
|
||||
"repositories":[
|
||||
{
|
||||
"type":"vcs",
|
||||
"url":"https://github.com/mducharme/charcoal-composer-installer"
|
||||
},
|
||||
{
|
||||
"type":"vcs",
|
||||
"url":"https://github.com/locomotivemtl/charcoal-legacy"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
{
|
||||
"project_name":"Boilerplate",
|
||||
|
||||
"databases":{
|
||||
"local":{
|
||||
"database":"boilerplate",
|
||||
"username":"root",
|
||||
"password":""
|
||||
},
|
||||
"lab":{
|
||||
"database":"",
|
||||
"username":"",
|
||||
"password":""
|
||||
},
|
||||
"live":{
|
||||
"database":"",
|
||||
"username":"",
|
||||
"password":""
|
||||
}
|
||||
},
|
||||
"default_database":"local",
|
||||
|
||||
"languages":{
|
||||
"fr":{
|
||||
"active":true
|
||||
},
|
||||
"en":{
|
||||
"active":true
|
||||
}
|
||||
},
|
||||
"default_language":"fr",
|
||||
|
||||
"modules":{
|
||||
"admin":{},
|
||||
"cms":{},
|
||||
"newsletter":{},
|
||||
"boilerplate":{}
|
||||
},
|
||||
|
||||
"objects":{
|
||||
|
||||
},
|
||||
|
||||
"apis":{
|
||||
|
||||
},
|
||||
|
||||
"url_options":{
|
||||
"use_rewrite":true
|
||||
}
|
||||
}
|
||||
120
setup_boilerplate.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
require_once('vendor/autoload.php');
|
||||
|
||||
function validate_project_name($project_name)
|
||||
{
|
||||
if(!is_string($project_name)) {
|
||||
return false;
|
||||
}
|
||||
if(!$project_name) {
|
||||
return false;
|
||||
}
|
||||
return !!preg_match('/^[a-z]+$/', $project_name);
|
||||
}
|
||||
|
||||
$climate = new League\CLImate\CLImate;
|
||||
|
||||
|
||||
$climate->description('Boilerplate setup: Rename the boilerplate files and classes');
|
||||
$climate->arguments->add([
|
||||
'project_name' => [
|
||||
'longPrefix' => 'name',
|
||||
'description' => 'Project (module) name',
|
||||
'defaultValue' => ''
|
||||
],
|
||||
'help' => [
|
||||
'longPrefix' => 'help',
|
||||
'description' => 'Prints a usage statement',
|
||||
'noValue' => true
|
||||
],
|
||||
'quiet' => [
|
||||
'prefix' => 'q',
|
||||
'longPrefix' => 'quit',
|
||||
'description' => 'Disable Output additional information on operations',
|
||||
'noValue' => false
|
||||
]
|
||||
]);
|
||||
|
||||
if($climate->arguments->defined('help')) {
|
||||
$climate->usage();
|
||||
die();
|
||||
}
|
||||
|
||||
$climate->underline()->out('Charcoal Boilerplate Module Setup');
|
||||
|
||||
$climate->arguments->parse();
|
||||
$project_name = $climate->arguments->get('project_name');
|
||||
$verbose = !!$climate->arguments->get('quiet');
|
||||
$verbose = true;
|
||||
|
||||
if(!$project_name) {
|
||||
$input = $climate->input('What is the name of the project?');
|
||||
$project_name = strtolower($input->prompt());
|
||||
}
|
||||
if(!validate_project_name($project_name)) {
|
||||
$climate->red()->out('Invalid project name. Operation aborted.');
|
||||
die();
|
||||
}
|
||||
|
||||
$climate->bold()->out(sprintf('Using "%s" as project name...', $project_name));
|
||||
|
||||
|
||||
|
||||
if(!function_exists('glob_recursive')) {
|
||||
function glob_recursive($pattern, $flags = 0)
|
||||
{
|
||||
$files = glob($pattern, $flags);
|
||||
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
|
||||
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
|
||||
$climate->out("\n".'Replacing file content...');
|
||||
foreach(glob_recursive("www/*") as $filename) {
|
||||
if(!is_dir($filename)) {
|
||||
$file = file_get_contents($filename);
|
||||
$num_replacement1 = 0;
|
||||
$num_replacement2 = 0;
|
||||
$content = preg_replace("/boilerplate/", $project_name, $file, -1, $num_replacement1);
|
||||
$content = preg_replace("/Boilerplate/", ucfirst($project_name), $content, -1, $num_replacement2);
|
||||
$num_replacements = ($num_replacement1+$num_replacement2);
|
||||
if($num_replacements > 0) {
|
||||
file_put_contents($filename, $content);
|
||||
if($verbose) {
|
||||
$climate->dim()->out(sprintf('%d occurence(s) of "boilerplate" has been changed to "%s" in file "%s"', $num_replacements, $project_name, $filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$climate->out("\n".'Renaming files and directories');
|
||||
$boilerplate_files = glob_recursive("www/*boilerplate*");
|
||||
$boilerplate_files = array_reverse($boilerplate_files);
|
||||
foreach($boilerplate_files as $filename) {
|
||||
$target_name = preg_replace("/boilerplate/", $project_name, basename($filename));
|
||||
$target_name = dirname($filename).'/'.$target_name;
|
||||
if($target_name != $filename) {
|
||||
rename($filename, $target_name);
|
||||
if($verbose) {
|
||||
$climate->dim()->out(sprintf('%s has been renamed to %s', $filename, $target_name));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$boilerplate_files = glob_recursive("www/*Boilerplate*");
|
||||
$boilerplate_files = array_reverse($boilerplate_files);
|
||||
foreach($boilerplate_files as $filename) {
|
||||
$climate->inline('.');
|
||||
$target_name = preg_replace("/Boilerplate/", ucfirst($project_name), basename($filename));
|
||||
$target_name = dirname($filename).'/'.$target_name;
|
||||
if($target_name != $filename) {
|
||||
rename($filename, $target_name);
|
||||
if($verbose) {
|
||||
$climate->dim()->out(sprintf('%s has been renamed to %s', $filename, $target_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$climate->green()->out("\n".'Success!');
|
||||
@@ -65,7 +65,7 @@ catch (PDOException $e) {
|
||||
// If here, DB is created. Setup config.json
|
||||
$climate->out('Setting up the database for the project...');
|
||||
|
||||
$filename = 'project-x/config/config.json';
|
||||
$filename = 'www/config/config.json';
|
||||
if(!file_exists($filename) || !is_writable($filename)) {
|
||||
$climate->red()->out('Could not open config.json or file not writeable');
|
||||
die();
|
||||
@@ -83,7 +83,7 @@ if(!isset($json['databases'])) {
|
||||
|
||||
$databases = array_keys($json['databases']);
|
||||
if(in_array($db_ident, $databases)) {
|
||||
$input = $climate->bold()->confirm('Database already exists in the config file. Overwrite?');
|
||||
$input = $climate->bold()->confirm('Database ident already exists in the config file. Overwrite?');
|
||||
if (!$input->confirmed()) {
|
||||
$climate->red()->out('Setup aborted.');
|
||||
die();
|
||||
@@ -98,7 +98,7 @@ $json['databases'][$db_ident] = [
|
||||
|
||||
$climate->green()->out('Database added successfully to config file.');
|
||||
|
||||
$input = $climate->bold()->confirm(sprintf('Do you want to use "%s" as the default database?', $db_name));
|
||||
$input = $climate->bold()->confirm(sprintf('Do you want to use "%s" as the default database ident?', $db_name));
|
||||
if ($input->confirmed()) {
|
||||
$json['default_database'] = $db_ident;
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
Order Deny,Allow
|
||||
Deny from all
|
||||
Order Deny,Allow
|
||||
Deny from all
|
||||
|
||||
44
www/config/config.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"project_name": "Boilerplate",
|
||||
"databases": {
|
||||
"local": {
|
||||
"database": "gdfg",
|
||||
"username": "root",
|
||||
"password": ""
|
||||
},
|
||||
"lab": {
|
||||
"database": "",
|
||||
"username": "",
|
||||
"password": ""
|
||||
},
|
||||
"live": {
|
||||
"database": "",
|
||||
"username": "",
|
||||
"password": ""
|
||||
}
|
||||
},
|
||||
"default_database": "local",
|
||||
"languages": {
|
||||
"fr": {
|
||||
"active": true
|
||||
},
|
||||
"en": {
|
||||
"active": true
|
||||
}
|
||||
},
|
||||
"default_language": "fr",
|
||||
"modules": {
|
||||
"admin": [],
|
||||
"cms": [],
|
||||
"newsletter": [],
|
||||
"boilerplate": []
|
||||
},
|
||||
"objects": [],
|
||||
"apis": [],
|
||||
"url_options": {
|
||||
"use_rewrite": true
|
||||
},
|
||||
"debug":{
|
||||
"active":false
|
||||
}
|
||||
}
|
||||
5
www/config/config.local.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"debug":{
|
||||
"active":true
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,27 @@
|
||||
error_reporting(E_ALL & ~E_STRICT);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
// Environment defaults
|
||||
date_default_timezone_set('America/Montreal');
|
||||
|
||||
|
||||
// Main Charcoal include. This is where the Charcoal autoloader is defined.
|
||||
include __DIR__.'/../charcoal/charcoal.php';
|
||||
|
||||
// JSON Configuration
|
||||
Charcoal::add_config(__DIR__.'/config.json');
|
||||
$application_env = Charcoal::application_env();
|
||||
if(file_exists(__DIR__ . '/config.'.$application_env.'.json')) {
|
||||
Charcoal::add_config(__DIR__ . '/config.'.$application_env.'.json');
|
||||
}
|
||||
|
||||
// Environment defaults
|
||||
date_default_timezone_set('America/Montreal');
|
||||
|
||||
// Configuration overwrite
|
||||
Charcoal::$config['ROOT'] = realpath(__DIR__).'/../';
|
||||
Charcoal::$config['URL'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
|
||||
if(isset($_SERVER['HTTP_HOST'])) {
|
||||
Charcoal::$config['URL'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
|
||||
}
|
||||
else {
|
||||
Charcoal::$config['URL'] = 'http://localhost/';
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |