deliverist / builder
项目构建器。
v2.0.0
2023-03-29 10:41 UTC
Requires
- php: >=5.6.0
- czproject/path-helper: ^4.0
- czproject/runner: ^1.0
- nette/utils: ^2.4 || ^3.0 || ^4.0
Requires (Dev)
- nette/tester: ^2.0
README
安装
composer require deliverist/builder
Deliverist\Builder
需要 PHP 5.6.0 或更高版本。
用法
<?php use Deliverist\Builder\Builder; use Deliverist\Builder\Commands; use Deliverist\Builder\Loggers; $builder = new Builder('/path/to/source/code', [ 'composer-install' => new Commands\ComposerInstall, 'rename' => new Commands\Rename, 'remove' => new Commands\Remove, ], new Loggers\TextLogger); $builder->make('composer-install') ->make('rename', ['from' => 'index.php', 'to' => 'www/index.php']) ->make('remove', ['file' => 'composer.lock']) ->make('composer-install');
命令
ApacheImports
在指定文件中展开 <!--#include file="file.txt" -->
语句。
$builder->make('apache-imports', ['file' => 'file-to-expand.txt']); $builder->make('apache-imports', ['files' => [ 'admin.js', 'front.js', ]]);
ComposerInstall
在 composer.json
目录下运行 composer install
。
$builder->make('composer-install'); $builder->make('composer-install', ['composerFile' => 'path/to/composer.json']);
复制
复制指定文件。
$builder->make('copy', ['from' => 'old.txt', 'to' => 'new.txt']); $builder->make('copy', ['files' => [ 'old.txt' => 'new.txt', ]]); $builder->make('copy', ['paths' => [ 'old/dir' => 'new/dir', ]]);
创建目录
创建指定目录。
$builder->make('create-directory', ['directory' => 'new-directory']); $builder->make('create-directory', ['directories' => [ 'new-directory', 'new-directory-2', ]]);
CssExpandImports
在指定文件中展开 @import 'file.css'
语句。
$builder->make('css-expand-imports', ['file' => 'file-to-expand.txt']); $builder->make('css-expand-imports', ['files' => [ 'admin.css', 'front.css', ]]);
GoogleAnalytics
在文件中替换占位符为 Google Analytics 脚本。
$builder->make('google-analytics', [ 'file' => 'path/to/file.php', 'code' => 'UA-9876-5', 'placeholder' => '%% GA %%', ]); // replaces placeholder '%% GA %%' in file $builder->make('google-analytics', ['file' => 'path/to/file.html', 'code' => 'UA-9876-5']); // uses placeholder '<!-- GA -->' in file $builder->make('google-analytics', ['file' => 'path/to/file.latte', 'code' => 'UA-9876-5']); // uses placeholder {* GA *} in file
GoogleClosureCompiler
在线 Google Closure Compiler 中压缩文件。
$builder->make('google-closure-compiler', ['file' => 'script.js']); $builder->make('google-closure-compiler', ['files' => [ 'script-1.js', 'script-2.js', ]]);
LessCompile
运行 lessc
编译 LESS 文件。
$builder->make('less-compile', ['file' => 'styles.less']); $builder->make('less-compile', ['files' => [ 'style-1.less', 'style-2.less', ]]);
MinifyContent
删除行首行尾的空行和空格。
$builder->make('minify-content', ['file' => 'file.txt']); $builder->make('minify-content', ['files' => [ 'file-1.txt', 'file-2.txt', ]]);
示例
输入
{block content}
<h1>Homepage</h1>
<p>
Lorem ipsum dolor sit amet.
</p>
{/block}
输出
{block content}
<h1>Homepage</h1>
<p>
Lorem ipsum dolor sit amet.
</p>
{/block}
PingUrl
打开 URL 并显示内容。
$builder->make('ping-url', ['url' => 'https://example.com/migrations.php']); $builder->make('ping-url', ['url' => 'https://example.com/migrations.php', 'validateSsl' => FALSE]); // disable SSL validation
移除
删除文件或目录。
$builder->make('remove', ['file' => 'path/to/file.txt']); $builder->make('remove', ['path' => 'path/to/directory']); $builder->make('remove', ['files' => [ 'path/to/file.txt', 'path/to/directory', ]]); $builder->make('remove', ['paths' => [ 'path/to/file.txt', 'path/to/directory', ]]);
重命名
重命名文件或目录。
$builder->make('rename', ['from' => 'old.txt', 'to' => 'new.txt']); $builder->make('rename', ['files' => [ 'old.txt' => 'new.txt', ]]);
替换内容
替换文件中的内容。
$builder->make('replace-content', [ 'file' => 'file.txt', 'replacements' => [ 'from' => 'to', 'old string' => 'new string', ], ]);
许可: 新 BSD 许可证
作者:Jan Pecha,https://www.janpecha.cz/