refactor: update names, load defaults from package.json

This commit is contained in:
2026-07-15 16:02:30 +05:00
parent 9b27e94d04
commit 4539d39576
13 changed files with 146 additions and 79 deletions
+60
View File
@@ -0,0 +1,60 @@
/**
* Reads extension settings metadata from package.json (single source of truth).
* Defaults / enum for Settings UI live in package.json `contributes.configuration`.
*/
import packageJson from "../package.json";
type ConfigProperty = {
type?: string;
default?: string | number | boolean | string[];
enum?: string[];
description?: string;
};
type PackageJsonShape = {
contributes: {
configuration: {
title: string;
properties: Record<string, ConfigProperty>;
};
};
};
const pkg = packageJson as PackageJsonShape;
const properties = pkg.contributes.configuration.properties;
/** VS Code configuration section (`xboctukFlow` from keys like `xboctukFlow.projectPath`). */
export function getConfigSection(): string {
const firstKey = Object.keys(properties)[0];
if (!firstKey) {
throw new Error("package.json has no contributes.configuration.properties");
}
const dot = firstKey.indexOf(".");
if (dot <= 0) {
throw new Error(`Invalid configuration key: ${firstKey}`);
}
return firstKey.slice(0, dot);
}
export type SettingKey = "projectPath" | "globalPath" | "fileExtension";
function property(key: SettingKey): ConfigProperty {
const fullKey = `${getConfigSection()}.${key}`;
const prop = properties[fullKey];
if (!prop) {
throw new Error(`Missing package.json setting: ${fullKey}`);
}
return prop;
}
/** Default from package.json (same as Settings UI default). */
export function getSettingDefault(key: SettingKey): string {
const value = property(key).default;
if (typeof value === "string") {
return value;
}
if (value === undefined || value === null) {
return "";
}
return String(value);
}
+3 -3
View File
@@ -22,7 +22,7 @@ export function activate(context: vscode.ExtensionContext) {
};
context.subscriptions.push(
vscode.window.registerTreeDataProvider("xboctFlow.tasks", tree),
vscode.window.registerTreeDataProvider("xboctukFlow.tasks", tree),
);
const ext = config.getFileExtension();
@@ -41,8 +41,8 @@ export function activate(context: vscode.ExtensionContext) {
vscode.StatusBarAlignment.Left,
);
statusBarItem.text = "$(checklist) Tasks";
statusBarItem.command = "xboctFlow.openDashboard";
statusBarItem.tooltip = "XBOCT flow — Open Dashboard";
statusBarItem.command = "xboctukFlow.openDashboard";
statusBarItem.tooltip = "XBOCTuK Flow — Open Dashboard";
statusBarItem.show();
context.subscriptions.push(statusBarItem);
+13 -6
View File
@@ -1,5 +1,6 @@
import * as path from "path";
import * as vscode from "vscode";
import { getConfigSection, getSettingDefault } from "@/config";
import { IConfigProvider } from "@/ports";
export class VscodeConfigProvider implements IConfigProvider {
@@ -7,18 +8,24 @@ export class VscodeConfigProvider implements IConfigProvider {
const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
if (!workspaceRoot) return undefined;
const config = vscode.workspace.getConfiguration("xboctFlow");
const relativePath = config.get<string>("projectPath") ?? ".vscode/tasks";
const config = vscode.workspace.getConfiguration(getConfigSection());
// get() already merges package.json defaults; fallback for safety.
const relativePath =
config.get<string>("projectPath") ?? getSettingDefault("projectPath");
return path.join(workspaceRoot, relativePath);
}
getGlobalTaskPath(): string | undefined {
const config = vscode.workspace.getConfiguration("xboctFlow");
return config.get<string>("globalPath") || undefined;
const config = vscode.workspace.getConfiguration(getConfigSection());
const globalPath =
config.get<string>("globalPath") ?? getSettingDefault("globalPath");
return globalPath || undefined;
}
getFileExtension(): string {
const config = vscode.workspace.getConfiguration("xboctFlow");
return config.get<string>("fileExtension") ?? ".task.md";
const config = vscode.workspace.getConfiguration(getConfigSection());
return (
config.get<string>("fileExtension") ?? getSettingDefault("fileExtension")
);
}
}
+7 -7
View File
@@ -226,27 +226,27 @@ export function registerTaskCommands(
deps: TaskCommandDeps,
): void {
context.subscriptions.push(
vscode.commands.registerCommand("xboctFlow.createTask", () =>
vscode.commands.registerCommand("xboctukFlow.createTask", () =>
runCreateTask(deps),
),
vscode.commands.registerCommand("xboctFlow.openTask", (item?: unknown) =>
vscode.commands.registerCommand("xboctukFlow.openTask", (item?: unknown) =>
runOpenTask(deps, item),
),
vscode.commands.registerCommand("xboctFlow.deleteTask", (item?: unknown) =>
vscode.commands.registerCommand("xboctukFlow.deleteTask", (item?: unknown) =>
runDeleteTask(deps, item),
),
vscode.commands.registerCommand(
"xboctFlow.changeStatus",
"xboctukFlow.changeStatus",
(item?: unknown) => runChangeStatus(deps, item),
),
vscode.commands.registerCommand("xboctFlow.openDashboard", () =>
vscode.commands.registerCommand("xboctukFlow.openDashboard", () =>
runOpenDashboard(deps),
),
vscode.commands.registerCommand(
"xboctFlow.openInDashboard",
"xboctukFlow.openInDashboard",
(item?: unknown) => runOpenInDashboard(deps, item),
),
vscode.commands.registerCommand("xboctFlow.openKanban", () =>
vscode.commands.registerCommand("xboctukFlow.openKanban", () =>
runOpenKanban(deps),
),
);
+3 -3
View File
@@ -56,8 +56,8 @@ export class TaskDashboardPanel {
}
const panel = vscode.window.createWebviewPanel(
"xboctFlow.dashboard",
"XBOCT flow",
"xboctukFlow.dashboard",
"XBOCTuK Flow",
vscode.ViewColumn.One,
{
enableScripts: true,
@@ -181,7 +181,7 @@ export class TaskDashboardPanel {
return;
case "createTask":
await vscode.commands.executeCommand("xboctFlow.createTask");
await vscode.commands.executeCommand("xboctukFlow.createTask");
await this.reloadTasks();
return;
}
+2 -2
View File
@@ -39,8 +39,8 @@ export class TaskKanbanPanel {
}
const panel = vscode.window.createWebviewPanel(
"xboctFlow.kanban",
"XBOCT flow — Kanban",
"xboctukFlow.kanban",
"XBOCTuK Flow — Kanban",
vscode.ViewColumn.One,
{
enableScripts: true,
+1 -1
View File
@@ -21,7 +21,7 @@ export class TaskTreeItem extends vscode.TreeItem {
}`,
);
this.command = {
command: "xboctFlow.openTask",
command: "xboctukFlow.openTask",
title: "Open Task",
arguments: [this],
};