Skip to content

Commit

Permalink
Merge pull request #26 from Hi-Folks/feat/updating-path
Browse files Browse the repository at this point in the history
refactoring building path
  • Loading branch information
roberto-butti authored Feb 3, 2024
2 parents 5d3f67f + 6e00c7b commit e202d61
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/Commands/BuildEpubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ protected function buildEpub(Collection $chapters, array $config, string $curren

$book->finalize();


//$epubFilename = $currentPath . '/export/' . $this->config->outputFileName() . '.epub';
$epubFilename = Config::buildPath(
$currentPath,
"export",
Expand Down
40 changes: 32 additions & 8 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ibis\Commands;

use Ibis\Config;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -52,9 +53,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$workingPath = "./";
}

$ibisConfigPath = $workingPath . '/ibis.php';
$contentPath = $workingPath . '/content/';
$assetsPath = $workingPath . '/assets';
$ibisConfigPath = Config::buildPath(
$workingPath,
'ibis.php'
);
$contentPath = Config::buildPath(
$workingPath,
'content'
);
$assetsPath = Config::buildPath(
$workingPath,
'assets'
);

$this->output->writeln('<info>Creating directory/files for:</info>');
$this->output->writeln('<info>✨ config/assets directory as: ' . $assetsPath . '</info>');
Expand All @@ -71,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);

$this->disk->makeDirectory(
$assetsPath . '/fonts'
Config::buildPath($assetsPath, 'fonts')
);

$assetsToCopy = [
Expand All @@ -84,8 +94,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int

foreach ($assetsToCopy as $assetToCopy) {
$this->disk->put(
$assetsPath . '/' . $assetToCopy,
$this->disk->get(__DIR__ . '/../../stubs/assets/' . $assetToCopy)
Config::buildPath($assetsPath, $assetToCopy),
$this->disk->get(
Config::buildPath(
__DIR__,
'..',
'..',
'stubs/assets',
$assetToCopy
)
)
);
}

Expand All @@ -97,15 +115,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);

$this->disk->copyDirectory(
__DIR__ . '/../../stubs/content',
Config::buildPath(
__DIR__,
'../../stubs/content'
),
$contentPath
);

$this->output->writeln('<info>✨ config file as: ' . $ibisConfigPath . '</info>');

$this->disk->put(
$ibisConfigPath,
$this->disk->get(__DIR__ . '/../../stubs/ibis.php')
$this->disk->get(Config::buildPath(
__DIR__,
'../../stubs/ibis.php'
))
);


Expand Down
9 changes: 7 additions & 2 deletions src/Commands/SampleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ibis\Commands;

use Ibis\Config;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -53,7 +54,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$themeName = $input->getArgument('theme');

$pdfFilename = $this->config->workingPath . '/export/' . $this->config->outputFileName() . '-' . $themeName . '.pdf';
$pdfFilename =
Config::buildPath($this->config->workingPath, 'export', $this->config->outputFileName() . '-' . $themeName . '.pdf');


if (!$this->disk->isFile($pdfFilename)) {
Expand All @@ -78,7 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$mpdf->WriteHTML('<p style="text-align: center; font-size: 16px; line-height: 40px;">' . $this->config->config['sample_notice'] . '</p>');
$sampleFileName = $this->config->workingPath . '/export/sample-' . $this->config->outputFileName() . '-' . $themeName . '.pdf';
$sampleFileName = Config::buildPath(
$this->config->workingPath,
'export/sample-' . $this->config->outputFileName() . '-' . $themeName . '.pdf'
);
$this->output->writeln('<fg=yellow>==></> Writing Sample PDF To Disk ...');
$mpdf->Output(
$sampleFileName
Expand Down
14 changes: 12 additions & 2 deletions src/Commands/SortContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ibis\Commands;

use Ibis\Config;
use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -36,7 +37,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$currentPath = getcwd();

collect($this->disk->files($currentPath . '/content'))->each(function ($file, $index) use ($currentPath): void {
collect($this->disk->files(
Config::buildPath(
$currentPath,
'content'
)
))->each(function ($file, $index) use ($currentPath): void {
$markdown = $this->disk->get(
$file->getPathname()
);
Expand All @@ -49,7 +55,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->disk->move(
$file->getPathName(),
$currentPath . '/content/' . Str::slug($newName) . '.md'
Config::buildPath(
$currentPath,
'content',
Str::slug($newName) . '.md'
)
);
});

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Config/Datasets.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
["./assets/myfile.png", ["./", "assets/", "myfile.png"]],
["./assets/myfile.png", ["./", "assets/", "/myfile.png"]],
["./assets/myfile.png", [".", "assets", "myfile.png"]],
["./export/some.epub", ["./", "export", "some.epub"]],
]);

0 comments on commit e202d61

Please sign in to comment.