Skip to content

Commit 77be328

Browse files
committed
Merge branch 'release/v0.7.0'
1 parent ac66a5f commit 77be328

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/cli/commands/apply.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function applyCommand(options: ApplyOptions): Promise<void> {
2222
}
2323

2424
// Read existing settings
25-
const existing = await readSettings();
25+
const existing = await readSettings(options.local);
2626

2727
// Create merge preview
2828
const { merged, changes } = createMultipleMergePreview(
@@ -32,7 +32,8 @@ export async function applyCommand(options: ApplyOptions): Promise<void> {
3232
);
3333

3434
// Display preview
35-
console.log("\n📋 適用予定の変更:");
35+
const settingsType = options.local ? "ローカル設定" : "共有設定";
36+
console.log(`\n📋 適用予定の変更 (${settingsType}):`);
3637
if (changes.added.length > 0) {
3738
console.log("\n🆕 追加される設定:");
3839
changes.added.forEach((change) => {
@@ -80,7 +81,7 @@ export async function applyCommand(options: ApplyOptions): Promise<void> {
8081
// Create backup if requested
8182
if (options.backup && existing) {
8283
try {
83-
const backupPath = await createBackup();
84+
const backupPath = await createBackup(options.local);
8485
console.log(`💾 バックアップを作成しました: ${backupPath}`);
8586
} catch (error) {
8687
const message = error instanceof Error ? error.message : String(error);
@@ -89,8 +90,11 @@ export async function applyCommand(options: ApplyOptions): Promise<void> {
8990
}
9091

9192
// Apply settings
92-
await writeSettings(merged);
93-
console.log("✅ 設定が正常に適用されました!");
93+
await writeSettings(merged, options.local);
94+
const successMessage = options.local
95+
? "✅ ローカル設定が正常に適用されました!"
96+
: "✅ 設定が正常に適用されました!";
97+
console.log(successMessage);
9498
} catch (error) {
9599
const message = error instanceof Error ? error.message : String(error);
96100
console.error("❌ エラーが発生しました:", message);

src/cli/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export async function main(): Promise<void> {
2020
.option("-u, --url <url>", "Apply settings from URLs (can be specified multiple times)")
2121
.option("--dry-run", "Preview changes without applying them")
2222
.option("--backup", "Create a backup before applying changes")
23-
.option("--force", "Apply changes without confirmation");
23+
.option("--force", "Apply changes without confirmation")
24+
.option("--local", "Apply settings to .claude/settings.local.json instead of settings.json");
2425

2526
// Custom parsing for multiple templates
2627
let multipleTemplates: string[] | undefined;

src/core/settings.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ClaudeSettings } from "../types/index.js";
55

66
const SETTINGS_DIR = ".claude";
77
const SETTINGS_FILE = "settings.json";
8+
const LOCAL_SETTINGS_FILE = "settings.local.json";
89

910
export async function findClaudeDirectory(): Promise<string | null> {
1011
let currentDir = process.cwd();
@@ -26,22 +27,23 @@ export async function findClaudeDirectory(): Promise<string | null> {
2627
return null;
2728
}
2829

29-
export async function getSettingsPath(): Promise<string> {
30+
export async function getSettingsPath(isLocal?: boolean): Promise<string> {
3031
const claudeDir = await findClaudeDirectory();
32+
const fileName = isLocal ? LOCAL_SETTINGS_FILE : SETTINGS_FILE;
3133

3234
if (!claudeDir) {
3335
// If no .claude directory found, create one in current directory
3436
const currentClaudeDir = join(process.cwd(), SETTINGS_DIR);
3537
await fs.mkdir(currentClaudeDir, { recursive: true });
36-
return join(currentClaudeDir, SETTINGS_FILE);
38+
return join(currentClaudeDir, fileName);
3739
}
3840

39-
return join(claudeDir, SETTINGS_FILE);
41+
return join(claudeDir, fileName);
4042
}
4143

42-
export async function readSettings(): Promise<ClaudeSettings | null> {
44+
export async function readSettings(isLocal?: boolean): Promise<ClaudeSettings | null> {
4345
try {
44-
const settingsPath = await getSettingsPath();
46+
const settingsPath = await getSettingsPath(isLocal);
4547
const content = await fs.readFile(settingsPath, "utf-8");
4648
const data = JSON.parse(content);
4749
return ClaudeSettingsSchema.parse(data);
@@ -53,14 +55,14 @@ export async function readSettings(): Promise<ClaudeSettings | null> {
5355
}
5456
}
5557

56-
export async function writeSettings(settings: ClaudeSettings): Promise<void> {
57-
const settingsPath = await getSettingsPath();
58+
export async function writeSettings(settings: ClaudeSettings, isLocal?: boolean): Promise<void> {
59+
const settingsPath = await getSettingsPath(isLocal);
5860
const validated = ClaudeSettingsSchema.parse(settings);
5961
await fs.writeFile(settingsPath, JSON.stringify(validated, null, 2), "utf-8");
6062
}
6163

62-
export async function createBackup(): Promise<string> {
63-
const settingsPath = await getSettingsPath();
64+
export async function createBackup(isLocal?: boolean): Promise<string> {
65+
const settingsPath = await getSettingsPath(isLocal);
6466
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
6567
const backupPath = settingsPath.replace(".json", `.backup-${timestamp}.json`);
6668

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ApplyOptions {
1414
dryRun?: boolean;
1515
backup?: boolean;
1616
force?: boolean;
17+
local?: boolean;
1718
}
1819

1920
export interface TemplateSource {

0 commit comments

Comments
 (0)