/** * Make a verification. * * @param Package $package * * @throws ValidatorException * * @return void */ public function verify(Package $package) { $path = $package->getDestination(); if (is_dir($path) || is_file($path) || $path == getcwd()) { throw new ValidatorException('Package already exists!'); } }
public function __invoke($dir, InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $output->writeln('<info>I need to know a little more about your future awesome laravel package...</info>'); $output->writeln(''); $package = new Package($this->askForPackageName(), $this->askForAuthor(), $dir); $package->setDescription($this->askForDescription()); $output->writeln(''); $output->writeln('<info>Crafting your laravel package...</info>'); $this->crafter->craft($package); $output->writeln(''); $output->writeln('<info>Successfully crafted!</info>'); }
/** * Craft the application with parameters. * * @param Package $package * * @return mixed */ public function craft(Package $package) { $stubPath = realpath(__DIR__ . '/../stubs'); // set delimiters $this->stubber->withDelimiters('{{', '}}'); // set keywords $this->stubber->setRaw($package->toArray()); $this->filesystem->mirror($stubPath, $package->getDestination()); // array of all stub files $stubFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($package->getDestination(), \RecursiveDirectoryIterator::SKIP_DOTS)); // find and replace foreach ($stubFiles as $stub) { $new = pathinfo($stub); $this->stubber->useStub($stub); if ($this->isConfigFile($new['basename'])) { $this->stubber->generate($new['dirname'] . '/' . Str::slug($package->getPackage()) . '.php'); } elseif ($this->isServiceProviderFile($new['basename'])) { $this->stubber->generate($new['dirname'] . '/' . $package->getPackage() . 'ServiceProvider.php'); } else { $this->stubber->generate($new['dirname'] . '/' . $new['filename']); } $this->filesystem->remove($stub); } }
/** * Make a verification. * * @param Package $package * * @throws ValidatorException * * @return void */ public function verify(Package $package) { if (null === $package->getName() || empty($package->getName())) { throw new ValidatorException('Package name is not defined!'); } }