electerm-data-tool 1.101.16 → 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 +66 -0
- package/README.zh-CN.md +68 -0
- package/package.json +1 -1
- package/src/common/app-props.js +16 -1
- package/src/index.js +37 -3
package/README.md
CHANGED
|
@@ -51,6 +51,39 @@ Available commands:
|
|
|
51
51
|
- `--help` - Show help information
|
|
52
52
|
- `--version` - Show version number
|
|
53
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
|
+
|
|
54
87
|
### 1. Database Migration
|
|
55
88
|
|
|
56
89
|
Migrate your Electerm database from v1 (NeDB) to v2 (SQLite):
|
|
@@ -145,6 +178,39 @@ The exported JSON follows this structure:
|
|
|
145
178
|
- The `passwordEncrypted` flag is removed from exported data
|
|
146
179
|
- Exported passwords are human-readable for backup purposes
|
|
147
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
|
+
|
|
148
214
|
## Requirements
|
|
149
215
|
|
|
150
216
|
- **Node.js**: 16.0.0 or higher
|
package/README.zh-CN.md
CHANGED
|
@@ -51,6 +51,39 @@ electerm-data-tool [command] [options]
|
|
|
51
51
|
- `--help` - 显示帮助信息
|
|
52
52
|
- `--version` - 显示版本号
|
|
53
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
|
+
|
|
54
87
|
### 1. 数据库迁移
|
|
55
88
|
|
|
56
89
|
将 Electerm 数据库从 v1 (NeDB) 迁移到 v2 (SQLite):
|
|
@@ -148,6 +181,41 @@ electerm-data-tool info
|
|
|
148
181
|
迁移时 NeDB 文件会自动备份为:
|
|
149
182
|
- `electerm.bookmarks.nedb-{timestamp}.bak`
|
|
150
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
|
+
|
|
151
219
|
## 示例流程
|
|
152
220
|
|
|
153
221
|
```bash
|
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)
|