whitecube/laravel-preset 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

whitecube/laravel-preset

Composer 安装命令:

composer require whitecube/laravel-preset

包简介

Custom Laravel Preset for the Whitecube workflow.

README 文档

README

This preset will install and setup everything that is needed for new Laravel projects at Whitecube.

To start a new project:

  1. Create the new Laravel project
laravel new my-project
cd my-project
  1. Install the preset
composer require whitecube/laravel-preset --dev
  1. Activate the preset
php artisan ui whitecube
  1. You're done! You can now compile, watch, etc!
yarn dev
yarn watch
yarn icons
yarn watch-icons

Everything you'd expect should be there, and you can get to work right away.

Setting up new Hiker projects

After doing the above commands, do the following:

  1. Add the Hiker repository to the composer.json file:
composer config repositories.hiker composer https://repo.hiker.dev
  1. The, run the following terminal commands:
composer require hiker-dev/hiker
  1. When prompted, add your Hiker.dev user & license. You can store these credentials in a auth.json, but don't forget to add this file to the project's .gitignore!

  2. Finally, run Hiker's installation command:

php artisan hiker:install

Publish the base files for common components

This package ships with a set of publishable components that will help setup the project's front-end basics in a few seconds. The following command will prompt for the components you can install:

php artisan publish:component

Creating new publishable components

In order to create a publishable component, one should simply create a new "Publisher" class inside src/Components/Publishers and implement Whitecube\LaravelPreset\Components\PublisherInterface :

namespace Whitecube\LaravelPreset\Components\Publishers;

use Whitecube\LaravelPreset\Components\File;
use Whitecube\LaravelPreset\Components\FilesCollection;
use Whitecube\LaravelPreset\Components\PublisherInterface;

class Wysiwyg implements PublisherInterface
{
    /**
     * Get the component's displayable name.
     */
    public function label(): string
    {
        return 'WYSIWYG section';
    }

    /**
     * Let the publisher prompt for eventual extra input
     * and return a collection of publishable files.
     */
    public function handle(): FilesCollection
    {
        $style = File::makeFromStub(
            stub: 'components/wysiwyg/part.scss',
            destination: resource_path('sass/parts/_wysiwyg.scss'),
        );

        $view = File::makeFromStub(
            stub: 'components/wysiwyg/view.blade.php',
            destination: resource_path('views/components/wysiwyg.blade.php'),
        );

        return FilesCollection::make([$style, $view]);
    }

    /**
     * Get the component's usage instructions
     */
    public function instructions(): ?string
    {
        return "1. Add `@import 'parts/wysiwyg';` to `resources/sass/app.scss`\r\n2. Use the blade component: `<x-wysiwyg><p>Some content</p></x-wysiwyg>`";
    }
}

Most of the heavy-lifting will be achieved inside the publisher's handle() method. For instance, it's a great place to prompt for additional component-specific information and configure the publishable files accordingly.

The handle() method's main purpose is to collect and return the publishable files, that's why this package provides a File class with several useful methods and features. First, you can choose to create a File instance using one of these methods:

  • File::makeFromStub(string $destination, string $stub): useful when working with existing files ;
  • File::make(string $destination, string $content, ?string $origin = null): useful when creating files from scratch.

Most of the time, File::makeFromStub should be used in order to keep a clear commit history on the component's original files somewhere in this package's components/[your-component] directory.

These File instances can be manipulated before publication with a few useful methods:

  • $sassFile->replaceVariableValue('wysiwyg_width_columns', 10);
  • $sassFile->replaceBemBase('wysiwyg', 'foo');
  • $bladeFile->replaceBemBase('wysiwyg', 'foo');

Of course, Laravel Prompts can be used anywhere inside a publisher's handle() method, which is useful for file configuration:

use function Laravel\Prompts\text;

$style = File::makeFromStub(
    stub: 'components/wysiwyg/part.scss',
    destination: resource_path('sass/parts/_wysiwyg.scss'),
);

$width = text(
    label: 'How many columns should the WYSIWYG\'s container width be?',
    default: 10,
    hint: 'Based on a 12 columns grid',
);

$style->replaceVariableValue('wysiwyg_width_columns', $width);

whitecube/laravel-preset 适用场景与选型建议

whitecube/laravel-preset 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.21k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel-preset」 「whitecube」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 whitecube/laravel-preset 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 whitecube/laravel-preset 我们能提供哪些服务?
定制开发 / 二次开发

基于 whitecube/laravel-preset 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-26