tooldock-cli 0.0.0-stage → 1.1.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/README.md CHANGED
@@ -1,3 +1,45 @@
1
- # Temporary Holding Version
1
+ # tooldock-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ToolDock 擴充開發工具,指令名稱是 `tooldock-ext`。這個套件沒有任何相依套件。
4
+
5
+ ```bash
6
+ npm install -D tooldock-cli
7
+ ```
8
+
9
+ 用 `npm create tooldock-extension` 建立的專案已經內建,不需要另外安裝。
10
+
11
+ | 指令 | 說明 |
12
+ |---|---|
13
+ | `tooldock-ext dev` | 以開發模式啟動 ToolDock 並載入目前的擴充。使用獨立的資料目錄,存檔後自動重新載入 |
14
+ | `tooldock-ext dev --inspect[=port]` | 後端開啟 Node inspector(預設 9229) |
15
+ | `tooldock-ext dev --inspect-brk[=port]` | 同上,並停在第一行等待除錯器 |
16
+ | `tooldock-ext dev --fresh` | 使用全新的暫存資料目錄 |
17
+ | `tooldock-ext validate` | 檢查 manifest、進入點、畫面檔、指令註冊、設定型別、相依是否已安裝 |
18
+ | `tooldock-ext pack [--out dir]` | 打包成 `.tbx`,只含 `dependencies` 的完整相依樹,並套用 `.tbxignore` |
19
+ | `tooldock-ext pack --sign [--key 檔案]` | 打包並以 Ed25519 簽章,同時產出 `.tbx.sha256` 與 `.tbx.sig`。私鑰依序取自 `--key`、環境變數 `TOOLDOCK_SIGNING_KEY` |
20
+ | `tooldock-ext pack --checksum` | 打包並只產出 `.tbx.sha256`(不簽章) |
21
+ | `tooldock-ext install` | 打包並安裝到本機的 ToolDock |
22
+ | `tooldock-ext keygen [--out dir] [--force]` | 產生簽章金鑰:私鑰存成 `tooldock-signing-key.pem`(權限 600,預設放在 `~/.tooldock/keys`),並印出公鑰字串 |
23
+ | `tooldock-ext verify <tbx> --public-key <字串>` | 驗證 `.tbx` 的 SHA-256(有 `.sha256` 檔時)與簽章(`.sig` 檔),失敗時結束代碼為 1。公鑰也可用環境變數 `TOOLDOCK_PUBLIC_KEY` 提供 |
24
+
25
+ **ToolDock 位置**
26
+
27
+ 依序尋找以下位置:
28
+ 1. `--app <路徑>`
29
+ 2. 環境變數 `TOOLDOCK_PATH`
30
+ 3. 預設安裝位置:
31
+ - macOS:`/Applications`、`~/Applications`
32
+ - Windows:`%LOCALAPPDATA%\Programs`、`%ProgramFiles%`
33
+ - Linux:`/opt/ToolDock`
34
+
35
+ 路徑可以指向 `.app`、執行檔,或平台原始碼目錄。
36
+
37
+ **發佈與簽章**
38
+
39
+ 在 GitHub Actions 自動發佈、金鑰管理與發佈檔格式,請參考 ToolDock repo 的 `docs/RELEASE.md`。簡要流程:
40
+
41
+ ```bash
42
+ npx tooldock-ext keygen # 產生金鑰,記下公鑰字串
43
+ TOOLDOCK_SIGNING_KEY="$(cat ~/.tooldock/keys/tooldock-signing-key.pem)" npx tooldock-ext pack --sign
44
+ npx tooldock-ext verify dist/<id>-<版本>.tbx --public-key <公鑰字串>
45
+ ```
@@ -0,0 +1,296 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const { spawn } = require('child_process');
7
+ const { validate } = require('../lib/manifest');
8
+ const { pack } = require('../lib/pack');
9
+ const { findApp } = require('../lib/find-app');
10
+ const sign = require('../lib/sign');
11
+
12
+ const tty = process.stdout.isTTY;
13
+ const color = (n) => (s) => (tty ? `\x1b[${n}m${s}\x1b[0m` : String(s));
14
+ const red = color(31);
15
+ const green = color(32);
16
+ const yellow = color(33);
17
+ const dim = color(2);
18
+ const bold = color(1);
19
+
20
+ const HELP = `
21
+ ${bold('tooldock-ext')} — ToolDock 擴充開發工具
22
+
23
+ 用法:tooldock-ext <指令> [選項]
24
+
25
+ 指令:
26
+ dev 以開發模式啟動 ToolDock 並載入目前的擴充(存檔即重載)
27
+ --inspect[=port] 後端開啟偵錯埠(預設 9229)
28
+ --inspect-brk[=port] 同上,並暫停在第一行等待除錯器
29
+ --fresh 使用全新的暫存資料目錄(乾淨狀態)
30
+ --app <路徑> 指定 ToolDock 執行檔、.app 或平台原始碼目錄
31
+ validate 檢查 manifest、檔案與相依套件
32
+ pack 打包成 .tbx(只含正式相依)
33
+ --out <資料夾> 輸出目錄(預設 dist)
34
+ --sign 簽章,同時產出 .tbx.sha256 與 .tbx.sig
35
+ --key <檔案> 私鑰檔(未指定時讀環境變數 TOOLDOCK_SIGNING_KEY)
36
+ --checksum 只產出 .tbx.sha256(不簽章)
37
+ keygen 產生 Ed25519 簽章金鑰
38
+ --out <資料夾> 私鑰存放位置(預設 ~/.tooldock/keys)
39
+ --force 覆寫已存在的金鑰
40
+ verify 驗證 .tbx 的 SHA-256 與簽章
41
+ tooldock-ext verify <檔案.tbx> --public-key <公鑰字串>
42
+ (公鑰也可用環境變數 TOOLDOCK_PUBLIC_KEY 提供)
43
+ install 打包並安裝到本機的 ToolDock(平台執行中時會轉交給執行中的視窗)
44
+ --app <路徑>
45
+ help 顯示說明
46
+
47
+ 環境變數:
48
+ TOOLDOCK_PATH ToolDock 位置
49
+ TOOLDOCK_SIGNING_KEY pack --sign 使用的私鑰(PEM 內容)
50
+ TOOLDOCK_PUBLIC_KEY verify 使用的公鑰字串
51
+ `;
52
+
53
+ function parse(argv) {
54
+ const [cmd = 'help', ...rest] = argv;
55
+ const opts = { _: [] };
56
+ for (let i = 0; i < rest.length; i++) {
57
+ const m = rest[i].match(/^--([a-z0-9-]+)(?:=(.*))?$/);
58
+ if (!m) { opts._.push(rest[i]); continue; }
59
+ const [, k, v] = m;
60
+ if (v !== undefined) opts[k] = v;
61
+ else if (['app', 'out', 'key', 'public-key', 'sig', 'sha256'].includes(k) && rest[i + 1] && !rest[i + 1].startsWith('--')) opts[k] = rest[++i];
62
+ else opts[k] = true;
63
+ }
64
+ return { cmd, opts };
65
+ }
66
+
67
+ function report(result) {
68
+ for (const w of result.warnings) console.log(`${yellow('⚠')} ${w}`);
69
+ for (const e of result.errors) console.log(`${red('✘')} ${e}`);
70
+ }
71
+
72
+ function runValidate(root, { quiet } = {}) {
73
+ const r = validate(root);
74
+ report(r);
75
+ if (r.errors.length) {
76
+ console.log(red(`\n驗證失敗:${r.errors.length} 個錯誤`));
77
+ process.exit(1);
78
+ }
79
+ if (!quiet) console.log(green(`✔ ${r.id}@${r.pkg.version} 驗證通過${r.warnings.length ? `(${r.warnings.length} 個警告)` : ''}`));
80
+ return r;
81
+ }
82
+
83
+ /** 平台支援 --extension-dev-path 的最低版本 */
84
+ const MIN_DEV_PLATFORM = '1.1.0';
85
+
86
+ function cmpVer(a, b) {
87
+ const x = String(a).split('.').map(Number);
88
+ const y = String(b).split('.').map(Number);
89
+ for (let i = 0; i < 3; i++) if ((x[i] || 0) !== (y[i] || 0)) return (x[i] || 0) - (y[i] || 0);
90
+ return 0;
91
+ }
92
+
93
+ /**
94
+ * 啟動平台並轉送輸出;若平台沒有印出「以開發模式載入 <id>」,代表平台不支援或沒有載入擴充,給出明確提示。
95
+ * (例如舊版平台會忽略 --extension-dev-path,或把啟動轉交給已在執行的舊版視窗後直接結束)
96
+ */
97
+ function runDev(command, args, id) {
98
+ return new Promise((resolve) => {
99
+ const child = spawn(command, args, { stdio: ['inherit', 'pipe', 'pipe'] });
100
+ const marker = `以開發模式載入 ${id}`;
101
+ let loaded = false;
102
+ let tail = '';
103
+ const watch = (stream, out) => stream.on('data', (d) => {
104
+ out.write(d);
105
+ if (!loaded) {
106
+ tail = (tail + d).slice(-4000);
107
+ if (tail.includes(marker)) loaded = true;
108
+ }
109
+ });
110
+ watch(child.stdout, process.stdout);
111
+ watch(child.stderr, process.stderr);
112
+ const hint = () => console.log(yellow(`
113
+ ⚠ ToolDock 沒有以開發模式載入「${id}」。常見原因:
114
+ 1. 安裝的 ToolDock 版本太舊(需要 ${MIN_DEV_PLATFORM} 以上),請更新後再試
115
+ 2. --app / TOOLDOCK_PATH 指向了別的程式
116
+ `));
117
+ const timer = setTimeout(() => { if (!loaded) hint(); }, 20000);
118
+ const forward = (sig) => () => child.kill(sig);
119
+ process.on('SIGINT', forward('SIGINT'));
120
+ process.on('SIGTERM', forward('SIGTERM'));
121
+ child.on('exit', (code) => {
122
+ clearTimeout(timer);
123
+ if (!loaded) hint();
124
+ resolve(code ?? 0);
125
+ });
126
+ child.on('error', (err) => { clearTimeout(timer); console.error(red(err.message)); resolve(1); });
127
+ });
128
+ }
129
+
130
+ function run(command, args) {
131
+ return new Promise((resolve) => {
132
+ const child = spawn(command, args, { stdio: 'inherit' });
133
+ const forward = (sig) => () => child.kill(sig);
134
+ process.on('SIGINT', forward('SIGINT'));
135
+ process.on('SIGTERM', forward('SIGTERM'));
136
+ child.on('exit', (code) => resolve(code ?? 0));
137
+ child.on('error', (err) => { console.error(red(err.message)); resolve(1); });
138
+ });
139
+ }
140
+
141
+ async function cmdDev(root, opts) {
142
+ const r = runValidate(root, { quiet: true });
143
+ const app = findApp(opts.app);
144
+ if (app.version && cmpVer(app.version, MIN_DEV_PLATFORM) < 0) {
145
+ throw new Error(`${app.label} 的版本是 ${app.version},不支援擴充開發模式;請更新 ToolDock 到 ${MIN_DEV_PLATFORM} 以上`);
146
+ }
147
+ const args = [...app.baseArgs, `--extension-dev-path=${root}`];
148
+ const inspect = opts['inspect-brk'] || opts.inspect;
149
+ // --inspect 不帶值時為 true,使用預設 9229
150
+ const port = typeof inspect === 'string' && Number(inspect) >= 1024 ? Number(inspect) : 9229;
151
+ if (inspect) {
152
+ args.push(`--${opts['inspect-brk'] ? 'inspect-brk' : 'inspect'}-extensions=${port}`);
153
+ }
154
+ if (opts.fresh) args.push(`--user-data-dir=${fs.mkdtempSync(path.join(os.tmpdir(), 'tooldock-dev-'))}`);
155
+ console.log(`${bold('ToolDock 擴充開發模式')}
156
+ 擴充 ${r.manifest.displayName || r.id} ${dim(`(${r.id}@${r.pkg.version})`)}
157
+ 平台 ${app.label}${app.version ? dim(` v${app.version}`) : ''}
158
+ 重新載入 存檔後自動重新載入後端與畫面${inspect ? `
159
+ 偵錯 後端 inspector 127.0.0.1:${port}${opts['inspect-brk'] ? '(暫停中,請附加除錯器)' : ''}
160
+ VS Code:執行「附加到擴充後端」,或在 Chrome 開啟 chrome://inspect` : ''}
161
+ 畫面偵錯 在分頁上按右鍵 →「檢查此畫面」
162
+ ${dim('按 Ctrl+C 結束')}
163
+ `);
164
+ process.exitCode = await runDev(app.command, args, r.id);
165
+ }
166
+
167
+ const shownPath = (file) => {
168
+ const rel = path.relative(process.cwd(), file);
169
+ return rel.startsWith('..') || path.isAbsolute(rel) ? file : rel;
170
+ };
171
+
172
+ /** 私鑰來源:--key <檔案> 優先,其次環境變數 TOOLDOCK_SIGNING_KEY */
173
+ function resolveSigningKey(opts) {
174
+ if (typeof opts.key === 'string') {
175
+ const file = path.resolve(opts.key);
176
+ if (!fs.existsSync(file)) throw new Error(`找不到私鑰檔:${file}`);
177
+ return sign.loadPrivateKey(fs.readFileSync(file, 'utf8'), `私鑰檔 ${file}`);
178
+ }
179
+ if (opts.key === true) throw new Error('--key 需要指定私鑰檔路徑');
180
+ if (process.env.TOOLDOCK_SIGNING_KEY && process.env.TOOLDOCK_SIGNING_KEY.trim()) {
181
+ return sign.loadPrivateKey(process.env.TOOLDOCK_SIGNING_KEY, '環境變數 TOOLDOCK_SIGNING_KEY');
182
+ }
183
+ throw new Error('pack --sign 需要私鑰:請用 --key <檔案> 指定,或設定環境變數 TOOLDOCK_SIGNING_KEY(可用 tooldock-ext keygen 產生)');
184
+ }
185
+
186
+ function cmdPack(root, opts) {
187
+ const r = runValidate(root, { quiet: true });
188
+ // 先讀私鑰,避免打包完才發現金鑰有問題
189
+ const key = opts.sign ? resolveSigningKey(opts) : null;
190
+ const outDir = path.resolve(root, typeof opts.out === 'string' ? opts.out : 'dist');
191
+ const res = pack(root, { outDir, id: r.id, version: r.pkg.version });
192
+ console.log(green(`✔ 已打包 ${shownPath(res.file)}`) + dim(`(${res.count} 個檔案,${(res.size / 1024).toFixed(1)} KB)`));
193
+ if (key) {
194
+ const s = sign.signFile(res.file, key);
195
+ console.log(green(`✔ 已產生 ${shownPath(s.sha256File)}`) + dim(`(${s.sha256})`));
196
+ console.log(green(`✔ 已簽章 ${shownPath(s.sigFile)}`));
197
+ console.log(dim(` 公鑰 ${s.publicKey}`));
198
+ Object.assign(res, s);
199
+ } else if (opts.checksum) {
200
+ const c = sign.writeChecksum(res.file);
201
+ console.log(green(`✔ 已產生 ${shownPath(c.file)}`) + dim(`(${c.hex})`));
202
+ res.sha256File = c.file;
203
+ res.sha256 = c.hex;
204
+ }
205
+ return res;
206
+ }
207
+
208
+ function cmdKeygen(opts) {
209
+ const dir = path.resolve(typeof opts.out === 'string' ? opts.out : path.join(os.homedir(), '.tooldock', 'keys'));
210
+ const keyFile = path.join(dir, sign.KEY_FILE);
211
+ const pubFile = path.join(dir, sign.PUB_FILE);
212
+ if (fs.existsSync(keyFile) && !opts.force) {
213
+ throw new Error(`私鑰已存在:${keyFile}\n 換金鑰後,商店索引裡的公鑰也要一起更新。確定要覆寫請加上 --force`);
214
+ }
215
+ const { privateKeyPem, publicKey } = sign.generateKeyPair();
216
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
217
+ fs.writeFileSync(keyFile, privateKeyPem, { mode: 0o600 });
218
+ fs.chmodSync(keyFile, 0o600); // 覆寫既有檔案時 mode 不會生效
219
+ fs.writeFileSync(pubFile, `${publicKey}\n`);
220
+ console.log(`${green('✔ 已產生 Ed25519 簽章金鑰')}
221
+ 私鑰 ${keyFile} ${dim('(權限 600,請勿提交到 git 或分享給他人)')}
222
+ 公鑰 ${pubFile}
223
+
224
+ ${bold('公鑰字串')}
225
+ ${publicKey}
226
+
227
+ ${bold('接下來')}
228
+ 1. 把私鑰加入擴充 repo 的 GitHub secret ${bold('TOOLDOCK_SIGNING_KEY')}:
229
+ gh secret set TOOLDOCK_SIGNING_KEY < "${keyFile}"
230
+ (或到 GitHub repo → Settings → Secrets and variables → Actions 貼上私鑰檔的完整內容)
231
+ 2. 把上面的公鑰字串提交到 ToolDock 商店索引,商店會用它驗證你發佈的 .tbx。
232
+ 3. 選用:把公鑰設為 repo variable ${bold('TOOLDOCK_PUBLIC_KEY')},CI 會在發佈前用它再驗證一次:
233
+ gh variable set TOOLDOCK_PUBLIC_KEY --body "${publicKey}"
234
+ ${dim('請另外備份私鑰;遺失後只能產生新金鑰並更新商店索引裡的公鑰。')}
235
+ `);
236
+ }
237
+
238
+ function cmdVerify(opts) {
239
+ const target = opts._[0];
240
+ if (!target) throw new Error('用法:tooldock-ext verify <檔案.tbx> --public-key <公鑰字串>');
241
+ const file = path.resolve(target);
242
+ if (!fs.existsSync(file)) throw new Error(`找不到檔案:${file}`);
243
+ const publicKey = typeof opts['public-key'] === 'string' ? opts['public-key'] : process.env.TOOLDOCK_PUBLIC_KEY;
244
+ if (!publicKey || !publicKey.trim()) throw new Error('缺少公鑰:請用 --public-key <公鑰字串> 指定,或設定環境變數 TOOLDOCK_PUBLIC_KEY');
245
+ const res = sign.verifyFile(file, {
246
+ publicKey,
247
+ sigPath: typeof opts.sig === 'string' ? path.resolve(opts.sig) : undefined,
248
+ sha256Path: typeof opts.sha256 === 'string' ? path.resolve(opts.sha256) : undefined,
249
+ });
250
+ console.log(bold(shownPath(file)));
251
+ for (const c of res.checks) {
252
+ const mark = c.skipped ? yellow('-') : c.ok ? green('✔') : red('✘');
253
+ console.log(` ${mark} ${c.name} ${dim(c.detail)}`);
254
+ }
255
+ if (!res.ok) {
256
+ const missing = res.checks.some((c) => c.missing);
257
+ console.log(red(missing
258
+ ? '\n驗證失敗:缺少發佈檔(未簽章的 .tbx 不會被商店收錄)'
259
+ : '\n驗證失敗:檔案可能被竄改,或公鑰與簽章用的私鑰不是同一組'));
260
+ process.exitCode = 1;
261
+ } else {
262
+ console.log(green('\n✔ 驗證通過'));
263
+ }
264
+ }
265
+
266
+ async function cmdInstall(root, opts) {
267
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tooldock-pack-'));
268
+ const res = cmdPack(root, { out: tmp });
269
+ const app = findApp(opts.app);
270
+ console.log(dim(`安裝到 ${app.label}…`));
271
+ process.exitCode = await run(app.command, [...app.baseArgs, `--install-extension=${res.file}`]);
272
+ fs.rmSync(tmp, { recursive: true, force: true });
273
+ }
274
+
275
+ (async () => {
276
+ const { cmd, opts } = parse(process.argv.slice(2));
277
+ const root = process.cwd();
278
+ try {
279
+ switch (cmd) {
280
+ case 'dev': await cmdDev(root, opts); break;
281
+ case 'validate': runValidate(root); break;
282
+ case 'pack': cmdPack(root, opts); break;
283
+ case 'install': await cmdInstall(root, opts); break;
284
+ case 'keygen': cmdKeygen(opts); break;
285
+ case 'verify': cmdVerify(opts); break;
286
+ case 'help': case '--help': case '-h': console.log(HELP); break;
287
+ default:
288
+ console.log(red(`未知的指令:${cmd}`));
289
+ console.log(HELP);
290
+ process.exitCode = 1;
291
+ }
292
+ } catch (err) {
293
+ console.error(red(`✘ ${err.message}`));
294
+ process.exitCode = 1;
295
+ }
296
+ })();
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+ /** 尋找本機安裝的 ToolDock(或平台原始碼目錄,供平台開發者使用) */
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+
7
+ function candidates() {
8
+ const home = os.homedir();
9
+ switch (process.platform) {
10
+ case 'darwin':
11
+ return [
12
+ '/Applications/ToolDock.app',
13
+ path.join(home, 'Applications', 'ToolDock.app'),
14
+ ];
15
+ case 'win32':
16
+ return [
17
+ path.join(process.env.LOCALAPPDATA || '', 'Programs', 'ToolDock', 'ToolDock.exe'),
18
+ path.join(process.env.ProgramFiles || 'C:\\Program Files', 'ToolDock', 'ToolDock.exe'),
19
+ ];
20
+ default:
21
+ return ['/opt/ToolDock/tooldock', '/usr/bin/tooldock', path.join(home, '.local', 'bin', 'tooldock')];
22
+ }
23
+ }
24
+
25
+ /**
26
+ * 回傳 { command, baseArgs, label }
27
+ * - .app 套件 → Contents/MacOS/ToolDock
28
+ * - 執行檔 → 直接執行
29
+ * - 平台原始碼目錄(package.json name = tooldock)→ 用該目錄的 electron 執行
30
+ */
31
+ function resolveTarget(p) {
32
+ if (!p || !fs.existsSync(p)) return null;
33
+ const st = fs.statSync(p);
34
+ if (st.isDirectory() && p.endsWith('.app')) {
35
+ const exe = path.join(p, 'Contents', 'MacOS', 'ToolDock');
36
+ if (!fs.existsSync(exe)) return null;
37
+ let version = null;
38
+ try {
39
+ const plist = fs.readFileSync(path.join(p, 'Contents', 'Info.plist'), 'utf8');
40
+ const m = plist.match(/<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/);
41
+ if (m) version = m[1];
42
+ } catch { /* 無法讀取版本 */ }
43
+ return { command: exe, baseArgs: [], label: p, version };
44
+ }
45
+ if (st.isDirectory()) {
46
+ const pkgFile = path.join(p, 'package.json');
47
+ if (!fs.existsSync(pkgFile)) return null;
48
+ const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
49
+ if (pkg.name !== 'tooldock') return null;
50
+ let electron;
51
+ try {
52
+ electron = require(require.resolve('electron', { paths: [p] })); // electron 套件匯出執行檔路徑
53
+ } catch {
54
+ throw new Error(`${p} 是平台原始碼,但尚未安裝相依套件(請先在該目錄執行 npm install)`);
55
+ }
56
+ return { command: electron, baseArgs: [p], label: `${p}(原始碼)`, version: pkg.version };
57
+ }
58
+ return { command: p, baseArgs: [], label: p, version: null };
59
+ }
60
+
61
+ function findApp(explicit) {
62
+ const tried = [];
63
+ for (const p of [explicit, process.env.TOOLDOCK_PATH, ...candidates()]) {
64
+ if (!p) continue;
65
+ tried.push(p);
66
+ const t = resolveTarget(path.resolve(p));
67
+ if (t) return t;
68
+ }
69
+ const err = new Error(
70
+ '找不到 ToolDock。請先安裝 ToolDock,或用 --app <路徑> / 環境變數 TOOLDOCK_PATH 指定執行檔(也可指向平台原始碼目錄)。\n'
71
+ + `已尋找:\n ${tried.join('\n ')}`,
72
+ );
73
+ err.code = 'APP_NOT_FOUND';
74
+ throw err;
75
+ }
76
+
77
+ module.exports = { findApp };
@@ -0,0 +1,136 @@
1
+ 'use strict';
2
+ /** 擴充 manifest 檢查(與平台載入規則一致,並多做檔案存在、相依安裝等開發期檢查) */
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const ID_RE = /^[a-z0-9][a-z0-9.-]{0,62}$/;
7
+ const SEMVER_RE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
8
+ const RANGE_RE = /^(\*|(\^|~|>=)?\d+\.\d+\.\d+)$/;
9
+ const EVENT_RE = /^(\*|onStartup|onView:.+|onCommand:.+|onPhase:.+)$/;
10
+
11
+ function readPkg(dir) {
12
+ const file = path.join(dir, 'package.json');
13
+ if (!fs.existsSync(file)) throw new Error(`找不到 ${file},請在擴充專案根目錄執行`);
14
+ try {
15
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
16
+ } catch (err) {
17
+ throw new Error(`package.json 格式錯誤:${err.message}`);
18
+ }
19
+ }
20
+
21
+ function resolveModule(dir, rel) {
22
+ const base = path.resolve(dir, rel);
23
+ for (const c of [base, `${base}.js`, `${base}.cjs`, path.join(base, 'index.js')]) {
24
+ if (fs.existsSync(c) && fs.statSync(c).isFile()) return c;
25
+ }
26
+ return null;
27
+ }
28
+
29
+ /** 從擴充根目錄尋找套件(與 Node 解析方式相同,往上找但不超出根目錄) */
30
+ function findPackage(root, fromDir, name) {
31
+ let dir = fromDir;
32
+ for (;;) {
33
+ const cand = path.join(dir, 'node_modules', name);
34
+ if (fs.existsSync(path.join(cand, 'package.json'))) return cand;
35
+ if (path.resolve(dir) === path.resolve(root)) return null;
36
+ const parent = path.dirname(dir);
37
+ if (parent === dir) return null;
38
+ dir = parent;
39
+ }
40
+ }
41
+
42
+ /** 正式相依(dependencies + optionalDependencies)的完整閉包;devDependencies 不會被打包 */
43
+ function productionPackages(root) {
44
+ const pkg = readPkg(root);
45
+ const keep = new Set();
46
+ const missing = [];
47
+ const visit = (fromDir, deps, optional) => {
48
+ for (const name of Object.keys(deps || {})) {
49
+ const dir = findPackage(root, fromDir, name);
50
+ if (!dir) { if (!optional) missing.push(name); continue; }
51
+ if (keep.has(dir)) continue;
52
+ keep.add(dir);
53
+ let p = {};
54
+ try { p = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')); } catch { /* ignore */ }
55
+ visit(dir, p.dependencies, false);
56
+ visit(dir, p.optionalDependencies, true);
57
+ }
58
+ };
59
+ visit(root, pkg.dependencies, false);
60
+ visit(root, pkg.optionalDependencies, true);
61
+ return { keep, missing };
62
+ }
63
+
64
+ function validate(dir) {
65
+ const errors = [];
66
+ const warnings = [];
67
+ const pkg = readPkg(dir);
68
+ const td = pkg.tooldock;
69
+ if (!td || typeof td !== 'object') {
70
+ return { errors: ['package.json 缺少 "tooldock" 欄位(擴充 manifest)'], warnings, pkg };
71
+ }
72
+ const id = String(td.id || pkg.name || '').toLowerCase();
73
+ if (!ID_RE.test(id)) errors.push(`id "${id}" 不合法:只能使用小寫英數、點與連字號,且以英數開頭`);
74
+ if (!SEMVER_RE.test(pkg.version || '')) errors.push(`version "${pkg.version}" 不是有效的 x.y.z 版本號`);
75
+ if (!td.displayName) warnings.push('建議設定 tooldock.displayName(顯示在工作台的名稱)');
76
+ if (!td.engine) warnings.push('建議設定 tooldock.engine(例如 "^1.0.0"),避免安裝到不相容的平台版本');
77
+ else if (!RANGE_RE.test(td.engine)) errors.push(`engine "${td.engine}" 格式不支援(可用 *、1.2.3、^1.2.3、~1.2.3、>=1.2.3)`);
78
+
79
+ const main = td.main || pkg.main;
80
+ let mainSrc = '';
81
+ if (main) {
82
+ const file = resolveModule(dir, main);
83
+ if (!file) errors.push(`找不到後端進入點 main: "${main}"`);
84
+ else mainSrc = fs.readFileSync(file, 'utf8');
85
+ }
86
+
87
+ const c = td.contributes || {};
88
+ const seen = new Set();
89
+ for (const v of c.views || []) {
90
+ if (!v.id) { errors.push('views[] 缺少 id'); continue; }
91
+ if (seen.has(v.id)) errors.push(`畫面 id 重複:${v.id}`);
92
+ seen.add(v.id);
93
+ if (!v.title) warnings.push(`畫面 ${v.id} 缺少 title`);
94
+ const entry = v.entry || 'ui/index.html';
95
+ const html = path.join(dir, entry);
96
+ if (!fs.existsSync(html)) errors.push(`畫面 ${v.id} 的 entry 不存在:${entry}`);
97
+ else if (!/tooldock:\/\/sdk\/ui-sdk\.js/.test(fs.readFileSync(html, 'utf8'))) {
98
+ warnings.push(`${entry} 沒有載入 tooldock://sdk/ui-sdk.js,將無法使用 window.tooldock`);
99
+ }
100
+ if (v.icon && /\.(svg|png|jpe?g)$/i.test(v.icon) && !fs.existsSync(path.join(dir, v.icon))) errors.push(`畫面 ${v.id} 的 icon 不存在:${v.icon}`);
101
+ }
102
+ const cmdSeen = new Set();
103
+ for (const cmd of c.commands || []) {
104
+ if (!cmd.id) { errors.push('commands[] 缺少 id'); continue; }
105
+ if (cmdSeen.has(cmd.id)) errors.push(`指令 id 重複:${cmd.id}`);
106
+ cmdSeen.add(cmd.id);
107
+ if (!cmd.title) warnings.push(`指令 ${cmd.id} 缺少 title(命令面板顯示用)`);
108
+ if (main && mainSrc && !mainSrc.includes(cmd.id)) warnings.push(`後端程式碼中找不到指令 "${cmd.id}" 的註冊(ctx.commands.register)`);
109
+ }
110
+ for (const ev of td.activationEvents || []) {
111
+ if (!EVENT_RE.test(ev)) errors.push(`不認得的啟用事件 "${ev}"(可用 onStartup、onView:、onCommand:、onPhase:)`);
112
+ }
113
+ if ((td.activationEvents || []).some((e) => e === 'onStartup' || e === '*')) {
114
+ warnings.push('使用 onStartup 會讓擴充隨平台常駐;若非背景服務,建議改用延遲載入');
115
+ }
116
+ for (const [key, def] of Object.entries(c.configuration || {})) {
117
+ if (!['string', 'number', 'boolean'].includes(def.type)) errors.push(`設定 ${key} 的 type 必須是 string / number / boolean`);
118
+ else if (def.default !== undefined && typeof def.default !== def.type) errors.push(`設定 ${key} 的 default 型別與 type 不符`);
119
+ if (def.enum && !Array.isArray(def.enum)) errors.push(`設定 ${key} 的 enum 必須是陣列`);
120
+ }
121
+ for (const [phase, fn] of Object.entries(c.lifecycle || {})) {
122
+ if (!main) errors.push(`contributes.lifecycle 需要後端 main(${phase} → ${fn})`);
123
+ else if (mainSrc && !new RegExp(`\\b${fn}\\b`).test(mainSrc)) warnings.push(`後端程式碼中找不到生命週期函式 ${fn}()(${phase})`);
124
+ }
125
+ if (!main && !(c.views || []).length) warnings.push('既沒有後端 main 也沒有畫面,這個擴充不會做任何事');
126
+
127
+ const { missing } = productionPackages(dir);
128
+ for (const name of missing) errors.push(`相依套件未安裝:${name}(請執行 npm install)`);
129
+ if (Object.keys(pkg.devDependencies || {}).some((d) => (pkg.dependencies || {})[d])) {
130
+ warnings.push('有套件同時列在 dependencies 與 devDependencies');
131
+ }
132
+
133
+ return { errors, warnings, pkg, id, manifest: td };
134
+ }
135
+
136
+ module.exports = { validate, productionPackages, readPkg };
package/lib/pack.js ADDED
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { writeZip } = require('./zip');
5
+ const { productionPackages } = require('./manifest');
6
+
7
+ /** 一律排除(再加上專案的 .tbxignore) */
8
+ const DEFAULT_IGNORE = [
9
+ '.git', '.github', '.vscode', '.idea', '.DS_Store', 'Thumbs.db',
10
+ '*.tbx', '*.log', '.tbxignore', '.gitignore', 'dist/', 'node_modules/.bin', 'node_modules/.cache',
11
+ 'node_modules/.package-lock.json', 'package-lock.json', '*.map',
12
+ // 簽章私鑰(tooldock-ext keygen 的預設檔名)絕不打包
13
+ 'tooldock-signing-key*.pem',
14
+ ];
15
+
16
+ /** 簡易 gitignore 風格比對:不含 / 的樣式比對任何層級的名稱;以 / 結尾只比對資料夾 */
17
+ function compile(pattern) {
18
+ let p = pattern.trim();
19
+ if (!p || p.startsWith('#')) return null;
20
+ const dirOnly = p.endsWith('/');
21
+ if (dirOnly) p = p.slice(0, -1);
22
+ const anchored = p.startsWith('/') || p.includes('/');
23
+ p = p.replace(/^\//, '');
24
+ const re = p
25
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
26
+ .replace(/\*\*\//g, '\u0000')
27
+ .replace(/\*\*/g, '\u0001')
28
+ .replace(/\*/g, '[^/]*')
29
+ .replace(/\?/g, '[^/]')
30
+ .replace(/\u0000/g, '(?:.*/)?')
31
+ .replace(/\u0001/g, '.*');
32
+ const regex = new RegExp(anchored ? `^${re}$` : `(^|/)${re}$`);
33
+ return { regex, dirOnly };
34
+ }
35
+
36
+ function loadIgnore(root) {
37
+ const extra = fs.existsSync(path.join(root, '.tbxignore'))
38
+ ? fs.readFileSync(path.join(root, '.tbxignore'), 'utf8').split(/\r?\n/)
39
+ : [];
40
+ return [...DEFAULT_IGNORE, ...extra].map(compile).filter(Boolean);
41
+ }
42
+
43
+ /** node_modules 中檔案所屬的套件根目錄(處理巢狀與 @scope) */
44
+ function packageRootOf(rel) {
45
+ const parts = rel.split('/');
46
+ let idx = -1;
47
+ for (let i = 0; i < parts.length; i++) if (parts[i] === 'node_modules') idx = i;
48
+ if (idx < 0 || idx + 1 >= parts.length) return null;
49
+ const take = parts[idx + 1].startsWith('@') ? 2 : 1;
50
+ return parts.slice(0, idx + 1 + take).join('/');
51
+ }
52
+
53
+ function collect(root) {
54
+ const rules = loadIgnore(root);
55
+ const { keep, missing } = productionPackages(root);
56
+ if (missing.length) throw new Error(`相依套件未安裝:${missing.join(', ')}(請先執行 npm install)`);
57
+ const keepRel = new Set([...keep].map((d) => path.relative(root, d).split(path.sep).join('/')));
58
+ const ignored = (rel, isDir) => rules.some((r) => (!r.dirOnly || isDir) && r.regex.test(rel));
59
+
60
+ const files = [];
61
+ const walk = (dir) => {
62
+ for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
63
+ const abs = path.join(dir, ent.name);
64
+ const rel = path.relative(root, abs).split(path.sep).join('/');
65
+ const isDir = ent.isDirectory();
66
+ if (ignored(rel, isDir)) continue;
67
+ // 只打包正式相依:devDependencies(例如 tooldock-cli、tooldock-types)不會進入套件
68
+ if (rel.split('/').includes('node_modules')) {
69
+ const isContainer = isDir && (ent.name === 'node_modules' || (ent.name.startsWith('@') && path.basename(dir) === 'node_modules'));
70
+ if (!isContainer && !keepRel.has(packageRootOf(isDir ? `${rel}/_` : rel))) continue;
71
+ }
72
+ if (ent.isSymbolicLink()) {
73
+ const real = fs.statSync(abs);
74
+ if (real.isDirectory()) walk(abs); else files.push({ name: rel, file: abs });
75
+ } else if (isDir) walk(abs);
76
+ else if (ent.isFile()) files.push({ name: rel, file: abs });
77
+ }
78
+ };
79
+ walk(root);
80
+ return files;
81
+ }
82
+
83
+ function pack(root, { outDir, id, version }) {
84
+ const files = collect(root);
85
+ fs.mkdirSync(outDir, { recursive: true });
86
+ const out = path.join(outDir, `${id}-${version}.tbx`);
87
+ // 套件內以擴充 id 為最上層資料夾,平台安裝時會自動辨識
88
+ writeZip(out, files.map((f) => ({ name: `${id}/${f.name}`, file: f.file })));
89
+ return { file: out, count: files.length, size: fs.statSync(out).size };
90
+ }
91
+
92
+ module.exports = { pack, collect };
package/lib/sign.js ADDED
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+ /**
3
+ * 發佈檔簽章(Ed25519,只用 Node 內建 crypto)
4
+ *
5
+ * 約定(商店依此驗證,請勿更改):
6
+ * 私鑰 PKCS8 PEM
7
+ * 公鑰 SPKI DER 的 base64 字串
8
+ * <tbx>.sha256 .tbx 的小寫 hex SHA-256,只有這一行,結尾不加換行
9
+ * <tbx>.sig crypto.sign(null, <.tbx 原始位元組>, privateKey) 的 base64,結尾不加換行
10
+ */
11
+ const crypto = require('crypto');
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+
15
+ const KEY_FILE = 'tooldock-signing-key.pem';
16
+ const PUB_FILE = 'tooldock-signing-key.pub';
17
+
18
+ function publicKeyString(key) {
19
+ return crypto.createPublicKey(key).export({ type: 'spki', format: 'der' }).toString('base64');
20
+ }
21
+
22
+ function generateKeyPair() {
23
+ const { privateKey } = crypto.generateKeyPairSync('ed25519');
24
+ return {
25
+ privateKeyPem: privateKey.export({ type: 'pkcs8', format: 'pem' }),
26
+ publicKey: publicKeyString(privateKey),
27
+ };
28
+ }
29
+
30
+ /** 讀取 PEM 私鑰;容許 secret 內的換行被存成字面上的 \n */
31
+ function loadPrivateKey(pem, source) {
32
+ let text = String(pem || '').trim();
33
+ if (!text.includes('\n') && text.includes('\\n')) text = text.replace(/\\n/g, '\n');
34
+ if (!text.includes('-----BEGIN')) throw new Error(`${source} 不是 PEM 格式的私鑰(應以 -----BEGIN PRIVATE KEY----- 開頭)`);
35
+ let key;
36
+ try {
37
+ key = crypto.createPrivateKey(text);
38
+ } catch (err) {
39
+ throw new Error(`${source} 無法讀取為私鑰:${err.message}`);
40
+ }
41
+ if (key.asymmetricKeyType !== 'ed25519') throw new Error(`${source} 不是 Ed25519 私鑰(是 ${key.asymmetricKeyType}),請用 tooldock-ext keygen 產生`);
42
+ return key;
43
+ }
44
+
45
+ function loadPublicKey(str) {
46
+ const b64 = String(str || '').trim();
47
+ if (!b64) throw new Error('缺少公鑰字串');
48
+ let key;
49
+ try {
50
+ key = crypto.createPublicKey({ key: Buffer.from(b64, 'base64'), format: 'der', type: 'spki' });
51
+ } catch (err) {
52
+ throw new Error(`公鑰字串無法解析(應為 SPKI DER 的 base64):${err.message}`);
53
+ }
54
+ if (key.asymmetricKeyType !== 'ed25519') throw new Error(`公鑰不是 Ed25519(是 ${key.asymmetricKeyType})`);
55
+ return key;
56
+ }
57
+
58
+ function sha256Hex(buf) {
59
+ return crypto.createHash('sha256').update(buf).digest('hex');
60
+ }
61
+
62
+ /** 產生 <tbx>.sha256 */
63
+ function writeChecksum(tbxPath) {
64
+ const hex = sha256Hex(fs.readFileSync(tbxPath));
65
+ const file = `${tbxPath}.sha256`;
66
+ fs.writeFileSync(file, hex);
67
+ return { file, hex };
68
+ }
69
+
70
+ /** 產生 <tbx>.sha256 與 <tbx>.sig,並用對應公鑰自我驗證一次 */
71
+ function signFile(tbxPath, privateKey) {
72
+ const data = fs.readFileSync(tbxPath);
73
+ const sig = crypto.sign(null, data, privateKey);
74
+ if (!crypto.verify(null, data, crypto.createPublicKey(privateKey), sig)) throw new Error('簽章自我驗證失敗');
75
+ const checksum = writeChecksum(tbxPath);
76
+ const sigFile = `${tbxPath}.sig`;
77
+ fs.writeFileSync(sigFile, sig.toString('base64'));
78
+ return { sha256File: checksum.file, sha256: checksum.hex, sigFile, publicKey: publicKeyString(privateKey) };
79
+ }
80
+
81
+ /**
82
+ * 驗證 .tbx。回傳每個檢查項目的結果,任一 ok=false 即為失敗。
83
+ * @param {string} tbxPath
84
+ * @param {{ publicKey: string, sigPath?: string, sha256Path?: string }} opts
85
+ */
86
+ function verifyFile(tbxPath, { publicKey, sigPath, sha256Path }) {
87
+ const key = loadPublicKey(publicKey);
88
+ const data = fs.readFileSync(tbxPath);
89
+ const checks = [];
90
+ const hex = sha256Hex(data);
91
+
92
+ const shaFile = sha256Path || `${tbxPath}.sha256`;
93
+ if (fs.existsSync(shaFile)) {
94
+ const expected = fs.readFileSync(shaFile, 'utf8').trim();
95
+ const ok = /^[0-9a-f]{64}$/.test(expected) && expected === hex;
96
+ checks.push({ name: 'SHA-256', ok, detail: ok ? hex : `檔案實際為 ${hex},${path.basename(shaFile)} 記載 ${expected || '(空白)'}` });
97
+ } else if (sha256Path) {
98
+ checks.push({ name: 'SHA-256', ok: false, missing: true, detail: `找不到 ${path.basename(shaFile)}` });
99
+ } else {
100
+ checks.push({ name: 'SHA-256', ok: true, skipped: true, detail: `${hex}(沒有 .sha256 檔,未比對)` });
101
+ }
102
+
103
+ const sigFile = sigPath || `${tbxPath}.sig`;
104
+ if (!fs.existsSync(sigFile)) {
105
+ checks.push({ name: '簽章', ok: false, missing: true, detail: `找不到 ${path.basename(sigFile)}` });
106
+ } else {
107
+ const b64 = fs.readFileSync(sigFile, 'utf8').trim();
108
+ const sig = Buffer.from(b64, 'base64');
109
+ const ok = sig.length === 64 && crypto.verify(null, data, key, sig);
110
+ checks.push({ name: '簽章', ok, detail: ok ? 'Ed25519 簽章正確' : '簽章與檔案或公鑰不符' });
111
+ }
112
+ return { ok: checks.every((c) => c.ok), checks, sha256: hex };
113
+ }
114
+
115
+ module.exports = {
116
+ KEY_FILE, PUB_FILE,
117
+ generateKeyPair, loadPrivateKey, loadPublicKey, publicKeyString,
118
+ sha256Hex, writeChecksum, signFile, verifyFile,
119
+ };
package/lib/zip.js ADDED
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+ /** 極簡 ZIP 寫入器(deflate、UTF-8 檔名),讓 CLI 不需任何相依套件 */
3
+ const fs = require('fs');
4
+ const zlib = require('zlib');
5
+
6
+ const CRC_TABLE = (() => {
7
+ const t = new Uint32Array(256);
8
+ for (let n = 0; n < 256; n++) {
9
+ let c = n;
10
+ for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
11
+ t[n] = c >>> 0;
12
+ }
13
+ return t;
14
+ })();
15
+
16
+ function crc32(buf) {
17
+ if (typeof zlib.crc32 === 'function') return zlib.crc32(buf) >>> 0;
18
+ let c = 0xffffffff;
19
+ for (let i = 0; i < buf.length; i++) c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
20
+ return (c ^ 0xffffffff) >>> 0;
21
+ }
22
+
23
+ function dosTime(d) {
24
+ return {
25
+ time: (d.getHours() << 11) | (d.getMinutes() << 5) | Math.floor(d.getSeconds() / 2),
26
+ date: ((d.getFullYear() - 1980) << 9) | ((d.getMonth() + 1) << 5) | d.getDate(),
27
+ };
28
+ }
29
+
30
+ /**
31
+ * @param {string} outFile
32
+ * @param {Array<{ name: string, file: string }>} entries name 為 zip 內路徑(使用 /)
33
+ */
34
+ function writeZip(outFile, entries) {
35
+ const chunks = [];
36
+ const central = [];
37
+ let offset = 0;
38
+ const { time, date } = dosTime(new Date());
39
+
40
+ for (const e of entries) {
41
+ const data = fs.readFileSync(e.file);
42
+ const deflated = zlib.deflateRawSync(data, { level: 9 });
43
+ const useDeflate = deflated.length < data.length;
44
+ const body = useDeflate ? deflated : data;
45
+ const name = Buffer.from(e.name, 'utf8');
46
+ const crc = crc32(data);
47
+
48
+ const local = Buffer.alloc(30);
49
+ local.writeUInt32LE(0x04034b50, 0);
50
+ local.writeUInt16LE(20, 4); // version needed
51
+ local.writeUInt16LE(0x0800, 6); // UTF-8 檔名
52
+ local.writeUInt16LE(useDeflate ? 8 : 0, 8);
53
+ local.writeUInt16LE(time, 10);
54
+ local.writeUInt16LE(date, 12);
55
+ local.writeUInt32LE(crc, 14);
56
+ local.writeUInt32LE(body.length, 18);
57
+ local.writeUInt32LE(data.length, 22);
58
+ local.writeUInt16LE(name.length, 26);
59
+ local.writeUInt16LE(0, 28);
60
+ chunks.push(local, name, body);
61
+
62
+ const cen = Buffer.alloc(46);
63
+ cen.writeUInt32LE(0x02014b50, 0);
64
+ cen.writeUInt16LE(0x031e, 4); // made by: UNIX, 3.0
65
+ cen.writeUInt16LE(20, 6);
66
+ cen.writeUInt16LE(0x0800, 8);
67
+ cen.writeUInt16LE(useDeflate ? 8 : 0, 10);
68
+ cen.writeUInt16LE(time, 12);
69
+ cen.writeUInt16LE(date, 14);
70
+ cen.writeUInt32LE(crc, 16);
71
+ cen.writeUInt32LE(body.length, 20);
72
+ cen.writeUInt32LE(data.length, 24);
73
+ cen.writeUInt16LE(name.length, 28);
74
+ cen.writeUInt32LE(((0o100644) << 16) >>> 0, 38); // 檔案權限
75
+ cen.writeUInt32LE(offset, 42);
76
+ central.push(cen, name);
77
+
78
+ offset += local.length + name.length + body.length;
79
+ }
80
+
81
+ const cenSize = central.reduce((s, b) => s + b.length, 0);
82
+ const end = Buffer.alloc(22);
83
+ end.writeUInt32LE(0x06054b50, 0);
84
+ end.writeUInt16LE(entries.length, 8);
85
+ end.writeUInt16LE(entries.length, 10);
86
+ end.writeUInt32LE(cenSize, 12);
87
+ end.writeUInt32LE(offset, 16);
88
+
89
+ fs.writeFileSync(outFile, Buffer.concat([...chunks, ...central, end]));
90
+ }
91
+
92
+ module.exports = { writeZip };
package/package.json CHANGED
@@ -1,6 +1,22 @@
1
1
  {
2
2
  "name": "tooldock-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "ToolDock 擴充開發工具:dev(開發模式啟動並偵錯)、validate、pack(含簽章)、install、keygen、verify",
5
+ "bin": {
6
+ "tooldock-ext": "bin/tooldock-ext.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "lib",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "keywords": [
17
+ "tooldock",
18
+ "extension",
19
+ "cli"
20
+ ],
21
+ "license": "MIT"
22
+ }