@@ -32,102 +32,119 @@ public function injectContentRepositoryRegistry(ContentRepositoryRegistry $conte
3232 }
3333
3434 /**
35- * Remove all *NodeObject.php and *NodeInterface.php from the NodeTypes folder of the specified package
35+ * Remove all *NodeObject.php and *NodeInterface.php from the NodeTypes folder of the specified packages
3636 *
37- * @param string $packageKey PackageKey to store the classes in
37+ * @param string $packageKeys PackageKey or Pattern, can be used seperated by comma
3838 * @return void
3939 */
40- public function cleanCommand (string $ packageKey ): void
40+ public function cleanCommand (string $ packageKeys ): void
4141 {
42- if ($ this ->packageManager ->isPackageAvailable ($ packageKey )) {
43- $ package = $ this ->packageManager ->getPackage ($ packageKey );
44- } else {
45- $ this ->output ->outputLine ("Unknown package " . $ packageKey );
46- $ this ->quit (1 );
47- }
48- if (!$ package instanceof FlowPackageInterface) {
49- $ this ->output ->outputLine ($ packageKey . " is not a Flow package " );
42+ $ packages = $ this ->findPackagesByPackageKeyPattern ($ packageKeys );
43+
44+ if (empty ($ packages )) {
45+ $ this ->output ->outputLine ('No packages found for packageKeys <error>"%s"</error>: ' , [$ packageKeys ]);
5046 $ this ->quit (1 );
47+ } else {
48+ $ keys = array_map (fn (FlowPackageInterface $ package ) => $ package ->getPackageKey (), $ packages );
49+ $ this ->output ->outputLine ('Removing NodeObjects and NodeInterfaces from packages <info>"%s"</info>: ' , [implode (', ' , $ keys )]);
5150 }
5251
53- $ packagePath = $ package ->getPackagePath ();
54- $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeObject.php ' );
55- if (is_array ($ files )) {
56- foreach ($ files as $ file ) {
57- if (is_file ($ file )) {
58- unlink ($ file );
52+ foreach ($ packages as $ package ) {
53+ $ packagePath = $ package ->getPackagePath ();
54+ if (!file_exists ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' )) {
55+ continue ;
56+ }
57+
58+ $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeObject.php ' );
59+ if (is_array ($ files )) {
60+ foreach ($ files as $ file ) {
61+ if (is_file ($ file )) {
62+ unlink ($ file );
63+ }
64+ $ this ->outputLine (' - ' . $ file );
5965 }
60- $ this ->outputLine (' - ' . $ file );
6166 }
62- }
63- $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeInterface.php ' );
64- if (is_array ($ files )) {
65- foreach ($ files as $ file ) {
66- if (is_file ($ file )) {
67- unlink ($ file );
67+ $ files = Files::readDirectoryRecursively ($ packagePath . DIRECTORY_SEPARATOR . 'NodeTypes ' , 'NodeInterface.php ' );
68+ if (is_array ($ files )) {
69+ foreach ($ files as $ file ) {
70+ if (is_file ($ file )) {
71+ unlink ($ file );
72+ }
73+ $ this ->outputLine (' - ' . $ file );
6874 }
69- $ this ->outputLine (' - ' . $ file );
7075 }
7176 }
7277 }
7378
7479 /**
7580 * Create new NodeTypeObjects for the selected Package
7681 *
77- * @param string $packageKey PackageKey
82+ * @param string $packageKeys PackageKey or Pattern, can be used seperated comma
7883 */
79- public function buildCommand (string $ packageKey , string $ crId = 'default ' ): void
84+ public function buildCommand (string $ packageKeys , string $ crId = 'default ' ): void
8085 {
81- $ package = $ this ->getPackage ($ packageKey );
86+ $ packages = $ this ->findPackagesByPackageKeyPattern ($ packageKeys );
87+
88+ if (empty ($ packages )) {
89+ $ this ->output ->outputLine ('No packages found for packageKeys <error>"%s"</error>: ' , [$ packageKeys ]);
90+ $ this ->quit (1 );
91+ } else {
92+ $ keys = array_map (fn (FlowPackageInterface $ package ) => $ package ->getPackageKey (), $ packages );
93+ $ this ->output ->outputLine ('Building NodeObjects and NodeInterfaces for packages <info>"%s"</info>: ' , [implode (', ' , $ keys )]);
94+ }
8295
8396 $ contentRepository = $ this ->contentRepositoryRegistry ->get (ContentRepositoryId::fromString ($ crId ));
8497 $ nodeTypeManager = $ contentRepository ->getNodeTypeManager ();
85- $ nodeTypes = $ nodeTypeManager ->getNodeTypes ();
98+ $ nodeTypes = $ nodeTypeManager ->getNodeTypes (true );
8699 $ nameSpecifications = [];
87-
88- foreach ($ nodeTypes as $ nodeType ) {
89- if (!str_starts_with ($ nodeType ->name ->value , $ packageKey . ': ' )) {
90- continue ;
100+ foreach ($ packages as $ package ) {
101+ foreach ($ nodeTypes as $ nodeType ) {
102+ if (!str_starts_with ($ nodeType ->name ->value , $ package ->getPackageKey () . ': ' )) {
103+ continue ;
104+ }
105+ $ nameSpecifications [$ nodeType ->name ->value ] = NodeTypeObjectNameSpecification::createFromNodeType ($ nodeType );
91106 }
92- $ nameSpecifications [$ nodeType ->name ->value ] = NodeTypeObjectNameSpecification::createFromPackageAndNodeType ($ package , $ nodeType );
93107 }
94-
95108 $ nameSpecificationsCollection = new NodeTypeObjectNameSpecificationCollection (...$ nameSpecifications );
96109
97- foreach ($ nodeTypes as $ nodeType ) {
98- if (!str_starts_with ($ nodeType ->name ->value , $ packageKey . ': ' )) {
99- continue ;
100- }
110+ // loop 2 build interfaces and objects
111+ foreach ($ packages as $ package ) {
112+ foreach ($ nodeTypes as $ nodeType ) {
113+ if (!str_starts_with ($ nodeType ->name ->value , $ package ->getPackageKey () . ': ' )) {
114+ continue ;
115+ }
101116
102- $ specification = NodeTypeObjectSpecification::createFromPackageAndNodeType ($ package , $ nodeType , $ nameSpecificationsCollection );
117+ $ specification = NodeTypeObjectSpecification::createFromPackageAndNodeType ($ package , $ nodeType , $ nameSpecificationsCollection );
103118
104- Files::createDirectoryRecursively ($ specification-> names ->directory );
119+ Files::createDirectoryRecursively ($ specification ->directory );
105120
106- if ($ specification ->names ->className ) {
107- file_put_contents (
108- $ specification ->names ->directory . DIRECTORY_SEPARATOR . $ specification ->names ->className . '.php ' ,
109- $ specification ->toPhpClassString ()
110- );
111- $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> ' . $ specification ->names ->className );
112- }
121+ $ generatedFiles = [];
122+ if ($ specification ->classFilename ) {
123+ file_put_contents (
124+ $ specification ->classFilename ,
125+ $ specification ->toPhpClassString ()
126+ );
127+ $ generatedFiles [] = $ specification ->names ->fullyQualifiedClassName ;
128+ }
129+ if ($ specification ->interfaceFilename ) {
130+ file_put_contents (
131+ $ specification ->interfaceFilename ,
132+ $ specification ->toPhpInterfaceString ()
133+ );
134+ $ generatedFiles [] = $ specification ->names ->fullyQualifiedInterfaceName ;
135+ }
113136
114- if ($ specification ->names ->interfaceName ) {
115- file_put_contents (
116- $ specification ->names ->directory . DIRECTORY_SEPARATOR . $ specification ->names ->interfaceName . '.php ' ,
117- $ specification ->toPhpInterfaceString ()
118- );
119- $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> ' . $ specification ->names ->interfaceName );
137+ $ this ->outputLine (' - ' . $ specification ->names ->nodeTypeName . ' -> <info> ' . implode (', ' , $ generatedFiles ) . '</info> ' );
120138 }
121139 }
122140 }
123141
124142 /**
125143 * @param string $packageKey
126- * @return FlowPackageInterface
127144 * @throws \Neos\Flow\Cli\Exception\StopCommandException
128145 * @throws \Neos\Flow\Package\Exception\UnknownPackageException
129146 */
130- protected function getPackage (string $ packageKey ): FlowPackageInterface
147+ protected function getPackage (string $ packageKey ): FlowPackageInterface & GenericPackage
131148 {
132149 if ($ this ->packageManager ->isPackageAvailable ($ packageKey )) {
133150 $ package = $ this ->packageManager ->getPackage ($ packageKey );
@@ -167,7 +184,28 @@ protected function getPackage(string $packageKey): FlowPackageInterface
167184 $ this ->outputLine ('<error>No PSR4-NodeTypes namespace for the NodeTypes folder is registered via composer</error> ' );
168185 $ this ->quit (1 );
169186 }
170-
171187 return $ package ;
172188 }
189+
190+ /**
191+ * @param string $packageKeys
192+ * @return FlowPackageInterface[]
193+ */
194+ protected function findPackagesByPackageKeyPattern (string $ packageKeys ): array
195+ {
196+ $ packageKeyPatterns = explode (', ' , $ packageKeys );
197+
198+ $ allFlowPackages = $ this ->packageManager ->getFlowPackages ();
199+
200+ $ packages = [];
201+ foreach ($ allFlowPackages as $ flowPackage ) {
202+ foreach ($ packageKeyPatterns as $ packageKeyPattern ) {
203+ if (fnmatch ($ packageKeyPattern , $ flowPackage ->getPackageKey ())) {
204+ $ packages [ $ flowPackage ->getPackageKey () ] = $ flowPackage ;
205+ break ;
206+ }
207+ }
208+ }
209+ return $ packages ;
210+ }
173211}
0 commit comments