diff --git a/composer.json b/composer.json
index f6ba9fd..458c297 100644
--- a/composer.json
+++ b/composer.json
@@ -7,8 +7,9 @@
"require": {
"php": ">=5.6"
},
- "require-dev": {
- "symfony/console": "~2.3|~3.0"
+ "suggest": {
+ "symfony/console": "[Gin CLI] Required for the proper operation of Console component",
+ "symfony/finder": "[Gin CLI] Needed for `gin tonik:shake` command"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index 8deadf8..ccb8e2c 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,10 +4,288 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "befb322ab50afe53c445680b0300e6a8",
- "content-hash": "79a440e4222b487a38579005997e3a2c",
+ "hash": "8b8e4067a1427ac350dbd4d586b2d46e",
+ "content-hash": "54f7332fbf95e5a5d46d5a78cfd141dc",
"packages": [],
- "packages-dev": [],
+ "packages-dev": [
+ {
+ "name": "psr/log",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/log.git",
+ "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
+ "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psr\\Log\\": "Psr/Log/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for logging libraries",
+ "homepage": "https://github.com/php-fig/log",
+ "keywords": [
+ "log",
+ "psr",
+ "psr-3"
+ ],
+ "time": "2016-10-10 12:19:37"
+ },
+ {
+ "name": "symfony/console",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/console.git",
+ "reference": "08efa49aa07dde0747198c6075a1061c750e9884"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/console/zipball/08efa49aa07dde0747198c6075a1061c750e9884",
+ "reference": "08efa49aa07dde0747198c6075a1061c750e9884",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9",
+ "symfony/debug": "~2.8|~3.0",
+ "symfony/polyfill-mbstring": "~1.0"
+ },
+ "require-dev": {
+ "psr/log": "~1.0",
+ "symfony/dependency-injection": "~2.8|~3.0",
+ "symfony/event-dispatcher": "~2.8|~3.0",
+ "symfony/filesystem": "~2.8|~3.0",
+ "symfony/http-kernel": "~2.8|~3.0",
+ "symfony/process": "~2.8|~3.0"
+ },
+ "suggest": {
+ "psr/log": "For using the console logger",
+ "symfony/event-dispatcher": "",
+ "symfony/filesystem": "",
+ "symfony/process": ""
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Console\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Console Component",
+ "homepage": "https://symfony.com",
+ "time": "2017-01-11 12:05:48"
+ },
+ {
+ "name": "symfony/debug",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/debug.git",
+ "reference": "88d66d1f16dd99bd0ba0712a941b7207d07e62cd"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/debug/zipball/88d66d1f16dd99bd0ba0712a941b7207d07e62cd",
+ "reference": "88d66d1f16dd99bd0ba0712a941b7207d07e62cd",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9",
+ "psr/log": "~1.0"
+ },
+ "conflict": {
+ "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
+ },
+ "require-dev": {
+ "symfony/class-loader": "~2.8|~3.0",
+ "symfony/http-kernel": "~2.8|~3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Debug\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Debug Component",
+ "homepage": "https://symfony.com",
+ "time": "2017-01-15 16:05:29"
+ },
+ {
+ "name": "symfony/finder",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/finder.git",
+ "reference": "791ac099b1687c0bd82f7230ec0d8fc8550c81dc"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/finder/zipball/791ac099b1687c0bd82f7230ec0d8fc8550c81dc",
+ "reference": "791ac099b1687c0bd82f7230ec0d8fc8550c81dc",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.9"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Finder\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Finder Component",
+ "homepage": "https://symfony.com",
+ "time": "2017-01-02 20:33:09"
+ },
+ {
+ "name": "symfony/polyfill-mbstring",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/polyfill-mbstring.git",
+ "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4",
+ "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "suggest": {
+ "ext-mbstring": "For best performance"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Polyfill\\Mbstring\\": ""
+ },
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill for the Mbstring extension",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "mbstring",
+ "polyfill",
+ "portable",
+ "shim"
+ ],
+ "time": "2016-11-14 01:06:16"
+ }
+ ],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": [],
diff --git a/gin b/gin
new file mode 100644
index 0000000..487b361
--- /dev/null
+++ b/gin
@@ -0,0 +1,12 @@
+#!/usr/bin/env php
+app = new Application($this->banner);
+ $this->dir = $dir;
+
$this->bootstrap();
}
@@ -63,8 +66,18 @@ protected function bootstrap()
*/
protected function addCommands(array $commands)
{
- foreach ($commands as $command) {
- $this->app->add(new $command);
+ foreach ($commands as $name) {
+ $command = new $name;
+
+ $command->addOption(
+ 'directory',
+ 'dir',
+ InputOption::VALUE_REQUIRED,
+ 'Root directory path of theme.',
+ $this->dir
+ );
+
+ $this->app->add($command);
}
}
}
\ No newline at end of file
diff --git a/src/Gin/Foundation/Console/Command/ShakeCommand.php b/src/Gin/Foundation/Console/Command/ShakeCommand.php
index bd3d071..276acfa 100644
--- a/src/Gin/Foundation/Console/Command/ShakeCommand.php
+++ b/src/Gin/Foundation/Console/Command/ShakeCommand.php
@@ -4,10 +4,12 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\RuntimeException;
+use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;
+use Symfony\Component\Finder\Finder;
class ShakeCommand extends Command
{
@@ -17,14 +19,26 @@ class ShakeCommand extends Command
* @var array
*/
protected $questions = [
- 'theme.name' => 'Theme Name [theme.name]',
- 'theme.uri' => 'Theme URI [theme.uri]',
- 'theme.description' => 'Theme Description [theme.description]',
- 'theme.version' => 'Theme Version [theme.version]',
- 'theme.author' => 'Author [theme.author]',
- 'theme.author.uri' => 'Author URI [theme.uri]',
- 'theme.textdomain' => 'Theme Textdomain [theme.textdomain]',
- 'theme.namespace' => 'Theme Namespace [theme.namespace]',
+ 'theme.name' => 'Theme Name [theme.name]',
+ 'theme.uri' => 'Theme URI [theme.uri]',
+ 'theme.description' => 'Theme Description [theme.description]',
+ 'theme.version' => 'Theme Version [theme.version]',
+ 'theme.author' => 'Author [theme.author]',
+ 'theme.author.uri' => 'Author URI [theme.author.uri]',
+ 'theme.textdomain' => 'Theme Textdomain [theme.textdomain]',
+ 'theme.namespace' => 'Theme Namespace [theme.namespace]',
+ ];
+
+ protected $ignore = [
+ "node_modules",
+ "vendor"
+ ];
+
+ protected $files = [
+ "/index.php",
+ "/404.php",
+ "/composer.json",
+ "/style.css"
];
/**
@@ -75,8 +89,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->askQuestions();
if ($this->askForConfirmation()) {
- $output->writeln('Initializing theme ...');
-
$this->rename();
return;
@@ -112,7 +124,7 @@ public function askQuestions()
*/
public function askForDetail($key, $value)
{
- $question = new Question("{$value}: ");
+ $question = new Question("{$value}: ");
$question->setNormalizer(function ($value) {
return trim($value);
@@ -142,7 +154,7 @@ public function askForDetail($key, $value)
public function askForConfirmation()
{
$question = new ChoiceQuestion(
- 'Ready to start initialization procedure. Want to continue?',
+ 'Ready to start initialization procedure. Changes will be irreversible, want to continue?',
['yes', 'no'],
1
);
@@ -166,17 +178,37 @@ public function askForConfirmation()
*/
protected function rename()
{
- setlocale(LC_CTYPE, "en_US.UTF-8");
-
- foreach ($this->answers as $key => $answer) {
- $this->findAndReplaceInDir(
- './',
- "{{ {$key} }}",
- escapeshellcmd($answer)
- );
+ $finder = new Finder();
+
+ $finder->files()
+ ->name('*.php')
+ ->name('*.css')
+ ->name('*.json')
+ ->exclude($this->ignore)
+ ->in($this->getInput()->getOption('directory'));
+
+ $progress = new ProgressBar($this->getOutput(), count($finder));
+
+ $progress->setFormat("[%bar%] %current%/%max% files\n");
+
+ foreach ($finder as $file) {
+ foreach ($this->answers as $key => $answer) {
+ if ($file->getExtension() !== 'json') {
+ $answer = stripslashes($answer);
+ }
+
+ file_put_contents(
+ $file->getRealPath(),
+ str_replace("{{ {$key} }}", $answer, $file->getContents())
+ );
+ }
+
+ $progress->advance();
}
- $this->getOutput()->writeln('Theme successufully initialized. Cheers!>');
+ $progress->finish();
+
+ $this->getOutput()->writeln("Theme successufully initialized. Cheers!>");
}
/**