@@ -165,36 +165,37 @@ protected function execute(InputInterface $input, OutputInterface $output)
165
165
166
166
$ this ->io ->text (['' , ' // Update encore entry dependencies ' , '' ]);
167
167
168
- if (file_exists ($ this ->kernel ->getProjectDir ().DIRECTORY_SEPARATOR .'package.json ' )) {
169
- $ this ->io ->writeln ('Collect encore entry dependencies ' );
170
- $ encorePackageData = [
171
- 'name ' => '@hundh/encore-entry-dependencies ' ,
172
- 'version ' => date ('Ymd ' ).'. ' .date ('Hi ' ).'. ' .time (),
173
- 'dependencies ' => $ extensionDependencies ,
174
- ];
175
- $ encoreAssetsPath = 'vendor ' .DIRECTORY_SEPARATOR .'heimrichhannot ' .DIRECTORY_SEPARATOR .'encore-entry-dependencies ' ;
176
-
177
- (new Filesystem ())->dumpFile (
178
- $ this ->kernel ->getProjectDir ().DIRECTORY_SEPARATOR .$ encoreAssetsPath .DIRECTORY_SEPARATOR .'package.json ' ,
179
- json_encode ($ encorePackageData , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES )
180
- );
181
-
182
- $ this ->io ->writeln ('Register dependencies in project ' );
183
- $ packageData = json_decode (file_get_contents ($ this ->kernel ->getProjectDir ().DIRECTORY_SEPARATOR .'package.json ' ), true );
184
-
185
- $ packageData ['dependencies ' ] = array_merge (
186
- ['@hundh/encore-entry-dependencies ' => 'file:. ' .DIRECTORY_SEPARATOR .$ encoreAssetsPath .DIRECTORY_SEPARATOR ],
187
- $ packageData ['dependencies ' ] ?? []
188
- );
189
-
190
- (new Filesystem ())->dumpFile (
191
- $ this ->kernel ->getProjectDir ().DIRECTORY_SEPARATOR .'package.json ' ,
192
- json_encode ($ packageData , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES )
193
- );
194
- } else {
195
- $ this ->io ->warning ('No package.json could be found in your project. This file must be present for encore to work! ' );
168
+ $ projectPackageJsonPath = $ this ->kernel ->getProjectDir ().DIRECTORY_SEPARATOR .'package.json ' ;
169
+ if (!file_exists ($ projectPackageJsonPath )) {
170
+ throw new \Exception ('No package.json could be found in your project. This file must be present for encore to work! ' );
196
171
}
197
172
173
+ $ this ->io ->writeln ('Collect encore entry dependencies ' );
174
+ $ encorePackageData = [
175
+ 'name ' => '@hundh/encore-entry-dependencies ' ,
176
+ 'version ' => date ('Ymd ' ).'. ' .date ('Hi ' ).'. ' .time (),
177
+ 'dependencies ' => $ extensionDependencies ,
178
+ ];
179
+ $ encoreAssetsPath = 'vendor ' .DIRECTORY_SEPARATOR .'heimrichhannot ' .DIRECTORY_SEPARATOR .'encore-entry-dependencies ' ;
180
+
181
+ (new Filesystem ())->dumpFile (
182
+ $ this ->kernel ->getProjectDir ().DIRECTORY_SEPARATOR .$ encoreAssetsPath .DIRECTORY_SEPARATOR .'package.json ' ,
183
+ json_encode ($ encorePackageData , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES )
184
+ );
185
+
186
+ $ this ->io ->writeln ('Register dependencies in project ' );
187
+ $ packageData = json_decode (file_get_contents ($ projectPackageJsonPath ), true , 512 , \JSON_THROW_ON_ERROR );
188
+
189
+ $ packageData ['dependencies ' ] = array_merge (
190
+ ['@hundh/encore-entry-dependencies ' => 'file:. ' .DIRECTORY_SEPARATOR .$ encoreAssetsPath .DIRECTORY_SEPARATOR ],
191
+ $ packageData ['dependencies ' ] ?? []
192
+ );
193
+
194
+ (new Filesystem ())->dumpFile (
195
+ $ projectPackageJsonPath ,
196
+ json_encode ($ packageData , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES )
197
+ );
198
+
198
199
if (!empty ($ encoreJsEntries )) {
199
200
$ this ->io ->text (['' , ' // Output encore_bundles.js ' , '' ]);
200
201
0 commit comments