Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Automatically create a skeleton configuration file if none exists
Browse files Browse the repository at this point in the history
fixes #20
  • Loading branch information
fredemmott committed Jan 18, 2018
1 parent df0112d commit a212498
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/builders/HHImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a212498

Please sign in to comment.