shineunited/conductor-gitignore-addon

Conductor 的插件,用于管理项目的 gitignore 文件。

1.0.1 2023-06-26 16:40 UTC

This package is auto-updated.

Last update: 2024-09-26 19:27:18 UTC


README

License Latest Version PHP Version Main Status Release Status Develop Status

描述

结合 Conductor,此插件会自动修改项目的 .gitignore 文件,以排除 Conductor 安装的路径或由其他包显式指定的路径。

安装

要添加 conductor-gitignore-addon,建议使用 composer。

$ composer require shineunited/conductor-gitignore-addon

配置

gitignore 插件使用 Conductor 配置框架来解析项目 composer.json 文件 'extra' 部分中的参数。

参数

gitignore.ignore-lockfile

(布尔值) 如果为 true,将 composer 锁文件 (composer.lock) 添加到 gitignore 文件中。默认为 false。

gitignore.ignore-pharfile

(布尔值) 如果为 true,将 composer phar 文件 (composer.phar) 添加到 gitignore 文件中。默认为 true。

gitignore.ignore-vendordir

(布尔值) 如果为 true,将整个 vendor 目录添加到 gitignore 文件中。默认为 true。

gitignore.ignore-packages

(布尔值) 如果为 true,自动将除 vendor 目录之外由 conductor 安装器安装的任何包添加到 gitignore 文件中。默认为 true。

示例

{
	"name": "example/project",
	"type": "project",
	"extra": {
		"gitignore": {
			"ignore-lockfile": true,
			"ignore-pharfile": false,
			"ignore-vendordir": true,
			"ignore-packages": true
		}
	}
}

用法

GitignoreProvider 能力

除了基于项目配置自动添加的 gitignore 规则外,通过 GitignoreProvider 能力,composer 插件可以显式添加各种规则。

示例插件

插件必须实现 Capable 并提供 GitignoreProvider 能力。

<?php

namespace Example\Project;

use Composer\Composer;
use Composer\IO\IOInterface;
use ShineUnited\Conductor\Addon\Gitignore\Capability\GitignoreProvider;

class ComposerPlugin implements PluginInterface, Capable {

	public function activate(Composer $composer, IOInterface $io): void {
		// ...
	}

	public function deactivate(Composer $composer, IOInterface $io): void {
		// ...
	}

	public function uninstall(Composer $composer, IOInterface $io): void {
		// ...
	}

	public function getCapabilities(): array {
		return [
			GitignoreProvider::class => ExampleGitignoreProvider::class
		];
	}
}

示例提供者

提供者必须实现该能力,并返回一个包含 gitignore RuleInterface 对象的列表。

<?php

namespace Example\Project;

use ShineUnited\Conductor\Addon\Gitignore\Capability\GitignoreProvider;
use ShineUnited\Conductor\Addon\Gitignore\Pattern\Rule;

class ExampleGitignoreProvider implements GitignoreProvider {

	public function getGitignores(): array {
		return [
			new Rule('path/to/ignore'),
			new Rule('another/path/to/ignore')
		];
	}
}