shamaseen/laravel-files-generator

只需一个命令,就可以从模板生成任何类型的文件,真的是任何类型。

0.5.2 2022-06-26 01:05 UTC

This package is auto-updated.

Last update: 2024-09-26 06:15:20 UTC


README

只需一个命令,就可以从模板生成任何类型的文件,真的是任何类型。



Build Licence

快速开始


生成单个文件

从命令行

php artisan generate:stub pathToStub.stub pathToOutput.extension --replace='key 1' --with='value 1' --replace="key 2" --with='value 2'

在运行时

FilesGenerator::stub('PathToYourStubFile.extension')
        ->replace('string to be replaced','The replacement value')
        ->output('outputPath.extension');

生成多个文件

从命令行

php artisan generate:config 'pathToYourConfig/configFileName.php'

在运行时

FilesGenerator::fromConfigFile('configPath.php');

从配置文件中删除生成的文件

从命令行

php artisan ungenerate:config 'pathToYourConfig/configFileName.php'

在运行时

FilesUngenerator::fromConfigFile('configPath.php');

安装

运行

composer require shamaseen/laravel-files-generator

发布包配置文件

php artisan vendor:publish --provider='Shamaseen\Generator\GeneratorServiceProvider'

配置文件

要从配置文件生成多个文件,您需要首先创建一个配置文件,配置文件是一个必须返回数组的PHP文件,可以是单维数组或多维数组,具体取决于您想要生成多少个文件。

例如,要使用单个命令从2个模板生成2个文件,首先创建您的配置文件

<?php
return 
[
    [
        'stub' => 'first.stub',
        'output' => 'first.generated',
        'replace' => [
            '{% to be replaced 1 %}' => 'value',
            '{% to be replaced 2 %}' => 'value'
        ]
    ],
    [
        'stub' => 'second.stub',
        'output' => 'second.generated',
        'replace' => [
            '{% to be replaced 1 %}' => 'value',
        ]
    ]
];

现在运行此命令以生成两个文件

php artisan generate:config 'pathToYourConfig/configFileName.php'

许可

laravel files generator是一个在MIT许可条款下分发的免费软件。