承接 acelords/laravel-model-ts-type 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

acelords/laravel-model-ts-type

最新稳定版本:v1.0.1

Composer 安装命令:

composer require acelords/laravel-model-ts-type

包简介

This package makes it possible to generate TypeScript types based on your models

README 文档

README

Generate TypeScript types based on your models.

Usage

Installation

Install the package using composer:

composer require --dev scrumble-nl/laravel-model-ts-type

Generating types

php artisan types:generate {--modelDir=} {--outputDir=} {--model=} {--noKebabCase}

Additional options:

Option Default value Description
modelDir app/Models The root directory where the package can find all Laravel models
outputDir resources/js/models The root directory for outputting the .d.ts files
namespace false The namespace of the generated Types. Use false if you don't prefer to have one
noKebabCase false Whether the file name should be formatted to kebab case
model null Choose to generate a model for a specific file. For example you can use App\Models\User
indentationSpaces 4 The amount of spaces used for indentation
export_types true Whether to export the types or not.

If you want to change the default values you can publish the config file and change it to you liking.

NOTE: Do not forget to add the directory to your typeroots in tsconfig.json

What does it do?

This package takes (almost) all off Laravel's magic into account. It follows these steps for generating a Type:

  1. Retrieve all fields from te database (only MySQL/MariaDB supported) and map them to default types (string, number, etc.)
  2. Add relations for the Model, they will point to the related generated Type
  3. Add the attribute getters for the Model
  4. Check the casts attribute
  5. Remove all fields that are in the hidden attribute

Example output

export type Company = {
    id: number;
    name: string;
    created_at: string /* Date */ | null;
    updated_at: string /* Date */ | null;
    slug: string;
    welcome_message: string | null;
    contact_information: string | null;
    main_color: string | null;
    logo_src: string | null;
    user_field: any[];
    language: any[];
    team_site: any[];
    is_api_enabled: boolean;
    kaizen_user_field: string;
    faqs?: Faq[] | null;
    users?: User[] | null;
    team_properties: TeamProperty[] | null;
    editor_images: EditorImage[] | null;
    meta_data?: any[];
};

Roadmap

  • Add tests (in progress)
  • Generate types for packagized models
  • Create command to generate type for 1 model
  • Implement unqualified name for relation doc blocks

Contributing

If you would like to see additions/changes to this package you are always welcome to add some code or improve it.

Scrumble

This product has been originally developed by Scrumble for internal use. As we have been using lots of open source packages we wanted to give back to the community. We hope this helps you getting forward as much as other people helped us!

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-24