@waterwx/dsh-novel-forge 0.1.0 → 1.0.0-alpha
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 +162 -111
- package/cordis.patch.yml +1 -1
- package/lib/client.js +54165 -2666
- package/lib/index.js +11895 -2211
- package/lib/types/ai-scan.d.ts +36 -0
- package/lib/types/assets.d.ts +19 -4
- package/lib/types/assistant.d.ts +6 -0
- package/lib/types/author-assets.d.ts +25 -0
- package/lib/types/bookshelf.d.ts +8 -1
- package/lib/types/client/api.d.ts +235 -3
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/llmLive.d.ts +33 -0
- package/lib/types/client/locales.d.ts +101 -28
- package/lib/types/client/panel/AdaptModeView.d.ts +5 -0
- package/lib/types/client/panel/AssetsTab.d.ts +6 -1
- package/lib/types/client/panel/AuthorAssetsView.d.ts +4 -0
- package/lib/types/client/panel/AuthorHome.d.ts +34 -0
- package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
- package/lib/types/client/panel/CreateBookView.d.ts +13 -0
- package/lib/types/client/panel/DirectorView.d.ts +7 -0
- package/lib/types/client/panel/FlowGuide.d.ts +22 -0
- package/lib/types/client/panel/GlobalAssetLibraryView.d.ts +4 -0
- package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
- package/lib/types/client/panel/ImportModal.d.ts +7 -0
- package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
- package/lib/types/client/panel/LiveFeedLog.d.ts +5 -0
- package/lib/types/client/panel/MangaRoleLibrary.d.ts +20 -0
- package/lib/types/client/panel/MangaWorkspace.d.ts +12 -0
- package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
- package/lib/types/client/panel/ModelManager.d.ts +14 -0
- package/lib/types/client/panel/ModelPicker.d.ts +11 -0
- package/lib/types/client/panel/NovelPanel.d.ts +1 -1
- package/lib/types/client/panel/ProgressConsole.d.ts +17 -0
- package/lib/types/client/panel/ProgressHomeView.d.ts +5 -0
- package/lib/types/client/panel/PropLibrary.d.ts +8 -0
- package/lib/types/client/panel/ReaderView.d.ts +8 -0
- package/lib/types/client/panel/ReasoningSection.d.ts +10 -0
- package/lib/types/client/panel/RunPanel.d.ts +5 -0
- package/lib/types/client/panel/SceneLibrary.d.ts +16 -0
- package/lib/types/client/panel/SettingsView.d.ts +16 -0
- package/lib/types/client/panel/ShelfView.d.ts +15 -0
- package/lib/types/client/panel/StoryboardTab.d.ts +19 -0
- package/lib/types/client/panel/StyleCard.d.ts +8 -0
- package/lib/types/client/panel/StyleGallery.d.ts +1 -0
- package/lib/types/client/panel/WorldTab.d.ts +10 -0
- package/lib/types/client/panel/helpers.d.ts +10 -0
- package/lib/types/client/panel/views.d.ts +77 -0
- package/lib/types/client/run-status.d.ts +19 -0
- package/lib/types/client/text.d.ts +9 -0
- package/lib/types/comic-presets.d.ts +12 -0
- package/lib/types/engine.d.ts +250 -8
- package/lib/types/global-assets.d.ts +6 -0
- package/lib/types/index.d.ts +24 -2
- package/lib/types/llm-live.d.ts +44 -0
- package/lib/types/manga-genre-rules.d.ts +22 -0
- package/lib/types/market-radar-scan.d.ts +19 -0
- package/lib/types/market-radar-sources.d.ts +31 -0
- package/lib/types/novel-context.d.ts +80 -0
- package/lib/types/prompt-utils.d.ts +35 -0
- package/lib/types/prompting.d.ts +35 -0
- package/lib/types/protocol.d.ts +1453 -5
- package/lib/types/review-policy.d.ts +97 -0
- package/lib/types/run.d.ts +32 -0
- package/lib/types/shot-language.d.ts +46 -0
- package/lib/types/src/ai-scan.d.ts +36 -0
- package/lib/types/src/assets.d.ts +37 -0
- package/lib/types/src/assistant.d.ts +45 -0
- package/lib/types/src/author-assets.d.ts +25 -0
- package/lib/types/src/bookshelf.d.ts +42 -0
- package/lib/types/src/client/api.d.ts +234 -0
- package/lib/types/src/client/docx.d.ts +15 -0
- package/lib/types/src/client/index.d.ts +14 -0
- package/lib/types/src/client/locales.d.ts +212 -0
- package/lib/types/src/client/mount.d.ts +9 -0
- package/lib/types/src/client/panel/AdaptModeView.d.ts +5 -0
- package/lib/types/src/client/panel/AssetsTab.d.ts +12 -0
- package/lib/types/src/client/panel/AssistantTab.d.ts +7 -0
- package/lib/types/src/client/panel/AuthorAssetsView.d.ts +4 -0
- package/lib/types/src/client/panel/AuthorHome.d.ts +32 -0
- package/lib/types/src/client/panel/BookshelfBar.d.ts +11 -0
- package/lib/types/src/client/panel/CreateBookView.d.ts +9 -0
- package/lib/types/src/client/panel/FlowGuide.d.ts +22 -0
- package/lib/types/src/client/panel/GlobalAssetLibraryView.d.ts +4 -0
- package/lib/types/src/client/panel/ImportModal.d.ts +7 -0
- package/lib/types/src/client/panel/MangaRoleLibrary.d.ts +20 -0
- package/lib/types/src/client/panel/MangaWorkspace.d.ts +12 -0
- package/lib/types/src/client/panel/ModelManager.d.ts +14 -0
- package/lib/types/src/client/panel/NovelPanel.d.ts +13 -0
- package/lib/types/src/client/panel/ProgressConsole.d.ts +17 -0
- package/lib/types/src/client/panel/ProgressHomeView.d.ts +5 -0
- package/lib/types/src/client/panel/PropLibrary.d.ts +8 -0
- package/lib/types/src/client/panel/ReaderView.d.ts +8 -0
- package/lib/types/src/client/panel/ReasoningSection.d.ts +10 -0
- package/lib/types/src/client/panel/RunPanel.d.ts +5 -0
- package/lib/types/src/client/panel/SceneLibrary.d.ts +16 -0
- package/lib/types/src/client/panel/SettingsView.d.ts +16 -0
- package/lib/types/src/client/panel/ShelfView.d.ts +15 -0
- package/lib/types/src/client/panel/StoryboardTab.d.ts +19 -0
- package/lib/types/src/client/panel/StyleCard.d.ts +8 -0
- package/lib/types/src/client/panel/StyleGallery.d.ts +1 -0
- package/lib/types/src/client/panel/WorldTab.d.ts +10 -0
- package/lib/types/src/client/panel/controller.d.ts +19 -0
- package/lib/types/src/client/panel/helpers.d.ts +18 -0
- package/lib/types/src/client/panel/views.d.ts +77 -0
- package/lib/types/src/client/sidebar-entry.d.ts +13 -0
- package/lib/types/src/client/text.d.ts +9 -0
- package/lib/types/src/comic-presets.d.ts +12 -0
- package/lib/types/src/docx.d.ts +19 -0
- package/lib/types/src/engine.d.ts +402 -0
- package/lib/types/src/index.d.ts +79 -0
- package/lib/types/src/manga-genre-rules.d.ts +22 -0
- package/lib/types/src/novel-context.d.ts +80 -0
- package/lib/types/src/prompt-utils.d.ts +35 -0
- package/lib/types/src/protocol.d.ts +2176 -0
- package/lib/types/src/review-policy.d.ts +97 -0
- package/lib/types/src/routes.d.ts +29 -0
- package/lib/types/src/run.d.ts +32 -0
- package/lib/types/src/shot-language.d.ts +46 -0
- package/lib/types/src/story-beat-language.d.ts +35 -0
- package/lib/types/src/style-library.d.ts +33 -0
- package/lib/types/story-beat-language.d.ts +35 -0
- package/lib/types/style-library.d.ts +33 -0
- package/package.json +57 -42
- package/scripts/patch-schemastery.mjs +47 -0
- package/src/ai-scan.ts +179 -0
- package/src/assets.ts +1774 -518
- package/src/assistant.ts +915 -547
- package/src/author-assets.ts +147 -0
- package/src/bookshelf.ts +32 -2
- package/src/client/api.ts +666 -254
- package/src/client/index.ts +3 -1
- package/src/client/llmLive.ts +101 -0
- package/src/client/locales.ts +178 -31
- package/src/client/mount.tsx +1 -1
- package/src/client/panel/AdaptModeView.tsx +535 -0
- package/src/client/panel/AssetsTab.tsx +168 -51
- package/src/client/panel/AssistantTab.tsx +339 -188
- package/src/client/panel/AuthorAssetsView.tsx +208 -0
- package/src/client/panel/AuthorHome.tsx +234 -0
- package/src/client/panel/BookAnalysisView.tsx +60 -0
- package/src/client/panel/BookshelfBar.tsx +63 -9
- package/src/client/panel/CreateBookView.tsx +371 -0
- package/src/client/panel/DirectorView.tsx +200 -0
- package/src/client/panel/GlobalAssetLibraryView.tsx +172 -0
- package/src/client/panel/IdeaInspirationView.tsx +71 -0
- package/src/client/panel/ImportModal.tsx +303 -0
- package/src/client/panel/KnowledgeBaseView.tsx +73 -0
- package/src/client/panel/LiveFeedLog.tsx +67 -0
- package/src/client/panel/MarketRadarView.tsx +374 -0
- package/src/client/panel/ModelManager.tsx +205 -0
- package/src/client/panel/NovelPanel.tsx +4713 -990
- package/src/client/panel/ProgressConsole.tsx +63 -0
- package/src/client/panel/ProgressHomeView.tsx +87 -0
- package/src/client/panel/ReaderView.tsx +306 -0
- package/src/client/panel/ReasoningSection.tsx +31 -0
- package/src/client/panel/RunPanel.tsx +204 -0
- package/src/client/panel/SettingsView.tsx +265 -0
- package/src/client/panel/ShelfView.tsx +242 -0
- package/src/client/panel/WorldTab.tsx +202 -0
- package/src/client/panel/helpers.ts +50 -0
- package/src/client/panel/panel.module.css +4325 -526
- package/src/client/panel/views.tsx +346 -0
- package/src/client/run-status.ts +100 -0
- package/src/client/sidebar-entry.ts +1 -1
- package/src/client/text.ts +28 -0
- package/src/engine.ts +4230 -1019
- package/src/global-assets.ts +59 -0
- package/src/index.ts +123 -9
- package/src/llm-live.ts +68 -0
- package/src/market-radar-scan.ts +41 -0
- package/src/market-radar-sources.ts +173 -0
- package/src/novel-context.ts +287 -0
- package/src/prompt-utils.ts +73 -0
- package/src/prompting.ts +159 -0
- package/src/protocol.ts +1998 -539
- package/src/review-policy.ts +161 -0
- package/src/routes.ts +3277 -955
- package/src/run.ts +338 -0
- package/lib/client.js.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 作者资产库/总数据(跨书)— 按作者维度聚合的可复用资产。
|
|
3
|
+
* 与书架同惯例持久化到 ~/.dsh/dsh-novel-forge-author-assets.json。
|
|
4
|
+
* 提供读取/持久化/新增或更新/删除,以及「导入默认」:把书架书的写作资产/角色 +
|
|
5
|
+
* 内置全局库(题材/反AI规则/风格模板/推进模式)批量沉淀成资产条目(默认库)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
9
|
+
import { homedir } from 'node:os'
|
|
10
|
+
import { join } from 'node:path'
|
|
11
|
+
import { randomBytes } from 'node:crypto'
|
|
12
|
+
import type { AuthorAssetLibrary, AuthorStyleAsset, GenreNode, AntiAiRule, StyleTemplate, ProgressionMode } from './protocol.ts'
|
|
13
|
+
|
|
14
|
+
import { loadBookshelf } from './bookshelf.ts'
|
|
15
|
+
import { loadProject } from './engine.ts'
|
|
16
|
+
|
|
17
|
+
/** 作者资产库配置文件路径。 */
|
|
18
|
+
export function authorAssetsFile(): string {
|
|
19
|
+
return join(homedir(), '.dsh', 'dsh-novel-forge-author-assets.json')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 默认空资产库。 */
|
|
23
|
+
function defaultLibrary(): AuthorAssetLibrary {
|
|
24
|
+
return { version: 1, items: [] }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 读取作者资产库(不存在/损坏则返回空库,不抛错)。 */
|
|
28
|
+
export function loadAuthorAssets(): AuthorAssetLibrary {
|
|
29
|
+
const file = authorAssetsFile()
|
|
30
|
+
if (!existsSync(file)) return defaultLibrary()
|
|
31
|
+
try {
|
|
32
|
+
let raw = readFileSync(file, 'utf8')
|
|
33
|
+
if (raw.charCodeAt(0) === 0xFEFF) raw = raw.slice(1)
|
|
34
|
+
const parsed = JSON.parse(raw) as Partial<AuthorAssetLibrary>
|
|
35
|
+
if (!Array.isArray(parsed.items)) return defaultLibrary()
|
|
36
|
+
return { version: 1, items: parsed.items }
|
|
37
|
+
} catch {
|
|
38
|
+
return defaultLibrary()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 持久化作者资产库。 */
|
|
43
|
+
export function saveAuthorAssets(library: AuthorAssetLibrary): void {
|
|
44
|
+
const file = authorAssetsFile()
|
|
45
|
+
mkdirSync(join(homedir(), '.dsh'), { recursive: true })
|
|
46
|
+
writeFileSync(file, JSON.stringify(library, null, 2), 'utf8')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 新建一条资产(自动生成 id 与时间戳)。 */
|
|
50
|
+
export function createAuthorAsset(input: Omit<AuthorStyleAsset, 'id' | 'createdAt' | 'updatedAt'>): AuthorStyleAsset {
|
|
51
|
+
const now = new Date().toISOString()
|
|
52
|
+
const asset: AuthorStyleAsset = {
|
|
53
|
+
...input,
|
|
54
|
+
id: 'aa-' + Date.now().toString(36) + '-' + randomBytes(3).toString('hex'),
|
|
55
|
+
sourceBooks: input.sourceBooks ?? [],
|
|
56
|
+
tags: input.tags ?? [],
|
|
57
|
+
createdAt: now,
|
|
58
|
+
updatedAt: now,
|
|
59
|
+
}
|
|
60
|
+
const library = loadAuthorAssets()
|
|
61
|
+
library.items.push(asset)
|
|
62
|
+
saveAuthorAssets(library)
|
|
63
|
+
return asset
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 按 id 更新一条资产;不存在则追加。 */
|
|
67
|
+
export function upsertAuthorAsset(input: AuthorStyleAsset): AuthorAssetLibrary {
|
|
68
|
+
const library = loadAuthorAssets()
|
|
69
|
+
const idx = library.items.findIndex(a => a.id === input.id)
|
|
70
|
+
const now = new Date().toISOString()
|
|
71
|
+
if (idx >= 0) {
|
|
72
|
+
const prev = library.items[idx]
|
|
73
|
+
if (prev !== undefined) {
|
|
74
|
+
library.items[idx] = {
|
|
75
|
+
...prev,
|
|
76
|
+
...input,
|
|
77
|
+
id: prev.id,
|
|
78
|
+
createdAt: prev.createdAt,
|
|
79
|
+
updatedAt: now,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
library.items.push({ ...input, createdAt: input.createdAt !== '' ? input.createdAt : now, updatedAt: now })
|
|
84
|
+
}
|
|
85
|
+
saveAuthorAssets(library)
|
|
86
|
+
return library
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 删除一条资产;返回更新后的资产库。 */
|
|
90
|
+
export function removeAuthorAsset(id: string): AuthorAssetLibrary {
|
|
91
|
+
const library = loadAuthorAssets()
|
|
92
|
+
library.items = library.items.filter(a => a.id !== id)
|
|
93
|
+
saveAuthorAssets(library)
|
|
94
|
+
return library
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 导入默认:把书架所有书的写作资产/角色 + 内置全局库批量沉淀到作者资产库。
|
|
99
|
+
* 按 `kind:name` 去重(已存在则跳过),不覆盖用户已有条目。
|
|
100
|
+
* @returns 更新后的资产库。
|
|
101
|
+
*/
|
|
102
|
+
export function importDefaultAuthorAssets(): AuthorAssetLibrary {
|
|
103
|
+
const library = loadAuthorAssets()
|
|
104
|
+
const seen = new Set(library.items.map(a => a.kind + ':' + a.name))
|
|
105
|
+
const now = new Date().toISOString()
|
|
106
|
+
const push = (kind: AuthorStyleAsset['kind'], name: string, summary: string, content: string, tags: string[], sourceBooks: string[], structured?: Record<string, unknown>): void => {
|
|
107
|
+
const key = kind + ':' + name.trim()
|
|
108
|
+
if (name.trim() === '' || seen.has(key)) return
|
|
109
|
+
seen.add(key)
|
|
110
|
+
library.items.push({
|
|
111
|
+
id: 'aa-' + Date.now().toString(36) + '-' + randomBytes(3).toString('hex'),
|
|
112
|
+
kind, name: name.trim(), summary: summary.trim(), content: content.trim(),
|
|
113
|
+
sourceBooks, tags, structured, createdAt: now, updatedAt: now,
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// 1) 清理内置公共库重复沉淀:作者库只保留个人沉淀,不再收录内置公共资产。
|
|
118
|
+
const builtinKinds = new Set<AuthorStyleAsset['kind']>(['genre', 'antiAi', 'progression', 'style', 'plotBeat'])
|
|
119
|
+
library.items = library.items.filter(a => !(a.tags.includes('内置') && builtinKinds.has(a.kind) && (a.sourceBooks ?? []).length === 0))
|
|
120
|
+
|
|
121
|
+
// 2) 书架里的书:写作资产 + 角色模板
|
|
122
|
+
const shelf = loadBookshelf()
|
|
123
|
+
for (const book of shelf.books) {
|
|
124
|
+
const project = loadProject(book.outputDir)
|
|
125
|
+
if (project === undefined) continue
|
|
126
|
+
const src = [project.bookName]
|
|
127
|
+
const assets = project.assets
|
|
128
|
+
if (assets !== undefined) {
|
|
129
|
+
if (assets.genre !== undefined) push('genre', assets.genre.name, assets.genre.description, assets.genre.description, ['书', '题材'], src, { description: assets.genre.description });
|
|
130
|
+
if (assets.primaryProgression !== undefined) push('progression', assets.primaryProgression.name, assets.primaryProgression.driver, '驱动:' + assets.primaryProgression.driver + '\n期待:' + assets.primaryProgression.readerExpectation, src, [], { driver: assets.primaryProgression.driver, primary: true });
|
|
131
|
+
for (const p of assets.auxiliaryProgressions ?? []) push('progression', p.name, p.driver, '驱动:' + p.driver + '\n期待:' + p.readerExpectation, src, [], { driver: p.driver, primary: false });
|
|
132
|
+
for (const r of assets.antiAiRules ?? []) push('antiAi', r.name, r.avoid, '避免:' + r.avoid + '\n修正:' + r.fix, src, [], { avoid: r.avoid, fix: r.fix, detectPatterns: r.detectPatterns });
|
|
133
|
+
for (const s of assets.styleAssets ?? []) push('style', s.name, s.proseRules.join(';'),
|
|
134
|
+
'叙述:' + s.proseRules.join(';') + '\n台词:' + s.dialogueRules.join(';') + '\n描写:' + s.descriptionRules.join(';') + '\n边界:' + s.boundaries.join(';'), src, [], { sourceText: s.sourceText });
|
|
135
|
+
}
|
|
136
|
+
// 作者库角色模板只收男主/女主(可复用原型),其余角色/路人不入库,避免刷屏。
|
|
137
|
+
for (const role of project.roles ?? []) {
|
|
138
|
+
if (role.roleLabel !== 'protagonist' && role.roleLabel !== 'female_lead') continue
|
|
139
|
+
const persona = ('定位:' + role.roleLabel + '\n身份:' + role.identity + '\n性格:' + role.traits.join('、') + '\n目标:' + role.goals + '\n关系:' + role.relations.join('、') + '\n成长线:' + (role.arc.length > 0 ? role.arc.join(' > ') : '—') + '\n知情度:' + role.knowledge.join('、')).trim();
|
|
140
|
+
push('roleTemplate', role.name, role.identity, persona, src, [], { roleLabel: role.roleLabel, traits: role.traits, relations: role.relations, arc: role.arc, knowledge: role.knowledge });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
saveAuthorAssets(library)
|
|
145
|
+
return library
|
|
146
|
+
}
|
|
147
|
+
|
package/src/bookshelf.ts
CHANGED
|
@@ -57,11 +57,14 @@ export function bookshelfSnapshot(store: BookshelfStore): BookshelfSnapshot {
|
|
|
57
57
|
books: store.books.map(book => {
|
|
58
58
|
const project = loadProject(book.outputDir)
|
|
59
59
|
const done = project === undefined ? 0 : project.chapters.filter(c => c.status === 'approved' || c.status === 'written' || c.status === 'rejected').length
|
|
60
|
+
const hasCover = project?.coverPath !== undefined && project.coverPath !== '' && existsSync(join(book.outputDir, project.coverPath))
|
|
60
61
|
return {
|
|
61
62
|
...book,
|
|
62
63
|
done,
|
|
63
64
|
total: project?.chapters.length ?? 0,
|
|
64
65
|
hasProject: project !== undefined,
|
|
66
|
+
hasCover,
|
|
67
|
+
blurb: project?.blurb,
|
|
65
68
|
}
|
|
66
69
|
}),
|
|
67
70
|
activeBookId: store.activeBookId,
|
|
@@ -80,6 +83,17 @@ export function createBook(bookName: string, outputDir: string): BookEntry {
|
|
|
80
83
|
return book
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
/** 更新某本书的书名(开书向导导入大纲后书名以大纲首行为准)。 */
|
|
87
|
+
export function renameBook(id: string, bookName: string): boolean {
|
|
88
|
+
const store = loadBookshelf()
|
|
89
|
+
const book = store.books.find(b => b.id === id)
|
|
90
|
+
if (book === undefined) return false
|
|
91
|
+
book.bookName = bookName
|
|
92
|
+
book.updatedAt = new Date().toISOString()
|
|
93
|
+
saveBookshelf(store)
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
/**
|
|
84
98
|
* 播种:书架为空时,把指定输出目录下已有的项目自动登记为第一本书。
|
|
85
99
|
* 兼容升级场景 —— 旧版插件直接在输出目录写项目,从未登记书架。
|
|
@@ -100,6 +114,22 @@ export function seedBookshelfFromOutputDir(outputDir: string): boolean {
|
|
|
100
114
|
return true
|
|
101
115
|
}
|
|
102
116
|
|
|
117
|
+
/** 导入已有项目目录到书架:校验 novel-project.json,已存在则直接激活。 */
|
|
118
|
+
export function importDir(outputDir: string): { book: BookEntry; existed: boolean } {
|
|
119
|
+
const project = loadProject(outputDir)
|
|
120
|
+
if (project === undefined) throw new Error(`目录中未找到有效的 novel-project.json:${outputDir}`)
|
|
121
|
+
const store = loadBookshelf()
|
|
122
|
+
const existed = store.books.find(b => b.outputDir === outputDir)
|
|
123
|
+
if (existed !== undefined) {
|
|
124
|
+
store.activeBookId = existed.id
|
|
125
|
+
saveBookshelf(store)
|
|
126
|
+
return { book: existed, existed: true }
|
|
127
|
+
}
|
|
128
|
+
const bookName = project.bookName !== '' ? project.bookName : (outputDir.split(/[\\/]/).pop() ?? '未命名小说')
|
|
129
|
+
const book = createBook(bookName, outputDir)
|
|
130
|
+
return { book, existed: false }
|
|
131
|
+
}
|
|
132
|
+
|
|
103
133
|
/** 激活一本书。 */
|
|
104
134
|
export function activateBook(id: string): BookEntry | undefined {
|
|
105
135
|
const store = loadBookshelf()
|
|
@@ -130,8 +160,8 @@ export function activeBookOutputDir(): string | undefined {
|
|
|
130
160
|
return book?.outputDir
|
|
131
161
|
}
|
|
132
162
|
|
|
133
|
-
/**
|
|
163
|
+
/** 默认输出目录推断:~/.dsh/novels/书名。 */
|
|
134
164
|
export function defaultOutputDirFor(bookName: string): string {
|
|
135
165
|
const clean = bookName.replace(/[\\/:*?"<>|]/g, '').trim().slice(0, 40) || '未命名小说'
|
|
136
|
-
return join(homedir(), '
|
|
166
|
+
return join(homedir(), '.dsh', 'novels', clean)
|
|
137
167
|
}
|