13
13
use T3Docs \GuidesCli \Generation \DocumentationGenerator ;
14
14
use T3Docs \VersionHandling \Packagist \ComposerPackage ;
15
15
use T3Docs \VersionHandling \Packagist \PackagistService ;
16
+ use T3Docs \VersionHandling \Typo3VersionMapping ;
16
17
17
18
/**
18
19
* You can run this command, for example like
@@ -57,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
57
58
}
58
59
59
60
if ($ input ->getOption ('quiet ' )) {
60
- echo 'This command is interactive and requires user input. ' . PHP_EOL ;
61
+ echo '<error> This command is interactive and requires user input. </error> ' . PHP_EOL ;
61
62
return Command::INVALID ;
62
63
}
63
64
@@ -66,12 +67,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
66
67
return Command::INVALID ;
67
68
}
68
69
69
- $ output ->writeln ('Welcome to the <comment>TYPO3 documentation</comment> project setup wizard ' );
70
+ $ output ->writeln ('Welcome to the <comment>TYPO3 documentation guide </comment> setup wizard ' );
70
71
$ output ->writeln ('This wizard will help you to create a new documentation project in the current directory (or work directory). ' );
71
72
$ output ->writeln ('' );
72
73
73
74
$ composerInfo = $ this ->getComposerInfo ($ output );
74
75
76
+ if ($ composerInfo === null ) {
77
+ $ output ->writeln ('<error>No composer.json was found in the current or work directory. Use option --working-dir to set the work directory.</error> ' );
78
+ return Command::FAILURE ;
79
+ }
80
+
75
81
/** @var QuestionHelper $helper */
76
82
$ helper = $ this ->getHelper ('question ' );
77
83
@@ -87,7 +93,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
87
93
});
88
94
$ format = $ helper ->ask ($ input , $ output , $ question );
89
95
90
- $ projectNameQuestion = new Question (sprintf ('What is the title of your documentation? <comment>[%s]</comment>: ' , $ composerInfo ?->getComposerName()), $ composerInfo ?->getComposerName());
96
+ $ projectNameQuestion = new Question (
97
+ sprintf ('What is the title of your documentation? <comment>[%s]</comment>: ' , $ composerInfo ->getComposerName ()),
98
+ $ composerInfo ->getComposerName ()
99
+ );
91
100
$ projectNameQuestion ->setValidator (function ($ answer ) {
92
101
if (is_null ($ answer ) || trim ($ answer ) === '' ) {
93
102
throw new \RuntimeException ('The project title cannot be empty. ' );
@@ -98,36 +107,45 @@ protected function execute(InputInterface $input, OutputInterface $output): int
98
107
$ projectName = $ helper ->ask ($ input , $ output , $ projectNameQuestion );
99
108
100
109
$ question = $ this ->createValidatedUrlQuestion (
101
- sprintf ('What is the URL of your project \'s homepage? <comment>[%s]</comment>: ' , $ composerInfo ?->getHomepage()),
102
- $ composerInfo ?->getHomepage(),
103
- ['https://extensions.typo3.org/package/ ' . $ composerInfo ?->getComposerName()]
110
+ 'What is the URL of your project \'s homepage? <comment>[%s]</comment>: ' ,
111
+ [
112
+ $ composerInfo ->getHomepage (),
113
+ 'https://extensions.typo3.org/package/ ' . $ composerInfo ->getExtensionKey (),
114
+ ]
104
115
);
105
116
$ projectHomePage = $ helper ->ask ($ input , $ output , $ question );
106
117
107
118
108
119
$ question = $ this ->createValidatedUrlQuestion (
109
- sprintf (sprintf ('What is the URL of your project \'s repository? <comment>[%s]</comment> ' , 'https://github.com/ ' . $ composerInfo ?->getComposerName()), 'https://github.com/ ' . $ composerInfo ?->getComposerName()),
110
- $ composerInfo ?->getHomepage(),
120
+ 'What is the URL of your project \'s repository? <comment>[%s]</comment> ' ,
111
121
[
112
- ' https://github.com/ ' . $ composerInfo?->getComposerName (),
113
- 'https://gitlab .com/ ' . $ composerInfo? ->getComposerName(),
114
- $ composerInfo?->getHomepage (),
122
+ $ composerInfo-> getHomepage (),
123
+ 'https://github .com/ ' . $ composerInfo ->getComposerName (),
124
+ ' https://gitlab.com/ ' . $ composerInfo-> getComposerName (),
115
125
]
116
126
);
117
127
$ repositoryUrl = $ helper ->ask ($ input , $ output , $ question );
118
128
119
129
$ question = $ this ->createValidatedUrlQuestion (
120
- sprintf ('Where can users report issues? <comment>[%s]</comment> ' , $ composerInfo ?->getIssues()),
121
- $ composerInfo ?->getIssues(),
130
+ 'Where can users report issues? <comment>[%s]</comment> ' ,
122
131
[
123
- ' https://github.com/ ' . $ composerInfo?->getComposerName() . ' /issues ' ,
124
- ' https://gitlab.com/ ' . $ composerInfo ?->getComposerName() . '/- /issues ' ,
125
- $ composerInfo ?->getHomepage() ,
132
+ $ composerInfo-> getIssues () ,
133
+ $ repositoryUrl . '/issues ' ,
134
+ $ repositoryUrl . ' /-/issues ' ,
126
135
]
127
136
);
128
137
129
138
$ issuesUrl = $ helper ->ask ($ input , $ output , $ question );
130
- $ typo3CoreVersion = $ helper ->ask ($ input , $ output , new Question ('Which version of TYPO3 is the preferred version to use? <comment>[stable]</comment>: ' , 'stable ' ));
139
+
140
+ // Get LTS versions from the Typo3VersionMapping class
141
+ $ ltsEnumCases = Typo3VersionMapping::getLtsVersions ();
142
+
143
+ // Extract the values of these enum cases
144
+ $ ltsValues = array_map (static fn (Typo3VersionMapping $ enumValue ) => $ enumValue ->value , $ ltsEnumCases );
145
+
146
+ $ question = new Question ('Which version of TYPO3 is the preferred version to use? <comment>[stable]</comment>: ' , Typo3VersionMapping::getDefault ()->value );
147
+ $ question ->setAutocompleterValues ([Typo3VersionMapping::Stable->value , Typo3VersionMapping::Dev->value , ...$ ltsValues ]);
148
+ $ typo3CoreVersion = $ helper ->ask ($ input , $ output , $ question );
131
149
132
150
$ question = new Question ('Do you want generate some Documentation? (yes/no) ' , 'yes ' );
133
151
$ question ->setValidator (function ($ answer ) {
@@ -184,8 +202,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
184
202
'format ' => $ format ,
185
203
'useMd ' => ($ format === 'md ' ),
186
204
'projectName ' => $ projectName ,
187
- 'description ' => $ composerInfo? ->getDescription(),
188
- 'composerName ' => $ composerInfo? ->getComposerName(),
205
+ 'description ' => $ composerInfo ->getDescription (),
206
+ 'composerName ' => $ composerInfo ->getComposerName (),
189
207
'projectHomePage ' => $ projectHomePage ,
190
208
'issuesUrl ' => $ issuesUrl ,
191
209
'repositoryUrl ' => $ repositoryUrl ,
@@ -201,17 +219,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
201
219
}
202
220
203
221
/**
204
- * @param ?scalar $default
205
222
* @param array<mixed> $autocompleteValues
206
223
*/
207
- private function createValidatedUrlQuestion (string $ questionText , mixed $ default , array $ autocompleteValues = []): Question
224
+ private function createValidatedUrlQuestion (string $ questionText , array $ autocompleteValues = []): Question
208
225
{
209
- $ question = new Question ($ questionText , $ default );
226
+ $ default = null ;
227
+ $ autocompleteValuesFiltered = [];
228
+ foreach ($ autocompleteValues as $ value ) {
229
+ if ($ value !== null && $ value !== '' && is_scalar ($ value )) {
230
+ $ default ??= (string )$ value ;
231
+ $ autocompleteValuesFiltered [] = (string )$ value ;
232
+ }
233
+ }
234
+ $ question = new Question (sprintf ($ questionText , $ default ), $ default );
210
235
if (!empty ($ autocompleteValues )) {
211
- $ question ->setAutocompleterValues ($ autocompleteValues );
236
+ $ question ->setAutocompleterValues ($ autocompleteValuesFiltered );
212
237
}
213
238
$ question ->setValidator (function ($ answer ) {
214
- if (!is_null ($ answer ) && !filter_var ($ answer , FILTER_VALIDATE_URL )) {
239
+ if (!is_null ($ answer ) && $ answer !== '' && !filter_var ($ answer , FILTER_VALIDATE_URL )) {
215
240
throw new \RuntimeException ('The URL is not valid ' );
216
241
}
217
242
return $ answer ;
@@ -228,19 +253,16 @@ private function getComposerInfo(OutputInterface $output): ComposerPackage|null
228
253
}
229
254
230
255
$ output ->writeln ('A <comment>composer.json</comment> file was found in the current directory. ' );
231
- $ packageName = $ this ->fetchComposerPackageName ();
232
- if (!is_string ($ packageName )) {
233
- $ output ->writeln ('The package name could not be determined from the <comment>composer.json</comment> file. ' );
234
- return null ;
235
- }
236
256
237
- $ composerInfo = (new PackagistService ())->getComposerInfo ($ packageName );
238
- $ output ->writeln (sprintf ('The package <comment>%s</comment> was found on packagist.org ' , $ composerInfo ->getComposerName ()));
257
+ $ composerInfo = (new PackagistService ())->getComposerInfoFromJson ($ this ->fetchComposerArray () ?? []);
239
258
240
259
return $ composerInfo ;
241
260
}
242
261
243
- private function fetchComposerPackageName (): string |null
262
+ /**
263
+ * @return array<string, mixed>|null
264
+ */
265
+ private function fetchComposerArray (): array |null
244
266
{
245
267
$ fileContent = file_get_contents ('composer.json ' );
246
268
if ($ fileContent === false ) {
@@ -253,7 +275,7 @@ private function fetchComposerPackageName(): string|null
253
275
return null ;
254
276
}
255
277
256
- return $ composerJson[ ' name ' ] ;
278
+ return $ composerJson ;
257
279
}
258
280
259
281
}
0 commit comments