Explorar el Código

refactor: 生成脚本移入 core/bin 供 composer hook 直接调用

runphp hace 1 mes
padre
commit
e3463fc237

+ 34 - 0
bin/generate-installed-sixshop.php

@@ -0,0 +1,34 @@
+<?php
+
+declare(strict_types=1);
+
+const EXTENSION_TYPE = 'sixshop-extension';
+
+$dir = __DIR__;
+while (!is_file($dir . '/vendor/composer/installed.php')) {
+    $parent = dirname($dir);
+    if ($parent === $dir) {
+        fwrite(STDERR, "Unable to locate vendor/composer/installed.php\n");
+        exit(1);
+    }
+    $dir = $parent;
+}
+$vendorDir = $dir . '/vendor';
+
+$installed = require $vendorDir . '/composer/installed.php';
+
+$installedSixShopExtensions = [
+    'root' => [],
+    'versions' => [],
+];
+$referenceMap = [];
+foreach ($installed['versions'] as $name => $package) {
+    if (isset($package['type']) && $package['type'] === EXTENSION_TYPE) {
+        $installedSixShopExtensions['versions'][$name] = $package;
+        $referenceMap[$name] = $package['reference'];
+    }
+}
+$installedSixShopExtensions['root']['reference'] = hash('md5', json_encode($referenceMap));
+
+$filePath = $vendorDir . '/composer/installedSixShop.php';
+file_put_contents($filePath, '<?php return ' . var_export($installedSixShopExtensions, true) . ';');

+ 1 - 1
src/Command/GenerateInstalledSixShopCommand.php

@@ -16,7 +16,7 @@ class GenerateInstalledSixShopCommand extends Command
 
     public function handle(): void
     {
-        require $this->app->getRootPath() . 'scripts/generate-installed-sixshop.php';
+        require dirname(__DIR__, 2) . '/bin/generate-installed-sixshop.php';
         $this->output->writeln('Generated: ' . $this->app->getRootPath() . 'vendor/composer/installedSixShop.php');
     }
 }