binary-collections 2.0.6 → 2.0.7
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/bin/git-diff.cmd +4 -0
- package/bin/git-fix-encoding.cmd +0 -0
- package/bin/nodekill.cmd +0 -0
- package/bin/nodekill.ps1 +0 -0
- package/bin/submodule-install +0 -0
- package/lib/{chunk-GA4DDV65.mjs → chunk-3LOB2P54.mjs} +3 -3
- package/lib/{chunk-M4IBUK4H.mjs → chunk-4LEXWIIF.mjs} +2 -2
- package/lib/chunk-BSD5CIRU.mjs +52 -0
- package/lib/chunk-FB6YIQYR.mjs +42 -0
- package/lib/{chunk-E75HJFJO.mjs → chunk-JL32QDSH.mjs} +2 -2
- package/lib/{chunk-LPLPQBYP.mjs → chunk-OKYLF2MU.mjs} +14 -14
- package/lib/chunk-VXZQNLPU.mjs +23 -0
- package/lib/del-gradle.cjs +12 -12
- package/lib/del-gradle.d.ts +1 -2
- package/lib/del-gradle.js +12 -69
- package/lib/del-gradle.mjs +3 -3
- package/lib/del-node-modules.cjs +12 -12
- package/lib/del-node-modules.d.ts +1 -2
- package/lib/del-node-modules.js +11 -68
- package/lib/del-node-modules.mjs +3 -3
- package/lib/del-ps.cjs +13 -626
- package/lib/del-ps.d.ts +1 -2
- package/lib/del-ps.js +27 -702
- package/lib/del-ps.mjs +5 -8
- package/lib/del-yarn-caches.cjs +12 -12
- package/lib/del-yarn-caches.d.ts +1 -2
- package/lib/del-yarn-caches.js +6 -63
- package/lib/del-yarn-caches.mjs +3 -3
- package/lib/find-node-modules-cli.cjs +59 -0
- package/lib/find-node-modules-cli.d.mts +1 -0
- package/lib/find-node-modules-cli.d.ts +2 -0
- package/lib/find-node-modules-cli.js +3 -0
- package/lib/find-node-modules-cli.mjs +14 -0
- package/lib/find-node-modules.cjs +31 -9
- package/lib/find-node-modules.d.mts +9 -1
- package/lib/find-node-modules.d.ts +9 -2
- package/lib/find-node-modules.js +41 -12
- package/lib/find-node-modules.mjs +5 -19
- package/lib/git-diff.cjs +74 -0
- package/lib/git-diff.d.cts +2 -0
- package/lib/git-diff.d.mts +87 -0
- package/lib/git-diff.d.ts +87 -0
- package/lib/git-diff.mjs +83 -0
- package/lib/git-purge.cjs +13 -626
- package/lib/git-purge.d.ts +1 -2
- package/lib/git-purge.js +53 -698
- package/lib/git-purge.mjs +4 -7
- package/lib/index.cjs +91 -1
- package/lib/index.d.mts +1 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +8 -2
- package/lib/index.mjs +12 -3
- package/lib/npm-run-series.d.ts +1 -0
- package/lib/npm-run-series.js +80 -56
- package/lib/npm-run-series.mjs +2 -2
- package/lib/package-resolutions.mjs +1 -1
- package/lib/ps/connected-domain.cjs +0 -0
- package/lib/ps/connected-domain.d.ts +1 -2
- package/lib/ps/connected-domain.js +196 -150
- package/lib/ps/connected-domain.mjs +3 -3
- package/lib/ps/index.cjs +0 -0
- package/lib/ps/index.d.mjs +2 -2
- package/lib/ps/index.d.ts +2 -26
- package/lib/ps/index.js +230 -535
- package/lib/ps/index.mjs +5 -5
- package/lib/ps/isWin.cjs +0 -0
- package/lib/ps/isWin.d.ts +1 -2
- package/lib/ps/isWin.js +1 -2
- package/lib/ps/isWin.mjs +3 -3
- package/lib/ps/table-parser.cjs +0 -0
- package/lib/ps/table-parser.d.ts +1 -3
- package/lib/ps/table-parser.js +254 -345
- package/lib/ps/table-parser.mjs +4 -4
- package/lib/submodule-install.cjs +118 -0
- package/lib/submodule-install.d.cts +2 -0
- package/lib/submodule-install.d.mts +141 -0
- package/lib/submodule-install.d.ts +141 -0
- package/lib/submodule-install.mjs +116 -0
- package/lib/utils.cjs +12 -12
- package/lib/utils.d.ts +4 -8
- package/lib/utils.js +43 -28
- package/lib/utils.mjs +3 -3
- package/lib/yarn-reinstall.cjs +42 -0
- package/lib/yarn-reinstall.d.cts +1 -0
- package/lib/yarn-reinstall.d.mts +45 -0
- package/lib/yarn-reinstall.d.ts +45 -0
- package/lib/yarn-reinstall.mjs +50 -0
- package/package.json +37 -39
- package/readme.md +174 -49
- package/eslint.config.cjs +0 -97
- package/lib/chunk-7MSZ52XC.mjs +0 -14
- package/lib/chunk-AVDT32AY.mjs +0 -20
- package/lib/chunk-S4SJ7SDW.mjs +0 -625
- package/lib/package-resolutions.js +0 -28
- package/lib/ps/index.d.js +0 -17
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
// Path to .env file
|
|
7
|
+
const envPath = path.resolve(__dirname, ".env");
|
|
8
|
+
// Check if .env exists and read it
|
|
9
|
+
if (fs.existsSync(envPath)) {
|
|
10
|
+
const envContent = fs.readFileSync(envPath, "utf8");
|
|
11
|
+
// Split into lines and process each
|
|
12
|
+
envContent.split("\n").forEach((line) => {
|
|
13
|
+
const trimmedLine = line.trim();
|
|
14
|
+
// Ignore empty lines and comments
|
|
15
|
+
if (!trimmedLine || trimmedLine.startsWith("#"))
|
|
16
|
+
return;
|
|
17
|
+
// Extract key and value
|
|
18
|
+
const [key, ...vals] = trimmedLine.split("=");
|
|
19
|
+
if (!key)
|
|
20
|
+
return;
|
|
21
|
+
const value = vals
|
|
22
|
+
.join("=")
|
|
23
|
+
.trim()
|
|
24
|
+
.replace(/^['"]|['"]$/g, ""); // Remove surrounding quotes
|
|
25
|
+
process.env[key.trim()] = value;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Parse CLI args
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
let ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
|
|
31
|
+
let REPO_PATH = ROOT;
|
|
32
|
+
for (let i = 0; i < args.length; i++) {
|
|
33
|
+
if (args[i] === "-cwd" && args[i + 1]) {
|
|
34
|
+
ROOT = path.resolve(args[++i]);
|
|
35
|
+
}
|
|
36
|
+
else if (args[i].startsWith("--cwd=")) {
|
|
37
|
+
ROOT = path.resolve(args[i].split("=")[1]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
console.log(`Installing submodules at ${ROOT}`);
|
|
41
|
+
// Get submodule paths
|
|
42
|
+
const submoduleList = runGit([
|
|
43
|
+
"-C",
|
|
44
|
+
REPO_PATH,
|
|
45
|
+
"config",
|
|
46
|
+
"-f",
|
|
47
|
+
".gitmodules",
|
|
48
|
+
"--get-regexp",
|
|
49
|
+
"^submodule\\..*\\.path$"
|
|
50
|
+
])
|
|
51
|
+
.split("\n")
|
|
52
|
+
.filter(Boolean);
|
|
53
|
+
for (const line of submoduleList) {
|
|
54
|
+
const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
|
|
55
|
+
const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
|
|
56
|
+
if (fs.existsSync(RELATIVE_MODULE_PATH)) {
|
|
57
|
+
console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
|
|
58
|
+
fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
|
|
59
|
+
}
|
|
60
|
+
const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
|
|
61
|
+
const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
|
|
62
|
+
let BRANCH = "master";
|
|
63
|
+
try {
|
|
64
|
+
BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
|
|
65
|
+
}
|
|
66
|
+
catch (_a) {
|
|
67
|
+
// silently ignore if branch is not set
|
|
68
|
+
}
|
|
69
|
+
const addResult = runGit(["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH], true);
|
|
70
|
+
if (addResult.status !== 0) {
|
|
71
|
+
console.warn(`Cannot add submodule ${MODULE_PATH}`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
|
|
75
|
+
if (process.env.ACCESS_TOKEN) {
|
|
76
|
+
let URL_WITH_TOKEN = "";
|
|
77
|
+
let repoInfo;
|
|
78
|
+
if (URL.includes("github.com")) {
|
|
79
|
+
repoInfo = URL.replace("https://github.com/", "");
|
|
80
|
+
URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
|
|
81
|
+
}
|
|
82
|
+
else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
|
|
83
|
+
repoInfo = URL.replace("https://gitlab.com/", "");
|
|
84
|
+
URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// For other Git providers, try a generic approach
|
|
88
|
+
const urlObj = new URL(URL);
|
|
89
|
+
repoInfo = urlObj.pathname.substring(1); // Remove leading slash
|
|
90
|
+
URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
|
|
91
|
+
}
|
|
92
|
+
if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
|
|
93
|
+
console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
|
|
94
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
|
|
98
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
|
|
99
|
+
if (fs.existsSync(GIT_MODULES)) {
|
|
100
|
+
console.log(`${MODULE_PATH} has submodules`);
|
|
101
|
+
const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
|
|
102
|
+
if (result.status !== 0) {
|
|
103
|
+
console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
|
|
104
|
+
process.exit(result.status);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
|
|
109
|
+
// ----------- Helper Functions -----------
|
|
110
|
+
function runGit(args, returnResult = false) {
|
|
111
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
112
|
+
if (returnResult)
|
|
113
|
+
return result;
|
|
114
|
+
if (result.status !== 0) {
|
|
115
|
+
throw new Error(result.stderr || `git ${args.join(" ")} failed`);
|
|
116
|
+
}
|
|
117
|
+
return result.stdout || "";
|
|
118
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require("child_process");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
// Path to .env file
|
|
7
|
+
const envPath = path.resolve(__dirname, ".env");
|
|
8
|
+
|
|
9
|
+
// Check if .env exists and read it
|
|
10
|
+
if (fs.existsSync(envPath)) {
|
|
11
|
+
const envContent = fs.readFileSync(envPath, "utf8");
|
|
12
|
+
|
|
13
|
+
// Split into lines and process each
|
|
14
|
+
envContent.split("\n").forEach((line) => {
|
|
15
|
+
const trimmedLine = line.trim();
|
|
16
|
+
|
|
17
|
+
// Ignore empty lines and comments
|
|
18
|
+
if (!trimmedLine || trimmedLine.startsWith("#")) return;
|
|
19
|
+
|
|
20
|
+
// Extract key and value
|
|
21
|
+
const [key, ...vals] = trimmedLine.split("=");
|
|
22
|
+
if (!key) return;
|
|
23
|
+
|
|
24
|
+
const value = vals
|
|
25
|
+
.join("=")
|
|
26
|
+
.trim()
|
|
27
|
+
.replace(/^['"]|['"]$/g, ""); // Remove surrounding quotes
|
|
28
|
+
process.env[key.trim()] = value;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Parse CLI args
|
|
33
|
+
const args = process.argv.slice(2);
|
|
34
|
+
let ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
|
|
35
|
+
let REPO_PATH = ROOT;
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < args.length; i++) {
|
|
38
|
+
if (args[i] === "-cwd" && args[i + 1]) {
|
|
39
|
+
ROOT = path.resolve(args[++i]);
|
|
40
|
+
} else if (args[i].startsWith("--cwd=")) {
|
|
41
|
+
ROOT = path.resolve(args[i].split("=")[1]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`Installing submodules at ${ROOT}`);
|
|
46
|
+
|
|
47
|
+
// Get submodule paths
|
|
48
|
+
const submoduleList = runGit([
|
|
49
|
+
"-C",
|
|
50
|
+
REPO_PATH,
|
|
51
|
+
"config",
|
|
52
|
+
"-f",
|
|
53
|
+
".gitmodules",
|
|
54
|
+
"--get-regexp",
|
|
55
|
+
"^submodule\\..*\\.path$"
|
|
56
|
+
])
|
|
57
|
+
.split("\n")
|
|
58
|
+
.filter(Boolean);
|
|
59
|
+
|
|
60
|
+
for (const line of submoduleList) {
|
|
61
|
+
const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
|
|
62
|
+
const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
|
|
63
|
+
|
|
64
|
+
if (fs.existsSync(RELATIVE_MODULE_PATH)) {
|
|
65
|
+
console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
|
|
66
|
+
fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
|
|
70
|
+
const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
|
|
71
|
+
|
|
72
|
+
let BRANCH = "master";
|
|
73
|
+
try {
|
|
74
|
+
BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
|
|
75
|
+
} catch {
|
|
76
|
+
// silently ignore if branch is not set
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const addResult = runGit(
|
|
80
|
+
["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH],
|
|
81
|
+
true
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (addResult.status !== 0) {
|
|
85
|
+
console.warn(`Cannot add submodule ${MODULE_PATH}`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
|
|
90
|
+
|
|
91
|
+
if (process.env.ACCESS_TOKEN) {
|
|
92
|
+
let URL_WITH_TOKEN = "";
|
|
93
|
+
let repoInfo;
|
|
94
|
+
|
|
95
|
+
if (URL.includes("github.com")) {
|
|
96
|
+
repoInfo = URL.replace("https://github.com/", "");
|
|
97
|
+
URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
|
|
98
|
+
} else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
|
|
99
|
+
repoInfo = URL.replace("https://gitlab.com/", "");
|
|
100
|
+
URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
|
|
101
|
+
} else {
|
|
102
|
+
// For other Git providers, try a generic approach
|
|
103
|
+
const urlObj = new URL(URL);
|
|
104
|
+
repoInfo = urlObj.pathname.substring(1); // Remove leading slash
|
|
105
|
+
URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
|
|
109
|
+
console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
|
|
110
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
|
|
115
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
|
|
116
|
+
|
|
117
|
+
if (fs.existsSync(GIT_MODULES)) {
|
|
118
|
+
console.log(`${MODULE_PATH} has submodules`);
|
|
119
|
+
const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
|
|
120
|
+
if (result.status !== 0) {
|
|
121
|
+
console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
|
|
122
|
+
process.exit(result.status);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
|
|
128
|
+
|
|
129
|
+
// ----------- Helper Functions -----------
|
|
130
|
+
|
|
131
|
+
function runGit(args, returnResult = false) {
|
|
132
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
133
|
+
|
|
134
|
+
if (returnResult) return result;
|
|
135
|
+
|
|
136
|
+
if (result.status !== 0) {
|
|
137
|
+
throw new Error(result.stderr || `git ${args.join(" ")} failed`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result.stdout || "";
|
|
141
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require("child_process");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
// Path to .env file
|
|
7
|
+
const envPath = path.resolve(__dirname, ".env");
|
|
8
|
+
|
|
9
|
+
// Check if .env exists and read it
|
|
10
|
+
if (fs.existsSync(envPath)) {
|
|
11
|
+
const envContent = fs.readFileSync(envPath, "utf8");
|
|
12
|
+
|
|
13
|
+
// Split into lines and process each
|
|
14
|
+
envContent.split("\n").forEach((line) => {
|
|
15
|
+
const trimmedLine = line.trim();
|
|
16
|
+
|
|
17
|
+
// Ignore empty lines and comments
|
|
18
|
+
if (!trimmedLine || trimmedLine.startsWith("#")) return;
|
|
19
|
+
|
|
20
|
+
// Extract key and value
|
|
21
|
+
const [key, ...vals] = trimmedLine.split("=");
|
|
22
|
+
if (!key) return;
|
|
23
|
+
|
|
24
|
+
const value = vals
|
|
25
|
+
.join("=")
|
|
26
|
+
.trim()
|
|
27
|
+
.replace(/^['"]|['"]$/g, ""); // Remove surrounding quotes
|
|
28
|
+
process.env[key.trim()] = value;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Parse CLI args
|
|
33
|
+
const args = process.argv.slice(2);
|
|
34
|
+
let ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
|
|
35
|
+
let REPO_PATH = ROOT;
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < args.length; i++) {
|
|
38
|
+
if (args[i] === "-cwd" && args[i + 1]) {
|
|
39
|
+
ROOT = path.resolve(args[++i]);
|
|
40
|
+
} else if (args[i].startsWith("--cwd=")) {
|
|
41
|
+
ROOT = path.resolve(args[i].split("=")[1]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`Installing submodules at ${ROOT}`);
|
|
46
|
+
|
|
47
|
+
// Get submodule paths
|
|
48
|
+
const submoduleList = runGit([
|
|
49
|
+
"-C",
|
|
50
|
+
REPO_PATH,
|
|
51
|
+
"config",
|
|
52
|
+
"-f",
|
|
53
|
+
".gitmodules",
|
|
54
|
+
"--get-regexp",
|
|
55
|
+
"^submodule\\..*\\.path$"
|
|
56
|
+
])
|
|
57
|
+
.split("\n")
|
|
58
|
+
.filter(Boolean);
|
|
59
|
+
|
|
60
|
+
for (const line of submoduleList) {
|
|
61
|
+
const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
|
|
62
|
+
const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
|
|
63
|
+
|
|
64
|
+
if (fs.existsSync(RELATIVE_MODULE_PATH)) {
|
|
65
|
+
console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
|
|
66
|
+
fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
|
|
70
|
+
const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
|
|
71
|
+
|
|
72
|
+
let BRANCH = "master";
|
|
73
|
+
try {
|
|
74
|
+
BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
|
|
75
|
+
} catch {
|
|
76
|
+
// silently ignore if branch is not set
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const addResult = runGit(
|
|
80
|
+
["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH],
|
|
81
|
+
true
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (addResult.status !== 0) {
|
|
85
|
+
console.warn(`Cannot add submodule ${MODULE_PATH}`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
|
|
90
|
+
|
|
91
|
+
if (process.env.ACCESS_TOKEN) {
|
|
92
|
+
let URL_WITH_TOKEN = "";
|
|
93
|
+
let repoInfo;
|
|
94
|
+
|
|
95
|
+
if (URL.includes("github.com")) {
|
|
96
|
+
repoInfo = URL.replace("https://github.com/", "");
|
|
97
|
+
URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
|
|
98
|
+
} else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
|
|
99
|
+
repoInfo = URL.replace("https://gitlab.com/", "");
|
|
100
|
+
URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
|
|
101
|
+
} else {
|
|
102
|
+
// For other Git providers, try a generic approach
|
|
103
|
+
const urlObj = new URL(URL);
|
|
104
|
+
repoInfo = urlObj.pathname.substring(1); // Remove leading slash
|
|
105
|
+
URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
|
|
109
|
+
console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
|
|
110
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
|
|
115
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
|
|
116
|
+
|
|
117
|
+
if (fs.existsSync(GIT_MODULES)) {
|
|
118
|
+
console.log(`${MODULE_PATH} has submodules`);
|
|
119
|
+
const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
|
|
120
|
+
if (result.status !== 0) {
|
|
121
|
+
console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
|
|
122
|
+
process.exit(result.status);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
|
|
128
|
+
|
|
129
|
+
// ----------- Helper Functions -----------
|
|
130
|
+
|
|
131
|
+
function runGit(args, returnResult = false) {
|
|
132
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
133
|
+
|
|
134
|
+
if (returnResult) return result;
|
|
135
|
+
|
|
136
|
+
if (result.status !== 0) {
|
|
137
|
+
throw new Error(result.stderr || `git ${args.join(" ")} failed`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result.stdout || "";
|
|
141
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
__dirname,
|
|
5
|
+
__filename,
|
|
6
|
+
init_esm_shims
|
|
7
|
+
} from "./chunk-VXZQNLPU.mjs";
|
|
8
|
+
import {
|
|
9
|
+
__commonJS,
|
|
10
|
+
__require
|
|
11
|
+
} from "./chunk-FB6YIQYR.mjs";
|
|
12
|
+
|
|
13
|
+
// src/submodule-install.cjs
|
|
14
|
+
var require_submodule_install = __commonJS({
|
|
15
|
+
"src/submodule-install.cjs"() {
|
|
16
|
+
init_esm_shims();
|
|
17
|
+
var { spawnSync } = __require("child_process");
|
|
18
|
+
var fs = __require("fs");
|
|
19
|
+
var path = __require("path");
|
|
20
|
+
var envPath = path.resolve(__dirname, ".env");
|
|
21
|
+
if (fs.existsSync(envPath)) {
|
|
22
|
+
const envContent = fs.readFileSync(envPath, "utf8");
|
|
23
|
+
envContent.split("\n").forEach((line) => {
|
|
24
|
+
const trimmedLine = line.trim();
|
|
25
|
+
if (!trimmedLine || trimmedLine.startsWith("#")) return;
|
|
26
|
+
const [key, ...vals] = trimmedLine.split("=");
|
|
27
|
+
if (!key) return;
|
|
28
|
+
const value = vals.join("=").trim().replace(/^['"]|['"]$/g, "");
|
|
29
|
+
process.env[key.trim()] = value;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var args = process.argv.slice(2);
|
|
33
|
+
var ROOT = runGit(["rev-parse", "--show-toplevel"]).trim();
|
|
34
|
+
var REPO_PATH = ROOT;
|
|
35
|
+
for (let i = 0; i < args.length; i++) {
|
|
36
|
+
if (args[i] === "-cwd" && args[i + 1]) {
|
|
37
|
+
ROOT = path.resolve(args[++i]);
|
|
38
|
+
} else if (args[i].startsWith("--cwd=")) {
|
|
39
|
+
ROOT = path.resolve(args[i].split("=")[1]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
console.log(`Installing submodules at ${ROOT}`);
|
|
43
|
+
var submoduleList = runGit([
|
|
44
|
+
"-C",
|
|
45
|
+
REPO_PATH,
|
|
46
|
+
"config",
|
|
47
|
+
"-f",
|
|
48
|
+
".gitmodules",
|
|
49
|
+
"--get-regexp",
|
|
50
|
+
"^submodule\\..*\\.path$"
|
|
51
|
+
]).split("\n").filter(Boolean);
|
|
52
|
+
for (const line of submoduleList) {
|
|
53
|
+
const [KEY, MODULE_PATH] = line.trim().split(/\s+/);
|
|
54
|
+
const RELATIVE_MODULE_PATH = path.join(ROOT, MODULE_PATH);
|
|
55
|
+
if (fs.existsSync(RELATIVE_MODULE_PATH)) {
|
|
56
|
+
console.log(`Deleting ${RELATIVE_MODULE_PATH}`);
|
|
57
|
+
fs.rmSync(RELATIVE_MODULE_PATH, { recursive: true, force: true });
|
|
58
|
+
}
|
|
59
|
+
const NAME = KEY.match(/^submodule\.(.*)\.path$/)[1];
|
|
60
|
+
const URL = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.url`]).trim();
|
|
61
|
+
let BRANCH = "master";
|
|
62
|
+
try {
|
|
63
|
+
BRANCH = runGit(["config", "-f", ".gitmodules", "--get", `submodule.${NAME}.branch`]).trim();
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
const addResult = runGit(
|
|
67
|
+
["-C", REPO_PATH, "submodule", "add", "--force", "-b", BRANCH, "--name", NAME, URL, MODULE_PATH],
|
|
68
|
+
true
|
|
69
|
+
);
|
|
70
|
+
if (addResult.status !== 0) {
|
|
71
|
+
console.warn(`Cannot add submodule ${MODULE_PATH}`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const GIT_MODULES = path.join(RELATIVE_MODULE_PATH, ".gitmodules");
|
|
75
|
+
if (process.env.ACCESS_TOKEN) {
|
|
76
|
+
let URL_WITH_TOKEN = "";
|
|
77
|
+
let repoInfo;
|
|
78
|
+
if (URL.includes("github.com")) {
|
|
79
|
+
repoInfo = URL.replace("https://github.com/", "");
|
|
80
|
+
URL_WITH_TOKEN = `https://${process.env.ACCESS_TOKEN}@github.com/${repoInfo}`;
|
|
81
|
+
} else if (URL.includes("gitlab.com") && typeof process.env.GITLAB_TOKEN === "string") {
|
|
82
|
+
repoInfo = URL.replace("https://gitlab.com/", "");
|
|
83
|
+
URL_WITH_TOKEN = `https://oauth2:${process.env.ACCESS_TOKEN}@gitlab.com/${repoInfo}`;
|
|
84
|
+
} else {
|
|
85
|
+
const urlObj = new URL(URL);
|
|
86
|
+
repoInfo = urlObj.pathname.substring(1);
|
|
87
|
+
URL_WITH_TOKEN = `${urlObj.protocol}//${process.env.ACCESS_TOKEN}@${urlObj.host}${urlObj.pathname}`;
|
|
88
|
+
}
|
|
89
|
+
if (URL_WITH_TOKEN && URL_WITH_TOKEN.length > 0) {
|
|
90
|
+
console.log(`Apply token for ${repoInfo} at ${MODULE_PATH} branch ${BRANCH}`);
|
|
91
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "remote", "set-url", "origin", URL_WITH_TOKEN]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "fetch", "--all"]);
|
|
95
|
+
runGit(["-C", RELATIVE_MODULE_PATH, "pull", "origin", BRANCH, "-X", "theirs"]);
|
|
96
|
+
if (fs.existsSync(GIT_MODULES)) {
|
|
97
|
+
console.log(`${MODULE_PATH} has submodules`);
|
|
98
|
+
const result = spawnSync("node", [__filename, "-cwd", RELATIVE_MODULE_PATH], { stdio: "inherit" });
|
|
99
|
+
if (result.status !== 0) {
|
|
100
|
+
console.error(`Recursive submodule failed for ${RELATIVE_MODULE_PATH}`);
|
|
101
|
+
process.exit(result.status);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
runGit(["-C", REPO_PATH, "submodule", "update", "--init", "--recursive"]);
|
|
106
|
+
function runGit(args2, returnResult = false) {
|
|
107
|
+
const result = spawnSync("git", args2, { encoding: "utf-8" });
|
|
108
|
+
if (returnResult) return result;
|
|
109
|
+
if (result.status !== 0) {
|
|
110
|
+
throw new Error(result.stderr || `git ${args2.join(" ")} failed`);
|
|
111
|
+
}
|
|
112
|
+
return result.stdout || "";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
export default require_submodule_install();
|
package/lib/utils.cjs
CHANGED
|
@@ -4,18 +4,6 @@ var argv = require("minimist")(process.argv.slice(2));
|
|
|
4
4
|
function getArgs() {
|
|
5
5
|
return argv;
|
|
6
6
|
}
|
|
7
|
-
function delStream(globStream) {
|
|
8
|
-
globStream.stream().on("data", (result) => {
|
|
9
|
-
const fullPath = path.resolve(process.cwd(), result);
|
|
10
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
11
|
-
const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
|
|
12
|
-
for (let i = 0; i < subdir.length; i++) {
|
|
13
|
-
del(subdir[i]);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
del(fullPath);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
7
|
function del(fullPath) {
|
|
20
8
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
21
9
|
const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
|
|
@@ -31,5 +19,17 @@ function del(fullPath) {
|
|
|
31
19
|
}
|
|
32
20
|
}
|
|
33
21
|
}
|
|
22
|
+
function delStream(globStream) {
|
|
23
|
+
globStream.stream().on("data", (result) => {
|
|
24
|
+
const fullPath = path.resolve(process.cwd(), result);
|
|
25
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
26
|
+
const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
|
|
27
|
+
for (let i = 0; i < subdir.length; i++) {
|
|
28
|
+
del(subdir[i]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
del(fullPath);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
34
|
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
35
35
|
module.exports = { del, delStream, getArgs, delay };
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import * as minimist from 'minimist';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* delete file recursive
|
|
5
3
|
* @param {string} fullPath
|
|
6
4
|
*/
|
|
7
|
-
|
|
5
|
+
export function del(fullPath: string): void;
|
|
8
6
|
/**
|
|
9
7
|
* glob stream handler
|
|
10
8
|
* @param {glob.Glob} globStream
|
|
11
9
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export function delStream(globStream: glob.Glob): void;
|
|
11
|
+
export function getArgs(): import("minimist").ParsedArgs;
|
|
14
12
|
/**
|
|
15
13
|
* async delayed
|
|
16
14
|
* @param {number} ms
|
|
17
15
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export { del, delStream, delay, getArgs };
|
|
16
|
+
export function delay(ms: number): Promise<any>;
|
package/lib/utils.js
CHANGED
|
@@ -1,35 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var argv = require("minimist")(process.argv.slice(2));
|
|
1
|
+
const { fs, path } = require("sbg-utility");
|
|
2
|
+
const argv = require("minimist")(process.argv.slice(2));
|
|
4
3
|
function getArgs() {
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
function delStream(globStream) {
|
|
8
|
-
globStream.stream().on("data", (result) => {
|
|
9
|
-
const fullPath = path.resolve(process.cwd(), result);
|
|
10
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
11
|
-
const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
|
|
12
|
-
for (let i = 0; i < subdir.length; i++) {
|
|
13
|
-
del(subdir[i]);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
del(fullPath);
|
|
17
|
-
});
|
|
4
|
+
return argv;
|
|
18
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* delete file recursive
|
|
8
|
+
* @param {string} fullPath
|
|
9
|
+
*/
|
|
19
10
|
function del(fullPath) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
12
|
+
// delete all files each package directory
|
|
13
|
+
const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
|
|
14
|
+
for (let i = 0; i < subdir.length; i++) {
|
|
15
|
+
del(subdir[i]);
|
|
16
|
+
}
|
|
24
17
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
else {
|
|
19
|
+
try {
|
|
20
|
+
fs.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7000 });
|
|
21
|
+
console.log("deleted", fullPath);
|
|
22
|
+
}
|
|
23
|
+
catch (_) {
|
|
24
|
+
console.log("failed delete", fullPath);
|
|
25
|
+
}
|
|
31
26
|
}
|
|
32
|
-
}
|
|
33
27
|
}
|
|
34
|
-
|
|
28
|
+
/**
|
|
29
|
+
* glob stream handler
|
|
30
|
+
* @param {glob.Glob} globStream
|
|
31
|
+
*/
|
|
32
|
+
function delStream(globStream) {
|
|
33
|
+
globStream.stream().on("data", (result) => {
|
|
34
|
+
const fullPath = path.resolve(process.cwd(), result);
|
|
35
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
36
|
+
// delete all files each package directory
|
|
37
|
+
const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
|
|
38
|
+
for (let i = 0; i < subdir.length; i++) {
|
|
39
|
+
del(subdir[i]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
del(fullPath);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* async delayed
|
|
47
|
+
* @param {number} ms
|
|
48
|
+
*/
|
|
49
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
35
50
|
module.exports = { del, delStream, getArgs, delay };
|
package/lib/utils.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
require_utils
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-OKYLF2MU.mjs";
|
|
5
|
+
import "./chunk-VXZQNLPU.mjs";
|
|
6
|
+
import "./chunk-FB6YIQYR.mjs";
|
|
7
7
|
export default require_utils();
|