milkee 2.3.1 → 2.4.0-dev.0
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 +208 -0
- package/dist/main.js +9 -1
- package/docs/PLUGIN-ja.md +143 -0
- package/docs/PLUGIN.md +143 -0
- package/package.json +1 -1
- package/temp/plugin/main.coffee +25 -0
- package/temp/plugin/publish.yml +47 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CONFIG_FILE, CWD, PLUGIN_KEYWORDS, TEMPLATES, TEMPLATE_DIR, confirmContinue, consola, copyTemplate, ensureDir, execSync, fs, initPackageJson, path, plugin, updatePackageJson,
|
|
3
|
+
indexOf = [].indexOf;
|
|
4
|
+
|
|
5
|
+
fs = require('fs');
|
|
6
|
+
|
|
7
|
+
path = require('path');
|
|
8
|
+
|
|
9
|
+
({execSync} = require('child_process'));
|
|
10
|
+
|
|
11
|
+
consola = require('consola');
|
|
12
|
+
|
|
13
|
+
({CWD, CONFIG_FILE} = require('../constants'));
|
|
14
|
+
|
|
15
|
+
confirmContinue = require('../options/confirm');
|
|
16
|
+
|
|
17
|
+
TEMPLATE_DIR = path.join(__dirname, '..', '..', 'temp', 'plugin');
|
|
18
|
+
|
|
19
|
+
TEMPLATES = [
|
|
20
|
+
{
|
|
21
|
+
src: 'main.coffee',
|
|
22
|
+
dest: 'src/main.coffee'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
src: 'coffee.config.cjs',
|
|
26
|
+
dest: CONFIG_FILE
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
src: 'publish.yml',
|
|
30
|
+
dest: '.github/workflows/publish.yml'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
src: '.gitignore',
|
|
34
|
+
dest: '.gitignore'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
src: '.gitattributes',
|
|
38
|
+
dest: '.gitattributes'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
src: '.npmignore',
|
|
42
|
+
dest: '.npmignore'
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// Create directory if not exists
|
|
47
|
+
ensureDir = function(filePath) {
|
|
48
|
+
var dir;
|
|
49
|
+
dir = path.dirname(filePath);
|
|
50
|
+
if (!fs.existsSync(dir)) {
|
|
51
|
+
return fs.mkdirSync(dir, {
|
|
52
|
+
recursive: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Copy template file
|
|
58
|
+
copyTemplate = function(src, dest) {
|
|
59
|
+
var content, destPath, srcPath;
|
|
60
|
+
srcPath = path.join(TEMPLATE_DIR, src);
|
|
61
|
+
destPath = path.join(CWD, dest);
|
|
62
|
+
if (!fs.existsSync(srcPath)) {
|
|
63
|
+
consola.error(`Template file not found: ${srcPath}`);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
ensureDir(destPath);
|
|
67
|
+
content = fs.readFileSync(srcPath, 'utf-8');
|
|
68
|
+
fs.writeFileSync(destPath, content);
|
|
69
|
+
consola.success(`Created \`${dest}\``);
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
PLUGIN_KEYWORDS = ['milkee', 'coffeescript', 'coffee', 'ext', 'plugin', 'milkee-plugin'];
|
|
74
|
+
|
|
75
|
+
// Update package.json
|
|
76
|
+
updatePackageJson = function() {
|
|
77
|
+
var base, error, i, keyword, len, pkg, pkgPath;
|
|
78
|
+
pkgPath = path.join(CWD, 'package.json');
|
|
79
|
+
try {
|
|
80
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
81
|
+
// Update main
|
|
82
|
+
pkg.main = 'dist/main.js';
|
|
83
|
+
// Update scripts
|
|
84
|
+
if (pkg.scripts == null) {
|
|
85
|
+
pkg.scripts = {};
|
|
86
|
+
}
|
|
87
|
+
if ((base = pkg.scripts).test == null) {
|
|
88
|
+
base.test = 'echo "Error: no test specified" && exit 0';
|
|
89
|
+
}
|
|
90
|
+
pkg.scripts.build = 'milkee';
|
|
91
|
+
// Update keywords
|
|
92
|
+
if (pkg.keywords == null) {
|
|
93
|
+
pkg.keywords = [];
|
|
94
|
+
}
|
|
95
|
+
for (i = 0, len = PLUGIN_KEYWORDS.length; i < len; i++) {
|
|
96
|
+
keyword = PLUGIN_KEYWORDS[i];
|
|
97
|
+
if (indexOf.call(pkg.keywords, keyword) < 0) {
|
|
98
|
+
pkg.keywords.push(keyword);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
102
|
+
consola.success("Updated `package.json`");
|
|
103
|
+
return true;
|
|
104
|
+
} catch (error1) {
|
|
105
|
+
error = error1;
|
|
106
|
+
consola.error("Failed to update package.json:", error);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Initialize package.json if not exists
|
|
112
|
+
initPackageJson = function() {
|
|
113
|
+
var error, pkgPath;
|
|
114
|
+
pkgPath = path.join(CWD, 'package.json');
|
|
115
|
+
if (!fs.existsSync(pkgPath)) {
|
|
116
|
+
consola.start("Initializing package.json...");
|
|
117
|
+
try {
|
|
118
|
+
execSync('npm init -y', {
|
|
119
|
+
cwd: CWD,
|
|
120
|
+
stdio: 'inherit'
|
|
121
|
+
});
|
|
122
|
+
consola.success("Created `package.json`");
|
|
123
|
+
} catch (error1) {
|
|
124
|
+
error = error1;
|
|
125
|
+
consola.error("Failed to create package.json:", error);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Main plugin setup function
|
|
133
|
+
plugin = async function() {
|
|
134
|
+
var confirmed, destPath, error, i, j, len, len1, overwrite, pkgPath, template;
|
|
135
|
+
consola.box("Milkee Plugin Setup");
|
|
136
|
+
consola.info("This will set up your project as a Milkee plugin.");
|
|
137
|
+
consola.info("");
|
|
138
|
+
consola.info("The following actions will be performed:");
|
|
139
|
+
pkgPath = path.join(CWD, 'package.json');
|
|
140
|
+
if (!fs.existsSync(pkgPath)) {
|
|
141
|
+
consola.info(" 0. Initialize package.json (npm init -y)");
|
|
142
|
+
}
|
|
143
|
+
consola.info(" 1. Install dependencies (consola, coffeescript, milkee)");
|
|
144
|
+
consola.info(" 2. Create template files:");
|
|
145
|
+
for (i = 0, len = TEMPLATES.length; i < len; i++) {
|
|
146
|
+
template = TEMPLATES[i];
|
|
147
|
+
consola.info(` - ${template.dest}`);
|
|
148
|
+
}
|
|
149
|
+
consola.info(" 3. Update package.json (main, scripts, keywords)");
|
|
150
|
+
consola.info("");
|
|
151
|
+
// Confirm before proceeding
|
|
152
|
+
confirmed = (await confirmContinue());
|
|
153
|
+
if (!confirmed) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
consola.info("");
|
|
157
|
+
// Initialize package.json if not exists
|
|
158
|
+
if (!initPackageJson()) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
// Install dependencies
|
|
163
|
+
consola.start("Installing dependencies...");
|
|
164
|
+
execSync('npm install consola', {
|
|
165
|
+
cwd: CWD,
|
|
166
|
+
stdio: 'inherit'
|
|
167
|
+
});
|
|
168
|
+
execSync('npm install -D coffeescript milkee', {
|
|
169
|
+
cwd: CWD,
|
|
170
|
+
stdio: 'inherit'
|
|
171
|
+
});
|
|
172
|
+
consola.success("Dependencies installed!");
|
|
173
|
+
} catch (error1) {
|
|
174
|
+
error = error1;
|
|
175
|
+
consola.error("Failed to install dependencies:", error);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
consola.info("");
|
|
179
|
+
// Create template files
|
|
180
|
+
consola.start("Creating template files...");
|
|
181
|
+
for (j = 0, len1 = TEMPLATES.length; j < len1; j++) {
|
|
182
|
+
template = TEMPLATES[j];
|
|
183
|
+
destPath = path.join(CWD, template.dest);
|
|
184
|
+
if (fs.existsSync(destPath)) {
|
|
185
|
+
overwrite = (await consola.prompt(`${template.dest} already exists. Overwrite?`, {
|
|
186
|
+
type: "confirm"
|
|
187
|
+
}));
|
|
188
|
+
if (!overwrite) {
|
|
189
|
+
consola.info(`Skipped \`${template.dest}\``);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
copyTemplate(template.src, template.dest);
|
|
194
|
+
}
|
|
195
|
+
consola.info("");
|
|
196
|
+
// Update package.json
|
|
197
|
+
consola.start("Updating package.json...");
|
|
198
|
+
updatePackageJson();
|
|
199
|
+
consola.info("");
|
|
200
|
+
consola.success("Milkee plugin setup complete!");
|
|
201
|
+
consola.info("");
|
|
202
|
+
consola.info("Next steps:");
|
|
203
|
+
consola.info(" 1. Edit `src/main.coffee` to implement your plugin");
|
|
204
|
+
consola.info(" 2. Run `npm run build` to compile");
|
|
205
|
+
return consola.info(" 3. Test your plugin locally");
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
module.exports = plugin;
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
|
-
var argv, compile, hideBin, pkg, setup, yargs;
|
|
2
|
+
var argv, compile, hideBin, pkg, plugin, setup, yargs;
|
|
3
3
|
|
|
4
4
|
yargs = require('yargs');
|
|
5
5
|
|
|
@@ -11,6 +11,8 @@ setup = require('./commands/setup');
|
|
|
11
11
|
|
|
12
12
|
compile = require('./commands/compile');
|
|
13
13
|
|
|
14
|
+
plugin = require('./commands/plugin');
|
|
15
|
+
|
|
14
16
|
argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').option('setup', {
|
|
15
17
|
alias: 's',
|
|
16
18
|
describe: "Generate a default config file",
|
|
@@ -19,10 +21,16 @@ argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').o
|
|
|
19
21
|
alias: 'c',
|
|
20
22
|
describe: "Compile CoffeeScript (default)",
|
|
21
23
|
type: 'boolean'
|
|
24
|
+
}).option('plugin', {
|
|
25
|
+
alias: 'p',
|
|
26
|
+
describe: "Set up a new Milkee plugin project",
|
|
27
|
+
type: 'boolean'
|
|
22
28
|
}).version('version', pkg.version).alias('v', 'version').help('help').alias('h', 'help').argv;
|
|
23
29
|
|
|
24
30
|
if (argv.setup) {
|
|
25
31
|
setup();
|
|
32
|
+
} else if (argv.plugin) {
|
|
33
|
+
plugin();
|
|
26
34
|
} else {
|
|
27
35
|
compile();
|
|
28
36
|
}
|
|
@@ -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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
fs = require 'fs'
|
|
2
|
+
path = require 'path'
|
|
3
|
+
consola = require 'consola'
|
|
4
|
+
|
|
5
|
+
pkg = require '../package.json'
|
|
6
|
+
PREFIX = "[#{pkg.name}]"
|
|
7
|
+
|
|
8
|
+
# Create a custom logger with prefix
|
|
9
|
+
c = {}
|
|
10
|
+
for method in ['log', 'info', 'success', 'warn', 'error', 'debug', 'start', 'box']
|
|
11
|
+
do (method) ->
|
|
12
|
+
c[method] = (args...) ->
|
|
13
|
+
if typeof args[0] is 'string'
|
|
14
|
+
args[0] = "#{PREFIX} #{args[0]}"
|
|
15
|
+
consola[method] args...
|
|
16
|
+
|
|
17
|
+
# Main plugin function
|
|
18
|
+
main = (compilationResult) ->
|
|
19
|
+
{ config, compiledFiles, stdout, stderr } = compilationResult
|
|
20
|
+
|
|
21
|
+
c.info "Compiled #{compiledFiles.length} file(s)"
|
|
22
|
+
for file in compiledFiles
|
|
23
|
+
c.log " - #{file}"
|
|
24
|
+
|
|
25
|
+
module.exports = main
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Manual Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
publish-npm:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
permissions:
|
|
10
|
+
id-token: write
|
|
11
|
+
contents: write
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repository
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Setup Node.js
|
|
17
|
+
uses: actions/setup-node@v4
|
|
18
|
+
with:
|
|
19
|
+
node-version: "20.x"
|
|
20
|
+
registry-url: "https://registry.npmjs.org"
|
|
21
|
+
|
|
22
|
+
- name: Install, Build, and Test
|
|
23
|
+
run: |
|
|
24
|
+
npm ci
|
|
25
|
+
npm run build
|
|
26
|
+
npm test
|
|
27
|
+
|
|
28
|
+
- name: Commit dist directory (if changed)
|
|
29
|
+
run: |
|
|
30
|
+
git config --global user.name "github-actions[bot]"
|
|
31
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
32
|
+
git add dist
|
|
33
|
+
# The following command creates a commit ONLY if there are staged changes.
|
|
34
|
+
git diff --staged --quiet || git commit -m "chore: update build artifacts"
|
|
35
|
+
git push
|
|
36
|
+
|
|
37
|
+
- name: Publish to npm
|
|
38
|
+
run: npm publish --provenance --access public
|
|
39
|
+
env:
|
|
40
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
41
|
+
|
|
42
|
+
- name: Create and Push Git Tag
|
|
43
|
+
run: |
|
|
44
|
+
# This step now runs after the dist commit, ensuring the tag points to the correct commit.
|
|
45
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
46
|
+
git tag "v$VERSION"
|
|
47
|
+
git push origin "v$VERSION"
|