22
33namespace BlameButton \LaravelDockerBuilder \Commands ;
44
5+ use BlameButton \LaravelDockerBuilder \Commands \Choices \ArtisanOptimize ;
56use BlameButton \LaravelDockerBuilder \Commands \Choices \NodeBuildTool ;
67use BlameButton \LaravelDockerBuilder \Commands \Choices \NodePackageManager ;
78use BlameButton \LaravelDockerBuilder \Commands \Choices \PhpVersion ;
@@ -12,10 +13,6 @@ class DockerGenerateCommand extends BaseCommand
1213{
1314 use InteractsWithTwig;
1415
15- const YES = 'yes ' ;
16- const NO = 'no ' ;
17- const NONE = 'none ' ;
18-
1916 protected $ name = 'docker:generate ' ;
2017
2118 protected $ description = 'Generate Dockerfiles ' ;
@@ -41,42 +38,23 @@ public function handle(): int
4138 ]),
4239 ]);
4340
44- $ dockerfiles -> each ( function ( $ value , $ key ) {
45- $ this -> info ( $ key );
46- });
41+ if (! is_dir ( $ dir = base_path ( ' .docker ' )) ) {
42+ mkdir ( $ dir );
43+ }
4744
48- return self ::SUCCESS ;
49- }
45+ foreach ($ dockerfiles as $ file => $ content ) {
46+ // Example: $PWD/.docker/{php,nginx}.dockerfile
47+ $ dockerfile = sprintf ("%s/%s " , $ dir , $ file );
5048
51- protected function getOptions (): array
52- {
49+ // Save Dockerfile contents
50+ file_put_contents ( $ dockerfile , $ content );
5351
54- return [
55- new InputOption (
56- name: 'php-version ' ,
57- shortcut: 'p ' ,
58- mode: InputOption::VALUE_REQUIRED ,
59- description: sprintf ("PHP version (supported: %s) " , join (', ' , PhpVersion::values ())),
60- ),
61- new InputOption (
62- name: 'optimize ' ,
63- shortcut: 'o ' ,
64- mode: InputOption::VALUE_NONE ,
65- description: 'Add "php artisan optimize" to entrypoint ' ,
66- ),
67- new InputOption (
68- name: 'node-package-manager ' ,
69- shortcut: 'm ' ,
70- mode: InputOption::VALUE_REQUIRED ,
71- description: sprintf ('Node Package Manager (supported: %s) ' , join (', ' , NodePackageManager::values ())),
72- ),
73- new InputOption (
74- name: 'node-build-tool ' ,
75- shortcut: 'b ' ,
76- mode: InputOption::VALUE_REQUIRED ,
77- description: sprintf ('Node Build Tool (supported: %s) ' , join (', ' , NodeBuildTool::values ())),
78- ),
79- ];
52+ // Output saved Dockerfile location
53+ $ filename = str ($ dockerfile )->after (base_path ())->trim ('/ ' );
54+ $ this ->info (sprintf ('Saved: %s ' , $ filename ));
55+ }
56+
57+ return self ::SUCCESS ;
8058 }
8159
8260 private function getPhpVersion (): string
@@ -102,10 +80,11 @@ public function getArtisanOptimize(): bool
10280
10381 $ choice = $ this ->choice (
10482 question: 'Do you want to run "php artisan optimize" when the image boots? ' ,
105- choices: [ self :: YES , self :: NO ] ,
106- default: self ::YES ,
83+ choices: ArtisanOptimize:: values () ,
84+ default: ArtisanOptimize ::YES ,
10785 );
108- return $ choice === self ::YES ;
86+
87+ return ArtisanOptimize::YES === $ choice ;
10988 }
11089
11190 private function getNodePackageManager (): string |false
@@ -123,7 +102,6 @@ private function getNodePackageManager(): string|false
123102 );
124103 }
125104
126-
127105 private function getNodeBuildTool (): string
128106 {
129107 if ($ option = $ this ->option ('node-build-tool ' )) {
@@ -138,4 +116,36 @@ private function getNodeBuildTool(): string
138116 default: NodeBuildTool::VITE ,
139117 );
140118 }
119+
120+
121+ protected function getOptions (): array
122+ {
123+
124+ return [
125+ new InputOption (
126+ name: 'php-version ' ,
127+ shortcut: 'p ' ,
128+ mode: InputOption::VALUE_REQUIRED ,
129+ description: sprintf ("PHP version (supported: %s) " , join (', ' , PhpVersion::values ())),
130+ ),
131+ new InputOption (
132+ name: 'optimize ' ,
133+ shortcut: 'o ' ,
134+ mode: InputOption::VALUE_NONE ,
135+ description: 'Add "php artisan optimize" to entrypoint ' ,
136+ ),
137+ new InputOption (
138+ name: 'node-package-manager ' ,
139+ shortcut: 'm ' ,
140+ mode: InputOption::VALUE_REQUIRED ,
141+ description: sprintf ('Node Package Manager (supported: %s) ' , join (', ' , NodePackageManager::values ())),
142+ ),
143+ new InputOption (
144+ name: 'node-build-tool ' ,
145+ shortcut: 'b ' ,
146+ mode: InputOption::VALUE_REQUIRED ,
147+ description: sprintf ('Node Build Tool (supported: %s) ' , join (', ' , NodeBuildTool::values ())),
148+ ),
149+ ];
150+ }
141151}
0 commit comments