Skip to content

Commit 2e34dbb

Browse files
Merge pull request #2 from johnlindquist/feature/add-install-and-editor-flags
feat: add install and editor flags with shorthand options
2 parents 988aac9 + 8c6f4de commit 2e34dbb

6 files changed

Lines changed: 101 additions & 33 deletions

File tree

.github/workflows/publish.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@ name: Publish to npm
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
packages: write
710

811
jobs:
912
publish:
1013
runs-on: ubuntu-latest
1114
steps:
12-
- name: Checkout repository
13-
uses: actions/checkout@v3
14-
15-
- name: Setup Node.js
16-
uses: actions/setup-node@v3
15+
- uses: actions/checkout@v3
1716
with:
18-
node-version: 16
17+
fetch-depth: 0
18+
- uses: actions/setup-node@v3
19+
with:
20+
node-version: 20.8.1
1921
registry-url: https://registry.npmjs.org
2022
always-auth: true
21-
23+
- uses: pnpm/action-setup@v2
24+
with:
25+
version: 8
2226
- name: Install dependencies
23-
run: npm install
24-
25-
- name: Build the project
26-
run: npm run build
27-
28-
# Semantic versioning is applied manually; CI does not commit any version changes.
29-
- name: Publish package
27+
run: pnpm install
28+
- name: Build
29+
run: pnpm run build
30+
- name: Release
31+
run: pnpm semantic-release
3032
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3134
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
32-
run: npm publish --access public --tag latest
35+
36+
# Semantic versioning is applied manually; CI does not commit any version changes.

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# [1.1.0](https://github.com/johnlindquist/worktree-cli/compare/v1.0.0...v1.1.0) (2025-03-20)
2+
3+
4+
### Features
5+
6+
* create worktrees in sibling directories ([37dc420](https://github.com/johnlindquist/worktree-cli/commit/37dc420cf1539c68a32926e97c2f35762f5392b0))
7+
8+
# 1.0.0 (2025-03-20)
9+
10+
11+
### Bug Fixes
12+
13+
* add write permissions for semantic-release ([d98cae6](https://github.com/johnlindquist/worktree-cli/commit/d98cae6472d06f9cb39f40c9df564143fdf577ef))
14+
* switch to pnpm ([b95819e](https://github.com/johnlindquist/worktree-cli/commit/b95819e3abd9a44b5b06b0036bedfa5fe3d7c825))
15+
* update Node.js version to 18 ([ab54632](https://github.com/johnlindquist/worktree-cli/commit/ab54632df1b7094fa6896470fa5f17efcce796f3))
16+
* update Node.js version to 20.8.1 ([b9d2190](https://github.com/johnlindquist/worktree-cli/commit/b9d2190b5c3b55ce1376ed6c244701a57a8b3d8d))
17+
* use npm install instead of npm ci ([988aac9](https://github.com/johnlindquist/worktree-cli/commit/988aac9a25d57da7d8d1923029211182e8a7e6a0))
18+
19+
20+
### Features
21+
22+
* add semantic-release for automated versioning ([11cddea](https://github.com/johnlindquist/worktree-cli/commit/11cddea6295a76beeec42371d429cf1d899b269a))

TESTING.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@
88

99
- The CI workflow will not make any commits or version bumps
1010
- Version updates should be handled manually outside of CI
11-
- Make sure you have set up the `NPM_TOKEN` secret in your GitHub repository settings
11+
- Make sure you have set up the `NPM_TOKEN` secret in your GitHub repository settings
12+
13+
## New Worktree Sibling Directory Test
14+
15+
1. In a test repository, run:
16+
```bash
17+
cursor-worktree new editor
18+
```
19+
2. Verify that a new sibling directory named `<currentDirectoryName>editor` is created.
20+
3. Confirm that the worktree is added to the Git repository and that the Cursor editor opens the new directory.

package.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cursor-worktree",
3-
"version": "0.0.0-development",
3+
"version": "1.1.0",
44
"description": "A CLI tool for managing Git worktrees with a focus on opening them in the Cursor editor.",
55
"author": "Your Name",
66
"license": "MIT",
@@ -11,7 +11,8 @@
1111
"scripts": {
1212
"build": "tsc",
1313
"start": "node dist/index.js",
14-
"dev": "tsc -w"
14+
"dev": "tsc -w",
15+
"semantic-release": "semantic-release"
1516
},
1617
"dependencies": {
1718
"chalk": "^5.2.0",
@@ -20,6 +21,24 @@
2021
},
2122
"devDependencies": {
2223
"@types/node": "^18.0.0",
23-
"typescript": "^5.0.2"
24+
"typescript": "^5.0.2",
25+
"@semantic-release/changelog": "^6.0.3",
26+
"@semantic-release/git": "^10.0.1",
27+
"semantic-release": "^23.0.2"
28+
},
29+
"release": {
30+
"branches": [
31+
"main"
32+
],
33+
"plugins": [
34+
"@semantic-release/commit-analyzer",
35+
"@semantic-release/release-notes-generator",
36+
"@semantic-release/changelog",
37+
"@semantic-release/npm",
38+
"@semantic-release/git"
39+
]
40+
},
41+
"publishConfig": {
42+
"access": "public"
2443
}
2544
}

src/commands/new.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import { execa } from "execa";
22
import chalk from "chalk";
33
import { stat } from "node:fs/promises";
4-
import { resolve } from "node:path";
4+
import { resolve, join, dirname, basename } from "node:path";
55

66
export async function newWorktreeHandler(
77
branchName: string = "main",
8-
options: { path?: string; checkout?: boolean }
8+
options: { path?: string; checkout?: boolean; install?: string; editor?: string }
99
) {
1010
try {
1111
// 1. Validate we're in a git repo
1212
await execa("git", ["rev-parse", "--is-inside-work-tree"]);
1313

1414
// 2. Build final path for the new worktree
15-
const folderName = options.path ?? `./${branchName}-worktree`;
15+
let folderName: string;
16+
if (options.path) {
17+
folderName = options.path;
18+
} else {
19+
const currentDir = process.cwd();
20+
const parentDir = dirname(currentDir);
21+
const currentDirName = basename(currentDir);
22+
// Create a sibling directory: current directory name concatenated with branchName
23+
folderName = join(parentDir, `${currentDirName}${branchName}`);
24+
}
1625
const resolvedPath = resolve(folderName);
1726

1827
// 3. (Optional) checkout new local branch if it doesn't exist yet
19-
// This step is only run if user passes `--checkout`
2028
if (options.checkout) {
21-
// Check if branch already exists
2229
const { stdout } = await execa("git", ["branch", "--list", branchName]);
2330
if (!stdout) {
2431
console.log(chalk.yellow(`Branch "${branchName}" doesn't exist locally. Creating...`));
@@ -27,20 +34,25 @@ export async function newWorktreeHandler(
2734
console.log(chalk.green(`Branch "${branchName}" found locally.`));
2835
}
2936
} else {
30-
// Ensure the branch is present, or you might want to skip this check
3137
console.log(chalk.gray(`Using branch "${branchName}". Make sure it exists (local or remote).`));
3238
}
3339

3440
// 4. Create the new worktree
3541
console.log(chalk.blue(`Creating new worktree for branch "${branchName}" at: ${resolvedPath}`));
3642
await execa("git", ["worktree", "add", resolvedPath, branchName]);
3743

38-
// 5. Open in Cursor editor
39-
// (Assuming "cursor <path>" is how you open a folder in Cursor)
40-
console.log(chalk.blue(`Opening ${resolvedPath} in Cursor...`));
41-
await execa("cursor", [resolvedPath], { stdio: "inherit" });
44+
// 5. (Optional) Install dependencies if --install flag is provided
45+
if (options.install) {
46+
console.log(chalk.blue(`Installing dependencies using ${options.install} in ${resolvedPath}...`));
47+
await execa(options.install, ["install"], { cwd: resolvedPath, stdio: "inherit" });
48+
}
49+
50+
// 6. Open in the specified editor (or default to "cursor")
51+
const editorCommand = options.editor || "cursor";
52+
console.log(chalk.blue(`Opening ${resolvedPath} in ${editorCommand}...`));
53+
await execa(editorCommand, [resolvedPath], { stdio: "inherit" });
4254

43-
console.log(chalk.green(`Worktree created and opened in Cursor successfully!`));
55+
console.log(chalk.green(`Worktree created, dependencies installed (if specified), and opened in ${editorCommand} successfully!`));
4456
} catch (error) {
4557
if (error instanceof Error) {
4658
console.error(chalk.red("Failed to create new worktree:"), error.message);

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ program
1818
.argument("[branchName]", "Name of the branch to base this worktree on")
1919
.option("-p, --path <path>", "Relative path/folder name for new worktree")
2020
.option("-c, --checkout", "Create new branch if it doesn't exist and checkout automatically", false)
21-
.description("Create a new worktree for the specified branch and open it in Cursor.")
21+
.option("-i, --install <packageManager>", "Package manager to use for installing dependencies (npm, pnpm, bun, etc.)")
22+
.option("-e, --editor <editor>", "Editor to use for opening the worktree (e.g., code, webstorm, windsurf, etc.)")
23+
.description("Create a new worktree for the specified branch, install dependencies if specified, and open in editor.")
2224
.action(newWorktreeHandler);
2325

2426
program

0 commit comments

Comments
 (0)