0.0.1 • Published 2 years ago

@component-builder/react v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

component-builder/react

Reactコンポーネントに関するファイルをCLIで生成するライブラリ。必要なファイルなどを手動で追加するのが手間なので作った。

近いうちに生成時のコード挿入もやろうと思っている。

Usage

component-builder componentName filePath

以下のように省略してscriptsに記述すると楽になる。

  "scripts": {
    "cb": "component-builder"
  },

npm run cb componentName filePath

yarn cb componentName filePath

filePathを省略

後述するconfigファイルにrootDirを記述している場合は省略可能。

config

component-builder.jsonをルートに作成、オプションを記述。

rootDir

生成するファイルの共通パスを設定。

{
  "rootDir": "src/components/"
}

outExtensions

生成するファイルの拡張子を指定。

{
  "outExtensions": [
  "index",
  "presenter",
  "types",
  "stories",
  "test",
  ]
}

index

index.tsxファイルを生成。

presenter

Container/Presenter構成を想定し、index.tsxpresenter.tsxを生成する。

types

コンポーネントに対する型定義ファイル、componentName.types.tsを生成する。

stories

Storybookで使用するcomponentName.stories.tsxを生成する。

test

テストライブラリで使用するcomponentName.test.tsxを生成する。

追加予定の案

  • .js, .jsx拡張子対応(現状はtsxのみ)
  • コードが記述された状態でファイル生成
  • クラスコンポーネント、関数コンポーネントをconfigで選べる
  • プリセット機能(生成するファイルのプリセットをconfigで設定し、それぞれ出力できるようにする)
  • 他ライブラリと連携(ESLint、prettierなど)