yapout 0.1.0
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.
- package/dist/chunk-DLHFRTYU.js +102 -0
- package/dist/index.js +4029 -0
- package/dist/worktree-ZZZIL7TK.js +15 -0
- package/package.json +37 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/worktree.ts
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { existsSync, symlinkSync, copyFileSync, mkdirSync } from "fs";
|
|
7
|
+
var WORKTREES_DIR = ".yapout/worktrees";
|
|
8
|
+
function getWorktreesDir(cwd) {
|
|
9
|
+
return join(cwd, WORKTREES_DIR);
|
|
10
|
+
}
|
|
11
|
+
function getWorktreePath(cwd, ticketId) {
|
|
12
|
+
return join(cwd, WORKTREES_DIR, ticketId);
|
|
13
|
+
}
|
|
14
|
+
function createWorktree(cwd, ticketId, branchName, baseBranch) {
|
|
15
|
+
const wtPath = getWorktreePath(cwd, ticketId);
|
|
16
|
+
const wtDir = getWorktreesDir(cwd);
|
|
17
|
+
if (!existsSync(wtDir)) mkdirSync(wtDir, { recursive: true });
|
|
18
|
+
execSync(
|
|
19
|
+
`git worktree add "${wtPath}" -b ${branchName} origin/${baseBranch}`,
|
|
20
|
+
{ cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }
|
|
21
|
+
);
|
|
22
|
+
const nodeModulesSrc = join(cwd, "node_modules");
|
|
23
|
+
const nodeModulesDst = join(wtPath, "node_modules");
|
|
24
|
+
if (existsSync(nodeModulesSrc) && !existsSync(nodeModulesDst)) {
|
|
25
|
+
try {
|
|
26
|
+
symlinkSync(nodeModulesSrc, nodeModulesDst, "junction");
|
|
27
|
+
} catch {
|
|
28
|
+
try {
|
|
29
|
+
execSync("npm install --prefer-offline", {
|
|
30
|
+
cwd: wtPath,
|
|
31
|
+
encoding: "utf-8",
|
|
32
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
33
|
+
timeout: 12e4
|
|
34
|
+
});
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const envFile of [".env", ".env.local"]) {
|
|
40
|
+
const src = join(cwd, envFile);
|
|
41
|
+
if (existsSync(src)) {
|
|
42
|
+
copyFileSync(src, join(wtPath, envFile));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return wtPath;
|
|
46
|
+
}
|
|
47
|
+
function removeWorktree(cwd, wtPath) {
|
|
48
|
+
try {
|
|
49
|
+
execSync(`git worktree remove "${wtPath}" --force`, {
|
|
50
|
+
cwd,
|
|
51
|
+
encoding: "utf-8",
|
|
52
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
53
|
+
});
|
|
54
|
+
} catch {
|
|
55
|
+
try {
|
|
56
|
+
execSync(`git worktree prune`, {
|
|
57
|
+
cwd,
|
|
58
|
+
encoding: "utf-8",
|
|
59
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
60
|
+
});
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function listWorktrees(cwd) {
|
|
66
|
+
const output = execSync("git worktree list --porcelain", {
|
|
67
|
+
cwd,
|
|
68
|
+
encoding: "utf-8",
|
|
69
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
70
|
+
});
|
|
71
|
+
const worktrees = [];
|
|
72
|
+
let currentPath = "";
|
|
73
|
+
let currentBranch = "";
|
|
74
|
+
for (const line of output.split("\n")) {
|
|
75
|
+
if (line.startsWith("worktree ")) {
|
|
76
|
+
currentPath = line.slice(9);
|
|
77
|
+
} else if (line.startsWith("branch ")) {
|
|
78
|
+
currentBranch = line.slice(7).replace("refs/heads/", "");
|
|
79
|
+
} else if (line === "") {
|
|
80
|
+
if (currentPath.includes(WORKTREES_DIR)) {
|
|
81
|
+
const parts = currentPath.split(/[/\\]/);
|
|
82
|
+
const ticketId = parts[parts.length - 1] || null;
|
|
83
|
+
worktrees.push({
|
|
84
|
+
path: currentPath,
|
|
85
|
+
branch: currentBranch,
|
|
86
|
+
ticketId
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
currentPath = "";
|
|
90
|
+
currentBranch = "";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return worktrees;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
getWorktreesDir,
|
|
98
|
+
getWorktreePath,
|
|
99
|
+
createWorktree,
|
|
100
|
+
removeWorktree,
|
|
101
|
+
listWorktrees
|
|
102
|
+
};
|