From eafbb486fcb56330990ae9c5781f7f0f845d7ae3 Mon Sep 17 00:00:00 2001 From: Gilbert Pellegrom Date: Tue, 10 Mar 2015 14:54:33 +0000 Subject: [PATCH] Add publish commands --- src/Commands/PublishAssets.php | 62 ++++++++++++++++++++++++++++++++++ src/Commands/PublishConfig.php | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 src/Commands/PublishAssets.php create mode 100644 src/Commands/PublishConfig.php 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