pan-stack-cli 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.
- package/README.md +1 -1
- package/lib/discover.js +9 -3
- package/lib/git/git-clone.js +1 -1
- package/lib/git/git-fetch-all.js +1 -1
- package/lib/git/git-grv.js +4 -8
- package/lib/git/git-gst.js +4 -8
- package/lib/git/git-pull.js +1 -1
- package/lib/git/git-push.js +1 -1
- package/lib/git/helpers/cli.js +56 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Sau đó gõ `pan` thay cho `./pan`.
|
|
|
33
33
|
|
|
34
34
|
Tuỳ chọn git (forward xuống script):
|
|
35
35
|
|
|
36
|
-
- `--base-dir DIR` — thư mục gốc cho path repo con (mặc định:
|
|
36
|
+
- `--base-dir DIR` — thư mục gốc cho path repo con (mặc định: thư mục chứa `.project.yaml`; tự walk-up từ cwd nếu không có ngay tại đó)
|
|
37
37
|
- `--dry-run` — chỉ in lệnh
|
|
38
38
|
- `[manifest]` — đường dẫn manifest (mặc định: `.project.yaml`)
|
|
39
39
|
|
package/lib/discover.js
CHANGED
|
@@ -64,12 +64,17 @@ function walkUpManifests(startDir) {
|
|
|
64
64
|
return found;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function
|
|
67
|
+
function findNearestProjectManifest(startDir = process.cwd()) {
|
|
68
68
|
const walked = walkUpManifests(startDir);
|
|
69
|
-
|
|
69
|
+
return walked[0] || null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function findNearestWorkspace(startDir = process.cwd()) {
|
|
73
|
+
const manifestPath = findNearestProjectManifest(startDir);
|
|
74
|
+
if (!manifestPath) {
|
|
70
75
|
return null;
|
|
71
76
|
}
|
|
72
|
-
return loadManifest(
|
|
77
|
+
return loadManifest(manifestPath);
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
function loadCommandSourcesForWorkspace(workspace) {
|
|
@@ -205,6 +210,7 @@ function isBuiltinGitCommand(name) {
|
|
|
205
210
|
module.exports = {
|
|
206
211
|
BUILTIN_GIT_COMMANDS,
|
|
207
212
|
PAN_CONFIG_FILE,
|
|
213
|
+
findNearestProjectManifest,
|
|
208
214
|
findNearestWorkspace,
|
|
209
215
|
loadAllCommandSources,
|
|
210
216
|
loadCommandSourcesForWorkspace,
|
package/lib/git/git-clone.js
CHANGED
package/lib/git/git-fetch-all.js
CHANGED
package/lib/git/git-grv.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Alias tương đương grv trong oh-my-zsh — hiển thị URL đầy đủ (fetch/push).
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const path = require("path");
|
|
9
8
|
const { parseCommonArgs, loadManifestRepos, printCommonOptions } = require("./helpers/cli");
|
|
10
9
|
const { ensureRepoExists, isGitRepo, listRemotesVerbose } = require("./helpers/git");
|
|
11
10
|
|
|
@@ -28,8 +27,7 @@ function printRepoRemotes({ label, destination, dryRun }) {
|
|
|
28
27
|
console.log("");
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
function showWorkspaceRootRemotes({
|
|
32
|
-
const workspaceRoot = path.resolve(baseDir || path.dirname(manifestPath || ".project.yaml"));
|
|
30
|
+
function showWorkspaceRootRemotes({ workspaceRoot, dryRun }) {
|
|
33
31
|
if (!isGitRepo(workspaceRoot)) {
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
@@ -64,16 +62,14 @@ function main() {
|
|
|
64
62
|
return;
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
manifestPath,
|
|
65
|
+
const { repos, workspaceRoot } = loadManifestRepos({
|
|
66
|
+
manifestPath: args.manifest,
|
|
70
67
|
baseDir: args.baseDir,
|
|
71
68
|
});
|
|
72
69
|
|
|
73
70
|
if (!args.noWorkspace) {
|
|
74
71
|
showWorkspaceRootRemotes({
|
|
75
|
-
|
|
76
|
-
baseDir: args.baseDir,
|
|
72
|
+
workspaceRoot,
|
|
77
73
|
dryRun: args.dryRun,
|
|
78
74
|
});
|
|
79
75
|
}
|
package/lib/git/git-gst.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Alias tương đương gst trong oh-my-zsh — chạy git status trên workspace + repo con.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const path = require("path");
|
|
9
8
|
const { parseCommonArgs, loadManifestRepos, printCommonOptions } = require("./helpers/cli");
|
|
10
9
|
const { ensureRepoExists, isGitRepo, runGitStatus } = require("./helpers/git");
|
|
11
10
|
|
|
@@ -22,8 +21,7 @@ function printRepoStatus({ label, destination, dryRun, gitArgs }) {
|
|
|
22
21
|
console.log("");
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
function showWorkspaceRootStatus({
|
|
26
|
-
const workspaceRoot = path.resolve(baseDir || path.dirname(manifestPath || ".project.yaml"));
|
|
24
|
+
function showWorkspaceRootStatus({ workspaceRoot, dryRun, gitArgs }) {
|
|
27
25
|
if (!isGitRepo(workspaceRoot)) {
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
@@ -62,16 +60,14 @@ function main() {
|
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
const gitArgs = args.gitArgs || [];
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
manifestPath,
|
|
63
|
+
const { repos, workspaceRoot } = loadManifestRepos({
|
|
64
|
+
manifestPath: args.manifest,
|
|
68
65
|
baseDir: args.baseDir,
|
|
69
66
|
});
|
|
70
67
|
|
|
71
68
|
if (!args.noWorkspace) {
|
|
72
69
|
showWorkspaceRootStatus({
|
|
73
|
-
|
|
74
|
-
baseDir: args.baseDir,
|
|
70
|
+
workspaceRoot,
|
|
75
71
|
dryRun: args.dryRun,
|
|
76
72
|
gitArgs,
|
|
77
73
|
});
|
package/lib/git/git-pull.js
CHANGED
package/lib/git/git-push.js
CHANGED
package/lib/git/helpers/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
const fs = require("fs");
|
|
3
|
+
const { findNearestProjectManifest } = require("../../discover");
|
|
3
4
|
const { parseManifest, manifestRepos, validateRepo } = require("./manifest");
|
|
4
5
|
|
|
5
6
|
function parseCommonArgs(argv, extraFlags = {}) {
|
|
@@ -51,19 +52,61 @@ function looksLikeManifest(arg) {
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
function resolveProjectWorkspace({
|
|
56
|
+
manifestPath = "",
|
|
57
|
+
baseDir = ".",
|
|
58
|
+
startDir = process.cwd(),
|
|
59
|
+
}) {
|
|
60
|
+
const manifestName = manifestPath || ".project.yaml";
|
|
61
|
+
const cwdManifest = path.isAbsolute(manifestName)
|
|
62
|
+
? manifestName
|
|
63
|
+
: path.resolve(startDir, manifestName);
|
|
64
|
+
|
|
65
|
+
let resolvedManifest = "";
|
|
66
|
+
let usedWalkUp = false;
|
|
67
|
+
|
|
68
|
+
if (fs.existsSync(cwdManifest)) {
|
|
69
|
+
resolvedManifest = cwdManifest;
|
|
70
|
+
} else {
|
|
71
|
+
const found = findNearestProjectManifest(startDir);
|
|
72
|
+
if (!found) {
|
|
73
|
+
const label = manifestPath || ".project.yaml";
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Manifest not found: ${label} (đã tìm từ ${startDir} lên thư mục cha)`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
resolvedManifest = found;
|
|
79
|
+
usedWalkUp = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const workspaceRoot = path.dirname(resolvedManifest);
|
|
83
|
+
let resolvedBaseDir;
|
|
84
|
+
if (baseDir === ".") {
|
|
85
|
+
resolvedBaseDir = usedWalkUp ? workspaceRoot : path.resolve(startDir, ".");
|
|
86
|
+
} else if (path.isAbsolute(baseDir)) {
|
|
87
|
+
resolvedBaseDir = baseDir;
|
|
88
|
+
} else {
|
|
89
|
+
resolvedBaseDir = path.resolve(startDir, baseDir);
|
|
58
90
|
}
|
|
59
91
|
|
|
92
|
+
return {
|
|
93
|
+
manifestPath: resolvedManifest,
|
|
94
|
+
baseDir: resolvedBaseDir,
|
|
95
|
+
workspaceRoot,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function loadManifestRepos({ manifestPath, baseDir, startDir = process.cwd() }) {
|
|
100
|
+
const workspace = resolveProjectWorkspace({ manifestPath, baseDir, startDir });
|
|
101
|
+
const { manifestPath: resolvedManifest, baseDir: resolvedBaseDir, workspaceRoot } =
|
|
102
|
+
workspace;
|
|
103
|
+
|
|
60
104
|
const data = parseManifest(resolvedManifest);
|
|
61
105
|
const repos = manifestRepos(data);
|
|
62
106
|
if (repos.length === 0) {
|
|
63
107
|
throw new Error("No repositories found in manifest.");
|
|
64
108
|
}
|
|
65
109
|
|
|
66
|
-
const resolvedBaseDir = path.resolve(baseDir);
|
|
67
110
|
const results = [];
|
|
68
111
|
for (const repo of repos) {
|
|
69
112
|
try {
|
|
@@ -83,7 +126,12 @@ function loadManifestRepos({ manifestPath, baseDir }) {
|
|
|
83
126
|
throw new Error("No valid repositories found in manifest.");
|
|
84
127
|
}
|
|
85
128
|
|
|
86
|
-
return
|
|
129
|
+
return {
|
|
130
|
+
repos: results,
|
|
131
|
+
manifestPath: resolvedManifest,
|
|
132
|
+
baseDir: resolvedBaseDir,
|
|
133
|
+
workspaceRoot,
|
|
134
|
+
};
|
|
87
135
|
}
|
|
88
136
|
|
|
89
137
|
function printCommonOptions() {
|
|
@@ -92,12 +140,13 @@ function printCommonOptions() {
|
|
|
92
140
|
|
|
93
141
|
options:
|
|
94
142
|
-h, --help show this help message and exit
|
|
95
|
-
--base-dir BASE_DIR Base directory for relative repo paths. Default:
|
|
143
|
+
--base-dir BASE_DIR Base directory for relative repo paths. Default: thư mục chứa .project.yaml (walk-up từ cwd nếu cần).
|
|
96
144
|
--dry-run Print commands only`;
|
|
97
145
|
}
|
|
98
146
|
|
|
99
147
|
module.exports = {
|
|
100
148
|
parseCommonArgs,
|
|
149
|
+
resolveProjectWorkspace,
|
|
101
150
|
loadManifestRepos,
|
|
102
151
|
printCommonOptions,
|
|
103
152
|
};
|