Skip to content

Commit edd0603

Browse files
committedApr 4, 2023
optimized errors in prepare command
1 parent bbfc6e8 commit edd0603

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.20.1] - 2023-04-04
6+
- Changed: more errors on prepare command if something went wrong
7+
58
## [1.20.0] - 2023-03-29
69
- Changed: show message in layout when entrypoints not generated
710
- Changed: added some english translations

‎src/Command/PrepareCommand.php

+29-28
Original file line numberDiff line numberDiff line change
@@ -165,36 +165,37 @@ protected function execute(InputInterface $input, OutputInterface $output)
165165

166166
$this->io->text(['', ' // Update encore entry dependencies', '']);
167167

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!');
196171
}
197172

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+
198199
if (!empty($encoreJsEntries)) {
199200
$this->io->text(['', ' // Output encore_bundles.js', '']);
200201

0 commit comments

Comments
 (0)
Failed to load comments.