massive / build-bundle
Massive Art Build Bundle
0.5.7
2024-04-05 11:35 UTC
Requires
- php: >=7.2.0
- symfony/config: ^4.3 || ^5.0 || ^6.0 || ^7.0
- symfony/console: ^4.3 || ^5.0 || ^6.0 || ^7.0
- symfony/dependency-injection: ^4.3 || ^5.0 || ^6.0 || ^7.0
- symfony/framework-bundle: ^4.3 || ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- matthiasnoback/symfony-dependency-injection-test: ^4.0 || ^5.0
- symfony/phpunit-bridge: ^5.4.33|^6.3.10|^7.0.1
README
Massive Build Bundle 提供了一个 massive:build
命令,该命令可以运行构建目标。
目标是可以执行任意代码的类,并且通过标签注册在依赖注入容器中。目标可以依赖于其他目标。
可以在应用程序的配置文件中创建虚拟目标。这些虚拟目标仅仅声明依赖关系,使您能够配置自定义构建过程。
此捆绑包的目的是提供一个可扩展、解耦的软件项目环境构建方式,特别是在开发环境中。
如果您经常发现自己连续执行多个 Symfony 命令来建立环境,那么这个捆绑包就适合您。
这个工具并不打算取代 Make 或 Ant 或 Phing。捆绑包应该只用于执行客户端应用程序中包含的构建步骤。
定义目标
您可以在应用程序的配置文件中定义新的构建目标
massive_build:
targets:
main:
dependencies:
target_one: ~
target_two: ~
target_three: ~
quick:
dependencies:
target_one: ~
上述设置将允许您执行
$ php app/console massive:build main
和
$ php app/console massive:build quick
创建构建类
您可以在应用程序/捆绑包中创建构建类。每个构建类应该有特定的职责。
一个最小示例
<?php namespace My\Web\Application; use Massive\Bundle\BuildBundle\Build\BuilderInterface; class MyBuilder implements BuilderInterface { protected $context; public function getName() { return 'mybuildername'; } public function getDependencies() { return array(); } public function build() { $application = $this->context->getApplication(); $input = $this->context->getInput(); $output = $this->context->getOutput(); $output->writeln('Hello World!'); } public function setContext(BuilderContext $context) { $this->context = $context; } }
- getName: 返回构建器的名称。
- getDependencies: 返回该构建器所依赖的任何构建器的 名称。
- build: 在此方法中执行所有逻辑。
- setContext: 由主构建命令自动调用,包含
Input
、Output
和Application
。
注册构建类
您可以在依赖注入容器中注册构建类,并使用标签进行标记。
<service id="sulu.core.build.builder.database" class="My\Web\Application\Builder\FooBuilder"> <tag name="massive_build.builder" /> </service>
添加全局选项和自定义
您可以使选项可用于您的命令(例如,指定应该 destroy
数据库,或者将用户 "x" 的名称设置为 "y")。
采用这种方法,您可以自由地以任何方式自定义 build
命令。
为此,您需要扩展 massive 的 BuildCommand
并配置 MassiveBuild 捆绑包以使用您扩展的类。
<?php namespace Sulu\Bundle\CoreBundle\Command; use Massive\Bundle\BuildBundle\Command\BuildCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; class SuluBuildCommand extends BuildCommand { public function configure() { parent::configure(); // change the name of the command from "massive:build" $this->setName('myapp:build'); // add an option $this->addOption('destroy', null, InputOption::VALUE_NONE, 'Destroy existing data'); } }
启动构建
您可以使用以下命令启动所有构建器
$ php app/console massive:build
启动特定目标
$ php app/console massive:build mytarget
如果您想查看可用的目标,请使用 --nobuild 选项
$ php app/console massive:build --nobuild Build Targets ============= +---+----------+--------------------+ | # | Builder | Deps | +---+----------+--------------------+ | 0 | database | | | 1 | phpcr | database | | 2 | fixtures | database | | 3 | user | database, fixtures | +---+----------+--------------------+
默认情况下,如果您指定了特定目标,构建系统将构建其所有依赖项,要禁用此功能,请使用 --nodeps
选项。
$ php app/console massive:build --nodeps