Exemplo n.º 1
0
 /**
  * Initializes a package template in the provided directory.
  *
  * @throws InvalidPathException
  *
  * @param $vendor
  * @param $package
  * @param $directory
  */
 public function initialize($vendor, $package, $directory)
 {
     if (!$this->files->exists($directory) || !$this->files->isDirectory($directory)) {
         throw new InvalidPathException("{$directory} does not exist or is not a valid directory.");
     }
     $packageComposer = new Package();
     $packageComposer->setVendor($vendor);
     $packageComposer->setPackage($package);
     $packageComposer->setDescription('Give your package template a good description');
     $packageComposer->setLicense(user_config('configuration.license', ''));
     $packageComposer->setAuthors(user_config('configuration.authors', []));
     $writer = new ConfigurationWriter($packageComposer->toArray());
     $writer['config'] = (object) ['vendor-dir' => '_newup_vendor'];
     $writer->save($directory . '/composer.json');
     $this->renderer->setData('package', $package);
     $this->renderer->setData('vendor', $vendor);
     $packageClass = $this->renderer->render('template');
     if (!$this->files->exists($directory . '/_newup/')) {
         $this->files->makeDirectory($directory . '/_newup/');
     }
     if ($this->shouldCreateTemplateDirectory && $this->files->exists($directory . '/_template') == false) {
         $this->files->makeDirectory($directory . '/_template');
     }
     $this->files->put($directory . '/_newup/Package.php', $packageClass);
 }
Exemplo n.º 2
0
 /**
  * Override the builderLoaded method so we can know when NewUp
  * has loaded the workbench playground. We can access user
  * arguments and options at this point in template
  * generation, which will prove very useful.
  */
 public function builderLoaded()
 {
     // Get the parsed vendor and package name from the user input. NewUp's Package class
     // provides a helper method just for this.
     $vendorPackageParts = PackageClass::parseVendorAndPackage($this->argument('package'));
     $vendor = $vendorPackageParts[0];
     $package = $vendorPackageParts[1];
     // Share the vendor and package with the template system.
     $this->with(['vendor' => $vendor, 'package' => $package]);
     if (!$this->option('resources')) {
         // If the user has not specified the resources option, we can just tell
         // NewUp to ignore the Laravel specific directories. It is important
         // to note that ignored paths are actually patterns.
         $this->ignorePath(['src/controllers*', 'src/migrations*', 'src/config*', 'src/views*', 'src/lang*', 'public/*']);
     }
     // Laravel 4's workbench tool created a "composer.json" file in the directory
     // of the new package. This is also very easy to accomplish using NewUp.
     // First, we will get a PackageClass instance that we can work with
     // and manipulate. Conveniently, the PackageClass's structure is
     // very close to that of a "composer.json" file. Since NewUp
     // allows users to configure the default authors and license
     // we can get a PackageClass instance with all of those
     // values already set.
     $composerJson = PackageClass::getConfiguredPackage();
     // Now we can set the vendor and package name, which we parsed earlier. We
     // will also need to add a few more things that the PackageClass cannot
     // handle on its own. We will take care of that later with the
     // ConfigurationWriter class.
     $composerJson->setVendor($vendor)->setPackage($package);
     // The PackageClass cannot save anything by itself, but a ConfigurationWriter
     // class is available that can. We can create a new instance of the writer
     // and pass all the values from the PackageClass as an array!
     $writer = new ConfigurationWriter($composerJson->toArray());
     // Before we save anything, we need to add a few more things to the final
     // "composer.json" file. We need to add the require, autoload and minimum
     // stability sections. Also take note that we are casting some arrays
     // into objects to get the desired output when everything is finally
     // saved in the JSON format.
     $writer['require'] = (object) ['php' => '>=5.4.0', 'illuminate/support' => '4.2.*'];
     $autoloadSection = ['psr-0' => (object) [Str::studly($vendor) . '\\\\' . Str::studly($package) . '\\\\' => 'src/']];
     // Add the migrations to the autoload section if the user specified the "resources" option.
     if ($this->option('resources')) {
         $autoloadSection['classmap'][] = 'src/migrations';
     }
     // Now we can add the autoload section.
     $writer['autoload'] = (object) $autoloadSection;
     $writer['minimum-stability'] = 'stable';
     // Now it is time to save the "composer.json" file.
     $writer->save($this->outputDirectory() . '/composer.json');
 }
Exemplo n.º 3
0
 /**
  * Called when the builder has loaded the package class.
  *
  * @return mixed
  */
 public function builderLoaded()
 {
     // Get the parsed vendor and package name from the user input. NewUp's Package class
     // provides a helper method just for this.
     $vendorPackageParts = PackageClass::parseVendorAndPackage($this->argument('package'));
     $vendor = $vendorPackageParts[0];
     $package = $vendorPackageParts[1];
     // Share the vendor and package with the template system.
     $this->with(['vendor' => $vendor, 'package' => $package]);
     // Just some setup code to create a composer.json file.
     $composerJson = PackageClass::getConfiguredPackage();
     $composerJson->setVendor($vendor)->setPackage($package);
     $writer = new ConfigurationWriter($composerJson->toArray());
     // Package requirements.
     $requirements = ['php' => $this->argument('phpv')];
     // Package dev requirements.
     $requireDev = [];
     // If the user specified PHPUnit support, we need to add that to the requirements.
     if ($this->option('phpunit')) {
         $requireDev['mockery/mockery'] = '~0.9.2';
         $requireDev['phpunit/phpunit'] = '~4.0';
         $this->line("Added 'mockery/mockery' and 'phpunit/phpunit' to composer dev dependencies.");
     } else {
         $this->ignorePath(['phpunit.xml', 'tests/*']);
     }
     // Gather TravisCI information.
     if ($this->option('travis')) {
         $this->gatherTravisCIRequirements();
         $this->with(['travisVersions' => $this->travisVersions]);
     } else {
         $this->ignorePath(['.travis.yml']);
     }
     $writer['require'] = (object) $requirements;
     $writer['require-dev'] = (object) $requireDev;
     // This next section will create the "autoload" section within the composer.json file.
     $autoLoader = $this->option('psr');
     $autoLoader == 'psr0' ? $autoLoader = 'psr-0' : ($autoLoader = 'psr-4');
     $autoloadSection = [$autoLoader => (object) [Str::studly($vendor) . '\\' . Str::studly($package) . '\\' => 'src/']];
     $this->line("Using {$autoLoader} autoloader.");
     // Now we can add the autoload section.
     $writer['autoload'] = (object) $autoloadSection;
     $writer['minimum-stability'] = 'stable';
     // Now it is time to save the "composer.json" file.
     $writer->save($this->outputDirectory() . '/composer.json');
     $this->info("Your package was generated! Make sure to set the description field in your composer.json file!");
 }
Exemplo n.º 4
0
 public function testSaveYamlWritesCorrectYaml()
 {
     $this->writer->saveYaml($this->getPath('test.yaml'));
     $this->assertEquals(loadFixtureContent('Configuration/expected.yaml'), $this->getContents('test.yaml'));
 }