Repository: melihovv/laravel-package-generator Branch: master Commit: 1de707a0bfba Files: 33 Total size: 38.2 KB Directory structure: gitextract_wkweo582/ ├── .editorconfig ├── .gitattributes ├── .github/ │ └── workflows/ │ └── default.yml ├── .gitignore ├── .styleci.yml ├── LICENSE ├── README.md ├── composer.json ├── config/ │ └── package-generator.php ├── skeleton/ │ ├── .editorconfig │ ├── .gitattributes.tpl │ ├── .github/ │ │ └── workflows/ │ │ └── default.yml │ ├── .gitignore.tpl │ ├── .styleci.yml │ ├── LICENSE.tpl │ ├── README.md.tpl │ ├── composer.json.tpl │ ├── phpunit.xml │ └── src/ │ └── ServiceProvider.php.tpl ├── src/ │ ├── Commands/ │ │ ├── PackageNew.php │ │ ├── PackageRemove.php │ │ └── Traits/ │ │ ├── ChangesComposerJson.php │ │ ├── CopiesSkeleton.php │ │ ├── InteractsWithComposer.php │ │ ├── InteractsWithGit.php │ │ ├── InteractsWithUser.php │ │ └── ManipulatesPackageFolder.php │ ├── Exceptions/ │ │ └── RuntimeException.php │ └── ServiceProvider.php └── stubs/ ├── Facade.php.tpl ├── MainClass.php.tpl ├── MainClassTest.php.tpl └── config.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [Makefile] indent_style = tab [*.php] indent_size = 4 ================================================ FILE: .gitattributes ================================================ * text=auto /.github export-ignore /tests export-ignore /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /.styleci.yml export-ignore /.sensiolabs.yml export-ignore /.coveralls.yml export-ignore /phpunit.xml export-ignore /CHANGELOG-* export-ignore /CONTRIBUTING.md export-ignore /CODE_OF_CONDUCT.md export-ignore ================================================ FILE: .github/workflows/default.yml ================================================ name: Run tests on: push: schedule: - cron: '0 0 * * *' jobs: php-tests: runs-on: ${{ matrix.os }} strategy: matrix: php: [7.4, 7.3, 7.2] laravel: [8.*, 7.*, 6.*] dependency-version: [prefer-lowest, prefer-stable] os: [ubuntu-latest, windows-latest] include: - laravel: 8.* testbench: 6.* - laravel: 7.* testbench: 5.* - laravel: 6.* testbench: 4.* exclude: - laravel: 8.* php: 7.2 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v1 - name: Setup PHP uses: shivammathur/setup-php@v1 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick coverage: none - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest ================================================ FILE: .gitignore ================================================ /vendor /.idea/ /node_modules /composer.lock /.phpunit.result.cache ================================================ FILE: .styleci.yml ================================================ preset: laravel ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2016 Alexander Melihov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ Laravel package generator ========================= [![GitHub Workflow Status](https://github.com/melihovv/laravel-package-generator/workflows/Run%20tests/badge.svg)](https://github.com/melihovv/laravel-package-generator/actions) [![styleci](https://styleci.io/repos/96041272/shield)](https://styleci.io/repos/96041272) [![Packagist](https://img.shields.io/packagist/v/melihovv/laravel-package-generator.svg)](https://packagist.org/packages/melihovv/laravel-package-generator) [![Packagist](https://poser.pugx.org/melihovv/laravel-package-generator/d/total.svg)](https://packagist.org/packages/melihovv/laravel-package-generator) [![Packagist](https://img.shields.io/packagist/l/melihovv/laravel-package-generator.svg)](https://packagist.org/packages/melihovv/laravel-package-generator) Simple package to quickly generate basic structure for other laravel packages. ## Install Install via composer ```bash composer require --dev melihovv/laravel-package-generator ``` Publish package config if you want customize default values ```bash php artisan vendor:publish --provider="Melihovv\LaravelPackageGenerator\ServiceProvider" --tag="config" ``` ## Available commands ### php artisan package:new -i {vendor} {package} Create new package. Example: `php artisan package:new Melihovv SomeAwesomePackage` This command will: * Create `packages/melihovv/some-awesome-package` folder * Register package in app composer.json * Copy package skeleton from skeleton folder to created folder (you can provide your custom skeleton path in config) * Run `git init packages/melihovv/some-awesome-package` * Run `composer update melihovv/some-awesome-package` * Run `composer dump-autoload` With interactive `-i` flag you will be prompted for every needed value from you. ### php artisan package:remove {vendor} {package} Remove the existing package. Example: `php artisan package:remove Melihovv SomeAwesomePackage` This command will: * Run `composer remove melihovv/some-awesome-package` * Remove `packages/melihovv/some-awesome-package` folder * Unregister package in app composer.json * Run `composer dump-autoload` Interactive mode also possible. ## Custom skeleton This package will copy all folders and files from specified skeleton path to package folder. You can use templates in your skeleton. All files with `tpl` extension will be provided with some variables available to use in them. `tpl` extension will be stripped. Available variables to use in templates: * vendor (e.g. Melihovv) * package (e.g. SomeAwesomePackage) * vendorFolderName (e.g. melihovv) * packageFolderName (e.g. some-awesome-package) * packageHumanName (e.g. Some awesome package) * composerName (e.g. melihovv/some-awesome-package) * composerDesc (e.g. A some awesome package) * composerKeywords (e.g. some,awesome,package) * licence (e.g. MIT) * phpVersion (e.g. >=7.0) * aliasName (e.g. some-awesome-package) * configFileName (e.g. some-awesome-package) * year (e.g. 2017) * name (e.g. Alexander Melihov) * email (e.g. amelihovv@ya.ru) * githubPackageUrl (e.g. https://github.com/melihov/some-awesome-package) ## Things you need to do manually: * In README.md: * StyleCI repository identifier * Package description * Usage section ## Security If you discover any security related issues, please email amelihovv@ya.ru instead of using the issue tracker. ## Credits - [Alexander Melihov](https://github.com/melihovv) - [All contributors](https://github.com/melihovv/laravel-package-generator/graphs/contributors) ================================================ FILE: composer.json ================================================ { "name": "melihovv/laravel-package-generator", "description": "A laravel package generator", "license": "MIT", "keywords": [ "laravel", "package", "generator" ], "type": "library", "authors": [ { "name": "Alexander Melihov", "email": "amelihovv@ya.ru" } ], "require": { "php": ">=7.2", "illuminate/container": "^6.0|^7.0|^8.0", "illuminate/console": "^6.0|^7.0|^8.0", "illuminate/filesystem": "^6.0|^7.0|^8.0", "illuminate/support": "^6.0|^7.0|^8.0", "illuminate/view": "^6.0|^7.0|^8.0" }, "autoload": { "psr-4": { "Melihovv\\LaravelPackageGenerator\\": "src" } }, "extra": { "laravel": { "providers": [ "Melihovv\\LaravelPackageGenerator\\ServiceProvider" ] } }, "config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true } } ================================================ FILE: config/package-generator.php ================================================ null, ]; ================================================ FILE: skeleton/.editorconfig ================================================ root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [Makefile] indent_style = tab [*.php] indent_size = 4 ================================================ FILE: skeleton/.gitattributes.tpl ================================================ * text=auto /.github export-ignore /tests export-ignore /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /.styleci.yml export-ignore /.sensiolabs.yml export-ignore /.coveralls.yml export-ignore /phpunit.xml export-ignore /CHANGELOG-* export-ignore /CONTRIBUTING.md export-ignore /CODE_OF_CONDUCT.md export-ignore ================================================ FILE: skeleton/.github/workflows/default.yml ================================================ name: Run tests on: push: schedule: - cron: '0 0 * * *' jobs: php-tests: runs-on: ${{ matrix.os }} strategy: matrix: php: [7.4, 7.3, 7.2] laravel: [7.*, 6.*] dependency-version: [prefer-lowest, prefer-stable] os: [ubuntu-latest, windows-latest] include: - laravel: 8.* testbench: 6.* - laravel: 7.* testbench: 5.* - laravel: 6.* testbench: 4.* exclude: - laravel: 8.* php: 7.2 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v1 - name: Setup PHP uses: shivammathur/setup-php@v1 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick coverage: none - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - name: Execute tests run: ./vendor/bin/phpunit ================================================ FILE: skeleton/.gitignore.tpl ================================================ /vendor /.idea /node_modules /composer.lock /.phpunit.result.cache ================================================ FILE: skeleton/.styleci.yml ================================================ preset: laravel ================================================ FILE: skeleton/LICENSE.tpl ================================================ The MIT License (MIT) Copyright (c) <> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: skeleton/README.md.tpl ================================================ # [![GitHub Workflow Status](https://github.com///workflows/Run%20tests/badge.svg)](https://github.com///actions) [![styleci](https://styleci.io/repos/CHANGEME/shield)](https://styleci.io/repos/CHANGEME) [![Packagist](https://img.shields.io/packagist/v//.svg)](https://packagist.org/packages//) [![Packagist](https://poser.pugx.org///d/total.svg)](https://packagist.org/packages//) [![Packagist](https://img.shields.io/packagist/l//.svg)](https://packagist.org/packages//) Package description: CHANGE ME ## Installation Install via composer ```bash composer require / ``` ### Publish package assets ```bash php artisan vendor:publish --provider="\\ServiceProvider" ``` ## Usage CHANGE ME ## Security If you discover any security related issues, please email instead of using the issue tracker. ## Credits - []() - [All contributors](/graphs/contributors) This package is bootstrapped with the help of [melihovv/laravel-package-generator](https://github.com/melihovv/laravel-package-generator). ================================================ FILE: skeleton/composer.json.tpl ================================================ { "name": "", "description": "", "license": "", "keywords": [ ], "type": "library", "authors": [ { "name": "", "email": "" } ], "require": { "php": "", "illuminate/support": "^6.0|^7.0|^8.0" }, "require-dev": { "orchestra/testbench": "^4.0|^5.0|^6.0", "phpunit/phpunit": "^8.4|^9.0" }, "autoload": { "psr-4": { "\\\\": "src" } }, "autoload-dev": { "psr-4": { "\\\\Tests\\": "tests" } }, "scripts": { "phpunit": "phpunit" }, "extra": { "laravel": { "providers": [ "\\\\ServiceProvider" ] } }, "config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true } } ================================================ FILE: skeleton/phpunit.xml ================================================ tests src ================================================ FILE: skeleton/src/ServiceProvider.php.tpl ================================================ namespace \; class ServiceProvider extends \Illuminate\Support\ServiceProvider { const CONFIG_PATH = __DIR__ . '/../config/.php'; public function boot() { $this->publishes([ self::CONFIG_PATH => config_path('.php'), ], 'config'); } public function register() { $this->mergeConfigFrom( self::CONFIG_PATH, '' ); $this->app->bind('', function () { return new (); }); } } ================================================ FILE: src/Commands/PackageNew.php ================================================ getVendor(); $package = $this->getPackage(); $vendorFolderName = $this->getVendorFolderName($vendor); $packageFolderName = $this->getPackageFolderName($package); $relPackagePath = "packages/$vendorFolderName/$packageFolderName"; $packagePath = base_path($relPackagePath); try { $this->createPackageFolder($packagePath); $this->registerPackage($vendorFolderName, $packageFolderName, $relPackagePath); $this->copySkeleton($packagePath, $vendor, $package, $vendorFolderName, $packageFolderName); $this->initRepo($packagePath); $this->composerUpdatePackage($vendorFolderName, $packageFolderName); $this->composerDumpAutoload(); $this->info('Finished. Are you ready to write awesome package?'); return 0; } catch (Exception $e) { $this->error($e->getMessage()); return -1; } } } ================================================ FILE: src/Commands/PackageRemove.php ================================================ getVendor(); $package = $this->getPackage(); $vendorFolderName = $this->getVendorFolderName($vendor); $packageFolderName = $this->getPackageFolderName($package); $relPackagePath = "packages/$vendorFolderName/$packageFolderName"; $packagePath = base_path($relPackagePath); try { $this->composerRemovePackage($vendorFolderName, $packageFolderName); $this->removePackageFolder($packagePath); $this->unregisterPackage($vendor, $package, "packages/$vendorFolderName/$packageFolderName"); $this->composerDumpAutoload(); return 0; } catch (Exception $e) { $this->error($e->getMessage()); return -1; } } } ================================================ FILE: src/Commands/Traits/ChangesComposerJson.php ================================================ info('Register package in composer.json.'); $composerJson = $this->loadComposerJson(); if (! isset($composerJson['repositories'])) { Arr::set($composerJson, 'repositories', []); } $filtered = array_filter($composerJson['repositories'], function ($repository) use ($relPackagePath) { return $repository['type'] === 'path' && $repository['url'] === $relPackagePath; }); if (count($filtered) === 0) { $this->info('Register composer repository for package.'); $composerJson['repositories'][] = (object) [ 'type' => 'path', 'url' => $relPackagePath, ]; } else { $this->info('Composer repository for package is already registered.'); } Arr::set($composerJson, "require.$vendor/$package", 'dev-master'); $this->saveComposerJson($composerJson); $this->info('Package was successfully registered in composer.json.'); } /** * Unregister package from composer.json. * * @param $vendor * @param $package * * @throws FileNotFoundException * @throws RuntimeException */ protected function unregisterPackage($vendor, $package, $relPackagePath) { $this->info('Unregister package from composer.json.'); $composerJson = $this->loadComposerJson(); unset($composerJson['require']["$vendor\\$package\\"]); $repositories = array_filter($composerJson['repositories'], function ($repository) use ($relPackagePath) { return $repository['type'] !== 'path' || $repository['url'] !== $relPackagePath; }); $composerJson['repositories'] = $repositories; if (count($composerJson['repositories']) === 0) { unset($composerJson['repositories']); } $this->saveComposerJson($composerJson); $this->info('Package was successfully unregistered from composer.json.'); } /** * Load and parse content of composer.json. * * @return array * * @throws FileNotFoundException * @throws RuntimeException */ protected function loadComposerJson() { $composerJsonPath = $this->getComposerJsonPath(); if (! File::exists($composerJsonPath)) { throw new FileNotFoundException('composer.json does not exist'); } $composerJsonContent = File::get($composerJsonPath); $composerJson = json_decode($composerJsonContent, true); if (! is_array($composerJson)) { throw new RuntimeException("Invalid composer.json file [$composerJsonPath]"); } return $composerJson; } /** * @param array $composerJson * * @throws RuntimeException */ protected function saveComposerJson($composerJson) { $newComposerJson = json_encode( $composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); $composerJsonPath = $this->getComposerJsonPath(); if (File::put($composerJsonPath, $newComposerJson) === false) { throw new RuntimeException("Cannot write to composer.json [$composerJsonPath]"); } } /** * Get composer.json path. * * @return string */ protected function getComposerJsonPath() { return base_path('composer.json'); } } ================================================ FILE: src/Commands/Traits/CopiesSkeleton.php ================================================ info('Copy skeleton.'); $skeletonDirPath = $this->getPathFromConfig( 'skeleton_dir_path', $this->packageBaseDir.'/skeleton' ); foreach (File::allFiles($skeletonDirPath, true) as $filePath) { $filePath = realpath($filePath); $destFilePath = Str::replaceFirst( $skeletonDirPath, $packagePath, $filePath ); $this->copyFileWithDirsCreating($filePath, $destFilePath); } $this->copyStubs($packagePath, $package, $packageFolderName); $variables = $this->getVariables( $vendor, $package, $vendorFolderName, $packageFolderName ); $this->replaceTemplates($packagePath, $variables); $this->info('Skeleton was successfully copied.'); } /** * Copy stubs. * * @param $packagePath * @param $package * @param $packageFolderName */ protected function copyStubs($packagePath, $package, $packageFolderName) { $facadeFilePath = $this->packageBaseDir.'/stubs/Facade.php.tpl'; $mainClassFilePath = $this->packageBaseDir.'/stubs/MainClass.php.tpl'; $mainClassTestFilePath = $this->packageBaseDir.'/stubs/MainClassTest.php.tpl'; $configFilePath = $this->packageBaseDir.'/stubs/config.php'; $filePaths = [ $facadeFilePath => "$packagePath/src/Facades/$package.php.tpl", $mainClassFilePath => "$packagePath/src/$package.php.tpl", $mainClassTestFilePath => "$packagePath/tests/{$package}Test.php.tpl", $configFilePath => "$packagePath/config/$packageFolderName.php", ]; foreach ($filePaths as $filePath => $destFilePath) { $this->copyFileWithDirsCreating($filePath, $destFilePath); } } /** * Substitute all variables in *.tpl files and remove tpl extension. * * @param string $packagePath * @param array $variables */ protected function replaceTemplates($packagePath, $variables) { $phpEngine = app()->make(PhpEngine::class); foreach (File::allFiles($packagePath, true) as $filePath) { $filePath = realpath($filePath); if (! Str::endsWith($filePath, '.tpl')) { continue; } try { $newFileContent = $phpEngine->get($filePath, $variables); } catch (Exception $e) { $this->error("Template [$filePath] contains syntax errors"); $this->error($e->getMessage()); continue; } $filePathWithoutTplExt = Str::replaceLast( '.tpl', '', $filePath ); File::put($filePathWithoutTplExt, $newFileContent); File::delete($filePath); } } /** * Copy source file to destination with needed directories creating. * * @param string $src * @param string $dest */ protected function copyFileWithDirsCreating($src, $dest) { $dirPathOfDestFile = dirname($dest); if (! File::exists($dirPathOfDestFile)) { File::makeDirectory($dirPathOfDestFile, 0755, true); } if (! File::exists($dest)) { File::copy($src, $dest); } } /** * Get variables for substitution in templates. * * @param string $vendor * @param string $package * @param string $vendorFolderName * @param string $packageFolderName * * @return array */ protected function getVariables( $vendor, $package, $vendorFolderName, $packageFolderName ) { $packageWords = str_replace('-', ' ', Str::snake($packageFolderName)); $composerDescription = $this->askUser( 'The composer description?', "A $packageWords" ); $composerKeywords = $this->getComposerKeywords($packageWords); $packageHumanName = $this->askUser( 'The package human name?', Str::title($packageWords) ); return [ 'vendor' => $vendor, 'package' => $package, 'vendorFolderName' => $vendorFolderName, 'packageFolderName' => $packageFolderName, 'packageHumanName' => $packageHumanName, 'composerName' => "$vendorFolderName/$packageFolderName", 'composerDesc' => $composerDescription, 'composerKeywords' => $composerKeywords, 'license' => $this->askUser('The package licence?', 'MIT'), 'phpVersion' => $this->askUser('Php version constraint?', '>=7.2'), 'aliasName' => $packageFolderName, 'configFileName' => $packageFolderName, 'year' => date('Y'), 'name' => $this->askUser('Your name?'), 'email' => $this->askUser('Your email?'), 'githubPackageUrl' => "https://github.com/$vendorFolderName/$packageFolderName", ]; } /** * Get path from config. * * @param string $configName * @param string $default * * @return string * * @throws RuntimeException */ protected function getPathFromConfig($configName, $default) { $path = config("package-generator.$configName"); if (empty($path)) { $path = $default; } else { $path = base_path($path); } $realPath = realpath($path); if ($realPath === false) { throw RuntimeException::noAccessTo($path); } return $realPath; } /** * Get composer keywords. * * @param $packageWords * * @return string */ protected function getComposerKeywords($packageWords) { $keywords = $this->askUser( 'The composer keywords? (comma delimited)', str_replace(' ', ',', $packageWords) ); $keywords = explode(',', $keywords); $keywords = array_map(function ($keyword) { return "\"$keyword\""; }, $keywords); return implode(",\n".str_repeat(' ', 4), $keywords); } } ================================================ FILE: src/Commands/Traits/InteractsWithComposer.php ================================================ composerRunCommand('composer dump-autoload'); } /** * Run "composer update $vendor/$package". * * @param string $vendor * @param string $package */ protected function composerUpdatePackage($vendor, $package) { $this->composerRunCommand("composer update --ignore-platform-reqs $vendor/$package"); } /** * Run "composer remove $vendor/$package". * * @param string $vendor * @param string $package */ protected function composerRemovePackage($vendor, $package) { $this->composerRunCommand("composer remove --ignore-platform-reqs $vendor/$package"); } /** * Run arbitrary composer command. * * @param $command */ protected function composerRunCommand($command) { $this->info("Run \"$command\"."); $output = []; exec($command, $output, $returnStatusCode); if ($returnStatusCode !== 0) { throw RuntimeException::commandExecutionFailed($command, $returnStatusCode); } $this->info("\"$command\" was successfully ran."); } } ================================================ FILE: src/Commands/Traits/InteractsWithGit.php ================================================ info("Run \"$command\"."); File::makeDirectory($dest, 0755, true); $output = []; exec($command, $output, $returnStatusCode); if ($returnStatusCode !== 0) { throw RuntimeException::commandExecutionFailed( $command, $returnStatusCode ); } $this->info("\"$command\" was successfully ran."); } /** * Init git repo. * @param string $repoPath */ protected function initRepo($repoPath) { $command = "git init $repoPath"; $this->info("Run \"$command\"."); $output = []; exec($command, $output, $returnStatusCode); if ($returnStatusCode !== 0) { throw RuntimeException::commandExecutionFailed( $command, $returnStatusCode ); } $this->info("\"$command\" was successfully ran."); } } ================================================ FILE: src/Commands/Traits/InteractsWithUser.php ================================================ argument('vendor') ?: $default; return $this->askUser('The vendor name?', $vendor); } /** * Get the name of package for the namespace. * * @param string $default * * @return string */ protected function getPackage($default = '') { $package = $this->argument('package') ?: $default; return $this->askUser('The package name?', $package); } /** * Get vendor folder name. * * @param string $vendor * * @return string */ protected function getVendorFolderName($vendor) { $vendorFolderName = Str::kebab($vendor); return $this->askUser('The vendor folder name?', $vendorFolderName); } /** * Get package folder name. * * @param string $package * * @return string */ protected function getPackageFolderName($package) { $packageFolderName = Str::kebab($package); return $this->askUser('The package folder name?', $packageFolderName); } /** * Ask user. * * @param $question * @param $defaultValue * * @return string */ protected function askUser($question, $defaultValue = '') { if ($this->option('interactive')) { return $this->ask($question, $defaultValue); } return $defaultValue; } } ================================================ FILE: src/Commands/Traits/ManipulatesPackageFolder.php ================================================ info('Create package folder.'); if (File::exists($packagePath)) { $this->info('Package folder already exists. Skipping.'); return; } if (! File::makeDirectory($packagePath, 0755, true)) { throw new RuntimeException('Cannot create package folder'); } $this->info('Package folder was successfully created.'); } /** * Remove package folder. * * @param $packagePath * * @throws RuntimeException */ protected function removePackageFolder($packagePath) { $this->info('Remove package folder.'); if (File::exists($packagePath)) { if (! File::deleteDirectory($packagePath)) { throw new RuntimeException('Cannot remove package folder'); } $this->info('Package folder was successfully removed.'); } else { $this->info('Package folder does not exists. Skipping.'); } } } ================================================ FILE: src/Exceptions/RuntimeException.php ================================================ publishes([ self::CONFIG_PATH => config_path('package-generator.php'), ], 'config'); if ($this->app->runningInConsole()) { $this->commands([ PackageNew::class, PackageRemove::class, ]); } } public function register() { $this->mergeConfigFrom( self::CONFIG_PATH, 'package-generator' ); } } ================================================ FILE: stubs/Facade.php.tpl ================================================ namespace \\Facades; use Illuminate\Support\Facades\Facade; class extends Facade { protected static function getFacadeAccessor() { return ''; } } ================================================ FILE: stubs/MainClass.php.tpl ================================================ namespace \; class { } ================================================ FILE: stubs/MainClassTest.php.tpl ================================================ namespace \\Tests; use \\Facades\; use \\ServiceProvider; use Orchestra\Testbench\TestCase; class Test extends TestCase { protected function getPackageProviders($app) { return [ServiceProvider::class]; } protected function getPackageAliases($app) { return [ '' => ::class, ]; } public function testExample() { $this->assertEquals(1, 1); } } ================================================ FILE: stubs/config.php ================================================