English | 日本語
カスタムプラグインで Milkee の機能を拡張できます。
-p (--plugin) コマンドでプラグインプロジェクトをセットアップ:
# グローバル
milkee -p
# ローカル
npx milkee -p以下が実行されます:
package.jsonの初期化(必要な場合)- 依存関係のインストール (
consola,coffeescript,milkee) - テンプレートファイルの作成
package.jsonの更新 (main,scripts,keywords)
your-plugin/
src/
main.coffee # プラグインのソース
dist/
main.js # コンパイル後の出力
.github/
workflows/
publish.yml # npm公開ワークフロー
coffee.config.cjs
package.json
fs = require 'fs'
path = require 'path'
consola = require 'consola'
pkg = require '../package.json'
PREFIX = "[#{pkg.name}]"
# プレフィックス付きカスタムロガー
c = {}
for method in ['log', 'info', 'success', 'warn', 'error', 'debug', 'start', 'box']
do (method) ->
c[method] = (args...) ->
if typeof args[0] is 'string'
args[0] = "#{PREFIX} #{args[0]}"
consola[method] args...
# メインプラグイン関数
main = (compilationResult) ->
{ config, compiledFiles, stdout, stderr } = compilationResult
c.info "#{compiledFiles.length} ファイルをコンパイルしました"
for file in compiledFiles
c.log " - #{file}"
module.exports = mainMilkee はコンパイル後にこのオブジェクトをプラグインに渡します:
| プロパティ | 型 | 説明 |
|---|---|---|
config |
object |
coffee.config.cjs の設定オブジェクト |
compiledFiles |
string[] |
コンパイルされた .js と .js.map のパス |
stdout |
string |
コンパイラの標準出力 |
stderr |
string |
コンパイラの標準エラー |
const myPlugin = require('your-plugin-name');
module.exports = {
entry: 'src',
output: 'dist',
milkee: {
plugins: [
myPlugin({ customOption: 'value' }),
]
}
};# プラグインをビルド
npm run build
# ローカルテスト用にリンク
npm link
# 別のプロジェクトで
npm link your-plugin-name同梱のワークフローで npm に手動公開:
- リポジトリに
NPM_TOKENシークレットを追加 - Actions → Manual Publish to npm に移動
- Run workflow をクリック
npm run build
npm publish --access public- 名前:
milkee-plugin-xxxまたは@yourname/milkee-plugin-xxx - キーワード(自動追加):
milkee,coffeescript,coffee,plugin,milkee-plugin
main = (compilationResult) ->
try
# ロジック
catch error
c.error "失敗:", error.message
throw error