Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Code Generatorを作ってコンポーネントを自動生成しよう / Let's make ...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
shike
October 04, 2019
Programming
2.3k
1
Share
Code Generatorを作ってコンポーネントを自動生成しよう / Let's make code generator
shike
October 04, 2019
More Decks by shike
See All by shike
TypeScript + GASでAPIを作る / Build API with TypeScript and GAS
shike0909
0
160
Nuxt + TypeScriptで SPAを作る / Build SPA with Nuxt and TypeScript
shike0909
0
150
Lighthouseを使った認証必須のGraphQL API / GraphQL API authentication with Lighthouse
shike0909
0
2.3k
Reduxについて / Redux introduction and TODO example with Redux
shike0909
0
130
Other Decks in Programming
See All in Programming
Agent Skills を社内で育てる仕組み作り
jackchuka
1
1.9k
Explore CoroutineScope
tomoeng11
0
180
Firefoxにコントリビューションして得られた学び
ken7253
2
160
開発とはなにか、Essenceカーネルで見えるもの
ukin0k0
0
140
[RubyKaigi 2026] Require Hooks
palkan
1
310
要はバランスからの卒業 #yumemi_grow
kajitack
0
120
実用!Hono RPC2026
yodaka
2
310
Are We Really Coding 10× Faster with AI?
kohzas
0
150
AWSはOSSをどのように 考えているのか?
akihisaikeda
0
110
2026-04-15 Spring IO - I Can See Clearly Now
jonatan_ivanov
1
200
From Formal Specification to Property Based Test
ohbarye
0
2.4k
空間オーディオの活用
objectiveaudio
0
150
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
44
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
420
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
180
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
The Language of Interfaces
destraynor
162
26k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
360
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Un-Boring Meetings
codingconduct
0
290
Typedesign – Prime Four
hannesfritz
42
3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1k
Transcript
Code Generatorを作って コンポーネントを自動生成しよう 2019/10/04 Gotanda.js 株式会社Cluex 柴山健吾
自己紹介 • 柴山健吾 • 株式会社Cluitグループの株式会社Cluex • Webグループ • バックエンドもフロントもやります •
好きな言語 ◦ TypeScript, Kotlin • Twitter ◦ @shikeapp0909
背景 • 新規プロダクトの立ち上げに際して、ディレクトリ構成含めて コンポーネント設計について議論した • チーム内にAtomic Design経験者がいなかったが、 Atoms, Molecules, Organismsみたいな粒度で分類分けして管理したい
• あまり厳密にしすぎずLv1, Lv2, Lv3くらいのゆるさで 十分ではないかという結論に至った • Storybookも導入し、もちろんテストもちゃんとやるので、 それも含めたディレクトリ構成どうするかを考えた
• DMMさんのこの記事に感銘を受けた ◦ DMM動画サービスの問題を解決しようとしている話(コンポーネント編) ◦ https://inside.dmm.com/entry/2018/07/12/components • テストもStorybookもコンポーネントと1 : 1の関係になるので、
同じディレクト内に収めるのはとてもGood • さらにそのディレクトリごと自動生成するというのが非常にGood • ということで分類とコンポーネント名を渡すと コンポーネントを自動生成するCLIを作ることに 背景
最終的なディレクトリ構成
CLIを作っていく! • 言語 ◦ Node.js • 使用ライブラリ ◦ inquirer(https://github.com/SBoudrias/Inquirer.js) ▪
対話形式でのコマンドラインを作成するためのライブラリ ◦ mustache(https://github.com/janl/mustache.js/) ▪ テンプレート ◦ signale(https://github.com/klaussinani/signale) ▪ オシャレなログを出力できる
InquirerはCLIでよく見るプロンプトを作成するやつ
signaleはスタイルやアイコンつきのログ出力するやつ
実際のコード
None
None
None
None
package.jsonのscriptに追加 作成したファイルをnodeで実行するようにpackage.jsonのscriptに定義 "component:generate": "node ./cli/generateComponent"
None
コンポーネントの作成が捗る!
まとめ • CLIを作るにはinquirerを使うと簡単 • Code Generatorを作るにはinquirer + mustacheが便利 • さらにsignaleを使うとログをオシャレにできる
• 自動生成は正義