Skip to content

kazz187/boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

boilerplate

テンプレートレポジトリから、新規プロジェクトを作成するためのツールです。

Installation

go install github.com/kazz187/boilerplate@latest

How to use

A. リモートから直接生成する (推奨)

--repo を指定すると一時ディレクトリに git clone してから gen を実行します。事前に手元へ clone する必要はありません。

boilerplate gen --repo [email protected]:kazz187/web-boilerplate.git --dst ./my-new-service

特定のブランチ・タグ・コミットを指定したい場合は --ref を併用します。

boilerplate gen --repo [email protected]:kazz187/web-boilerplate.git --ref v1.0.0 --dst ./my-new-service

--repo モードでは内部で git コマンドを使うため PATH に git バイナリが必要です。認証 (SSH agent / credential helper / ~/.ssh/config / ~/.netrc) はシステムの git にそのまま委譲されます。

B. ローカルに置いたテンプレートから生成する

すでに clone 済みのテンプレートを使う場合は --src を指定します。

cd /YOUR_WORKING_DIR/
git clone https://github.com/kazz187/web-boilerplate
boilerplate gen --src ./web-boilerplate --dst ./my-new-service

指定されたテンプレートレポジトリ内にある boilerplate.yaml ファイルを参照し、新プロジェクトで置換する文字列を調べます。

project: BoilerPlate
targets:
  - name: repository name
    string: web-boilerplate
  - name: go module path
    string: github.com/kazz187/web-boilerplate
  - name: buf registry
    string: buf.build/kazz187/boiler-plate
ignore_prefixes:
  - .git/
  - .idea/
  - .claude/
  - boilerplate.yml
  - backend/docker/mysql/data/
  - frontend/node_modules/

このような yaml がある場合、 gen 実行時に以下のように聞かれます。

New project name (example: BoilerPlate): MyNewService
New repository name (example: web-boilerplate): mynew-server
New go module path (example: github.com/kazz187/web-boilerplate): github.com/myorg/mynew-server
New buf registry (example: buf.build/kazz187/boiler-plate): buf.build/myorg/mynew-server

project name は特殊なキーワードです。 BoilerPlate のように2単語以上をキャメルケースで指定します。

  • BoilerPlate -> MyNewService
  • boiler-plate -> my-new-service
  • boiler_plate -> my_new_service

のように、 Snake, Kebab, Camel などのケースに対応してよしなに置換してくれます (詳細な生成される変換ルールは replace_rule.go 内の func NewReplaceRulesFromCamelCase() を参照)

targets は単純な置換です。 project name より優先的に先に置換されます。 上記の例だと以下のように置換されます。

  • web-boilerplate -> mynew-server
  • github.com/kazz187/web-boilerplate -> github.com/myorg/mynew-server
  • buf.build/kazz187/boiler-plate -> buf.build/myorg/mynew-server

置換対象は、ファイル内の文字列と、ファイル・ディレクトリ名の文字列です。

ignore_prefixes は置換対象から除外するパスの prefix を指定します。例えば .git などのコピーしたくないファイルを指定します。

Flags

Flag 説明
-s, --src=DIR ローカルのテンプレートディレクトリを指定 (--repo と排他)
-r, --repo=URL git URL を指定して一時ディレクトリに clone してから使用 (--src と排他)
--ref=NAME --repo 利用時に clone する branch / tag / commit。未指定ならデフォルトブランチ
-d, --dst=DIR 出力先ディレクトリ (必須)
-f, --force --dst が空でない場合に上書きを許可

--dst が存在し空でないディレクトリだった場合はデフォルトでエラー終了します。意図して上書きしたい場合は --force を付与します (--src / --repo どちらのモードでも同じ挙動)。

About

boilerplate is cli tool for creating new project from a boilerplate template repository

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages