milkee 2.4.0 → 2.4.2
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 +57 -6
- package/docs/PLUGIN-ja.md +143 -0
- package/docs/PLUGIN.md +143 -0
- package/package.json +1 -1
- package/temp/plugin/_gitignore +1 -0
package/dist/commands/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
|
-
var CONFIG_FILE, CWD, PLUGIN_KEYWORDS, TEMPLATES, TEMPLATE_DIR, confirmContinue, consola, copyTemplate, ensureDir, execSync, fs, generateReadme, initPackageJson, path, plugin, updatePackageJson,
|
|
2
|
+
var CONFIG_FILE, CWD, DOCS, DOCS_DIR, PLUGIN_KEYWORDS, TEMPLATES, TEMPLATE_DIR, confirmContinue, consola, copyDocs, copyTemplate, ensureDir, execSync, fs, generateReadme, initPackageJson, path, plugin, updatePackageJson,
|
|
3
3
|
indexOf = [].indexOf;
|
|
4
4
|
|
|
5
5
|
fs = require('fs');
|
|
@@ -16,6 +16,8 @@ confirmContinue = require('../options/confirm');
|
|
|
16
16
|
|
|
17
17
|
TEMPLATE_DIR = path.join(__dirname, '..', '..', 'temp', 'plugin');
|
|
18
18
|
|
|
19
|
+
DOCS_DIR = path.join(__dirname, '..', '..', 'docs');
|
|
20
|
+
|
|
19
21
|
TEMPLATES = [
|
|
20
22
|
{
|
|
21
23
|
src: 'main.coffee',
|
|
@@ -43,6 +45,17 @@ TEMPLATES = [
|
|
|
43
45
|
}
|
|
44
46
|
];
|
|
45
47
|
|
|
48
|
+
DOCS = [
|
|
49
|
+
{
|
|
50
|
+
src: 'PLUGIN.md',
|
|
51
|
+
dest: 'docs/PLUGIN.md'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
src: 'PLUGIN-ja.md',
|
|
55
|
+
dest: 'docs/PLUGIN-ja.md'
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
|
|
46
59
|
// Create directory if not exists
|
|
47
60
|
ensureDir = function(filePath) {
|
|
48
61
|
var dir;
|
|
@@ -70,6 +83,22 @@ copyTemplate = function(src, dest) {
|
|
|
70
83
|
return true;
|
|
71
84
|
};
|
|
72
85
|
|
|
86
|
+
// Copy docs file
|
|
87
|
+
copyDocs = function(src, dest) {
|
|
88
|
+
var content, destPath, srcPath;
|
|
89
|
+
srcPath = path.join(DOCS_DIR, src);
|
|
90
|
+
destPath = path.join(CWD, dest);
|
|
91
|
+
if (!fs.existsSync(srcPath)) {
|
|
92
|
+
consola.error(`Docs file not found: ${srcPath}`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
ensureDir(destPath);
|
|
96
|
+
content = fs.readFileSync(srcPath, 'utf-8');
|
|
97
|
+
fs.writeFileSync(destPath, content);
|
|
98
|
+
consola.success(`Created \`${dest}\``);
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
|
|
73
102
|
PLUGIN_KEYWORDS = ['milkee', 'coffeescript', 'coffee', 'ext', 'plugin', 'milkee-plugin'];
|
|
74
103
|
|
|
75
104
|
// Update package.json
|
|
@@ -158,7 +187,7 @@ generateReadme = function() {
|
|
|
158
187
|
|
|
159
188
|
// Main plugin setup function
|
|
160
189
|
plugin = async function() {
|
|
161
|
-
var confirmed, destPath, error, i, j, len, len1, overwrite, pkgPath, readmePath, template;
|
|
190
|
+
var confirmed, destPath, doc, error, i, j, k, l, len, len1, len2, len3, overwrite, pkgPath, readmePath, template;
|
|
162
191
|
consola.box("Milkee Plugin Setup");
|
|
163
192
|
consola.info("This will set up your project as a Milkee plugin.");
|
|
164
193
|
consola.info("");
|
|
@@ -173,8 +202,13 @@ plugin = async function() {
|
|
|
173
202
|
template = TEMPLATES[i];
|
|
174
203
|
consola.info(` - ${template.dest}`);
|
|
175
204
|
}
|
|
176
|
-
consola.info(" 3.
|
|
177
|
-
|
|
205
|
+
consola.info(" 3. Copy docs:");
|
|
206
|
+
for (j = 0, len1 = DOCS.length; j < len1; j++) {
|
|
207
|
+
doc = DOCS[j];
|
|
208
|
+
consola.info(` - ${doc.dest}`);
|
|
209
|
+
}
|
|
210
|
+
consola.info(" 4. Update package.json (main, scripts, keywords)");
|
|
211
|
+
consola.info(" 5. Generate README.md");
|
|
178
212
|
consola.info("");
|
|
179
213
|
// Confirm before proceeding
|
|
180
214
|
confirmed = (await confirmContinue());
|
|
@@ -206,8 +240,8 @@ plugin = async function() {
|
|
|
206
240
|
consola.info("");
|
|
207
241
|
// Create template files
|
|
208
242
|
consola.start("Creating template files...");
|
|
209
|
-
for (
|
|
210
|
-
template = TEMPLATES[
|
|
243
|
+
for (k = 0, len2 = TEMPLATES.length; k < len2; k++) {
|
|
244
|
+
template = TEMPLATES[k];
|
|
211
245
|
destPath = path.join(CWD, template.dest);
|
|
212
246
|
if (fs.existsSync(destPath)) {
|
|
213
247
|
overwrite = (await consola.prompt(`${template.dest} already exists. Overwrite?`, {
|
|
@@ -221,6 +255,23 @@ plugin = async function() {
|
|
|
221
255
|
copyTemplate(template.src, template.dest);
|
|
222
256
|
}
|
|
223
257
|
consola.info("");
|
|
258
|
+
// Copy docs
|
|
259
|
+
consola.start("Copying docs...");
|
|
260
|
+
for (l = 0, len3 = DOCS.length; l < len3; l++) {
|
|
261
|
+
doc = DOCS[l];
|
|
262
|
+
destPath = path.join(CWD, doc.dest);
|
|
263
|
+
if (fs.existsSync(destPath)) {
|
|
264
|
+
overwrite = (await consola.prompt(`${doc.dest} already exists. Overwrite?`, {
|
|
265
|
+
type: "confirm"
|
|
266
|
+
}));
|
|
267
|
+
if (!overwrite) {
|
|
268
|
+
consola.info(`Skipped \`${doc.dest}\``);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
copyDocs(doc.src, doc.dest);
|
|
273
|
+
}
|
|
274
|
+
consola.info("");
|
|
224
275
|
// Update package.json
|
|
225
276
|
consola.start("Updating package.json...");
|
|
226
277
|
updatePackageJson();
|
|
@@ -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
package/temp/plugin/_gitignore
CHANGED