@ts-max/deploy 0.0.17 → 0.0.19
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/index.cjs +15 -31
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -10,26 +10,8 @@ const axios = require("axios");
|
|
|
10
10
|
const os = require("os");
|
|
11
11
|
const chalk = require("chalk");
|
|
12
12
|
const inquirer = require("inquirer");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (e) {
|
|
16
|
-
for (const k in e) {
|
|
17
|
-
if (k !== "default") {
|
|
18
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: () => e[k]
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
n.default = e;
|
|
27
|
-
return Object.freeze(n);
|
|
28
|
-
}
|
|
29
|
-
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
30
|
-
const process__namespace = /* @__PURE__ */ _interopNamespaceDefault(process);
|
|
31
|
-
const __cwd = process__namespace.cwd();
|
|
32
|
-
const pak = require(path__namespace.join(__cwd, "package.json"));
|
|
13
|
+
const __cwd = process.cwd();
|
|
14
|
+
const pak = require(path.join(__cwd, "package.json"));
|
|
33
15
|
const account = getAccount();
|
|
34
16
|
const defaultConfig = {
|
|
35
17
|
CONFIG_FILE: "deploy/config.js",
|
|
@@ -39,7 +21,7 @@ const defaultConfig = {
|
|
|
39
21
|
APP_TITLE: pak.title || pak.name,
|
|
40
22
|
JENKINS_BASE_URL: "",
|
|
41
23
|
JENKINS_JOB_NAME: pak.name?.replace(/\s+/, "-").toLowerCase(),
|
|
42
|
-
JENKINS_JOB_XML_FILE:
|
|
24
|
+
JENKINS_JOB_XML_FILE: path.join(__dirname, "job.xml"),
|
|
43
25
|
RANCHER: false,
|
|
44
26
|
RANCHER_URL: void 0,
|
|
45
27
|
RANCHER_BEARER_TOKEN: void 0,
|
|
@@ -47,6 +29,7 @@ const defaultConfig = {
|
|
|
47
29
|
GIT_URL: getGitUrl(),
|
|
48
30
|
GIT_BRANCH: getGitBranch$1(),
|
|
49
31
|
NODE_VERSION: "18",
|
|
32
|
+
NOTICE_ENABLED: false,
|
|
50
33
|
NOTICE_USERS: void 0,
|
|
51
34
|
MESSAGE_URL: void 0,
|
|
52
35
|
MESSAGE_TOKEN: void 0
|
|
@@ -60,7 +43,7 @@ const config = Object.keys(defaultConfig).reduce((prev, curr) => {
|
|
|
60
43
|
}, {});
|
|
61
44
|
function getConfig() {
|
|
62
45
|
const CONFIG_FILE = getProcessEnv("CONFIG_FILE") || defaultConfig.CONFIG_FILE;
|
|
63
|
-
let configPath =
|
|
46
|
+
let configPath = path.resolve(__cwd, CONFIG_FILE);
|
|
64
47
|
return fs.existsSync(configPath) ? require(configPath) : {};
|
|
65
48
|
}
|
|
66
49
|
function val(key) {
|
|
@@ -72,8 +55,8 @@ function val(key) {
|
|
|
72
55
|
return _defaultValue;
|
|
73
56
|
}
|
|
74
57
|
function getProcessEnv(key) {
|
|
75
|
-
if (key in
|
|
76
|
-
const value =
|
|
58
|
+
if (key in process.env) {
|
|
59
|
+
const value = process.env[key];
|
|
77
60
|
if (value === "false") return false;
|
|
78
61
|
if (value === "true") return true;
|
|
79
62
|
return value;
|
|
@@ -87,11 +70,11 @@ function getAccount() {
|
|
|
87
70
|
function getGitRoot() {
|
|
88
71
|
let rootPath = __cwd;
|
|
89
72
|
while (rootPath) {
|
|
90
|
-
if (fs.existsSync(
|
|
73
|
+
if (fs.existsSync(path.join(rootPath, ".git"))) {
|
|
91
74
|
break;
|
|
92
75
|
}
|
|
93
|
-
const paths = rootPath.split(
|
|
94
|
-
rootPath = paths.slice(0, paths.length - 1).join(
|
|
76
|
+
const paths = rootPath.split(path.sep);
|
|
77
|
+
rootPath = paths.slice(0, paths.length - 1).join(path.sep);
|
|
95
78
|
}
|
|
96
79
|
if (rootPath) return rootPath;
|
|
97
80
|
throw new Error("非git仓库,或 非仓库中子文件夹");
|
|
@@ -106,7 +89,7 @@ function httpToSSH(url) {
|
|
|
106
89
|
}
|
|
107
90
|
function getGitUrl() {
|
|
108
91
|
const gitRoot = getGitRoot();
|
|
109
|
-
const gitConfigPath =
|
|
92
|
+
const gitConfigPath = path.join(gitRoot, ".git", "config");
|
|
110
93
|
const configContent = fs.readFileSync(gitConfigPath, "UTF-8");
|
|
111
94
|
const arr = configContent.split("\n ");
|
|
112
95
|
const url = arr.find((item) => item.startsWith("url = ")) || "";
|
|
@@ -174,7 +157,7 @@ async function showJenkinsLog(buildNumber) {
|
|
|
174
157
|
return new Promise((resolve, reject) => {
|
|
175
158
|
const log = getJenkinsLogStream(buildNumber);
|
|
176
159
|
log.on("data", function(text) {
|
|
177
|
-
|
|
160
|
+
process.stdout.write(text);
|
|
178
161
|
});
|
|
179
162
|
log.on("error", function(err) {
|
|
180
163
|
reject(err);
|
|
@@ -192,10 +175,10 @@ async function showJenkinsLog(buildNumber) {
|
|
|
192
175
|
async function getJenkinsConfigXml() {
|
|
193
176
|
const gitUrl = config.GIT_URL;
|
|
194
177
|
const branch = config.GIT_BRANCH;
|
|
195
|
-
const shell = fs.readFileSync(path.resolve(
|
|
178
|
+
const shell = fs.readFileSync(path.resolve(process.cwd(), config.SHELL_FILE), "UTF-8");
|
|
196
179
|
const nodeVersion = config.NODE_VERSION;
|
|
197
180
|
if (!gitUrl) throw Error("git 地址不能为空!");
|
|
198
|
-
let xmlTemplate = fs.readFileSync(path.resolve(
|
|
181
|
+
let xmlTemplate = fs.readFileSync(path.resolve(process.cwd(), config.JENKINS_JOB_XML_FILE), "UTF-8") || "";
|
|
199
182
|
const parser = new xml2js.Parser(
|
|
200
183
|
/* options */
|
|
201
184
|
);
|
|
@@ -294,6 +277,7 @@ async function showLog(buildNumber) {
|
|
|
294
277
|
config.DOMAIN && console.log(`- web访问域名: ${config.DOMAIN}`);
|
|
295
278
|
}
|
|
296
279
|
async function notice(buildNumber) {
|
|
280
|
+
if (!config.NOTICE_ENABLED) return;
|
|
297
281
|
const jenkinsAddress = getJenkinsAddress(`/${buildNumber}/console`);
|
|
298
282
|
const webAddress = await getWebAddress();
|
|
299
283
|
let users = config.NOTICE_USERS || [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-max/deploy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
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": "
|
|
48
|
+
"gitHead": "1652d23f73bbab0671dde071aa50af5ac4a259fd"
|
|
49
49
|
}
|