ones-fetch 1.3.0 → 1.4.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/bin/install.mjs +38 -12
- package/package.json +1 -1
package/bin/install.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { homedir, platform } from 'node:os';
|
|
6
|
-
import { writeFile, mkdir } from 'node:fs/promises';
|
|
6
|
+
import { writeFile, mkdir, cp, access } from 'node:fs/promises';
|
|
7
7
|
import { exec } from 'node:child_process';
|
|
8
8
|
import { promisify } from 'node:util';
|
|
9
9
|
|
|
@@ -11,11 +11,38 @@ const execAsync = promisify(exec);
|
|
|
11
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
12
|
const projectRoot = join(__dirname, '..');
|
|
13
13
|
|
|
14
|
+
// 固定安装目录(用户主目录下)
|
|
15
|
+
const installDir = join(homedir(), '.ones-fetch');
|
|
16
|
+
|
|
17
|
+
async function ensureInstallDir() {
|
|
18
|
+
try {
|
|
19
|
+
await access(installDir);
|
|
20
|
+
console.log(`使用现有安装目录: ${installDir}`);
|
|
21
|
+
} catch {
|
|
22
|
+
// 目录不存在,复制项目文件
|
|
23
|
+
console.log(`正在复制项目文件到 ${installDir}...`);
|
|
24
|
+
await mkdir(installDir, { recursive: true });
|
|
25
|
+
|
|
26
|
+
// 复制必要的文件和目录
|
|
27
|
+
try {
|
|
28
|
+
await cp(join(projectRoot, 'src'), join(installDir, 'src'), { recursive: true });
|
|
29
|
+
await cp(join(projectRoot, 'public'), join(installDir, 'public'), { recursive: true });
|
|
30
|
+
await cp(join(projectRoot, 'bin'), join(installDir, 'bin'), { recursive: true });
|
|
31
|
+
await cp(join(projectRoot, 'package.json'), join(installDir, 'package.json'));
|
|
32
|
+
await cp(join(projectRoot, 'package-lock.json'), join(installDir, 'package-lock.json')).catch(() => {});
|
|
33
|
+
console.log('✓ 项目文件复制完成');
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error('✗ 文件复制失败:', err.message);
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
async function createWindowsShortcut() {
|
|
15
42
|
const desktop = join(homedir(), 'Desktop');
|
|
16
43
|
const shortcutPath = join(desktop, 'ONES 采集工具.lnk');
|
|
17
|
-
const iconPath = join(
|
|
18
|
-
const vbsLauncher = join(
|
|
44
|
+
const iconPath = join(installDir, 'public', 'icon.ico');
|
|
45
|
+
const vbsLauncher = join(installDir, 'public', 'launcher.vbs');
|
|
19
46
|
|
|
20
47
|
// 创建 PowerShell 脚本来生成快捷方式
|
|
21
48
|
const psScript = `
|
|
@@ -23,13 +50,13 @@ $WshShell = New-Object -ComObject WScript.Shell
|
|
|
23
50
|
$Shortcut = $WshShell.CreateShortcut("${shortcutPath.replace(/\\/g, '\\\\')}")
|
|
24
51
|
$Shortcut.TargetPath = "wscript.exe"
|
|
25
52
|
$Shortcut.Arguments = '"${vbsLauncher.replace(/\\/g, '\\\\')}"'
|
|
26
|
-
$Shortcut.WorkingDirectory = "${
|
|
53
|
+
$Shortcut.WorkingDirectory = "${installDir.replace(/\\/g, '\\\\')}"
|
|
27
54
|
$Shortcut.IconLocation = "${iconPath.replace(/\\/g, '\\\\')},0"
|
|
28
55
|
$Shortcut.Description = "ONES 任务采集工具"
|
|
29
56
|
$Shortcut.Save()
|
|
30
57
|
`;
|
|
31
58
|
|
|
32
|
-
const tempPs1 = join(
|
|
59
|
+
const tempPs1 = join(installDir, 'temp-create-shortcut.ps1');
|
|
33
60
|
await writeFile(tempPs1, psScript, 'utf8');
|
|
34
61
|
|
|
35
62
|
try {
|
|
@@ -82,6 +109,9 @@ async function main() {
|
|
|
82
109
|
// 检测是否是通过 npx 或 postinstall 运行
|
|
83
110
|
const isPostInstall = process.env.npm_lifecycle_event === 'postinstall';
|
|
84
111
|
|
|
112
|
+
// 确保安装目录存在
|
|
113
|
+
await ensureInstallDir();
|
|
114
|
+
|
|
85
115
|
if (isPostInstall) {
|
|
86
116
|
// postinstall 时只创建快捷方式,不安装依赖
|
|
87
117
|
console.log('ONES Fetch 安装后配置\n');
|
|
@@ -103,9 +133,7 @@ async function main() {
|
|
|
103
133
|
console.log('\n使用方法:');
|
|
104
134
|
console.log(' 1. 双击桌面上的 "ONES 采集工具" 图标');
|
|
105
135
|
console.log(' 2. 浏览器会自动打开工具页面');
|
|
106
|
-
console.log(
|
|
107
|
-
console.log(` cd ${projectRoot}`);
|
|
108
|
-
console.log(' npm start');
|
|
136
|
+
console.log(`\n项目位置:${installDir}`);
|
|
109
137
|
return;
|
|
110
138
|
}
|
|
111
139
|
|
|
@@ -115,7 +143,7 @@ async function main() {
|
|
|
115
143
|
// 安装依赖
|
|
116
144
|
console.log('正在安装依赖...');
|
|
117
145
|
try {
|
|
118
|
-
await execAsync('npm install', { cwd:
|
|
146
|
+
await execAsync('npm install', { cwd: installDir });
|
|
119
147
|
console.log('✓ 依赖安装完成\n');
|
|
120
148
|
} catch (err) {
|
|
121
149
|
console.error('✗ 依赖安装失败:', err.message);
|
|
@@ -142,9 +170,7 @@ async function main() {
|
|
|
142
170
|
console.log('\n使用方法:');
|
|
143
171
|
console.log(' 1. 双击桌面上的 "ONES 采集工具" 图标');
|
|
144
172
|
console.log(' 2. 浏览器会自动打开工具页面');
|
|
145
|
-
console.log(
|
|
146
|
-
console.log(` cd ${projectRoot}`);
|
|
147
|
-
console.log(' npm start');
|
|
173
|
+
console.log(`\n项目位置:${installDir}`);
|
|
148
174
|
}
|
|
149
175
|
|
|
150
176
|
main().catch(console.error);
|