diff --git a/src/Commands/PublishAssets.php b/src/Commands/PublishAssets.php new file mode 100644 index 0000000..d96dbc7 --- /dev/null +++ b/src/Commands/PublishAssets.php @@ -0,0 +1,62 @@ +setName('publish:assets') + ->setDescription('Publish a plugin\'s asset files') + ->addArgument( + 'plugin', + InputArgument::REQUIRED, + 'What is the plugin name (found in composer.json)?' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $plugin = $input->getArgument('plugin'); + + if (!is_dir(BASE_PATH . 'vendor/' . $plugin)) { + return $output->writeln('Error: Plugin ' . $plugin . ' not found'); + } + if (!is_dir(BASE_PATH . 'vendor/' . $plugin . '/assets')) { + return $output->writeln('No assets found'); + } + + $files = glob(BASE_PATH . 'vendor/' . $plugin . '/assets/*'); + if (!empty($files)) { + $error = false; + foreach ($files as $file) { + $fileName = basename($file); + $destFolder = BASE_PATH . 'public/assets/plugins/' . $plugin . '/'; + if (!is_dir($destFolder)) { + if (is_writable(BASE_PATH . 'public/assets')) { + mkdir($destFolder, 0777, true); + } else { + return $output->writeln('Error: /public/assets folder is not writeable'); + } + } + + if (!copy($file, $destFolder . $fileName)) { + $error = true; + $output->writeln('Error: Failed to copy ' . $fileName . ''); + } + } + + if (!$error) { + $output->writeln('Successfully published ' . count($files) . ' assets'); + } + } else { + $output->writeln('No assets found'); + } + } + +} \ No newline at end of file diff --git a/src/Commands/PublishConfig.php b/src/Commands/PublishConfig.php new file mode 100644 index 0000000..c8baadd --- /dev/null +++ b/src/Commands/PublishConfig.php @@ -0,0 +1,62 @@ +setName('publish:config') + ->setDescription('Publish a plugin\'s config files') + ->addArgument( + 'plugin', + InputArgument::REQUIRED, + 'What is the plugin name (found in composer.json)?' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $plugin = $input->getArgument('plugin'); + + if (!is_dir(BASE_PATH . 'vendor/' . $plugin)) { + return $output->writeln('Error: Plugin ' . $plugin . ' not found'); + } + if (!is_dir(BASE_PATH . 'vendor/' . $plugin . '/config')) { + return $output->writeln('No config files found'); + } + + $files = glob(BASE_PATH . 'vendor/' . $plugin . '/config/*.php'); + if (!empty($files)) { + $error = false; + foreach ($files as $file) { + $fileName = basename($file); + $destFolder = BASE_PATH . 'config/plugins/' . $plugin . '/'; + if (!is_dir($destFolder)) { + if (is_writable(BASE_PATH . 'config')) { + mkdir($destFolder, 0777, true); + } else { + return $output->writeln('Error: /config folder is not writeable'); + } + } + + if (!copy($file, $destFolder . $fileName)) { + $error = true; + $output->writeln('Error: Failed to copy ' . $fileName . ''); + } + } + + if (!$error) { + $output->writeln('Successfully published ' . count($files) . ' config files'); + } + } else { + $output->writeln('No config files found'); + } + } + +} \ No newline at end of file