From bcbc1c1ca8b7f6c4daefa8aaf907d4643efa780f Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 12:21:23 +0500 Subject: [PATCH 01/12] Created the 404 pages for the theme --- theme/404.php | 9 +++++ theme/GulpFile.js | 53 ++++++++++++++++++++++++ theme/functions.php | 16 +++++++- theme/{js => resources/libs}/app.js | 0 theme/{ => resources}/sass/style.scss | 0 theme/views/includes/footer.twig | 2 + theme/views/includes/header.twig | 58 ++++++++++++++++++++++++++- theme/views/layouts/master.twig | 2 +- theme/views/pages/404.twig | 13 ++++++ theme/views/pages/index.twig | 15 +++++-- 10 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 theme/404.php create mode 100644 theme/GulpFile.js rename theme/{js => resources/libs}/app.js (100%) rename theme/{ => resources}/sass/style.scss (100%) create mode 100644 theme/views/pages/404.twig diff --git a/theme/404.php b/theme/404.php new file mode 100644 index 0000000..0fe0e00 --- /dev/null +++ b/theme/404.php @@ -0,0 +1,9 @@ +"; + array_map(function ($data) { + print_r($data); + }, func_get_args()); + echo ""; + die; + } +} diff --git a/theme/js/app.js b/theme/resources/libs/app.js similarity index 100% rename from theme/js/app.js rename to theme/resources/libs/app.js diff --git a/theme/sass/style.scss b/theme/resources/sass/style.scss similarity index 100% rename from theme/sass/style.scss rename to theme/resources/sass/style.scss diff --git a/theme/views/includes/footer.twig b/theme/views/includes/footer.twig index 691287b..ce0b40d 100644 --- a/theme/views/includes/footer.twig +++ b/theme/views/includes/footer.twig @@ -1,2 +1,4 @@ + + \ No newline at end of file diff --git a/theme/views/includes/header.twig b/theme/views/includes/header.twig index 18f678d..f1bc455 100644 --- a/theme/views/includes/header.twig +++ b/theme/views/includes/header.twig @@ -9,9 +9,65 @@ {% endif %} - + + + + + + \ No newline at end of file diff --git a/theme/views/layouts/master.twig b/theme/views/layouts/master.twig index d21f1e4..8091738 100644 --- a/theme/views/layouts/master.twig +++ b/theme/views/layouts/master.twig @@ -1,3 +1,3 @@ {% include 'views/includes/header.twig' %} -{% block content %}{% endblock %} +{% block content %} {% endblock %} {% include 'views/includes/footer.twig' %} diff --git a/theme/views/pages/404.twig b/theme/views/pages/404.twig new file mode 100644 index 0000000..8285714 --- /dev/null +++ b/theme/views/pages/404.twig @@ -0,0 +1,13 @@ +{% extends 'views/layouts/master.twig' %} + +{% block content %} + +
+
+ 404 +
+ +
+ + +{% endblock %} \ No newline at end of file diff --git a/theme/views/pages/index.twig b/theme/views/pages/index.twig index b044ac0..a747d47 100644 --- a/theme/views/pages/index.twig +++ b/theme/views/pages/index.twig @@ -2,8 +2,17 @@ {% block content %} -
-        Timber is ready for you - Build something amazing
-    
+
+
+ Pine +
+ + +
+ {% endblock %} \ No newline at end of file From 80e6d513c1f76efd82432ac8d5f2949cc8d948aa Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 12:24:19 +0500 Subject: [PATCH 02/12] Added the setupGulp method in the Theme --- src/Generators/Theme.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Generators/Theme.php b/src/Generators/Theme.php index e76361f..cca8fb2 100644 --- a/src/Generators/Theme.php +++ b/src/Generators/Theme.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Process\Process; /** * Class Theme @@ -44,13 +45,13 @@ class Theme * @param InputInterface $input * @param OutputInterface $output */ - public function __construct( $name, InputInterface $input, OutputInterface $output ) + public function __construct($name, InputInterface $input, OutputInterface $output) { - $this->name = $name; - $this->path = getcwd() . '/' . $name . '/wp-content/themes/' . $name; + $this->name = $name; + $this->path = getcwd() . '/' . $name . '/wp-content/themes/' . $name; $this->fileSystem = new Filesystem(); - $this->input = $input; - $this->output = $output; + $this->input = $input; + $this->output = $output; } public function getThemeFilesDirectory() @@ -66,11 +67,21 @@ public function generate() $this->createDirectory() ->installTimber() ->scaffoldWPTheme() - ->replaceThemeName(); + ->replaceThemeName() + ->setupGulp(); return $this; } + /** + * @return Process + */ + public function setupGulp() + { + $process = new Process("cd $this->path && echo {} > package.json && npm install gulp gulp-clean-css gulp-concat gulp-cssmin gulp-imagemin gulp-rename gulp-sass gulp-uglify streamqueue --save-dev"); + return $process; + } + /** * Create theme directory */ @@ -107,7 +118,7 @@ public function getInput() * @param InputInterface $input * @return Theme */ - public function setInput( $input ) + public function setInput($input) { $this->input = $input; @@ -126,7 +137,7 @@ public function getOutput() * @param OutputInterface $output * @return Theme */ - public function setOutput( $output ) + public function setOutput($output) { $this->output = $output; @@ -139,7 +150,7 @@ public function setOutput( $output ) * @param $directory * @return $this */ - protected function copyFiles( $directory ) + protected function copyFiles($directory) { $files = glob($directory . '/*'); From 47d92270b7eaea6675c0c9614e23afd0158991b2 Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 12:49:53 +0500 Subject: [PATCH 03/12] Change Client to verify false in verifyZipIntegrity method --- src/Console/NewCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Console/NewCommand.php b/src/Console/NewCommand.php index bb5e806..5ba1b7b 100644 --- a/src/Console/NewCommand.php +++ b/src/Console/NewCommand.php @@ -329,7 +329,9 @@ protected function createApplicationDirectory() */ protected function verifyZipIntegrity($algorithm = 'md5') { - $request = new Client(); + $request = new Client([ + 'verify' => false + ]); $response = $request->get($this->getUrl($algorithm)); $remoteChecksum = $response->getBody(); $localChecksum = md5_file($this->getZipFilePath()); From cd29c3966a55eae9e848e6ce8a2c9a77591f3215 Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 12:55:54 +0500 Subject: [PATCH 04/12] Modification in setupGulp method --- src/Generators/Theme.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Generators/Theme.php b/src/Generators/Theme.php index cca8fb2..2344710 100644 --- a/src/Generators/Theme.php +++ b/src/Generators/Theme.php @@ -78,8 +78,16 @@ public function generate() */ public function setupGulp() { - $process = new Process("cd $this->path && echo {} > package.json && npm install gulp gulp-clean-css gulp-concat gulp-cssmin gulp-imagemin gulp-rename gulp-sass gulp-uglify streamqueue --save-dev"); - return $process; + $process = new Process("cd $this->path && echo {} > package.json && npm install gulp gulp-clean-css gulp-concat gulp-imagemin gulp-rename gulp-sass gulp-uglify --save-dev"); + if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) { + $process->setTty(true); + } + + $process->run(function ( $type, $line ) { + $this->output->writeln($line); + }); + + return $this; } /** From 615621ef57d2232119f30276b09ce001991d3d2b Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 13:02:34 +0500 Subject: [PATCH 05/12] Add setTimeout method and assigned it to 180seconds --- src/Generators/Theme.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Generators/Theme.php b/src/Generators/Theme.php index 2344710..fe63c4d 100644 --- a/src/Generators/Theme.php +++ b/src/Generators/Theme.php @@ -68,7 +68,8 @@ public function generate() ->installTimber() ->scaffoldWPTheme() ->replaceThemeName() - ->setupGulp(); + ->setupGulp() + ->setTimeout(180); return $this; } @@ -90,6 +91,15 @@ public function setupGulp() return $this; } + /** + * Sets timeout for Symphony process + * @param $timeout + */ + public function setTimeout($timeout) + { + $this->timeout = $timeout; + } + /** * Create theme directory */ From a864d1c787398c6905dfe20a39e10dbd426525b6 Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 13:30:44 +0500 Subject: [PATCH 06/12] Add Timeout to setupGulp method --- src/Generators/Theme.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Generators/Theme.php b/src/Generators/Theme.php index fe63c4d..40def28 100644 --- a/src/Generators/Theme.php +++ b/src/Generators/Theme.php @@ -68,8 +68,7 @@ public function generate() ->installTimber() ->scaffoldWPTheme() ->replaceThemeName() - ->setupGulp() - ->setTimeout(180); + ->setupGulp(); return $this; } @@ -80,25 +79,22 @@ public function generate() public function setupGulp() { $process = new Process("cd $this->path && echo {} > package.json && npm install gulp gulp-clean-css gulp-concat gulp-imagemin gulp-rename gulp-sass gulp-uglify --save-dev"); + + + $process->setTimeout(2 * 3600); + if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) { $process->setTty(true); } $process->run(function ( $type, $line ) { $this->output->writeln($line); + }); return $this; } - /** - * Sets timeout for Symphony process - * @param $timeout - */ - public function setTimeout($timeout) - { - $this->timeout = $timeout; - } /** * Create theme directory From 171f30b95715e3d366d130fb4f88bf9868762ce1 Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 13:46:17 +0500 Subject: [PATCH 07/12] Added the option to setup Gulp --- src/Generators/Theme.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Generators/Theme.php b/src/Generators/Theme.php index 40def28..104f3e4 100644 --- a/src/Generators/Theme.php +++ b/src/Generators/Theme.php @@ -67,8 +67,13 @@ public function generate() $this->createDirectory() ->installTimber() ->scaffoldWPTheme() - ->replaceThemeName() - ->setupGulp(); + ->replaceThemeName(); + + if($this->input->getOption('skip-npm')) { + $this->setupGulp(); + } + +// ->setupGulp(); return $this; } From 48090f02944d33c612ec36464de5201b0fd72dbf Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 13:47:27 +0500 Subject: [PATCH 08/12] Added skip-npm option This option will allow users to choose whether to instal gulp or not while installing gulp --- src/Console/NewCommand.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Console/NewCommand.php b/src/Console/NewCommand.php index 5ba1b7b..2109a2b 100644 --- a/src/Console/NewCommand.php +++ b/src/Console/NewCommand.php @@ -92,11 +92,16 @@ public function setVersion($version) */ protected function configure() { + $this ->setName('new') ->setDescription('Create a new WordPress application with Timber.') ->addArgument('name', InputArgument::OPTIONAL, 'Your applications\'s name') - ->addArgument('version', InputArgument::OPTIONAL, 'The version of WordPress to download'); + ->addArgument('version', InputArgument::OPTIONAL, 'The version of WordPress to download') + + ->addOption('skip-npm', null, InputOption::VALUE_NONE, 'Pass this option if you want to skip npm packages'); + + } /** @@ -119,7 +124,7 @@ public function execute(InputInterface $input, OutputInterface $output) $zipFile = $this->download($output); - $output->writeln( 'Extracting package'); + $output->writeln('Extracting package'); $this->extract($zipFile); $output->writeln('Generating WordPress theme & installing timber'); From 633006c4622c729031904b8447a6b3c25c9496af Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 16:51:31 +0500 Subject: [PATCH 09/12] Adjusted the Body Style --- theme/views/includes/header.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/theme/views/includes/header.twig b/theme/views/includes/header.twig index f1bc455..ea8d750 100644 --- a/theme/views/includes/header.twig +++ b/theme/views/includes/header.twig @@ -25,6 +25,7 @@ font-weight: 100; height: 100vh; margin: 0; + margin-top:8%; } .full-height { From a5570620c8a4a53d8877d58e57a1e29cf304543c Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 17:19:19 +0500 Subject: [PATCH 10/12] QFE --- src/Generators/Theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generators/Theme.php b/src/Generators/Theme.php index 104f3e4..44b54c3 100644 --- a/src/Generators/Theme.php +++ b/src/Generators/Theme.php @@ -69,7 +69,7 @@ public function generate() ->scaffoldWPTheme() ->replaceThemeName(); - if($this->input->getOption('skip-npm')) { + if(!$this->input->getOption('skip-npm')) { $this->setupGulp(); } From ac4fdd06287c0beb08544629f429de942bee346a Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 17:40:07 +0500 Subject: [PATCH 11/12] Included NPM Support Added the ability to install npm packages while installing Pine --- src/Console/NewCommand.php | 2 +- src/Generators/Theme.php | 25 ++++++++++++++++++++----- theme/package.json | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 theme/package.json diff --git a/src/Console/NewCommand.php b/src/Console/NewCommand.php index 2109a2b..ebd495e 100644 --- a/src/Console/NewCommand.php +++ b/src/Console/NewCommand.php @@ -99,7 +99,7 @@ protected function configure() ->addArgument('name', InputArgument::OPTIONAL, 'Your applications\'s name') ->addArgument('version', InputArgument::OPTIONAL, 'The version of WordPress to download') - ->addOption('skip-npm', null, InputOption::VALUE_NONE, 'Pass this option if you want to skip npm packages'); + ->addOption('npm', null, InputOption::VALUE_NONE, 'Pass this option if you want to install npm packages'); } diff --git a/src/Generators/Theme.php b/src/Generators/Theme.php index 44b54c3..6760cf5 100644 --- a/src/Generators/Theme.php +++ b/src/Generators/Theme.php @@ -68,13 +68,11 @@ public function generate() ->installTimber() ->scaffoldWPTheme() ->replaceThemeName(); - - if(!$this->input->getOption('skip-npm')) { + + if($this->input->getOption('npm')) { $this->setupGulp(); } -// ->setupGulp(); - return $this; } @@ -83,7 +81,7 @@ public function generate() */ public function setupGulp() { - $process = new Process("cd $this->path && echo {} > package.json && npm install gulp gulp-clean-css gulp-concat gulp-imagemin gulp-rename gulp-sass gulp-uglify --save-dev"); + $process = new Process("cd $this->path && npm install"); $process->setTimeout(2 * 3600); @@ -202,7 +200,11 @@ protected function scaffoldWPTheme() private function replaceThemeName() { $stylesheet = $this->path . '/style.css'; + $packageJson = $this->path . '/package.json'; + /** + * Replace Author & Theme Name in style.css File + */ file_put_contents( $stylesheet, str_replace( @@ -212,6 +214,19 @@ private function replaceThemeName() ) ); + /** + * Replace Author & Package Name in package.json File + */ + file_put_contents( + $packageJson, + str_replace( + ['@THEME_NAME@', '@AUTHOR_NAME@'], + [$this->name, get_current_user()], + file_get_contents($packageJson) + ) + ); + + return $this; } } \ No newline at end of file diff --git a/theme/package.json b/theme/package.json new file mode 100644 index 0000000..be74c0d --- /dev/null +++ b/theme/package.json @@ -0,0 +1,15 @@ +{ + "name": "@THEME_NAME@", + "version": "1.0.0", + "description": "Pine uses NPM", + "author": "@AUTHOR_NAME@", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-clean-css": "^3.2.0", + "gulp-concat": "^2.6.1", + "gulp-imagemin": "^3.2.0", + "gulp-rename": "^1.2.2", + "gulp-sass": "^3.1.0", + "gulp-uglify": "^2.1.2" + } +} \ No newline at end of file From affab5d8b87e0c4dcc5ca56b73623fbb2026b326 Mon Sep 17 00:00:00 2001 From: usamamuneerchaudhary Date: Fri, 12 May 2017 17:55:12 +0500 Subject: [PATCH 12/12] Changed libs to js in GulpFile.js --- theme/GulpFile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/theme/GulpFile.js b/theme/GulpFile.js index 10570d1..ca9614b 100644 --- a/theme/GulpFile.js +++ b/theme/GulpFile.js @@ -31,7 +31,7 @@ gulp.task('images', function () { * Scripts Task */ gulp.task('scripts', function(){ - return gulp.src(['resources/libs/**/*.js']) + return gulp.src(['resources/js/**/*.js']) .pipe(concat('all.min.js')) .pipe(uglify()) .pipe(gulp.dest('assets/js/')) @@ -43,7 +43,7 @@ gulp.task('scripts', function(){ */ gulp.task('watch', function () { gulp.watch('resources/sass/**/*.scss', ['styles']); - gulp.watch('resources/libs/*.js', ['scripts']); + gulp.watch('resources/js/*.js', ['scripts']); }); /**