├── LICENSE ├── README.md ├── composer.json └── src ├── ServiceProvider.php └── ViewCompileCommand.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Alexander Melihov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Compile Views 2 | 3 | [![Build Status](https://travis-ci.org/melihovv/laravel-compile-views.svg?branch=master)](https://travis-ci.org/melihovv/laravel-compile-views) 4 | [![styleci](https://styleci.io/repos/109587030/shield)](https://styleci.io/repos/109587030) 5 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/melihovv/laravel-compile-views/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/melihovv/laravel-compile-views/?branch=master) 6 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/28893314-076d-4940-bfc2-d5aac1bfec0b/mini.png)](https://insight.sensiolabs.com/projects/28893314-076d-4940-bfc2-d5aac1bfec0b) 7 | 8 | [![Packagist](https://img.shields.io/packagist/v/melihovv/laravel-compile-views.svg)](https://packagist.org/packages/melihovv/laravel-compile-views) 9 | [![Packagist](https://poser.pugx.org/melihovv/laravel-compile-views/d/total.svg)](https://packagist.org/packages/melihovv/laravel-compile-views) 10 | [![Packagist](https://img.shields.io/packagist/l/melihovv/laravel-compile-views.svg)](https://packagist.org/packages/melihovv/laravel-compile-views) 11 | 12 | **Recently `view:cache` command was built in Laravel. So there is no need in this package anymore :)** 13 | 14 | Missing view:compile command for laravel. 15 | 16 | The perfect solution in combination with [blade minifier](https://github.com/HTMLMin/Laravel-HTMLMin): get minified compiled views with zero cost during your deploy script. 17 | 18 | ## Installation 19 | 20 | Install via composer 21 | ```bash 22 | composer require melihovv/laravel-compile-views 23 | ``` 24 | 25 | **Following step is optional if you use laravel>=5.5 with package 26 | auto discovery feature.** 27 | 28 | Add service provider to `config/app.php` in `providers` section 29 | ```php 30 | Melihovv\LaravelCompileViews\ServiceProvider::class, 31 | ``` 32 | 33 | ## Usage 34 | 35 | ```bash 36 | php artisan view:compile 37 | ``` 38 | 39 | ## Security 40 | 41 | If you discover any security related issues, please email amelihovv@ya.ru 42 | instead of using the issue tracker. 43 | 44 | ## Credits 45 | 46 | - [Alexander Melihov](https://github.com/melihovv/laravel-compile-views) 47 | - [All contributors](https://github.com/melihovv/laravel-compile-views/graphs/contributors) 48 | 49 | This package is bootstrapped with the help of 50 | [melihovv/laravel-package-generator](https://github.com/melihovv/laravel-package-generator). 51 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "melihovv/laravel-compile-views", 3 | "description": "Missing view:compile command for laravel.", 4 | "license": "MIT", 5 | "keywords": [ 6 | "laravel", 7 | "compile", 8 | "views" 9 | ], 10 | "type": "library", 11 | "authors": [ 12 | { 13 | "name": "Alexander Melihov", 14 | "email": "amelihovv@ya.ru" 15 | } 16 | ], 17 | "require": { 18 | "php": ">=7.0", 19 | "illuminate/support": "^5.3", 20 | "illuminate/view": "^5.3" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "Melihovv\\LaravelCompileViews\\": "src" 25 | } 26 | }, 27 | "extra": { 28 | "laravel": { 29 | "providers": [ 30 | "Melihovv\\LaravelCompileViews\\ServiceProvider" 31 | ] 32 | } 33 | }, 34 | "config": { 35 | "preferred-install": "dist", 36 | "sort-packages": true, 37 | "optimize-autoloader": true 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 12 | $this->commands([ 13 | ViewCompileCommand::class, 14 | ]); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/ViewCompileCommand.php: -------------------------------------------------------------------------------- 1 | getFinder(); 48 | 49 | $this->extensions = $finder->getExtensions(); 50 | 51 | collect($finder->getPaths()) 52 | ->each(function (string $path) { 53 | $this->compileViews(collect(Finder::create()->in($path)->exclude('vendor')->files())); 54 | }); 55 | 56 | collect($finder->getHints()) 57 | ->each(function ($paths, $namespace) { 58 | $this->compileViews(collect(Finder::create()->in(array_reverse($paths))->files()), $namespace); 59 | }); 60 | 61 | $this->info('Views were successfully compiled!'); 62 | 63 | return 0; 64 | } 65 | 66 | /** 67 | * @param Collection $viewFiles 68 | * @param string|null $namespace 69 | */ 70 | protected function compileViews(Collection $viewFiles, $namespace = null) 71 | { 72 | $viewFiles 73 | ->map(function (SplFileInfo $file) use ($namespace) { 74 | return $this->getViewName($file, $namespace); 75 | }) 76 | ->each(function (string $viewName) { 77 | $this->compileView($viewName); 78 | }); 79 | } 80 | 81 | /** 82 | * @param string $viewName 83 | */ 84 | protected function compileView(string $viewName) 85 | { 86 | try { 87 | View::make($viewName)->render(); 88 | } catch (Throwable $e) { 89 | } 90 | } 91 | 92 | /** 93 | * @param SplFileInfo $viewFile 94 | * @param string|null $namespace 95 | * @return string 96 | */ 97 | protected function getViewName($viewFile, $namespace = null) 98 | { 99 | $viewName = str_replace( 100 | array_merge([DIRECTORY_SEPARATOR], array_map(function (string $ext) { 101 | return ".$ext"; 102 | }, $this->extensions)), 103 | array_merge(['.'], array_map(function () { 104 | return ''; 105 | }, $this->extensions)), 106 | $viewFile->getRelativePathname() 107 | ); 108 | 109 | if ($namespace) { 110 | return $namespace.ViewFinderInterface::HINT_PATH_DELIMITER.$viewName; 111 | } 112 | 113 | return $viewName; 114 | } 115 | } 116 | --------------------------------------------------------------------------------