Skip to content

Commit 465e296

Browse files
committed
more cleanup
1 parent 7ed5503 commit 465e296

28 files changed

+390
-1323
lines changed

packages/cli/src/commands/config.ts

Lines changed: 3 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import {
22
createDefaultUserConfig,
3-
generateBranchName,
4-
loadRepoConfig,
53
loadUserConfig,
6-
saveRepoConfig,
74
saveUserConfig,
85
} from "@array/core";
9-
import { bold, cyan, dim, green, yellow } from "../utils/output";
10-
import { confirm, input, select } from "../utils/prompt";
6+
import { bold, dim, green, yellow } from "../utils/output";
7+
import { confirm, select } from "../utils/prompt";
118

12-
type ConfigSection = "tips" | "trunk" | "branch" | "reset";
9+
type ConfigSection = "tips" | "reset";
1310

1411
export async function config(): Promise<void> {
1512
console.log();
@@ -20,8 +17,6 @@ export async function config(): Promise<void> {
2017
"What would you like to configure?",
2118
[
2219
{ label: "Tips & hints", value: "tips" },
23-
{ label: "Branch naming", value: "branch" },
24-
{ label: "Trunk branch", value: "trunk" },
2520
{ label: "Reset all settings", value: "reset" },
2621
],
2722
);
@@ -37,12 +32,6 @@ export async function config(): Promise<void> {
3732
case "tips":
3833
await configureTips();
3934
break;
40-
case "branch":
41-
await configureBranch();
42-
break;
43-
case "trunk":
44-
await configureTrunk();
45-
break;
4635
case "reset":
4736
await resetConfig();
4837
break;
@@ -88,124 +77,10 @@ async function configureTips(): Promise<void> {
8877
}
8978
}
9079

91-
async function configureBranch(): Promise<void> {
92-
const userConfig = await loadUserConfig();
93-
const branch = userConfig.branch;
94-
95-
console.log(`${bold("Branch Naming")}`);
96-
console.log();
97-
console.log(` ${dim("Prefix:")} ${cyan(branch.prefix)}`);
98-
console.log(
99-
` ${dim("Include date:")} ${branch.includeDate ? green("yes") : "no"}`,
100-
);
101-
console.log(
102-
` ${dim("Include username:")} ${branch.includeUsername ? green("yes") : "no"}`,
103-
);
104-
console.log();
105-
console.log(` ${dim("Example:")} ${cyan(generateExampleBranch(branch))}`);
106-
console.log();
107-
108-
const action = await select("What would you like to change?", [
109-
{ label: "Change prefix", value: "prefix" },
110-
{
111-
label: branch.includeDate
112-
? "Disable date in branch"
113-
: "Include date in branch",
114-
value: "date",
115-
},
116-
{
117-
label: branch.includeUsername
118-
? "Disable username in branch"
119-
: "Include username in branch",
120-
value: "username",
121-
},
122-
{ label: "Back", value: "back" },
123-
]);
124-
125-
if (!action || action === "back") {
126-
return;
127-
}
128-
129-
if (action === "prefix") {
130-
const newPrefix = await input(
131-
`Enter new prefix (current: ${branch.prefix}):`,
132-
);
133-
if (newPrefix) {
134-
branch.prefix = newPrefix.endsWith("/") ? newPrefix : `${newPrefix}/`;
135-
await saveUserConfig(userConfig);
136-
console.log();
137-
console.log(` Prefix set to ${cyan(branch.prefix)}`);
138-
}
139-
} else if (action === "date") {
140-
branch.includeDate = !branch.includeDate;
141-
await saveUserConfig(userConfig);
142-
console.log();
143-
console.log(
144-
` Date in branch ${branch.includeDate ? green("enabled") : yellow("disabled")}`,
145-
);
146-
} else if (action === "username") {
147-
branch.includeUsername = !branch.includeUsername;
148-
await saveUserConfig(userConfig);
149-
console.log();
150-
console.log(
151-
` Username in branch ${branch.includeUsername ? green("enabled") : yellow("disabled")}`,
152-
);
153-
}
154-
155-
console.log();
156-
console.log(
157-
` ${dim("New example:")} ${cyan(generateExampleBranch(branch))}`,
158-
);
159-
}
160-
161-
function generateExampleBranch(branch: {
162-
prefix: string;
163-
includeDate: boolean;
164-
includeUsername: boolean;
165-
}): string {
166-
return generateBranchName({
167-
changeId: "a1b2c3d4e5f6",
168-
description: "my-feature",
169-
username: "username",
170-
config: branch,
171-
});
172-
}
173-
174-
async function configureTrunk(): Promise<void> {
175-
const cwd = process.cwd();
176-
const repoConfig = await loadRepoConfig(cwd);
177-
178-
if (!repoConfig) {
179-
console.log(yellow("Array is not initialized in this repo."));
180-
console.log(dim(` Run ${cyan("arr init")} first.`));
181-
return;
182-
}
183-
184-
console.log(`${bold("Trunk Branch")}`);
185-
console.log();
186-
console.log(` ${dim("Current trunk:")} ${cyan(repoConfig.trunk)}`);
187-
console.log();
188-
189-
const newTrunk = await input(
190-
`Enter new trunk branch (or leave empty to keep ${repoConfig.trunk}):`,
191-
);
192-
193-
if (newTrunk && newTrunk !== repoConfig.trunk) {
194-
repoConfig.trunk = newTrunk;
195-
await saveRepoConfig(cwd, repoConfig);
196-
console.log();
197-
console.log(` Trunk set to ${cyan(newTrunk)}.`);
198-
} else {
199-
console.log();
200-
console.log(dim(" No changes made."));
201-
}
202-
}
203-
20480
async function resetConfig(): Promise<void> {
20581
console.log(`${bold("Reset Configuration")}`);
20682
console.log();
20783
console.log(yellow(" This will reset all user preferences to defaults."));
208-
console.log(dim(" (Repo config and auth will not be affected.)"));
20984
console.log();
21085

21186
const confirmed = await confirm("Are you sure?");

packages/core/src/config.ts

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
11
import { homedir } from "node:os";
22
import { join } from "node:path";
33
import { z } from "zod";
4-
import { slugifyForBranch } from "./slugify";
5-
6-
const RepoConfigSchema = z.object({
7-
version: z.literal(1),
8-
trunk: z.string(),
9-
});
10-
11-
const BranchConfigSchema = z.object({
12-
prefix: z.string().default("arr/"),
13-
includeDate: z.boolean().default(false),
14-
includeUsername: z.boolean().default(false),
15-
});
164

175
const UserConfigSchema = z.object({
186
version: z.literal(1),
197
tipsEnabled: z.boolean().default(true),
208
tipsSeen: z.array(z.string()).default([]),
21-
branch: BranchConfigSchema.default({}),
229
});
2310

24-
export type BranchConfig = z.infer<typeof BranchConfigSchema>;
25-
26-
export type RepoConfig = z.infer<typeof RepoConfigSchema>;
2711
export type UserConfig = z.infer<typeof UserConfigSchema>;
2812

29-
const ARRAY_DIR = ".array";
30-
const REPO_CONFIG_FILE = "config.json";
3113
const USER_CONFIG_DIR = ".config/array";
3214
const USER_CONFIG_FILE = "config.json";
3315

@@ -39,38 +21,6 @@ function getUserConfigPath(): string {
3921
return join(getUserConfigDir(), USER_CONFIG_FILE);
4022
}
4123

42-
function getRepoConfigPath(cwd: string): string {
43-
return join(cwd, ARRAY_DIR, REPO_CONFIG_FILE);
44-
}
45-
46-
export async function loadRepoConfig(cwd: string): Promise<RepoConfig | null> {
47-
const configPath = getRepoConfigPath(cwd);
48-
49-
try {
50-
const file = Bun.file(configPath);
51-
if (!(await file.exists())) {
52-
return null;
53-
}
54-
55-
const content = await file.text();
56-
const parsed = JSON.parse(content);
57-
return RepoConfigSchema.parse(parsed);
58-
} catch {
59-
return null;
60-
}
61-
}
62-
63-
export async function saveRepoConfig(
64-
cwd: string,
65-
config: RepoConfig,
66-
): Promise<void> {
67-
const arrayDir = join(cwd, ARRAY_DIR);
68-
const configPath = getRepoConfigPath(cwd);
69-
70-
await ensureDir(arrayDir);
71-
await Bun.write(configPath, JSON.stringify(config, null, 2));
72-
}
73-
7424
export async function loadUserConfig(): Promise<UserConfig> {
7525
const configPath = getUserConfigPath();
7626

@@ -96,72 +46,15 @@ export async function saveUserConfig(config: UserConfig): Promise<void> {
9646
await Bun.write(configPath, JSON.stringify(config, null, 2));
9747
}
9848

99-
export function createDefaultRepoConfig(trunk: string): RepoConfig {
100-
return {
101-
version: 1,
102-
trunk,
103-
};
104-
}
105-
10649
export function createDefaultUserConfig(): UserConfig {
10750
return {
10851
version: 1,
10952
tipsEnabled: true,
11053
tipsSeen: [],
111-
branch: {
112-
prefix: "arr/",
113-
includeDate: false,
114-
includeUsername: false,
115-
},
11654
};
11755
}
11856

119-
export function createDefaultBranchConfig(): BranchConfig {
120-
return {
121-
prefix: "arr/",
122-
includeDate: false,
123-
includeUsername: false,
124-
};
125-
}
126-
127-
function formatDate(): string {
128-
const now = new Date();
129-
const year = now.getFullYear();
130-
const month = String(now.getMonth() + 1).padStart(2, "0");
131-
const day = String(now.getDate()).padStart(2, "0");
132-
return `${year}-${month}-${day}`;
133-
}
134-
135-
export interface BranchNameOptions {
136-
changeId: string;
137-
description: string;
138-
username?: string;
139-
config?: BranchConfig;
140-
}
141-
142-
export function generateBranchName(options: BranchNameOptions): string {
143-
const config = options.config ?? createDefaultBranchConfig();
144-
const parts: string[] = [];
145-
146-
parts.push(config.prefix.replace(/\/$/, ""));
147-
148-
if (config.includeDate) {
149-
parts.push(formatDate());
150-
}
151-
152-
if (config.includeUsername && options.username) {
153-
parts.push(options.username);
154-
}
155-
156-
parts.push(options.changeId.slice(0, 8));
157-
parts.push(slugifyForBranch(options.description));
158-
159-
return parts.join("/");
160-
}
161-
16257
export async function isRepoInitialized(cwd: string): Promise<boolean> {
163-
// Fully stateless: a repo is initialized if it has both .git and .jj
164-
// No .array directory required
16558
try {
16659
const { stat } = await import("node:fs/promises");
16760
const [gitExists, jjExists] = await Promise.all([

packages/core/src/executor/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/core/src/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,11 @@ export {
2222
resolveCommandAlias,
2323
} from "./commands";
2424
export {
25-
type BranchConfig,
26-
type BranchNameOptions,
27-
createDefaultBranchConfig,
28-
createDefaultRepoConfig,
2925
createDefaultUserConfig,
30-
generateBranchName,
3126
getTip,
3227
isRepoInitialized,
33-
loadRepoConfig,
3428
loadUserConfig,
3529
markTipSeen,
36-
type RepoConfig,
37-
saveRepoConfig,
3830
saveUserConfig,
3931
shouldShowTip,
4032
TIPS,

packages/core/src/init.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface InitOptions {
1616
export interface InitResult {
1717
trunk: string;
1818
jjInitialized: boolean;
19-
configCreated: boolean;
2019
}
2120

2221
export async function checkPrerequisites(): Promise<Prerequisites> {
@@ -322,13 +321,9 @@ export async function init(
322321
}
323322
}
324323

325-
// No .array config needed - fully stateless
326-
// Trunk is stored in jj's config via revset-aliases."trunk()"
327-
328324
return ok({
329325
trunk,
330326
jjInitialized,
331-
configCreated: false, // No longer creating .array config
332327
});
333328
}
334329

0 commit comments

Comments
 (0)