Beispiel #1
0
 public function __construct(Reflector $module)
 {
     $makeFunctionDoc = function ($function) {
         return FunctionDocFactory::createFunctionDocFromReflector($function);
     };
     $this->module = $module;
     $this->functionDocs = Arrays::map($makeFunctionDoc, $this->getFunctions());
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // This command must be run from the project root directory. A reasonable(ly hacky) way to check this is to check for
     // the existence of the composer.json file.
     if (!file_exists(getcwd() . '/composer.json')) {
         $output->writeln('<error>This command must be run from the project\'s root directory.</error>');
         return;
     }
     // Given a fully qualified namespace, convert \ to / and make a file path with the md extension
     $namespaceToPath = Lambda::compose(Strings::concat('.md'), Strings::join('/'), Strings::split('\\'));
     // Given a fully qualified namespace, create the containing directory
     $namespaceToDir = Lambda::compose(Strings::join('/'), Arrays::init(), Strings::split('\\'));
     // A tree that represents the organization of the modules we're generating documentation for
     $moduleDirectory = [];
     // For each module, we're going to generate a documentation file and place it in the auto-generate folder in the
     // root docs directory. We're going to build up the module directory as we go
     foreach ($input->getArgument('modules') as $module) {
         $moduleDoc = FunctionDocFactory::createModuleDocFromName($module);
         $moduleDocMarkdownDirectory = getcwd() . '/docs/auto-generate/' . $namespaceToDir($module);
         $moduleDocMarkdownFileLocation = getcwd() . '/docs/auto-generate/' . $namespaceToPath($module);
         $moduleDirectory = Lens::setL(Lens::pathLensSafe(Strings::split('\\', $module)), 'auto-generate/' . $namespaceToPath($module), $moduleDirectory);
         // Sort the functions in the docs alphabetically
         $functions = Arrays::sort(function ($fA, $fB) {
             return $fA->properName() <=> $fB->properName();
         }, $moduleDoc->getFunctionDocs());
         // For each function in this module, add the markdown content to a buffer
         $buffer = '';
         foreach ($functions as $function) {
             $buffer .= $this->generateFunctionDocMarkdown($function);
         }
         // Make sure the location we're putting it exists
         if (!is_dir($moduleDocMarkdownDirectory)) {
             // 777 all day every day
             mkdir($moduleDocMarkdownDirectory, 0777, true);
         }
         // Then put it there
         file_put_contents($moduleDocMarkdownFileLocation, $buffer);
     }
     // Write the mkdocs.yml file in the project directory
     file_put_contents(getcwd() . '/mkdocs.yml', $this->generateMkdocsYaml($moduleDirectory));
 }