electerm-data-tool 1.0.0 → 1.101.17
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 +68 -17
- package/README.zh-CN.md +253 -0
- package/package.json +1 -1
- package/src/common/app-props.js +16 -1
- package/src/index.js +37 -3
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Electerm Data Tool
|
|
2
2
|
|
|
3
|
+
[中文文档 (Chinese README)](./README.zh-CN.md)
|
|
4
|
+
|
|
3
5
|
A command-line utility for managing Electerm application data, including database migration from v1 (NeDB) to v2 (SQLite) and data export functionality.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
@@ -49,6 +51,39 @@ Available commands:
|
|
|
49
51
|
- `--help` - Show help information
|
|
50
52
|
- `--version` - Show version number
|
|
51
53
|
|
|
54
|
+
Available options:
|
|
55
|
+
|
|
56
|
+
- `-d, --data-path <path>` - Custom path to electerm data directory (for portable installations)
|
|
57
|
+
|
|
58
|
+
### Custom Data Path (Portable Support)
|
|
59
|
+
|
|
60
|
+
For portable installations where Electerm data is stored in a custom location, use the `--data-path` option:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Export data from custom location
|
|
64
|
+
electerm-data-tool --data-path /path/to/portable/electerm export backup.json
|
|
65
|
+
|
|
66
|
+
# Migrate data in custom location
|
|
67
|
+
electerm-data-tool --data-path /path/to/portable/electerm migrate
|
|
68
|
+
|
|
69
|
+
# Check info for custom location
|
|
70
|
+
electerm-data-tool --data-path /path/to/portable/electerm info
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Examples:**
|
|
74
|
+
```bash
|
|
75
|
+
# Windows portable installation
|
|
76
|
+
electerm-data-tool --data-path "C:\PortableApps\Electerm\Data" export backup.json
|
|
77
|
+
|
|
78
|
+
# macOS custom installation
|
|
79
|
+
electerm-data-tool --data-path "/Volumes/USB/electerm-data" migrate
|
|
80
|
+
|
|
81
|
+
# Linux custom installation
|
|
82
|
+
electerm-data-tool --data-path "/opt/electerm/data" info
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The tool will validate that the specified path exists before proceeding.
|
|
86
|
+
|
|
52
87
|
### 1. Database Migration
|
|
53
88
|
|
|
54
89
|
Migrate your Electerm database from v1 (NeDB) to v2 (SQLite):
|
|
@@ -143,14 +178,43 @@ The exported JSON follows this structure:
|
|
|
143
178
|
- The `passwordEncrypted` flag is removed from exported data
|
|
144
179
|
- Exported passwords are human-readable for backup purposes
|
|
145
180
|
|
|
181
|
+
## Environment Variables
|
|
182
|
+
|
|
183
|
+
The tool supports the following environment variables for configuration:
|
|
184
|
+
|
|
185
|
+
### `APP_PATH` (Legacy)
|
|
186
|
+
|
|
187
|
+
Sets the base application data directory. This is the legacy method still supported for backward compatibility.
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
APP_PATH=/custom/path electerm-data-tool info
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Data Path Priority
|
|
194
|
+
|
|
195
|
+
The tool uses the following priority order for determining the data path:
|
|
196
|
+
|
|
197
|
+
1. **`--data-path` option** (highest priority) - Command-line argument
|
|
198
|
+
2. **`APP_PATH` environment variable** - Legacy support
|
|
199
|
+
3. **Default platform path** (lowest priority) - System default
|
|
200
|
+
|
|
201
|
+
**Examples:**
|
|
202
|
+
```bash
|
|
203
|
+
# Using command-line option (recommended)
|
|
204
|
+
electerm-data-tool --data-path /path/to/data info
|
|
205
|
+
|
|
206
|
+
# Using environment variable (legacy)
|
|
207
|
+
APP_PATH=/path/to/data electerm-data-tool info
|
|
208
|
+
|
|
209
|
+
# Command-line option overrides environment variable
|
|
210
|
+
APP_PATH=/path/one electerm-data-tool --data-path /path/two info
|
|
211
|
+
# Will use /path/two
|
|
212
|
+
```
|
|
213
|
+
|
|
146
214
|
## Requirements
|
|
147
215
|
|
|
148
216
|
- **Node.js**: 16.0.0 or higher
|
|
149
217
|
- **For SQLite (v2)**: Node.js 22.0.0 or higher
|
|
150
|
-
- **Dependencies**:
|
|
151
|
-
- `commander` - CLI framework
|
|
152
|
-
- `@yetzt/nedb` - NeDB database support
|
|
153
|
-
- `nanoid` - ID generation
|
|
154
218
|
|
|
155
219
|
## File Locations
|
|
156
220
|
|
|
@@ -204,19 +268,6 @@ electerm-data-tool info
|
|
|
204
268
|
electerm-data-tool export ~/electerm-backup-after-migration.json
|
|
205
269
|
```
|
|
206
270
|
|
|
207
|
-
### Using with npm scripts
|
|
208
|
-
|
|
209
|
-
```bash
|
|
210
|
-
# Quick migration
|
|
211
|
-
npm run migrate
|
|
212
|
-
|
|
213
|
-
# Quick export
|
|
214
|
-
npm run export ~/backup.json
|
|
215
|
-
|
|
216
|
-
# Quick info
|
|
217
|
-
npm run info
|
|
218
|
-
```
|
|
219
|
-
|
|
220
271
|
## Troubleshooting
|
|
221
272
|
|
|
222
273
|
### Migration Issues
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Electerm 数据工具
|
|
2
|
+
|
|
3
|
+
[English README](./README.md)
|
|
4
|
+
|
|
5
|
+
一个用于管理 Electerm 应用数据的命令行工具,支持从 v1 (NeDB) 到 v2 (SQLite) 的数据库迁移,以及数据导出。
|
|
6
|
+
|
|
7
|
+
## 功能特性
|
|
8
|
+
|
|
9
|
+
- 🔄 **数据库迁移**:将 Electerm 数据从 v1 (NeDB) 迁移到 v2 (SQLite)
|
|
10
|
+
- 📤 **数据导出**:将所有 Electerm 数据导出为一个包含明文密码的 JSON 文件
|
|
11
|
+
- 📊 **数据库信息**:显示当前 Electerm 数据库的信息
|
|
12
|
+
- 🔐 **密码解密**:导出时自动解密密码,便于备份
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
### 推荐:npx 直接运行
|
|
17
|
+
|
|
18
|
+
无需安装,直接使用 npx 运行:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx electerm-data-tool migrate
|
|
22
|
+
npx electerm-data-tool export ~/backup.json
|
|
23
|
+
npx electerm-data-tool info
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 全局安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install -g electerm-data-tool
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 使用方法
|
|
33
|
+
|
|
34
|
+
### 命令总览
|
|
35
|
+
|
|
36
|
+
**npx 方式(无需安装):**
|
|
37
|
+
```bash
|
|
38
|
+
npx electerm-data-tool [command] [options]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**全局安装方式:**
|
|
42
|
+
```bash
|
|
43
|
+
electerm-data-tool [command] [options]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
可用命令:
|
|
47
|
+
|
|
48
|
+
- `migrate` - 数据库从 v1 迁移到 v2
|
|
49
|
+
- `export <path>` - 导出所有数据为 JSON 文件
|
|
50
|
+
- `info` - 显示数据库信息
|
|
51
|
+
- `--help` - 显示帮助信息
|
|
52
|
+
- `--version` - 显示版本号
|
|
53
|
+
|
|
54
|
+
可用选项:
|
|
55
|
+
|
|
56
|
+
- `-d, --data-path <路径>` - 指定 Electerm 数据目录(便携版/自定义路径支持)
|
|
57
|
+
|
|
58
|
+
### 自定义数据路径(便携版支持)
|
|
59
|
+
|
|
60
|
+
对于便携版或 Electerm 数据存储在自定义位置的情况,可通过 `--data-path` 选项指定数据目录:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# 从自定义目录导出数据
|
|
64
|
+
electerm-data-tool --data-path /path/to/portable/electerm export backup.json
|
|
65
|
+
|
|
66
|
+
# 迁移自定义目录数据
|
|
67
|
+
electerm-data-tool --data-path /path/to/portable/electerm migrate
|
|
68
|
+
|
|
69
|
+
# 查看自定义目录信息
|
|
70
|
+
electerm-data-tool --data-path /path/to/portable/electerm info
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**示例:**
|
|
74
|
+
```bash
|
|
75
|
+
# Windows 便携版
|
|
76
|
+
electerm-data-tool --data-path "C:\\PortableApps\\Electerm\\Data" export backup.json
|
|
77
|
+
|
|
78
|
+
# macOS U 盘
|
|
79
|
+
electerm-data-tool --data-path "/Volumes/USB/electerm-data" migrate
|
|
80
|
+
|
|
81
|
+
# Linux 自定义安装
|
|
82
|
+
electerm-data-tool --data-path "/opt/electerm/data" info
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
工具会校验指定路径是否存在。
|
|
86
|
+
|
|
87
|
+
### 1. 数据库迁移
|
|
88
|
+
|
|
89
|
+
将 Electerm 数据库从 v1 (NeDB) 迁移到 v2 (SQLite):
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
electerm-data-tool migrate
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
此命令将:
|
|
96
|
+
- 检查是否需要迁移
|
|
97
|
+
- 将所有 NeDB 文件数据迁移到 SQLite 数据库
|
|
98
|
+
- 备份原始 NeDB 文件(带时间戳)
|
|
99
|
+
- 执行必要的数据升级
|
|
100
|
+
|
|
101
|
+
**注意**:需要 Node.js 22.0.0 及以上版本。
|
|
102
|
+
|
|
103
|
+
### 2. 数据导出
|
|
104
|
+
|
|
105
|
+
将所有 Electerm 数据导出为包含明文密码的 JSON 文件:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
electerm-data-tool export /path/to/backup.json
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
示例:
|
|
112
|
+
```bash
|
|
113
|
+
electerm-data-tool export ~/electerm-backup-2025-09-03.json
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 3. 数据库信息
|
|
117
|
+
|
|
118
|
+
查看当前 Electerm 数据库信息:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
electerm-data-tool info
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
将显示:
|
|
125
|
+
- 数据库类型(v1 NeDB 或 v2 SQLite)
|
|
126
|
+
- 各表数据条数
|
|
127
|
+
- 如需迁移会有提示
|
|
128
|
+
|
|
129
|
+
## 数据库自动检测
|
|
130
|
+
|
|
131
|
+
工具会自动检测当前数据库类型:
|
|
132
|
+
- **v1 (NeDB)**:原始文件型数据库
|
|
133
|
+
- **v2 (SQLite)**:新版数据库(需 Node.js 22+)
|
|
134
|
+
|
|
135
|
+
导出时:
|
|
136
|
+
- 检测到 v1 用 NeDB 方式导出
|
|
137
|
+
- 检测到 v2 用 SQLite 方式导出
|
|
138
|
+
- 密码自动解密为明文
|
|
139
|
+
|
|
140
|
+
## 数据结构
|
|
141
|
+
|
|
142
|
+
导出 JSON 结构如下:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"bookmarks": [...],
|
|
147
|
+
"bookmarkGroups": [...],
|
|
148
|
+
"terminalThemes": [...],
|
|
149
|
+
"quickCommands": [...],
|
|
150
|
+
"profiles": [...],
|
|
151
|
+
"config": {...},
|
|
152
|
+
"addressBookmarks": [...],
|
|
153
|
+
"lastStates": [...],
|
|
154
|
+
"data": [...],
|
|
155
|
+
"log": [...],
|
|
156
|
+
"dbUpgradeLog": [...]
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 密码处理
|
|
161
|
+
|
|
162
|
+
- Electerm 内部密码为加密存储
|
|
163
|
+
- 导出时自动解密为明文
|
|
164
|
+
- 导出数据不含 `passwordEncrypted` 字段
|
|
165
|
+
- 便于备份和迁移
|
|
166
|
+
|
|
167
|
+
## 依赖要求
|
|
168
|
+
|
|
169
|
+
- **Node.js**:16.0.0 及以上
|
|
170
|
+
- **SQLite (v2)**:需 Node.js 22.0.0 及以上
|
|
171
|
+
- **依赖包**:
|
|
172
|
+
- `commander` - CLI 框架
|
|
173
|
+
- `@yetzt/nedb` - NeDB 支持
|
|
174
|
+
- `nanoid` - ID 生成
|
|
175
|
+
|
|
176
|
+
## 数据文件位置
|
|
177
|
+
|
|
178
|
+
- NeDB (v1):`~/.electerm/users/{username}/electerm.{table}.nedb`
|
|
179
|
+
- SQLite (v2):`~/.electerm/users/{username}/electerm.db`
|
|
180
|
+
|
|
181
|
+
迁移时 NeDB 文件会自动备份为:
|
|
182
|
+
- `electerm.bookmarks.nedb-{timestamp}.bak`
|
|
183
|
+
|
|
184
|
+
### 数据路径优先级
|
|
185
|
+
|
|
186
|
+
Electerm 数据工具会按如下优先级查找数据目录:
|
|
187
|
+
|
|
188
|
+
1. `--data-path` 命令行参数(最高优先级)
|
|
189
|
+
2. `APP_PATH` 环境变量(兼容旧用法)
|
|
190
|
+
3. 默认平台路径(最低优先级)
|
|
191
|
+
|
|
192
|
+
**示例:**
|
|
193
|
+
```bash
|
|
194
|
+
# 推荐:命令行参数
|
|
195
|
+
electerm-data-tool --data-path /path/to/data info
|
|
196
|
+
|
|
197
|
+
# 兼容旧用法:环境变量
|
|
198
|
+
APP_PATH=/path/to/data electerm-data-tool info
|
|
199
|
+
|
|
200
|
+
# 命令行参数优先生效
|
|
201
|
+
APP_PATH=/path/one electerm-data-tool --data-path /path/two info
|
|
202
|
+
# 实际使用 /path/two
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## 环境变量
|
|
206
|
+
|
|
207
|
+
工具支持如下环境变量进行配置:
|
|
208
|
+
|
|
209
|
+
### `APP_PATH`(兼容旧用法)
|
|
210
|
+
|
|
211
|
+
设置应用数据目录(旧用法,仍然兼容):
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
APP_PATH=/custom/path electerm-data-tool info
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
如需便携/自定义目录,推荐使用 `--data-path` 选项。
|
|
218
|
+
|
|
219
|
+
## 示例流程
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# 1. 查看数据库状态
|
|
223
|
+
npx electerm-data-tool info
|
|
224
|
+
|
|
225
|
+
# 2. 迁移前导出备份
|
|
226
|
+
npx electerm-data-tool export ~/electerm-backup-before-migration.json
|
|
227
|
+
|
|
228
|
+
# 3. 执行迁移
|
|
229
|
+
npx electerm-data-tool migrate
|
|
230
|
+
|
|
231
|
+
# 4. 验证迁移结果
|
|
232
|
+
npx electerm-data-tool info
|
|
233
|
+
|
|
234
|
+
# 5. 迁移后再导出一次
|
|
235
|
+
npx electerm-data-tool export ~/electerm-backup-after-migration.json
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 常见问题
|
|
239
|
+
|
|
240
|
+
- **迁移报错/SQLite 报错**:请确认 Node.js 版本 >= 22
|
|
241
|
+
- **导出密码为乱码**:请升级到最新版工具
|
|
242
|
+
- **命令未找到**:请确认已全局安装或用 npx 运行
|
|
243
|
+
|
|
244
|
+
## 安全提示
|
|
245
|
+
|
|
246
|
+
- 导出文件包含明文密码,请妥善保存
|
|
247
|
+
- 用完请及时删除导出文件
|
|
248
|
+
- 本工具所有操作均在本地完成,不会上传数据
|
|
249
|
+
|
|
250
|
+
## 相关链接
|
|
251
|
+
|
|
252
|
+
- [Electerm 主项目](https://github.com/electerm/electerm)
|
|
253
|
+
- [English README](./README.md)
|
package/package.json
CHANGED
package/src/common/app-props.js
CHANGED
|
@@ -17,7 +17,22 @@ function getAppPath () {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
function getElectermDataPath () {
|
|
21
|
+
// Priority order:
|
|
22
|
+
// 1. ELECTERM_DATA_PATH (set by --data-path option)
|
|
23
|
+
// 2. APP_PATH (legacy environment variable)
|
|
24
|
+
// 3. Default platform-specific path
|
|
25
|
+
if (process.env.ELECTERM_DATA_PATH) {
|
|
26
|
+
return process.env.ELECTERM_DATA_PATH
|
|
27
|
+
}
|
|
28
|
+
return process.env.APP_PATH || getAppPath()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Use a getter to ensure we always get the current path
|
|
32
|
+
Object.defineProperty(exports, 'appPath', {
|
|
33
|
+
get: getElectermDataPath
|
|
34
|
+
})
|
|
35
|
+
|
|
21
36
|
exports.defaultUserName = 'default_user'
|
|
22
37
|
exports.packInfo = {
|
|
23
38
|
version
|
package/src/index.js
CHANGED
|
@@ -27,6 +27,26 @@ program
|
|
|
27
27
|
.name('electerm-data-tool')
|
|
28
28
|
.description('CLI tool for electerm data migration and export')
|
|
29
29
|
.version(pkg.version)
|
|
30
|
+
.option('-d, --data-path <path>', 'Custom path to electerm data directory (for portable installations)')
|
|
31
|
+
.hook('preAction', (thisCommand) => {
|
|
32
|
+
// Set custom data path if provided
|
|
33
|
+
if (thisCommand.opts().dataPath) {
|
|
34
|
+
const { existsSync } = require('fs')
|
|
35
|
+
const { resolve } = require('path')
|
|
36
|
+
|
|
37
|
+
const customPath = resolve(thisCommand.opts().dataPath)
|
|
38
|
+
|
|
39
|
+
// Validate that the custom path exists
|
|
40
|
+
if (!existsSync(customPath)) {
|
|
41
|
+
console.error(`❌ Custom data path does not exist: ${customPath}`)
|
|
42
|
+
console.error(' Please ensure the directory exists or check the path.')
|
|
43
|
+
process.exit(1)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
process.env.ELECTERM_DATA_PATH = customPath
|
|
47
|
+
console.log(`📁 Using custom data path: ${customPath}`)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
30
50
|
|
|
31
51
|
/**
|
|
32
52
|
* Migration command - migrates from NeDB (v1) to SQLite (v2)
|
|
@@ -48,6 +68,11 @@ program
|
|
|
48
68
|
}
|
|
49
69
|
|
|
50
70
|
log.info('Starting migration process...')
|
|
71
|
+
|
|
72
|
+
// Show the data path being used
|
|
73
|
+
const { appPath } = require('./common/app-props')
|
|
74
|
+
console.log(`📁 Data path: ${appPath}`)
|
|
75
|
+
|
|
51
76
|
await migrate()
|
|
52
77
|
log.info('Migration completed successfully!')
|
|
53
78
|
console.log('✅ Migration from NeDB to SQLite completed successfully!')
|
|
@@ -69,6 +94,10 @@ program
|
|
|
69
94
|
try {
|
|
70
95
|
log.info('Starting data export...')
|
|
71
96
|
|
|
97
|
+
// Show the data path being used
|
|
98
|
+
const { appPath } = require('./common/app-props')
|
|
99
|
+
console.log(`📁 Data path: ${appPath}`)
|
|
100
|
+
|
|
72
101
|
// Check if migration is needed to determine which database to use
|
|
73
102
|
const { checkMigrate } = require('./migrate/migrate-1-to-2')
|
|
74
103
|
const shouldMigrate = checkMigrate()
|
|
@@ -172,6 +201,12 @@ program
|
|
|
172
201
|
.description('Display information about the current electerm data')
|
|
173
202
|
.action(async () => {
|
|
174
203
|
try {
|
|
204
|
+
// Show the data path being used
|
|
205
|
+
const { appPath } = require('./common/app-props')
|
|
206
|
+
console.log('📊 Electerm Data Information')
|
|
207
|
+
console.log(`📁 Data path: ${appPath}`)
|
|
208
|
+
console.log('='.repeat(50))
|
|
209
|
+
|
|
175
210
|
// Check if migration is needed to determine which database to use
|
|
176
211
|
const { checkMigrate } = require('./migrate/migrate-1-to-2')
|
|
177
212
|
const shouldMigrate = checkMigrate()
|
|
@@ -206,9 +241,8 @@ program
|
|
|
206
241
|
}
|
|
207
242
|
|
|
208
243
|
const { dbAction, tables } = dbModule
|
|
209
|
-
console.log('📊 Electerm Data Information')
|
|
210
244
|
console.log(`Database Type: ${dbType}`)
|
|
211
|
-
console.log('='.repeat(
|
|
245
|
+
console.log('='.repeat(50))
|
|
212
246
|
|
|
213
247
|
let totalRecords = 0
|
|
214
248
|
for (const table of tables) {
|
|
@@ -222,7 +256,7 @@ program
|
|
|
222
256
|
}
|
|
223
257
|
}
|
|
224
258
|
|
|
225
|
-
console.log('='.repeat(
|
|
259
|
+
console.log('='.repeat(50))
|
|
226
260
|
console.log(`Total Records: ${totalRecords}`)
|
|
227
261
|
} catch (error) {
|
|
228
262
|
console.error('❌ Failed to read data:', error.message)
|