milkee 2.4.1 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/plugin.js +1 -1
- package/docs/PLUGIN-ja.md +143 -0
- package/docs/PLUGIN.md +143 -0
- package/package.json +1 -1
- package/temp/plugin/coffee.config.cjs +2 -0
package/dist/commands/plugin.js
CHANGED
|
@@ -99,7 +99,7 @@ copyDocs = function(src, dest) {
|
|
|
99
99
|
return true;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
PLUGIN_KEYWORDS = ['milkee', 'coffeescript', 'coffee', '
|
|
102
|
+
PLUGIN_KEYWORDS = ['milkee', 'coffeescript', 'coffee', 'plugin', 'milkee-plugin'];
|
|
103
103
|
|
|
104
104
|
// Update package.json
|
|
105
105
|
updatePackageJson = function() {
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Milkee プラグインの作成
|
|
2
|
+
|
|
3
|
+
カスタムプラグインで Milkee の機能を拡張できます。
|
|
4
|
+
|
|
5
|
+
## クイックスタート
|
|
6
|
+
|
|
7
|
+
`-p` (`--plugin`) コマンドでプラグインプロジェクトをセットアップ:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# グローバル
|
|
11
|
+
milkee -p
|
|
12
|
+
|
|
13
|
+
# ローカル
|
|
14
|
+
npx milkee -p
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
以下が実行されます:
|
|
18
|
+
1. `package.json` の初期化(必要な場合)
|
|
19
|
+
2. 依存関係のインストール (`consola`, `coffeescript`, `milkee`)
|
|
20
|
+
3. テンプレートファイルの作成
|
|
21
|
+
4. `package.json` の更新 (`main`, `scripts`, `keywords`)
|
|
22
|
+
|
|
23
|
+
## プロジェクト構造
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
your-plugin/
|
|
27
|
+
src/
|
|
28
|
+
main.coffee # プラグインのソース
|
|
29
|
+
dist/
|
|
30
|
+
main.js # コンパイル後の出力
|
|
31
|
+
.github/
|
|
32
|
+
workflows/
|
|
33
|
+
publish.yml # npm公開ワークフロー
|
|
34
|
+
coffee.config.cjs
|
|
35
|
+
package.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## プラグインの書き方
|
|
39
|
+
|
|
40
|
+
### 基本テンプレート
|
|
41
|
+
|
|
42
|
+
```coffee
|
|
43
|
+
fs = require 'fs'
|
|
44
|
+
path = require 'path'
|
|
45
|
+
consola = require 'consola'
|
|
46
|
+
|
|
47
|
+
pkg = require '../package.json'
|
|
48
|
+
PREFIX = "[#{pkg.name}]"
|
|
49
|
+
|
|
50
|
+
# プレフィックス付きカスタムロガー
|
|
51
|
+
c = {}
|
|
52
|
+
for method in ['log', 'info', 'success', 'warn', 'error', 'debug', 'start', 'box']
|
|
53
|
+
do (method) ->
|
|
54
|
+
c[method] = (args...) ->
|
|
55
|
+
if typeof args[0] is 'string'
|
|
56
|
+
args[0] = "#{PREFIX} #{args[0]}"
|
|
57
|
+
consola[method] args...
|
|
58
|
+
|
|
59
|
+
# メインプラグイン関数
|
|
60
|
+
main = (compilationResult) ->
|
|
61
|
+
{ config, compiledFiles, stdout, stderr } = compilationResult
|
|
62
|
+
|
|
63
|
+
c.info "#{compiledFiles.length} ファイルをコンパイルしました"
|
|
64
|
+
for file in compiledFiles
|
|
65
|
+
c.log " - #{file}"
|
|
66
|
+
|
|
67
|
+
module.exports = main
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### コンパイル結果
|
|
71
|
+
|
|
72
|
+
Milkee はコンパイル後にこのオブジェクトをプラグインに渡します:
|
|
73
|
+
|
|
74
|
+
| プロパティ | 型 | 説明 |
|
|
75
|
+
| :-------------- | :--------- | :--------------------------------------------- |
|
|
76
|
+
| `config` | `object` | `coffee.config.cjs` の設定オブジェクト |
|
|
77
|
+
| `compiledFiles` | `string[]` | コンパイルされた `.js` と `.js.map` のパス |
|
|
78
|
+
| `stdout` | `string` | コンパイラの標準出力 |
|
|
79
|
+
| `stderr` | `string` | コンパイラの標準エラー |
|
|
80
|
+
|
|
81
|
+
### coffee.config.cjs での使用
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const myPlugin = require('your-plugin-name');
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
entry: 'src',
|
|
88
|
+
output: 'dist',
|
|
89
|
+
milkee: {
|
|
90
|
+
plugins: [
|
|
91
|
+
myPlugin({ customOption: 'value' }),
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## ビルド & テスト
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# プラグインをビルド
|
|
101
|
+
npm run build
|
|
102
|
+
|
|
103
|
+
# ローカルテスト用にリンク
|
|
104
|
+
npm link
|
|
105
|
+
|
|
106
|
+
# 別のプロジェクトで
|
|
107
|
+
npm link your-plugin-name
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 公開
|
|
111
|
+
|
|
112
|
+
### GitHub Actions を使用
|
|
113
|
+
|
|
114
|
+
同梱のワークフローで npm に手動公開:
|
|
115
|
+
|
|
116
|
+
1. リポジトリに `NPM_TOKEN` シークレットを追加
|
|
117
|
+
2. **Actions** → **Manual Publish to npm** に移動
|
|
118
|
+
3. **Run workflow** をクリック
|
|
119
|
+
|
|
120
|
+
### 手動
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm run build
|
|
124
|
+
npm publish --access public
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## ベストプラクティス
|
|
128
|
+
|
|
129
|
+
### 命名規則 & キーワード
|
|
130
|
+
|
|
131
|
+
- 名前: `milkee-plugin-xxx` または `@yourname/milkee-plugin-xxx`
|
|
132
|
+
- キーワード(自動追加): `milkee`, `coffeescript`, `coffee`, `ext`, `plugin`, `milkee-plugin`
|
|
133
|
+
|
|
134
|
+
### エラーハンドリング
|
|
135
|
+
|
|
136
|
+
```coffee
|
|
137
|
+
main = (compilationResult) ->
|
|
138
|
+
try
|
|
139
|
+
# ロジック
|
|
140
|
+
catch error
|
|
141
|
+
c.error "失敗:", error.message
|
|
142
|
+
throw error
|
|
143
|
+
```
|
package/docs/PLUGIN.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Creating a Milkee Plugin
|
|
2
|
+
|
|
3
|
+
Extend Milkee's functionality with custom plugins.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
Run `-p` (`--plugin`) command to set up your plugin project:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# global
|
|
11
|
+
milkee -p
|
|
12
|
+
|
|
13
|
+
# or local
|
|
14
|
+
npx milkee -p
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This will:
|
|
18
|
+
1. Initialize `package.json` (if needed)
|
|
19
|
+
2. Install dependencies (`consola`, `coffeescript`, `milkee`)
|
|
20
|
+
3. Create template files
|
|
21
|
+
4. Update `package.json` (`main`, `scripts`, `keywords`)
|
|
22
|
+
|
|
23
|
+
## Project Structure
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
your-plugin/
|
|
27
|
+
src/
|
|
28
|
+
main.coffee # Your plugin source
|
|
29
|
+
dist/
|
|
30
|
+
main.js # Compiled output
|
|
31
|
+
.github/
|
|
32
|
+
workflows/
|
|
33
|
+
publish.yml # npm publish workflow
|
|
34
|
+
coffee.config.cjs
|
|
35
|
+
package.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Writing Your Plugin
|
|
39
|
+
|
|
40
|
+
### Basic Template
|
|
41
|
+
|
|
42
|
+
```coffee
|
|
43
|
+
fs = require 'fs'
|
|
44
|
+
path = require 'path'
|
|
45
|
+
consola = require 'consola'
|
|
46
|
+
|
|
47
|
+
pkg = require '../package.json'
|
|
48
|
+
PREFIX = "[#{pkg.name}]"
|
|
49
|
+
|
|
50
|
+
# Custom logger with prefix
|
|
51
|
+
c = {}
|
|
52
|
+
for method in ['log', 'info', 'success', 'warn', 'error', 'debug', 'start', 'box']
|
|
53
|
+
do (method) ->
|
|
54
|
+
c[method] = (args...) ->
|
|
55
|
+
if typeof args[0] is 'string'
|
|
56
|
+
args[0] = "#{PREFIX} #{args[0]}"
|
|
57
|
+
consola[method] args...
|
|
58
|
+
|
|
59
|
+
# Main plugin function
|
|
60
|
+
main = (compilationResult) ->
|
|
61
|
+
{ config, compiledFiles, stdout, stderr } = compilationResult
|
|
62
|
+
|
|
63
|
+
c.info "Compiled #{compiledFiles.length} file(s)"
|
|
64
|
+
for file in compiledFiles
|
|
65
|
+
c.log " - #{file}"
|
|
66
|
+
|
|
67
|
+
module.exports = main
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Compilation Result
|
|
71
|
+
|
|
72
|
+
Milkee passes this object to your plugin after compilation:
|
|
73
|
+
|
|
74
|
+
| Property | Type | Description |
|
|
75
|
+
| :-------------- | :--------- | :--------------------------------------------- |
|
|
76
|
+
| `config` | `object` | Full config from `coffee.config.cjs` |
|
|
77
|
+
| `compiledFiles` | `string[]` | Paths to compiled `.js` and `.js.map` files |
|
|
78
|
+
| `stdout` | `string` | Compiler standard output |
|
|
79
|
+
| `stderr` | `string` | Compiler standard error |
|
|
80
|
+
|
|
81
|
+
### Using in coffee.config.cjs
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const myPlugin = require('your-plugin-name');
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
entry: 'src',
|
|
88
|
+
output: 'dist',
|
|
89
|
+
milkee: {
|
|
90
|
+
plugins: [
|
|
91
|
+
myPlugin({ customOption: 'value' }),
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Build & Test
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Build your plugin
|
|
101
|
+
npm run build
|
|
102
|
+
|
|
103
|
+
# Link for local testing
|
|
104
|
+
npm link
|
|
105
|
+
|
|
106
|
+
# In another project
|
|
107
|
+
npm link your-plugin-name
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Publishing
|
|
111
|
+
|
|
112
|
+
### Using GitHub Actions
|
|
113
|
+
|
|
114
|
+
The included workflow publishes to npm manually:
|
|
115
|
+
|
|
116
|
+
1. Add `NPM_TOKEN` secret to your repository
|
|
117
|
+
2. Go to **Actions** → **Manual Publish to npm**
|
|
118
|
+
3. Click **Run workflow**
|
|
119
|
+
|
|
120
|
+
### Manual
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm run build
|
|
124
|
+
npm publish --access public
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Best Practices
|
|
128
|
+
|
|
129
|
+
### Naming & Keywords
|
|
130
|
+
|
|
131
|
+
- Name: `milkee-plugin-xxx` or `@yourname/milkee-plugin-xxx`
|
|
132
|
+
- Keywords (auto-added): `milkee`, `coffeescript`, `coffee`, `ext`, `plugin`, `milkee-plugin`
|
|
133
|
+
|
|
134
|
+
### Error Handling
|
|
135
|
+
|
|
136
|
+
```coffee
|
|
137
|
+
main = (compilationResult) ->
|
|
138
|
+
try
|
|
139
|
+
# Your logic
|
|
140
|
+
catch error
|
|
141
|
+
c.error "Failed:", error.message
|
|
142
|
+
throw error
|
|
143
|
+
```
|
package/package.json
CHANGED
|
@@ -29,6 +29,8 @@ module.exports = {
|
|
|
29
29
|
// refresh: false,
|
|
30
30
|
// Before compiling, confirm "Do you want to Continue?"
|
|
31
31
|
// confirm: false,
|
|
32
|
+
// After compiling, copy non-coffee files from entry to output directory. (Only works when options.join is false)
|
|
33
|
+
// copy: false,
|
|
32
34
|
},
|
|
33
35
|
plugins: []
|
|
34
36
|
},
|