Skip to content

Commit

Permalink
Improved Check markdown command output
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Apr 11, 2024
1 parent 34be0a2 commit 4f81c98
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
10 changes: 7 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

Expand All @@ -19,7 +20,10 @@
->withPreparedSets(
deadCode: true,
codeQuality: true,
earlyReturn: true,
codingStyle: true,
typeDeclarations: true,
codingStyle: true
);
earlyReturn: true
)
->withSkip([
PostIncDecToPreIncDecRector::class,
]);
35 changes: 25 additions & 10 deletions src/Console/Commands/CheckMarkdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@
class CheckMarkdown extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fusion:check {--dir=}';
protected $signature = 'fusion:check
{--dir= : the directory of the Markdown files }';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Check the Markdown files';
protected $description = 'It shows the list of the frontmatter fields of each Markdown file found';

/**
* Execute the console command.
*/
public function handle(): void
{
$this->info('Parsing the Markdown Files');

$this->output->title('Parsing the Markdown Files');
$filesystem = new FileSystem();
$contentDirectory = $this->option('dir');
if (is_null($contentDirectory)) {
$contentDirectory = resource_path('content');
}

foreach (File::directories($contentDirectory) as $directory) {
$this->info('Directory: '.$directory);
$this->components->twoColumnDetail('<info>Directory</info>', sprintf('<info>%s</info>', $directory));
//$this->output->->info('Directory: '.$directory);
$numberNoMarkdown = 0;
$numberMarkdown = 0;
foreach (File::files($directory) as $file) {
$slug = $file->getFilenameWithoutExtension();
$extension = $file->getExtension();
Expand All @@ -45,9 +46,23 @@ public function handle(): void
$fileContent = $filesystem->get($file->getRealPath());

$object = YamlFrontMatter::parse($fileContent);
$this->components->twoColumnDetail($extension.' - '.$filename, implode('; ', array_keys($object->matter())));
//dd($object->matter());
if ($extension == 'md') {
$numberMarkdown++;
$this->components->twoColumnDetail(' - '.$filename, implode('; ', array_keys($object->matter())));
} else {
$numberNoMarkdown++;
}
}

if ($numberMarkdown == 0) {
$this->warn('No Markdown files in '.$directory);
}

if ($numberNoMarkdown > 0) {
$this->warn(sprintf('Found %d files, with a no markdown extensions', $numberNoMarkdown));
}

$this->output->newLine();
}
}
}
16 changes: 16 additions & 0 deletions src/Console/Commands/SyncModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,24 @@ class SyncModel extends GeneratorCommand
*/
protected $description = 'Sync the Model file from Markdown definition';

/**
* The auto-detected model name retrieved from the markdown folder.
* For example for resources/content/article the model name
* will be the folder base name in PascalCase format so Article
*
* @var string
*/
protected $modelName = '';

/**
* The auto-detected frontmatter field names retrieved
* by parsing all the markdown files in a specific folder
* The format of the field list is in string, useful to be used
* in the model for example:
* '"title", "description", "published"'
*
* @var string
*/
protected $frontmatterFields = '';

/**
Expand Down

0 comments on commit 4f81c98

Please sign in to comment.