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
UnJSを使って軽率にCLIを作ってみたらめちゃくちゃ便利だった / create CLI w...
Search
にー兄さん
July 26, 2024
Programming
1.9k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
UnJSを使って軽率にCLIを作ってみたらめちゃくちゃ便利だった / create CLI with UnJS
v-tokyo 12でLT登壇したスライド資料です
Web版:
https://drumath2237.github.io/slides-create-cli-with-unjs/
にー兄さん
July 26, 2024
More Decks by にー兄さん
See All by にー兄さん
ついにAuraも登場したのでJetpack XR SDKについて今一度語りたい / i wanna talk about xreal aura
drumath2237
0
36
『Ground Truth: How We Create Geometrically Accurate Reconstructions (Niantic Spatial Blog)』 を読む / read Ground Truth: How We Create Geometrically Accurate Reconstructions
drumath2237
0
73
この時代にOSS開発に向き合ってみる / face the oss development in this era
drumath2237
0
58
プログラマの職能が代替可能になりつつあるこの時代でプログラムと向き合う修行を積む / dedicating myself to the discipline of programming
drumath2237
0
100
個人的3D Gaussian Splattingニュースをご紹介 / sharing 3d gaussian splatting news
drumath2237
0
640
Jetpack XR SDKから紐解くAndroid XR開発と技術選定のヒント / about-androidxr-and-jetpack-xr-sdk
drumath2237
1
830
XRエンジニアの視点から XRのイマと社会実装の実現について考える / thinking-about-xr-popularization
drumath2237
0
95
軽率にプログラミング言語のシンタックスについて考えてみよう / lets-think-about-programming-lang-syntax
drumath2237
0
140
エンジニアが軽率に趣味から始める、OSS貢献を軸とした個人活動 / oss-contribution-as-a-hoby-project
drumath2237
0
110
Other Decks in Programming
See All in Programming
LLMは4年分のCompose移行を再現できるのか?実プロダクト279件のXMLで探る自動化の境界線
makun
0
230
T3DD26: From RAGs to Riches
martinhelmich
0
130
AIエージェント時代のコードレビューを設計する
nogu66
3
740
仕様駆動開発の消費期限
watany
20
9.2k
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
490
信頼性の目標を誰も求めてない
shubox
0
450
Flow は今どうなっているか
mizdra
PRO
0
810
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
290
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
640
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
130
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
280
Introducing Stack Pull Request in GitHub
kkamegawa
0
120
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.7k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Abbi's Birthday
coloredviolet
3
9.6k
Git: the NoSQL Database
bkeepers
PRO
432
67k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
Color Theory Basics | Prateek | Gurzu
gurzu
0
450
The Curious Case for Waylosing
cassininazir
1
490
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
How GitHub (no longer) Works
holman
316
150k
Transcript
UnJSを使って軽率に CLIを作ってみたら めちゃくちゃ便利だった にー兄さん@ninisan_drumath v-tokyo #21
にー兄さん ソフトウェアエンジニア@HoloLab inc. Babylon.js勉強会運営 Iwaken Lab. 好きなもの Babylon.js / WebXR
Device API / C# ねこ / コーヒー / ウィスキー / ギター アカウント @ninisan_drumath @drumath2237
本日の話 個人開発しているCLIでUnJSを使ってみた どんなパッケージを使ったのか、用途別にご紹介 UnJSのパッケージが気になっている方に刺さると嬉しいです
アジェンダ 1. はじめに 2. 使用したUnJSパッケージ 3. おわりに
はじめに
create-babylon-app とは Babylon.jsのプロジェクトを簡単に作成 するためのCLI コマンドラインから質問に答えるとプロ ジェクトができ、そのまま開発できる手 軽さが売り お手元のターミナルでぜひ試してみてくだ さい! GitHub:
https://github.com/drumath2237/create- babylon-app npm create babylon-app
create-babylon-appの要件 1. 作成するプロジェクト名を指定 2. テンプレートを選択 3. 設定を反映したプロジェクトを作成 create-viteやNuxt CLIの動作に近いので参考にしている。
UnJSとは UnJSは、Nuxt 開発チームが中心となっ て開発・メンテナンスされている、あら ゆるJavaScriptフレームワーク上で統一 的に動作するユーティリティーツール・ ライブラリ群です。 つまりUnJSはパッケージそのものではな く、パッケージ群のこと。 2024/07/26時点で63個ものパッケージが
提供されていてすごい 1. 『UnJS にどんなツールがあるのか、上位30件すべて紹 介してみた(前編)』より ↩︎ [1]
UnJSを使ってみたい 便利なパッケージがたくさんあるんだなぁ 自分でメンテしているCLIに使えないか な…? 当初はcitty目当てで調べ始めた GANGANさんのツイートを発見
使用したUnJSパッケージ
使用したパッケージ一覧 unbuild citty jiti consola giget pkg-types
citty Elegant CLI Builder いわゆるCLIフレームワーク的なものだと思 う コマンドライン引数やサブコマンドなど、 いい感じに設定できて良さげ 今回は run
に処理を書いただけだけど、自 動で --help などに対応してくれるのはう れしい Nuxt CLIの中身を見ると使い方が分かりや すい import { defineCommand, runMain } from "citty"; const main = defineCommand({ meta: { name: "hello", version: "1.0.0", description: "My Awesome CLI App", }, args: { name: { type: "positional", description: "Your name", required: true, }, }, run({ args }) { console.log(`Hi, ${args.name}!`); }, }); runMain(main);
None
giget Download templates and git repositories with pleasure! GitHubなどからファイルをごそっとダウン ロードしてローカルに展開できる
Scaffoldingツールにはもってこいのツール 内部でnypmも使っているので、ダウンロー ドした後にnpmやpnpmで依存解決も可能 使用例 特定のディレクトリも指定できる const { dir: appDir } = await downloadTemplate( `${githubRepoUrlBase}/${templateName}`, { dir: projectName, install: doInstall, }, ); const githubRepoUrlBase = "gh:drumath2237/create const templateName = `${buildTool}-${language}`;
pkg-types Node.js utilities and TypeScript definitions for package.json and tsconfig.json
ディレクトリやファイルパスを指定して package.json や tsconfig をを読み書きできる 自前で書いてもいいけど、型がついたりするのでいい感じ // パッケージ名を変更 const packageJson = await readPackageJSON(appDir); if (packageJson.name) { packageJson.name = projectName; const jsonPath = path.resolve(appDir, "package.json"); await writePackageJSON(jsonPath, packageJson); }
jiti Runtime TypeScript and ESM support for Node.js 開発中にビルドせずに動作を確認するとき に使用
もともとはvite-nodeを使っていたが なんとなく移行してみた 特殊な使い方はしておらず、シンプルにts ファイルを指定して実行するだけ unbuild A unified javascript build system ビルドツールの選択肢はいろいろある中で 元々はtscでコンパイルした.cjsを bin に指 定して動かしていた バンドルなども考慮したいと思い移行 Zero Configでも普通に動くし、 build.config.ts にビルド設定を記述可能 pnpm exec jiti src/run.ts import { defineBuildConfig } from "unbuild"; export default defineBuildConfig({ entries: ["./src/index.ts"], });
おわりに
None
参考文献 UnJS https://unjs.io/ create-babylon-app v1.0に向けたアプデ作業 https://zenn.dev/drumath2237/scraps/b085d5f90b65f3 drumath2237/create-babylon-app https://github.com/drumath2237/create-babylon-app