@burglekitt/worktree 0.1.1 → 0.1.2

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.
@@ -65,6 +65,8 @@ export default class Branch extends BaseCommand {
65
65
  }
66
66
  async run() {
67
67
  const { args, flags } = await this.parse(Branch);
68
+ // If there is no source flag provided, make sure defaultSourceBranch is configured
69
+ await this.verifyConfig(flags.source ? [] : ["defaultSourceBranch"]);
68
70
  const branchName = await this.getBranchName(args.branchName);
69
71
  const sourceBranch = await this.getSourceBranch(flags.source);
70
72
  const projectPath = await gitCreateWorktree(branchName, sourceBranch);
@@ -1,11 +1,14 @@
1
1
  import { EOL } from "node:os";
2
2
  import { confirm, input } from "@inquirer/prompts";
3
3
  import { Args, Flags } from "@oclif/core";
4
+ import chalk from "chalk";
4
5
  import { BaseCommand } from "../lib/base-command.js";
5
6
  import { CONFIG_NAMES } from "../lib/constants.js";
6
7
  import { gitGetConfigValue, gitSetConfigValue } from "../lib/git.js";
7
8
  import { conjoin } from "../lib/utils.js";
8
9
  import { isValidBranch, isValidCommand, isValidEmail, validateConfigValue, } from "../lib/validators.js";
10
+ // TODO: Implement properly when Jira integration has been added
11
+ const JIRA_ENABLED = false;
9
12
  export default class Config extends BaseCommand {
10
13
  static description = "Configure worktree CLI settings";
11
14
  static examples = ["<%= config.bin %> <%= command.id %>"];
@@ -51,7 +54,7 @@ export default class Config extends BaseCommand {
51
54
  }
52
55
  async renderInput(missing) {
53
56
  const configNames = await this.getPromptConfigNames(missing);
54
- const hasJiraPrompt = !!configNames.find((name) => name.startsWith("jira"));
57
+ const hasJiraPrompt = JIRA_ENABLED && !!configNames.find((name) => name.startsWith("jira"));
55
58
  // First check if there is anything to prompt
56
59
  if (configNames.length === 0) {
57
60
  this.log("No missing config found.");
@@ -95,12 +98,15 @@ export default class Config extends BaseCommand {
95
98
  });
96
99
  await gitSetConfigValue("codeEditor", codeEditor);
97
100
  }
101
+ this.log(`${chalk.green("✔")} Configuration complete!${EOL}`);
98
102
  }
99
103
  isValidArgName(name) {
100
104
  return CONFIG_NAMES.includes(name);
101
105
  }
102
106
  async run() {
103
107
  const { args, flags } = await this.parse(Config);
108
+ // Mark that config has been called at least once
109
+ await gitSetConfigValue("has-called-config", "true");
104
110
  if (args.name) {
105
111
  if (!this.isValidArgName(args.name)) {
106
112
  this.error([
@@ -1,6 +1,10 @@
1
1
  import { Command } from "@oclif/core";
2
2
  import type { CommandError } from "@oclif/core/interfaces";
3
+ import type { ConfigName } from "./constants.js";
3
4
  export declare abstract class BaseCommand extends Command {
5
+ private confirmFirstTimeConfig;
6
+ private confirmMissingConfig;
7
+ protected verifyConfig(configNames?: ConfigName[]): Promise<void>;
4
8
  protected openWorktreePath(path: string): Promise<void>;
5
9
  protected catch(error: CommandError): Promise<any>;
6
10
  }
@@ -1,9 +1,38 @@
1
1
  import { exec } from "node:child_process";
2
+ import { confirm } from "@inquirer/prompts";
2
3
  import { Command } from "@oclif/core";
3
4
  import chalk from "chalk";
4
5
  import ora from "ora";
5
6
  import { gitGetConfigValue } from "./git.js";
6
7
  export class BaseCommand extends Command {
8
+ confirmFirstTimeConfig() {
9
+ const message = "Looks like this is your first time running the CLI. Do you want to run the config command now?";
10
+ return confirm({ message });
11
+ }
12
+ confirmMissingConfig() {
13
+ const message = "Some required configuration values are missing. Do you want to run the config command now?";
14
+ return confirm({ message });
15
+ }
16
+ async verifyConfig(configNames = []) {
17
+ if ((await gitGetConfigValue("has-called-config")) !== "true") {
18
+ if (await this.confirmFirstTimeConfig()) {
19
+ await this.config.runCommand("config");
20
+ return;
21
+ }
22
+ }
23
+ let isMissingConfig = false;
24
+ for (const name of configNames) {
25
+ if (!(await gitGetConfigValue(name))) {
26
+ isMissingConfig = true;
27
+ break;
28
+ }
29
+ }
30
+ if (isMissingConfig) {
31
+ if (await this.confirmMissingConfig()) {
32
+ await this.config.runCommand("config", ["--missing"]);
33
+ }
34
+ }
35
+ }
7
36
  async openWorktreePath(path) {
8
37
  const codeEditor = await gitGetConfigValue("codeEditor");
9
38
  if (codeEditor) {
@@ -1,2 +1,2 @@
1
- export declare const CONFIG_NAMES: readonly ["jira.domain", "jira.email", "jira.apiToken", "codeEditor", "defaultSourceBranch"];
1
+ export declare const CONFIG_NAMES: readonly ["has-called-config", "jira.domain", "jira.email", "jira.apiToken", "codeEditor", "defaultSourceBranch"];
2
2
  export type ConfigName = (typeof CONFIG_NAMES)[number];
@@ -1,4 +1,5 @@
1
1
  export const CONFIG_NAMES = [
2
+ "has-called-config",
2
3
  "jira.domain",
3
4
  "jira.email",
4
5
  "jira.apiToken",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burglekitt/worktree",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A CLI tool for managing git worktrees with enhanced workflow features",
5
5
  "main": "./bin/run.js",
6
6
  "type": "module",
@@ -38,6 +38,7 @@
38
38
  "oclif": {
39
39
  "bin": "@burglekitt/worktree",
40
40
  "binAliases": [
41
+ "@burglekitt/worktree",
41
42
  "worktree"
42
43
  ],
43
44
  "plugins": [