mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-06 00:05:42 +08:00
sort pkg.json
This commit is contained in:
@@ -57,6 +57,15 @@ class SortConfigCommand extends BaseCommand
|
||||
return static::FAILURE;
|
||||
}
|
||||
break;
|
||||
case 'pkg':
|
||||
$file = json_decode(FileSystem::readFile(ROOT_DIR . '/config/pkg.json'), true);
|
||||
ConfigValidator::validatePkgs($file);
|
||||
ksort($file);
|
||||
if (!file_put_contents(ROOT_DIR . '/config/pkg.json', json_encode($file, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n")) {
|
||||
$this->output->writeln('<error>Write file pkg.json failed!</error>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->output->writeln("<error>invalid config name: {$name}</error>");
|
||||
return 1;
|
||||
|
||||
@@ -70,4 +70,9 @@ class ConfigValidator
|
||||
{
|
||||
is_array($data) || throw new ValidationException('ext.json is broken');
|
||||
}
|
||||
|
||||
public static function validatePkgs(mixed $data): void
|
||||
{
|
||||
is_array($data) || throw new \_PHPStan_c997ea9ee\Nette\Schema\ValidationException('pkg.json is broken');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user