@ts-max/deploy 0.0.19 → 0.0.20

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.
Files changed (2) hide show
  1. package/dist/index.cjs +26 -18
  2. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -26,8 +26,10 @@ const defaultConfig = {
26
26
  RANCHER_URL: void 0,
27
27
  RANCHER_BEARER_TOKEN: void 0,
28
28
  RANCHER_NAME_SPACE: "front-center",
29
- GIT_URL: getGitUrl(),
30
- GIT_BRANCH: getGitBranch$1(),
29
+ // Git information is resolved lazily in val() so explicit configuration can
30
+ // be used even when the command is run outside a Git worktree.
31
+ GIT_URL: "",
32
+ GIT_BRANCH: "",
31
33
  NODE_VERSION: "18",
32
34
  NOTICE_ENABLED: false,
33
35
  NOTICE_USERS: void 0,
@@ -47,11 +49,13 @@ function getConfig() {
47
49
  return fs.existsSync(configPath) ? require(configPath) : {};
48
50
  }
49
51
  function val(key) {
50
- let _defaultValue = defaultConfig[key];
51
- if (_defaultValue === void 0 || _defaultValue === "") _defaultValue = account[key];
52
52
  const envValue = getProcessEnv(key);
53
53
  if (envValue !== void 0) return envValue;
54
54
  if (key in customerConfig) return customerConfig[key];
55
+ if (key === "GIT_URL") return getGitUrl() || account[key];
56
+ if (key === "GIT_BRANCH") return getGitBranch$1();
57
+ let _defaultValue = defaultConfig[key];
58
+ if (_defaultValue === void 0 || _defaultValue === "") _defaultValue = account[key];
55
59
  return _defaultValue;
56
60
  }
57
61
  function getProcessEnv(key) {
@@ -68,16 +72,15 @@ function getAccount() {
68
72
  return JSON.parse(res.getBody("utf8"));
69
73
  }
70
74
  function getGitRoot() {
71
- let rootPath = __cwd;
72
- while (rootPath) {
73
- if (fs.existsSync(path.join(rootPath, ".git"))) {
74
- break;
75
- }
76
- const paths = rootPath.split(path.sep);
77
- rootPath = paths.slice(0, paths.length - 1).join(path.sep);
75
+ try {
76
+ return child_process.execSync("git rev-parse --show-toplevel", {
77
+ cwd: __cwd,
78
+ encoding: "utf8",
79
+ stdio: ["ignore", "pipe", "ignore"]
80
+ }).trim();
81
+ } catch {
82
+ throw new Error("非git仓库,或 非仓库中子文件夹");
78
83
  }
79
- if (rootPath) return rootPath;
80
- throw new Error("非git仓库,或 非仓库中子文件夹");
81
84
  }
82
85
  function httpToSSH(url) {
83
86
  if (!url) return url;
@@ -89,11 +92,16 @@ function httpToSSH(url) {
89
92
  }
90
93
  function getGitUrl() {
91
94
  const gitRoot = getGitRoot();
92
- const gitConfigPath = path.join(gitRoot, ".git", "config");
93
- const configContent = fs.readFileSync(gitConfigPath, "UTF-8");
94
- const arr = configContent.split("\n ");
95
- const url = arr.find((item) => item.startsWith("url = ")) || "";
96
- return httpToSSH(url.replace("url = ", ""));
95
+ try {
96
+ const url = child_process.execSync("git config --get remote.origin.url", {
97
+ cwd: gitRoot,
98
+ encoding: "utf8",
99
+ stdio: ["ignore", "pipe", "ignore"]
100
+ }).trim();
101
+ return httpToSSH(url);
102
+ } catch {
103
+ return "";
104
+ }
97
105
  }
98
106
  function getGitBranch$1() {
99
107
  return child_process.execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-max/deploy",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "部署脚本",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.ts",
@@ -45,5 +45,5 @@
45
45
  "cli"
46
46
  ],
47
47
  "license": "MIT",
48
- "gitHead": "1652d23f73bbab0671dde071aa50af5ac4a259fd"
48
+ "gitHead": "9e20383e4c4e28f8be62e7953abffb07c204af09"
49
49
  }