micloud-cli 0.5.0 → 0.5.1
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.en.md +1 -1
- package/README.md +1 -1
- package/dist/core/config.js +11 -5
- package/dist/note/commands/sync.js +21 -7
- package/dist/note/config.js +10 -1
- package/dist/note/sync.js +15 -11
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -54,7 +54,7 @@ Supported Markdown: headings, lists, checkboxes, quotes, dividers, bold / italic
|
|
|
54
54
|
| Command | Description |
|
|
55
55
|
|---|---|
|
|
56
56
|
| `list` / `search` / `info <id>` / `stats` | List, search, details, statistics |
|
|
57
|
-
| `pull -o <dir>` | Incremental pull: already-pulled recordings are skipped, even if you moved the files away |
|
|
57
|
+
| `pull -o <dir>` | Incremental pull: already-pulled recordings are skipped, even if you moved the files away; `--limit n` pulls the newest n not-yet-pulled ones per run |
|
|
58
58
|
| `download <id...>` | Download by id; `--stdout` to pipe |
|
|
59
59
|
| `url <id>` / `play <id>` | Temporary direct link (no login needed, about 4 hours), play in a player |
|
|
60
60
|
| `delete` | Move to trash: by id, by filter, or `--pulled` (pulled and verified locally) |
|
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ Markdown 支持标题、列表、复选框、引用、分割线、加粗 / 斜
|
|
|
54
54
|
| 命令 | 说明 |
|
|
55
55
|
|---|---|
|
|
56
56
|
| `list` / `search` / `info <id>` / `stats` | 列出、搜索、详情、统计 |
|
|
57
|
-
| `pull -o <目录>` |
|
|
57
|
+
| `pull -o <目录>` | 增量拉取:拉过的自动跳过,即使你已把文件移走;`--limit n` 每次只拉最新 n 条待拉取的 |
|
|
58
58
|
| `download <id...>` | 按 id 下载;`--stdout` 写到管道 |
|
|
59
59
|
| `url <id>` / `play <id>` | 临时直链(免登录、约 4 小时有效)、在线播放 |
|
|
60
60
|
| `delete` | 移到回收站:按 id、筛选条件,或 `--pulled`(已拉到本地且校验一致的) |
|
package/dist/core/config.js
CHANGED
|
@@ -33,15 +33,21 @@ export async function loadProjectConfig() {
|
|
|
33
33
|
}
|
|
34
34
|
/** 读取某个服务的配置节(原样返回,由服务自己校验字段);笔记节缺失时回落到旧版配置 */
|
|
35
35
|
export async function loadSection(service) {
|
|
36
|
+
return (await locateSection(service)).section;
|
|
37
|
+
}
|
|
38
|
+
/** 同 `loadSection`,同时返回配置实际来自哪个文件(回落到旧版配置时不是 `getConfigPath()`) */
|
|
39
|
+
export async function locateSection(service) {
|
|
36
40
|
const section = (await loadProjectConfig())[service];
|
|
37
41
|
if (section && typeof section === "object" && !Array.isArray(section))
|
|
38
|
-
return section;
|
|
42
|
+
return { section, file: getConfigPath() };
|
|
39
43
|
if (service === "note") {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
const file = join(getProjectRoot(), LEGACY_NOTE_CONFIG);
|
|
45
|
+
const legacy = await readJson(file);
|
|
46
|
+
if (legacy && typeof legacy === "object" && !Array.isArray(legacy)) {
|
|
47
|
+
return { section: legacy, file };
|
|
48
|
+
}
|
|
43
49
|
}
|
|
44
|
-
return {};
|
|
50
|
+
return { section: {}, file: getConfigPath() };
|
|
45
51
|
}
|
|
46
52
|
/** 写回某个服务的配置节(其他服务的配置原样保留) */
|
|
47
53
|
export async function saveSection(service, section) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getClient } from "./shared.js";
|
|
2
|
-
import { buildSyncPlan, executeSyncPlan, } from "../sync.js";
|
|
3
|
-
import { resolveSyncMode, resolveOutputDir, setSyncMode, loadUserConfig, loadState, saveState, getUserConfigPath, getStatePath, ALL_MODES, } from "../config.js";
|
|
2
|
+
import { buildSyncPlan, executeSyncPlan, emptyApplied, } from "../sync.js";
|
|
3
|
+
import { resolveSyncMode, resolveOutputDir, setSyncMode, loadUserConfig, loadState, saveState, getUserConfigPath, getStatePath, getEffectiveUserConfigPath, hasLegacyOnlyState, ALL_MODES, } from "../config.js";
|
|
4
4
|
import { isJsonMode, success, logInfo, fail, prompt, EXIT_PARTIAL_FAILURE, } from "../../core/output.js";
|
|
5
5
|
import { createInterface } from "node:readline";
|
|
6
6
|
import { actionForSide } from "../sync-diff.js";
|
|
@@ -45,12 +45,12 @@ export async function syncCommand(opts) {
|
|
|
45
45
|
logInfo(`🔁 同步模式:${mode}(${MODE_DESC[mode]})`);
|
|
46
46
|
const { plan, state, folders, stateChanged } = await buildSyncPlan(client, outputDir, mode, isJsonMode());
|
|
47
47
|
if (plan.length === 0) {
|
|
48
|
-
//
|
|
49
|
-
if (stateChanged && !opts.dryRun) {
|
|
48
|
+
// 首次同步认领了已有本地文件、或旧版状态文件需改存新名字时:虽无动作,但状态需要落盘
|
|
49
|
+
if ((stateChanged || (await hasLegacyOnlyState(outputDir))) && !opts.dryRun) {
|
|
50
50
|
state.lastSync = Date.now();
|
|
51
51
|
await saveState(outputDir, state);
|
|
52
52
|
}
|
|
53
|
-
success(
|
|
53
|
+
success(emptyResult(outputDir, mode, !!opts.dryRun), () => {
|
|
54
54
|
logInfo("✅ 已是最新,无需同步");
|
|
55
55
|
});
|
|
56
56
|
return;
|
|
@@ -135,10 +135,11 @@ export async function syncInitCommand() {
|
|
|
135
135
|
export async function syncStatusCommand(opts) {
|
|
136
136
|
try {
|
|
137
137
|
const config = await loadUserConfig();
|
|
138
|
+
const configFile = await getEffectiveUserConfigPath();
|
|
138
139
|
const outputDir = await resolveOutputDir(opts.output);
|
|
139
140
|
const state = await loadState(outputDir);
|
|
140
|
-
success({ config, outputDir, state }, () => {
|
|
141
|
-
logInfo(`配置文件:${
|
|
141
|
+
success({ configFile, config, outputDir, state }, () => {
|
|
142
|
+
logInfo(`配置文件:${configFile}`);
|
|
142
143
|
logInfo(`同步模式:${config.syncMode ?? "manual(默认)"}`);
|
|
143
144
|
if (config.output)
|
|
144
145
|
logInfo(`默认目录:${config.output}`);
|
|
@@ -160,6 +161,19 @@ export async function syncStatusCommand(opts) {
|
|
|
160
161
|
function describe(it) {
|
|
161
162
|
return SCENARIO_DESC[it.scenario] ?? it.scenario;
|
|
162
163
|
}
|
|
164
|
+
/** 无需同步时的结果:结构与有变更时一致,调用方无需区分两种形态 */
|
|
165
|
+
function emptyResult(outputDir, mode, dryRun) {
|
|
166
|
+
return {
|
|
167
|
+
total: 0,
|
|
168
|
+
applied: emptyApplied(),
|
|
169
|
+
conflicts: [],
|
|
170
|
+
errors: [],
|
|
171
|
+
outputDir,
|
|
172
|
+
mode,
|
|
173
|
+
dryRun,
|
|
174
|
+
plan: [],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
163
177
|
function planSummary(plan) {
|
|
164
178
|
return plan.map((it) => ({
|
|
165
179
|
id: it.id,
|
package/dist/note/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile, rm } from "node:fs/promises";
|
|
2
2
|
import { join, resolve, relative, isAbsolute } from "node:path";
|
|
3
|
-
import { getConfigPath, getDefaultOutputDir as coreDefaultOutputDir, getProjectRoot, loadSection, resolveOutputPath, saveSection, } from "../core/config.js";
|
|
3
|
+
import { getConfigPath, getDefaultOutputDir as coreDefaultOutputDir, getProjectRoot, loadSection, locateSection, resolveOutputPath, saveSection, } from "../core/config.js";
|
|
4
4
|
import { logInfo } from "../core/output.js";
|
|
5
5
|
import { fileExists, writeFileAtomic } from "../core/utils.js";
|
|
6
6
|
/**
|
|
@@ -60,6 +60,10 @@ export async function loadUserConfig() {
|
|
|
60
60
|
fileNameTemplate: typeof raw.fileNameTemplate === "string" ? raw.fileNameTemplate : undefined,
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
+
/** 笔记配置实际来自的文件(没有 note 节而回落到旧版配置时是旧文件) */
|
|
64
|
+
export async function getEffectiveUserConfigPath() {
|
|
65
|
+
return (await locateSection("note")).file;
|
|
66
|
+
}
|
|
63
67
|
/** 写入笔记配置(其他服务的配置原样保留);旧版配置文件从此不再使用,提示可删除 */
|
|
64
68
|
export async function saveUserConfig(cfg) {
|
|
65
69
|
const section = {};
|
|
@@ -106,6 +110,11 @@ export async function loadState(outputDir) {
|
|
|
106
110
|
return emptyState();
|
|
107
111
|
}
|
|
108
112
|
}
|
|
113
|
+
/** output 里是否只有旧版状态文件(需要在下次同步时迁移到新文件名) */
|
|
114
|
+
export async function hasLegacyOnlyState(outputDir) {
|
|
115
|
+
return (!(await fileExists(getStatePath(outputDir))) &&
|
|
116
|
+
(await fileExists(join(outputDir, LEGACY_STATE_FILENAME))));
|
|
117
|
+
}
|
|
109
118
|
/**
|
|
110
119
|
* 原子写回同步状态(自动创建父目录,幂等)。
|
|
111
120
|
* 写成功后移除旧版状态文件,避免两份状态并存、旧版工具读到过期的基线。
|
package/dist/note/sync.js
CHANGED
|
@@ -255,6 +255,20 @@ export async function exportNotes(client, outputDir, force = false, quiet = fals
|
|
|
255
255
|
outputDir,
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
|
+
/** 各动作计数全为 0 */
|
|
259
|
+
export function emptyApplied() {
|
|
260
|
+
return {
|
|
261
|
+
skip: 0,
|
|
262
|
+
"update-local": 0,
|
|
263
|
+
"update-remote": 0,
|
|
264
|
+
"create-local": 0,
|
|
265
|
+
"create-remote": 0,
|
|
266
|
+
"delete-local": 0,
|
|
267
|
+
"delete-remote": 0,
|
|
268
|
+
"drop-state": 0,
|
|
269
|
+
conflict: 0,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
258
272
|
/**
|
|
259
273
|
* 构建同步计划:对每条笔记做 3-way diff 并按 mode 决策动作。
|
|
260
274
|
* 不触碰云端与本地文件;只在内存中修正 state(认领、去重),由调用方决定是否落盘。
|
|
@@ -434,17 +448,7 @@ async function dedupeStatePaths(state, outputDir) {
|
|
|
434
448
|
export async function executeSyncPlan(client, outputDir, mode, plan, state, folders, opts = {}) {
|
|
435
449
|
const { dryRun = false, quiet = false, resolveConflict } = opts;
|
|
436
450
|
const fileNameTemplate = (await loadUserConfig()).fileNameTemplate;
|
|
437
|
-
const applied =
|
|
438
|
-
skip: 0,
|
|
439
|
-
"update-local": 0,
|
|
440
|
-
"update-remote": 0,
|
|
441
|
-
"create-local": 0,
|
|
442
|
-
"create-remote": 0,
|
|
443
|
-
"delete-local": 0,
|
|
444
|
-
"delete-remote": 0,
|
|
445
|
-
"drop-state": 0,
|
|
446
|
-
conflict: 0,
|
|
447
|
-
};
|
|
451
|
+
const applied = emptyApplied();
|
|
448
452
|
const conflicts = [];
|
|
449
453
|
const errors = [];
|
|
450
454
|
let processed = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "micloud-cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "AI-friendly CLI for Xiaomi Cloud (i.mi.com): notes (read, write, sync to Markdown) and recordings (list, download, incremental pull, cleanup), with one login.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|