ones-fetch 1.4.3 → 1.4.5

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
@@ -7,7 +7,7 @@
7
7
  策划电脑上已有 Node.js,执行一条命令即可:
8
8
 
9
9
  ```bash
10
- npx ones-fetch@latest
10
+ npx ones-fetch@latest install
11
11
  ```
12
12
 
13
13
  或者使用 npm 安装:
package/bin/cli.mjs ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+
3
+ const command = process.argv[2] || '';
4
+
5
+ function printHelp() {
6
+ console.log('ONES Fetch\n');
7
+ console.log('用法:');
8
+ console.log(' ones-fetch 一次性启动工具');
9
+ console.log(' ones-fetch install 安装到本地并创建桌面快捷方式');
10
+ }
11
+
12
+ async function main() {
13
+ if (command === 'install') {
14
+ const { runInstallFlow } = await import('./install.mjs');
15
+ await runInstallFlow();
16
+ return;
17
+ }
18
+
19
+ if (command === '--help' || command === '-h' || command === 'help') {
20
+ printHelp();
21
+ return;
22
+ }
23
+
24
+ if (command) {
25
+ console.error(`不支持的命令: ${command}`);
26
+ printHelp();
27
+ process.exit(1);
28
+ }
29
+
30
+ await import('../src/server.mjs');
31
+ }
32
+
33
+ main().catch((error) => {
34
+ console.error(error instanceof Error ? error.message : String(error));
35
+ process.exit(1);
36
+ });
package/bin/install.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { fileURLToPath } from 'node:url';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { homedir, platform } from 'node:os';
6
6
  import { writeFile, mkdir, cp, access, rm, readFile } from 'node:fs/promises';
@@ -155,39 +155,9 @@ Categories=Utility;
155
155
  console.log(`✓ 桌面快捷方式已创建: ${desktopFile}`);
156
156
  }
157
157
 
158
- async function main() {
159
- // 检测是否是通过 npx 或 postinstall 运行
160
- const isPostInstall = process.env.npm_lifecycle_event === 'postinstall';
161
-
162
- // 确保安装目录存在
158
+ export async function runInstallFlow() {
163
159
  await ensureInstallDir();
164
160
 
165
- if (isPostInstall) {
166
- // postinstall 时只创建快捷方式,不安装依赖
167
- console.log('ONES Fetch 安装后配置\n');
168
- console.log('正在创建桌面快捷方式...');
169
- try {
170
- const os = platform();
171
- if (os === 'win32') {
172
- await createWindowsShortcut();
173
- } else if (os === 'darwin') {
174
- await createMacShortcut();
175
- } else {
176
- await createLinuxShortcut();
177
- }
178
- } catch (err) {
179
- console.error('✗ 快捷方式创建失败:', err.message);
180
- // 不退出,允许安装继续
181
- }
182
- console.log('\n✓ 配置完成!');
183
- console.log('\n使用方法:');
184
- console.log(' 1. 双击桌面上的 "ONES 采集工具" 图标');
185
- console.log(' 2. 浏览器会自动打开工具页面');
186
- console.log(`\n项目位置:${installDir}`);
187
- return;
188
- }
189
-
190
- // npx 运行时的完整安装流程
191
161
  console.log('ONES Fetch 安装程序\n');
192
162
 
193
163
  // 安装依赖
@@ -223,4 +193,9 @@ async function main() {
223
193
  console.log(`\n项目位置:${installDir}`);
224
194
  }
225
195
 
226
- main().catch(console.error);
196
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
197
+ runInstallFlow().catch((error) => {
198
+ console.error(error instanceof Error ? error.message : String(error));
199
+ process.exit(1);
200
+ });
201
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "ones-fetch",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "type": "module",
5
5
  "description": "ONES Fetch — Web app for recursive ONES subtask crawling",
6
6
  "bin": {
7
- "ones-fetch": "./bin/install.mjs"
7
+ "ones-fetch": "bin/cli.mjs"
8
8
  },
9
9
  "scripts": {
10
10
  "start": "node src/server.mjs",