├── .gitignore ├── README.md ├── behat.yml ├── composer.json ├── composer.lock ├── features ├── bootstrap │ ├── CliContext.php │ └── CoreDomainContext.php ├── cli │ └── create-module.feature └── core │ └── create-module.feature ├── phpspec.yml ├── spec └── Generators │ └── Type │ └── ModuleSpec.php └── src ├── Generators ├── Templates │ └── module.xml.template └── Type │ └── Module.php └── GeneratorsModule ├── Commands └── GeneratorCommand.php ├── etc ├── di.xml └── module.xml └── registration.php /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fast Workflow in Magento 2 With Custom Generators 2 | * WIP * This module is still under active development and should be considered alpha 3 | 4 | With this module installed you will have access to many new commands available via the magento CLI. These are intended to speed up the developer workflow 5 | 6 | - `generate:model` 7 | - `generate:view` 8 | - `generate:controller` 9 | - `generate:resource-model` 10 | - `generate:collection` 11 | - `generate:repository` 12 | - `generate:helper` 13 | - `generate:interface` 14 | 15 | ## Installation 16 | 17 | TBC 18 | -------------------------------------------------------------------------------- /behat.yml: -------------------------------------------------------------------------------- 1 | default: 2 | suites: 3 | core_features: 4 | paths: [ %paths.base%/features/core ] 5 | contexts: [ CoreDomainContext ] 6 | cli_features: 7 | paths: [ %paths.base%/features/cli ] 8 | contexts: [ CliContext ] 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jcowie/generators", 3 | "description": "Generate new classes for M2", 4 | "license": "MIT", 5 | "type": "magento2-module", 6 | "require": { 7 | "php": "~5.5.0|~5.6.0|~7.0.0", 8 | "magento/product-community-edition": "2.1.2", 9 | "composer/composer": "~1.0", 10 | "symfony/yaml": "2.*", 11 | "symfony/filesystem": "~2" 12 | }, 13 | "require-dev": { 14 | "phpspec/phpspec": "^2.4.1", 15 | "nagno/phpspec-bootstrap-magento2": "~1.0", 16 | "phpunit/phpunit": "~3.7", 17 | "bossa/phpspec2-expect": "*", 18 | "behat/behat": "3.*", 19 | "symfony/process" : "*", 20 | "phpunit/phpunit": "~4.5" 21 | }, 22 | "repositories": [ 23 | { 24 | "type": "composer", 25 | "url": "https://repo.magento.com/" 26 | }, 27 | { 28 | "type": "git", 29 | "url": "https://github.com/nagno/phpspec-bootstrap-magento2.git" 30 | } 31 | ], 32 | "autoload": { 33 | "files": [ "src/GeneratorsModule/registration.php" ], 34 | "psr-4": { 35 | "Jcowie\\GeneratorsModule\\": "src/GeneratorsModule/", 36 | "Jcowie\\Generators\\": "src/Generators/" 37 | } 38 | }, 39 | "autoload-dev": { 40 | "psr-4": { 41 | "Jcowie\\GeneratorsModule\\": "src/GeneratorsModule/", 42 | "Jcowie\\Generators\\": "src/Generators/", 43 | "Magento\\" : "vendor/magento/magento2ce/app/code/", 44 | "Magento\\Framework\\": "vendor/magento/magento2ce/lib/internal/" 45 | } 46 | }, 47 | "config": { 48 | "bin-dir": "bin" 49 | }, 50 | "minimum-stability": "alpha", 51 | "prefer-stable": true 52 | } 53 | -------------------------------------------------------------------------------- /features/bootstrap/CliContext.php: -------------------------------------------------------------------------------- 1 | filesystem = new Filesystem(); 24 | } 25 | 26 | /** 27 | * @Given The Generator CLI option exists 28 | */ 29 | public function theGeneratorCliOptionExists() 30 | { 31 | // @TODO parse the output from the magento command me thinks 32 | return true; 33 | } 34 | 35 | /** 36 | * @When I run :command 37 | */ 38 | public function iRun($command) 39 | { 40 | $process = new Process("php " . getcwd() . "/../../../". $command); 41 | $process->run(); 42 | 43 | $this->output = $process->getOutput(); 44 | } 45 | 46 | /** 47 | * @Then I should see an error message 48 | */ 49 | public function iShouldSeeAnErrorMessage() 50 | { 51 | expect($this->output)->notToBe(null); 52 | } 53 | 54 | /** 55 | * @Then I should see :output 56 | */ 57 | public function iShouldSee($output) 58 | { 59 | expect(trim($this->output))->toBe($output); 60 | } 61 | 62 | /** 63 | * @AfterScenario 64 | */ 65 | public function cleanFs() 66 | { 67 | $this->filesystem->remove("app"); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /features/bootstrap/CoreDomainContext.php: -------------------------------------------------------------------------------- 1 | filesystem = new Filesystem(); 24 | $this->moduleGenerator = new \Jcowie\Generators\Type\Module($this->filesystem); 25 | } 26 | 27 | /** 28 | * @Given The generator file exists 29 | */ 30 | public function theGeneratorFileExists() 31 | { 32 | return true; 33 | } 34 | 35 | /** 36 | * @When I run the generator with the path :path 37 | */ 38 | public function iRunTheGenerator($path) 39 | { 40 | $this->path = $path; 41 | $this->output = $this->moduleGenerator->make($path); 42 | } 43 | 44 | /** 45 | * @Then I should see a folder that patches the path 46 | */ 47 | public function thenIShouldSeeAnExceptionAsNoNameIsSetForTheModule() 48 | { 49 | if ($this->filesystem->exists($this->path)) { 50 | return true; 51 | } 52 | return false; 53 | } 54 | 55 | /** 56 | * @AfterScenario 57 | */ 58 | public function cleanFs() 59 | { 60 | $folders = explode("/", $this->path); 61 | 62 | $this->filesystem->remove($folders[0]); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /features/cli/create-module.feature: -------------------------------------------------------------------------------- 1 | Feature: The Generator module should generate a module when called 2 | In order to create Magento 2 Modules 3 | As a extension developer 4 | I want to create modules from the CLI 5 | 6 | Scenario: The generator CLI command will exist and provide a error when no path is set 7 | Given The Generator CLI option exists 8 | When I run "bin/magento generate:module" 9 | Then I should see an error message 10 | 11 | Scenario: The generator CLI command will create the module structure when path is set 12 | Given The Generator CLI option exists 13 | When I run "bin/magento generate:module app/code/test" 14 | Then I should see "Module folder created" 15 | -------------------------------------------------------------------------------- /features/core/create-module.feature: -------------------------------------------------------------------------------- 1 | Feature: The Generator module should generate a module when called 2 | In order to create Magento 2 Modules 3 | As a extension developer 4 | I want to create modules from the CLI 5 | 6 | Scenario: The generator will error if no name is passed 7 | Given The generator file exists 8 | When I run the generator with the path "app/code/test" 9 | Then I should see a folder that patches the path 10 | -------------------------------------------------------------------------------- /phpspec.yml: -------------------------------------------------------------------------------- 1 | bootstrap: '../../../app/autoload.php' 2 | formatter.name: pretty 3 | extensions: 4 | - Nagno\Phpspec\BootstrapMagento2\Bootstrap 5 | suites: 6 | generator_suite: 7 | namespace: Jcowie 8 | psr4_prefix: Jcowie 9 | -------------------------------------------------------------------------------- /spec/Generators/Type/ModuleSpec.php: -------------------------------------------------------------------------------- 1 | beConstructedWith($filesystem); 13 | } 14 | 15 | function it_is_initializable() 16 | { 17 | $this->shouldHaveType('Jcowie\Generators\Type\Module'); 18 | } 19 | 20 | function it_should_throw_an_exception_if_a_module_folder_already_exists($filesystem) 21 | { 22 | $path = 'app/code/test/test/'; 23 | $filesystem->exists($path)->willReturn(true); 24 | $this->shouldThrow(new \Exception("Error module already exists"))->duringMake($path); 25 | } 26 | 27 | function it_should_create_a_folder_given_a_valid_path($filesystem) 28 | { 29 | $path = 'app/code/test/test'; 30 | $filesystem->exists($path)->willReturn(false); 31 | $filesystem->mkdir($path, 0700)->willReturn(true); 32 | $this->make($path)->shouldReturn(true); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Generators/Templates/module.xml.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Generators/Type/Module.php: -------------------------------------------------------------------------------- 1 | filesystem = $filesystem; 19 | } 20 | 21 | /** 22 | * @param $path 23 | * @throws \Exception 24 | */ 25 | public function make($path) 26 | { 27 | if ($this->filesystem->exists($path)) { 28 | throw new \Exception("Error module already exists"); 29 | } 30 | 31 | return $this->filesystem->mkdir($path, 0700); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/GeneratorsModule/Commands/GeneratorCommand.php: -------------------------------------------------------------------------------- 1 | generator = $generator; 24 | parent::__construct(); 25 | } 26 | 27 | protected function configure() 28 | { 29 | $this->setName('generate:module'); 30 | $this->setDescription('Build a magento 2 module from the command line'); 31 | $this->addArgument( 32 | 'name', 33 | InputArgument::REQUIRED, 34 | 'Module Name ( Test/Module/ ) ' 35 | ); 36 | parent::configure(); 37 | } 38 | 39 | protected function execute(InputInterface $input, OutputInterface $output) 40 | { 41 | $this->generator->make($input->getArgument('name')); 42 | $output->writeln("Module folder created"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/GeneratorsModule/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Jcowie\GeneratorsModule\Commands\GeneratorCommand 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/GeneratorsModule/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/GeneratorsModule/registration.php: -------------------------------------------------------------------------------- 1 |