From a2124986412f2c86d7da84b67a8c7b37bde25a3f Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Thu, 18 Jan 2018 14:05:10 -0800 Subject: [PATCH] Automatically create a skeleton configuration file if none exists fixes #20 --- src/builders/HHImporter.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/builders/HHImporter.php b/src/builders/HHImporter.php index dfb781d..05b37f6 100644 --- a/src/builders/HHImporter.php +++ b/src/builders/HHImporter.php @@ -21,6 +21,34 @@ public function __construct( IncludedRoots $included_roots, ) { $config_file = $root.'/hh_autoload.json'; + if (!\file_exists($config_file)) { + $roots = (ImmVector { 'src', 'lib' }) + ->filter($x ==> \is_dir($root.'/'.$x)); + $dev_roots = (ImmVector { 'test', 'tests', 'examples', 'example' }) + ->filter($x ==> \is_dir($root.'/'.$x)); + \file_put_contents( + $config_file, + \json_encode( + shape( + 'roots' => $roots, + 'devRoots' => $dev_roots, + 'devFailureHandler' => HHClientFallbackHandler::class, + ), + JSON_PRETTY_PRINT, + )."\n", + ); + \fprintf( + STDERR, + "An hh_autoload.json is required; a skeleton has been written to %s.\n". + "If changes are needed, run vendor/bin/hh-autoload after editing.\n". + "\n". + "*** WARNING ***\n". + "This project will not work correctly unless vendor/hh_autoload.php is required.\n". + "*** WARNING ***\n". + "\n", + $config_file, + ); + } $config = ConfigurationLoader::fromFile($config_file); $this->config = $config;