mirror of
https://github.com/evdboom/Bindery.git
synced 2026-07-22 06:49:36 +00:00
commit
32d815f66c
2 changed files with 28 additions and 21 deletions
|
|
@ -932,21 +932,20 @@ export default class BinderyPlugin extends Plugin {
|
|||
const binderyFolder = path.join(bookPath, BINDERY_FOLDER);
|
||||
const settingsPath = path.join(binderyFolder, SETTINGS_FILENAME);
|
||||
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
return; // already initialised
|
||||
}
|
||||
const isNew = !fs.existsSync(settingsPath);
|
||||
|
||||
// Derive the default book title from the folder name (or vault name for root mode)
|
||||
const vaultName = trimmedBookRoot
|
||||
? path.basename(bookPath)
|
||||
: this.app.vault.getName();
|
||||
try {
|
||||
loadAuthoringTools().toolInitWorkspace(bookPath, {
|
||||
loadAuthoringTools().toolInitWorkspace(bookPath, isNew ? {
|
||||
bookTitle: vaultName,
|
||||
author: '',
|
||||
storyFolder: 'Story',
|
||||
});
|
||||
} : {});
|
||||
} catch {
|
||||
if (!isNew) { return; } // already initialised — skip fallback for re-init
|
||||
fs.mkdirSync(binderyFolder, { recursive: true });
|
||||
const defaultSettings = {
|
||||
bookTitle: vaultName,
|
||||
|
|
|
|||
|
|
@ -295,21 +295,26 @@ async function initWorkspaceCommand(context?: vscode.ExtensionContext) {
|
|||
if (!root) { vscode.window.showErrorMessage('No workspace folder open.'); return; }
|
||||
|
||||
const settingsPath = getSettingsPath(root);
|
||||
let existingSettings: WorkspaceSettings | undefined;
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
const choice = await vscode.window.showQuickPick(
|
||||
[
|
||||
{ label: 'Re-initialize', description: 'Overwrites settings.json (translations.json is kept)', value: true as const },
|
||||
{ label: 'Cancel', value: false as const },
|
||||
{ label: 'Re-initialize', description: 'Merges updates into existing settings; existing values are pre-filled', value: true as const },
|
||||
{ label: 'Cancel', value: false as const },
|
||||
],
|
||||
{ placeHolder: '.bindery/settings.json already exists' }
|
||||
);
|
||||
if (!choice?.value) { return; }
|
||||
try { existingSettings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')) as WorkspaceSettings; }
|
||||
catch { /* corrupt — proceed as new */ }
|
||||
}
|
||||
|
||||
const existingTitle = typeof existingSettings?.bookTitle === 'string' ? existingSettings.bookTitle : undefined;
|
||||
const title = await vscode.window.showInputBox({
|
||||
title: 'Bindery: Initialize (1/4)',
|
||||
prompt: 'Book title',
|
||||
placeHolder: 'e.g. The Hollow Road',
|
||||
value: existingTitle,
|
||||
});
|
||||
if (title === undefined) { return; }
|
||||
|
||||
|
|
@ -317,13 +322,14 @@ async function initWorkspaceCommand(context?: vscode.ExtensionContext) {
|
|||
title: 'Bindery: Initialize (2/4)',
|
||||
prompt: 'Author name',
|
||||
placeHolder: 'e.g. Jane Smith',
|
||||
value: existingSettings?.author,
|
||||
});
|
||||
if (author === undefined) { return; }
|
||||
|
||||
const storyFolder = await vscode.window.showInputBox({
|
||||
title: 'Bindery: Initialize (3/4)',
|
||||
prompt: 'Story folder name (relative to workspace root)',
|
||||
value: 'Story',
|
||||
value: existingSettings?.storyFolder ?? 'Story',
|
||||
});
|
||||
if (!storyFolder) { return; }
|
||||
|
||||
|
|
@ -331,14 +337,15 @@ async function initWorkspaceCommand(context?: vscode.ExtensionContext) {
|
|||
title: 'Bindery: Initialize (4/5)',
|
||||
prompt: 'Target audience (used for AI review feedback)',
|
||||
placeHolder: 'e.g. 12+, adults, 8-10',
|
||||
value: existingSettings?.targetAudience,
|
||||
});
|
||||
if (audience === undefined) { return; }
|
||||
|
||||
const currentFormatOnSave = existingSettings?.formatOnSave ?? false;
|
||||
const formatOption = await vscode.window.showQuickPick(
|
||||
[
|
||||
{ label: 'No', value: false as const },
|
||||
{ label: 'Yes', value: true as const },
|
||||
],
|
||||
currentFormatOnSave
|
||||
? [{ label: 'Yes', value: true as const }, { label: 'No', value: false as const }]
|
||||
: [{ label: 'No', value: false as const }, { label: 'Yes', value: true as const }],
|
||||
{ title: 'Bindery: Initialize (5/5)', placeHolder: 'Auto-apply typography on save (Story folder only)?' }
|
||||
);
|
||||
if (!formatOption) { return; }
|
||||
|
|
@ -366,19 +373,20 @@ async function initWorkspaceCommand(context?: vscode.ExtensionContext) {
|
|||
const languages = detectedLangs.length > 0 ? detectedLangs : [DEFAULT_LANGUAGE];
|
||||
const slug = title.replaceAll(/[^a-zA-Z0-9]+/g, '_').replaceAll(/^_|_$/g, '') || 'Book';
|
||||
settings = {
|
||||
...existingSettings,
|
||||
...(title ? { bookTitle: title } : {}),
|
||||
...(author ? { author } : {}),
|
||||
...(audience ? { targetAudience: audience } : {}),
|
||||
storyFolder,
|
||||
notesFolder: 'Notes',
|
||||
arcFolder: 'Arc',
|
||||
charactersFolder: 'Notes/Characters',
|
||||
sessionFile: 'SESSION.md',
|
||||
preferencesFile: 'PREFERENCES.md',
|
||||
mergedOutputDir: 'Merged',
|
||||
mergeFilePrefix: slug,
|
||||
formatOnSave: false,
|
||||
languages,
|
||||
notesFolder: existingSettings?.notesFolder ?? 'Notes',
|
||||
arcFolder: existingSettings?.arcFolder ?? 'Arc',
|
||||
charactersFolder: existingSettings?.charactersFolder ?? 'Notes/Characters',
|
||||
sessionFile: existingSettings?.sessionFile ?? 'SESSION.md',
|
||||
preferencesFile: existingSettings?.preferencesFile ?? 'PREFERENCES.md',
|
||||
mergedOutputDir: existingSettings?.mergedOutputDir ?? 'Merged',
|
||||
mergeFilePrefix: existingSettings?.mergeFilePrefix ?? slug,
|
||||
formatOnSave: existingSettings?.formatOnSave ?? false,
|
||||
languages: existingSettings?.languages?.length ? existingSettings.languages : languages,
|
||||
};
|
||||
const writeIfMissing = (filePath: string, content: string): void => {
|
||||
if (fs.existsSync(filePath)) { return; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue