├── .gitignore ├── Console └── WorkbenchMakeCommand.php ├── Package.php ├── PackageCreator.php ├── README.md ├── Starter.php ├── WorkbenchServiceProvider.php ├── composer.json ├── config.php └── stubs ├── .travis.yml ├── composer.json ├── gitignore.txt ├── phpunit.xml ├── plain.composer.json ├── plain.provider.stub └── provider.stub /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock -------------------------------------------------------------------------------- /Console/WorkbenchMakeCommand.php: -------------------------------------------------------------------------------- 1 | creator = $creator; 44 | } 45 | 46 | /** 47 | * Execute the console command. 48 | */ 49 | public function fire() 50 | { 51 | $workbench = $this->runCreator($this->buildPackage()); 52 | 53 | $this->info('Package workbench created!'); 54 | 55 | $this->callComposerUpdate($workbench); 56 | } 57 | 58 | /** 59 | * Run the package creator class for a given Package. 60 | * 61 | * @param \Pingpong\Workbench\Package $package 62 | * 63 | * @return string 64 | */ 65 | protected function runCreator($package) 66 | { 67 | $path = $this->laravel->basePath().'/workbench'; 68 | 69 | $plain = !$this->option('resources'); 70 | 71 | return $this->creator->create($package, $path, $plain); 72 | } 73 | 74 | /** 75 | * Call the composer update routine on the path. 76 | * 77 | * @param string $path 78 | */ 79 | protected function callComposerUpdate($path) 80 | { 81 | chdir($path); 82 | 83 | passthru('composer install -v'); 84 | } 85 | 86 | /** 87 | * Build the package details from user input. 88 | * 89 | * @return \Illuminate\Workbench\Package 90 | * 91 | * @throws \UnexpectedValueException 92 | */ 93 | protected function buildPackage() 94 | { 95 | list($vendor, $name) = $this->getPackageSegments(); 96 | 97 | $config = $this->laravel['config']['workbench']; 98 | 99 | if (is_null($config['email'])) { 100 | throw new \UnexpectedValueException("Please set the author's email in the workbench configuration file."); 101 | } 102 | 103 | return new Package($vendor, $name, $config['name'], $config['email']); 104 | } 105 | 106 | /** 107 | * Get the package vendor and name segments from the input. 108 | * 109 | * @return array 110 | */ 111 | protected function getPackageSegments() 112 | { 113 | $package = $this->argument('package'); 114 | 115 | return array_map('studly_case', explode('/', $package, 2)); 116 | } 117 | 118 | /** 119 | * Get the console command arguments. 120 | * 121 | * @return array 122 | */ 123 | protected function getArguments() 124 | { 125 | return array( 126 | array('package', InputArgument::REQUIRED, 'The name (vendor/name) of the package.'), 127 | ); 128 | } 129 | 130 | /** 131 | * Get the console command options. 132 | * 133 | * @return array 134 | */ 135 | protected function getOptions() 136 | { 137 | return array( 138 | array('resources', 'r', InputOption::VALUE_NONE, 'Create Laravel specific directories.'), 139 | ); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Package.php: -------------------------------------------------------------------------------- 1 | name = $name; 60 | $this->email = $email; 61 | $this->vendor = $vendor; 62 | $this->author = $author; 63 | $this->lowerName = snake_case($name, '-'); 64 | $this->lowerVendor = snake_case($vendor, '-'); 65 | } 66 | 67 | /** 68 | * Get the full package name. 69 | * 70 | * @return string 71 | */ 72 | public function getFullName() 73 | { 74 | return $this->lowerVendor.'/'.$this->lowerName; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /PackageCreator.php: -------------------------------------------------------------------------------- 1 | files = $files; 48 | } 49 | 50 | /** 51 | * Create a new package stub. 52 | * 53 | * @param \Illuminate\Workbench\Package $package 54 | * @param string $path 55 | * @param bool $plain 56 | * 57 | * @return string 58 | */ 59 | public function create(Package $package, $path, $plain = true) 60 | { 61 | $directory = $this->createDirectory($package, $path); 62 | 63 | // To create the package, we will spin through a list of building blocks that 64 | // make up each package. We'll then call the method to build that block on 65 | // the class, which keeps the actual building of stuff nice and cleaned. 66 | foreach ($this->getBlocks($plain) as $block) { 67 | $this->{"write{$block}"}($package, $directory, $plain); 68 | } 69 | 70 | return $directory; 71 | } 72 | 73 | /** 74 | * Create a package with all resource directories. 75 | * 76 | * @param \Illuminate\Workbench\Package $package 77 | * @param string $path 78 | */ 79 | public function createWithResources(Package $package, $path) 80 | { 81 | return $this->create($package, $path, false); 82 | } 83 | 84 | /** 85 | * Get the blocks for a given package. 86 | * 87 | * @param bool $plain 88 | * 89 | * @return array 90 | */ 91 | protected function getBlocks($plain) 92 | { 93 | return $plain ? $this->basicBlocks : $this->blocks; 94 | } 95 | 96 | /** 97 | * Write the support files to the package root. 98 | * 99 | * @param \Illuminate\Workbench\Package $package 100 | * @param string $directory 101 | * @param bool $plain 102 | */ 103 | public function writeSupportFiles(Package $package, $directory, $plain) 104 | { 105 | foreach (array('PhpUnit', 'Travis', 'Composer', 'Ignore') as $file) { 106 | $this->{"write{$file}File"}($package, $directory, $plain); 107 | } 108 | } 109 | 110 | /** 111 | * Write the PHPUnit stub file. 112 | * 113 | * @param \Illuminate\Workbench\Package $package 114 | * @param string $directory 115 | */ 116 | protected function writePhpUnitFile(Package $package, $directory) 117 | { 118 | $stub = __DIR__.'/stubs/phpunit.xml'; 119 | 120 | $this->files->copy($stub, $directory.'/phpunit.xml'); 121 | } 122 | 123 | /** 124 | * Write the Travis stub file. 125 | * 126 | * @param \Illuminate\Workbench\Package $package 127 | * @param string $directory 128 | */ 129 | protected function writeTravisFile(Package $package, $directory) 130 | { 131 | $stub = __DIR__.'/stubs/.travis.yml'; 132 | 133 | $this->files->copy($stub, $directory.'/.travis.yml'); 134 | } 135 | 136 | /** 137 | * Write the Composer.json stub file. 138 | * 139 | * @param \Illuminate\Workbench\Package $package 140 | * @param string $directory 141 | * @param bool $plain 142 | */ 143 | protected function writeComposerFile(Package $package, $directory, $plain) 144 | { 145 | $stub = $this->getComposerStub($plain); 146 | 147 | $stub = $this->formatPackageStub($package, $stub); 148 | 149 | $this->files->put($directory.'/composer.json', $stub); 150 | } 151 | 152 | /** 153 | * Get the Composer.json stub file contents. 154 | * 155 | * @param bool $plain 156 | * 157 | * @return string 158 | */ 159 | protected function getComposerStub($plain) 160 | { 161 | if ($plain) { 162 | return $this->files->get(__DIR__.'/stubs/plain.composer.json'); 163 | } 164 | 165 | return $this->files->get(__DIR__.'/stubs/composer.json'); 166 | } 167 | 168 | /** 169 | * Write the stub .gitignore file for the package. 170 | * 171 | * @param \Illuminate\Workbench\Package $package 172 | * @param string $directory 173 | * @param bool $plain 174 | */ 175 | public function writeIgnoreFile(Package $package, $directory, $plain) 176 | { 177 | $this->files->copy(__DIR__.'/stubs/gitignore.txt', $directory.'/.gitignore'); 178 | } 179 | 180 | /** 181 | * Create the support directories for a package. 182 | * 183 | * @param \Illuminate\Workbench\Package $package 184 | * @param string $directory 185 | */ 186 | public function writeSupportDirectories(Package $package, $directory) 187 | { 188 | foreach (array('config', 'resources/lang', 'migrations', 'resources/views') as $support) { 189 | $this->writeSupportDirectory($package, $support, $directory); 190 | } 191 | } 192 | 193 | /** 194 | * Write a specific support directory for the package. 195 | * 196 | * @param \Illuminate\Workbench\Package $package 197 | * @param string $support 198 | * @param string $directory 199 | */ 200 | protected function writeSupportDirectory(Package $package, $support, $directory) 201 | { 202 | // Once we create the source directory, we will write an empty file to the 203 | // directory so that it will be kept in source control allowing the dev 204 | // to go ahead and push these components to GitHub right on creation. 205 | $path = $directory.'/src/'.$support; 206 | 207 | $this->files->makeDirectory($path, 0777, true); 208 | 209 | $this->files->put($path.'/.gitkeep', ''); 210 | } 211 | 212 | /** 213 | * Create the public directory for the package. 214 | * 215 | * @param \Illuminate\Workbench\Package $package 216 | * @param string $directory 217 | * @param bool $plain 218 | */ 219 | public function writePublicDirectory(Package $package, $directory, $plain) 220 | { 221 | if ($plain) { 222 | return; 223 | } 224 | 225 | $this->files->makeDirectory($directory.'/public'); 226 | 227 | $this->files->put($directory.'/public/.gitkeep', ''); 228 | } 229 | 230 | /** 231 | * Create the test directory for the package. 232 | * 233 | * @param \Illuminate\Workbench\Package $package 234 | * @param string $directory 235 | */ 236 | public function writeTestDirectory(Package $package, $directory) 237 | { 238 | $this->files->makeDirectory($directory.'/tests'); 239 | 240 | $this->files->put($directory.'/tests/.gitkeep', ''); 241 | } 242 | 243 | /** 244 | * Write the stub ServiceProvider for the package. 245 | * 246 | * @param \Illuminate\Workbench\Package $package 247 | * @param string $directory 248 | * @param bool $plain 249 | */ 250 | public function writeServiceProvider(Package $package, $directory, $plain) 251 | { 252 | // Once we have the service provider stub, we will need to format it and make 253 | // the necessary replacements to the class, namespaces, etc. Then we'll be 254 | // able to write it out into the package's workbench directory for them. 255 | $stub = $this->getProviderStub($package, $plain); 256 | 257 | $this->writeProviderStub($package, $directory, $stub); 258 | } 259 | 260 | /** 261 | * Write the service provider stub for the package. 262 | * 263 | * @param \Illuminate\Workbench\Package $package 264 | * @param string $directory 265 | * @param string $stub 266 | */ 267 | protected function writeProviderStub(Package $package, $directory, $stub) 268 | { 269 | $path = $this->createClassDirectory($package, $directory); 270 | 271 | // The primary source directory where the package's classes will live may not 272 | // exist yet, so we will need to create it before we write these providers 273 | // out to that location. We'll go ahead and create now here before then. 274 | $file = $path.'/'.$package->name.'ServiceProvider.php'; 275 | 276 | $this->files->put($file, $stub); 277 | } 278 | 279 | /** 280 | * Get the stub for a ServiceProvider. 281 | * 282 | * @param \Illuminate\Workbench\Package $package 283 | * @param bool $plain 284 | * 285 | * @return string 286 | */ 287 | protected function getProviderStub(Package $package, $plain) 288 | { 289 | return $this->formatPackageStub($package, $this->getProviderFile($plain)); 290 | } 291 | 292 | /** 293 | * Load the raw service provider file. 294 | * 295 | * @param bool $plain 296 | * 297 | * @return string 298 | */ 299 | protected function getProviderFile($plain) 300 | { 301 | if ($plain) { 302 | return $this->files->get(__DIR__.'/stubs/plain.provider.stub'); 303 | } 304 | 305 | return $this->files->get(__DIR__.'/stubs/provider.stub'); 306 | } 307 | 308 | /** 309 | * Create the main source directory for the package. 310 | * 311 | * @param \Illuminate\Workbench\Package $package 312 | * @param string $directory 313 | * 314 | * @return string 315 | */ 316 | protected function createClassDirectory(Package $package, $directory) 317 | { 318 | $path = $directory.'/src/'.$package->vendor.'/'.$package->name; 319 | 320 | if (!$this->files->isDirectory($path)) { 321 | $this->files->makeDirectory($path, 0777, true); 322 | } 323 | 324 | return $path; 325 | } 326 | 327 | /** 328 | * Format a generic package stub file. 329 | * 330 | * @param \Illuminate\Workbench\Package $package 331 | * @param string $stub 332 | * 333 | * @return string 334 | */ 335 | protected function formatPackageStub(Package $package, $stub) 336 | { 337 | foreach (get_object_vars($package) as $key => $value) { 338 | $stub = str_replace('{{'.snake_case($key).'}}', $value, $stub); 339 | } 340 | 341 | return $stub; 342 | } 343 | 344 | /** 345 | * Create a workbench directory for the package. 346 | * 347 | * @param \Illuminate\Workbench\Package $package 348 | * @param string $path 349 | * 350 | * @return string 351 | * 352 | * @throws \InvalidArgumentException 353 | */ 354 | protected function createDirectory(Package $package, $path) 355 | { 356 | $fullPath = $path.'/'.$package->getFullName(); 357 | 358 | // If the directory doesn't exist, we will go ahead and create the package 359 | // directory in the workbench location. We will use this entire package 360 | // name when creating the directory to avoid any potential conflicts. 361 | if (!$this->files->isDirectory($fullPath)) { 362 | $this->files->makeDirectory($fullPath, 0777, true); 363 | 364 | return $fullPath; 365 | } 366 | 367 | throw new \InvalidArgumentException('Package exists.'); 368 | } 369 | } 370 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel 5 Workbench 2 | 3 | ### Version Compability 4 | 5 | | Laravel Version | Workbench Version | 6 | |-----------------|-------------------| 7 | | 5.2.* | 5.2.* | 8 | | 5.3.* | 5.3.* | 9 | | 5.4.* | 5.4.* | 10 | 11 | ### Installation 12 | 13 | You can install the package via composer command line by running this following command. 14 | 15 | ``` 16 | composer require pingpong/workbench 17 | ``` 18 | 19 | After the package installed, add `Pingpong\Workbench\WorkbenchServiceProvider` to your `providers` array in `config/app.php` file. 20 | 21 | And the last, publish the package's configuration by running: 22 | 23 | ``` 24 | php artisan vendor:publish 25 | ``` 26 | 27 | That will publish the `workbench.php` config file to your `config/` folder and you need to set the name and email of package creators on it. 28 | 29 | ## Autoloading Workbench 30 | 31 | You can autoload the workbench by adding this following command to your `bootstrap/autoload.php` file. Put this following command at the very bottom of script. 32 | 33 | ```php 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | Register The Workbench Loaders 37 | |-------------------------------------------------------------------------- 38 | | 39 | | The Laravel workbench provides a convenient place to develop packages 40 | | when working locally. However we will need to load in the Composer 41 | | auto-load files for the packages so that these can be used here. 42 | | 43 | */ 44 | if (is_dir($workbench = __DIR__.'/../workbench')) { 45 | Pingpong\Workbench\Starter::start($workbench); 46 | } 47 | ``` 48 | 49 | ### Creating A Package 50 | 51 | > Before you create a package, you need to update `name` and `email` config value in your `config/workbench.php` file. 52 | 53 | Creating a basic package. 54 | 55 | ``` 56 | php artisan workbench vendor/package 57 | ``` 58 | 59 | Creating a package with generating some scaffold resources. 60 | 61 | ``` 62 | php artisan workbench vendor/package --resources 63 | ``` 64 | 65 | ### Other Documentation 66 | 67 | > For more documentation you can visit [the official laravel documentation](http://laravel.com/docs/5.2/packages) 68 | -------------------------------------------------------------------------------- /Starter.php: -------------------------------------------------------------------------------- 1 | in($path)->files()->name('autoload.php')->depth('<= 3')->followLinks(); 27 | 28 | foreach ($autoloads as $file) { 29 | $files->requireOnce($file->getRealPath()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WorkbenchServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 25 | __DIR__.'/config.php' => $path, 26 | ], 'config'); 27 | 28 | if (file_exists($path)) { 29 | $this->mergeConfigFrom($path, 'workbench'); 30 | } 31 | } 32 | 33 | /** 34 | * Register the service provider. 35 | */ 36 | public function register() 37 | { 38 | $this->app->singleton('package.creator', function ($app) { 39 | return new PackageCreator($app['files']); 40 | }); 41 | 42 | $this->app->singleton('command.workbench', function ($app) { 43 | return new WorkbenchMakeCommand($app['package.creator']); 44 | }); 45 | 46 | $this->commands('command.workbench'); 47 | } 48 | 49 | /** 50 | * Get the services provided by the provider. 51 | * 52 | * @return array 53 | */ 54 | public function provides() 55 | { 56 | return array('package.creator', 'command.workbench'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pingpong/workbench", 3 | "description": "Laravel 5 Workbench.", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Taylor Otwell", 8 | "email": "taylorotwell@gmail.com" 9 | }, 10 | { 11 | "name": "Warsono", 12 | "email": "warsono16694@gmail.com" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.5.9", 17 | "illuminate/filesystem": "5.4.*", 18 | "illuminate/support": "5.4.*" 19 | }, 20 | "require-dev": { 21 | "illuminate/console": "5.4.*" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "Pingpong\\Workbench\\": "" 26 | } 27 | }, 28 | "extra": { 29 | "branch-alias": { 30 | "dev-master": "5.2-dev" 31 | } 32 | }, 33 | "minimum-stability": "stable" 34 | } 35 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | '', 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Workbench Author E-Mail Address 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Like the option above, your e-mail address is used when generating new 24 | | workbench packages. The e-mail is placed in your composer.json file 25 | | automatically after the package is created by the workbench tool. 26 | | 27 | */ 28 | 29 | 'email' => '', 30 | 31 | ]; 32 | -------------------------------------------------------------------------------- /stubs/.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.5 5 | - 5.6 6 | - 7.0 7 | - hhvm 8 | 9 | before_script: 10 | - travis_retry composer self-update 11 | - travis_retry composer install --prefer-source --no-interaction --dev 12 | 13 | script: phpunit 14 | -------------------------------------------------------------------------------- /stubs/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{lower_vendor}}/{{lower_name}}", 3 | "description": "", 4 | "authors": [ 5 | { 6 | "name": "{{author}}", 7 | "email": "{{email}}" 8 | } 9 | ], 10 | "require": { 11 | "php": ">=5.5.9", 12 | "illuminate/support": "5.4.*" 13 | }, 14 | "autoload": { 15 | "classmap": [ 16 | "src/migrations" 17 | ], 18 | "psr-4": { 19 | "{{vendor}}\\{{name}}\\": "src/{{vendor}}/{{name}}" 20 | } 21 | }, 22 | "minimum-stability": "stable" 23 | } 24 | -------------------------------------------------------------------------------- /stubs/gitignore.txt: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /stubs/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /stubs/plain.composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{lower_vendor}}/{{lower_name}}", 3 | "description": "", 4 | "authors": [ 5 | { 6 | "name": "{{author}}", 7 | "email": "{{email}}" 8 | } 9 | ], 10 | "require": { 11 | "php": ">=5.5.9", 12 | "illuminate/support": "5.4.*" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "{{vendor}}\\{{name}}\\": "src/{{vendor}}/{{name}}" 17 | } 18 | }, 19 | "minimum-stability": "stable" 20 | } 21 | -------------------------------------------------------------------------------- /stubs/plain.provider.stub: -------------------------------------------------------------------------------- 1 | loadTranslationsFrom(__DIR__ . '/../../resources/lang', '{{lower_name}}'); 24 | 25 | $this->loadViewsFrom(__DIR__ . '/../../resources/views', '{{lower_name}}'); 26 | } 27 | 28 | /** 29 | * Register the service provider. 30 | * 31 | * @return void 32 | */ 33 | public function register() 34 | { 35 | // 36 | } 37 | 38 | /** 39 | * Get the services provided by the provider. 40 | * 41 | * @return array 42 | */ 43 | public function provides() 44 | { 45 | return []; 46 | } 47 | 48 | } 49 | --------------------------------------------------------------------------------