Move config name to const and change nostow to stowignore
This commit is contained in:
@ -24,7 +24,7 @@ $unwrap = $parsed->get('w');
|
||||
$stowName = $parsed->get('stow-directory');
|
||||
$stowPath = path($cwd, $stowName);
|
||||
|
||||
$config = new config($stowPath);
|
||||
$config = new config($stowPath, stow::CONFIG_FILE_NAME);
|
||||
$targetPath = $config->get('targetPath', dirname($stowPath, 2));
|
||||
|
||||
if (!is_dir($stowPath)) {
|
||||
|
@ -5,6 +5,10 @@ readonly class stow
|
||||
public const ACTION_STOW = 'stow';
|
||||
public const ACTION_UNSTOW = 'unstow';
|
||||
|
||||
public const STOW_IGNORE_FILE = '.stowignore';
|
||||
public const CONFIG_FILE_NAME = 'config.stow.php';
|
||||
|
||||
|
||||
public function __construct(
|
||||
private string $action = self::ACTION_STOW,
|
||||
private bool $backup = false,
|
||||
@ -14,12 +18,12 @@ readonly class stow
|
||||
|
||||
private function getNoStow(string $path): array
|
||||
{
|
||||
if (file_exists(path($path, '.nostow'))) {
|
||||
$noStow = file_get_contents(path($path, '.nostow'));
|
||||
if (file_exists(path($path, self::STOW_IGNORE_FILE))) {
|
||||
$noStow = file_get_contents(path($path, self::STOW_IGNORE_FILE));
|
||||
if ($noStow === false) {
|
||||
return [];
|
||||
}
|
||||
return array_values(array_filter(array_map('trim', explode(PHP_EOL, $noStow))));
|
||||
return array_values(array_filter(array_map(trim(...), explode(PHP_EOL, $noStow))));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
@ -28,7 +32,7 @@ readonly class stow
|
||||
function run(string $sourcePath, string $targetPath): void
|
||||
{
|
||||
$noStow = $this->getNoStow($sourcePath);
|
||||
$sourceFiles = array_diff(scandir($sourcePath), ['..', '.', 'config.php', '.nostow', ...$noStow]);
|
||||
$sourceFiles = array_diff(scandir($sourcePath), ['..', '.', self::CONFIG_FILE_NAME, self::STOW_IGNORE_FILE, ...$noStow]);
|
||||
|
||||
foreach ($sourceFiles as $sourceFile) {
|
||||
$targetFile = path($targetPath, $sourceFile);
|
||||
|
Reference in New Issue
Block a user