Browse Source

Allow processing assets of only specified plugin.

ADmad 11 years ago
parent
commit
20c09860ca
2 changed files with 45 additions and 9 deletions
  1. 21 6
      src/Shell/PluginAssetsShell.php
  2. 24 3
      tests/TestCase/Shell/PluginAssetsShellTest.php

+ 21 - 6
src/Shell/PluginAssetsShell.php

@@ -30,20 +30,31 @@ class PluginAssetsShell extends Shell {
  * fallback to copying the assets. For vendor namespaced plugin, parent folder
  * for vendor name are created if required.
  *
+ * @param string|string $name Name of plugin for which to symlink assets.
+ *   If null all plugins will be processed.
  * @return void
  */
-	public function symlink() {
-		$this->_process($this->_list());
+	public function symlink($name = null) {
+		$this->_process($this->_list($name));
 	}
 
 /**
  * Get list of plugins to process. Plugins without a webroot directory are skipped.
  *
- * @return array
+ * @param string|string $name Name of plugin for which to symlink assets.
+ *   If null all plugins will be processed.
+ * @return array List of plugins with meta data.
  */
-	protected function _list() {
+	protected function _list($name = null) {
+		if ($name === null) {
+			$pluginsList = Plugin::loaded();
+		} else {
+			$pluginsList = [$name];
+		}
+
 		$plugins = [];
-		foreach (Plugin::loaded() as $plugin) {
+
+		foreach ($pluginsList as $plugin) {
 			$path = Plugin::path($plugin) . 'webroot';
 			if (!is_dir($path)) {
 				$this->out('', 1, Shell::VERBOSE);
@@ -72,6 +83,7 @@ class PluginAssetsShell extends Shell {
 				'namespaced' => $namespaced
 			];
 		}
+
 		return $plugins;
 	}
 
@@ -192,7 +204,10 @@ class PluginAssetsShell extends Shell {
 		$parser = parent::getOptionParser();
 
 		$parser->addSubcommand('symlink', [
-			'help' => 'Symlink / copy assets to app\'s webroot'
+			'help' => 'Symlink / copy assets to app\'s webroot.'
+		])->addArgument('name', [
+			'help' => 'A specific plugin you want to symlink assets for.',
+			'optional' => true,
 		]);
 
 		return $parser;

+ 24 - 3
tests/TestCase/Shell/PluginAssetsShellTest.php

@@ -36,7 +36,7 @@ class PluginAssetsShellTest extends TestCase {
 		parent::setUp();
 
 		$this->skipIf(
-			DIRECTORY_SEPARATOR === '\\',
+			DS === '\\',
 			'Skip PluginAssetsShell tests on windows to prevent side effects for UrlHelper tests on AppVeyor.'
 		);
 
@@ -74,7 +74,7 @@ class PluginAssetsShellTest extends TestCase {
 		$path = WWW_ROOT . 'test_plugin';
 		$link = new \SplFileInfo($path);
 		$this->assertTrue(file_exists($path . DS . 'root.js'));
-		if (DIRECTORY_SEPARATOR === '\\') {
+		if (DS === '\\') {
 			$this->assertTrue($link->isDir());
 			$folder = new Folder($path);
 			$folder->delete();
@@ -107,7 +107,7 @@ class PluginAssetsShellTest extends TestCase {
 		$this->shell->symlink();
 		$path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
 		$link = new \SplFileInfo($path);
-		if (DIRECTORY_SEPARATOR === '\\') {
+		if (DS === '\\') {
 			$this->assertTrue($link->isDir());
 		} else {
 			$this->assertTrue($link->isLink());
@@ -150,4 +150,25 @@ class PluginAssetsShellTest extends TestCase {
 		$this->assertFalse(file_exists(WWW_ROOT . 'test_plugin_two'));
 	}
 
+/**
+ * testSymlinkingSpecifiedPlugin
+ *
+ * @return void
+ */
+	public function testSymlinkingSpecifiedPlugin() {
+		Plugin::load('TestPlugin');
+		Plugin::load('Company/TestPluginThree');
+
+		$this->shell->symlink('TestPlugin');
+
+		$path = WWW_ROOT . 'test_plugin';
+		$link = new \SplFileInfo($path);
+		$this->assertTrue(file_exists($path . DS . 'root.js'));
+
+		$path = WWW_ROOT . 'company' . DS . 'test_plugin_three';
+		$link = new \SplFileInfo($path);
+		$this->assertFalse($link->isDir());
+		$this->assertFalse($link->isLink());
+	}
+
 }