parser = new ComponentParser( config('livewire.class_namespace'), config('livewire.view_path'), $this->argument('name') ); $this->newParser = new ComponentParserFromExistingComponent( config('livewire.class_namespace'), config('livewire.view_path'), $this->argument('new-name'), $this->parser ); $force = $this->option('force'); $inline = $this->option('inline'); $test = $this->option('test'); $class = $this->copyClass($force, $inline); if (! $inline) $view = $this->copyView($force); if ($test){ $test = $this->copyTest($force); } $this->refreshComponentAutodiscovery(); $this->line(" COMPONENT COPIED 🤙\n"); $class && $this->line("CLASS: {$this->parser->relativeClassPath()} => {$this->newParser->relativeClassPath()}"); if (! $inline) $view && $this->line("VIEW: {$this->parser->relativeViewPath()} => {$this->newParser->relativeViewPath()}"); if ($test) $test && $this->line("Test: {$this->parser->relativeTestPath()} => {$this->newParser->relativeTestPath()}"); } protected function copyTest($force) { if (File::exists($this->newParser->testPath()) && ! $force) { $this->line(" WHOOPS-IE-TOOTLES 😳 \n"); $this->line("Test already exists: {$this->newParser->relativeTestPath()}"); return false; } $this->ensureDirectoryExists($this->newParser->testPath()); return File::copy("{$this->parser->testPath()}", $this->newParser->testPath()); } protected function copyClass($force, $inline) { if (File::exists($this->newParser->classPath()) && ! $force) { $this->line(" WHOOPS-IE-TOOTLES 😳 \n"); $this->line("Class already exists: {$this->newParser->relativeClassPath()}"); return false; } $this->ensureDirectoryExists($this->newParser->classPath()); return File::put($this->newParser->classPath(), $this->newParser->classContents($inline)); } protected function copyView($force) { if (File::exists($this->newParser->viewPath()) && ! $force) { $this->line("View already exists: {$this->newParser->relativeViewPath()}"); return false; } $this->ensureDirectoryExists($this->newParser->viewPath()); return File::copy("{$this->parser->viewPath()}", $this->newParser->viewPath()); } }