@winner-fed/winner-deploy 4.3.5 → 4.3.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.
@@ -0,0 +1,16 @@
1
+ 1. scripts/js/confuse.js
2
+ 用 path.join(pkgRoot, webAppName, configBase + '.js') 定位配置文件,不再写死 frame-layout/sysconfig.js。
3
+ 参数约定:argv[1] = SEE 的 webAppName;argv[2] = 配置名(不含 .js,默认 sysconfig);argv[3] = 发布包根目录(可选,默认可用 path.resolve(__dirname, '..', '..'))。
4
+ 支持环境变量 WEB_APP_NAME、CONFIG_FILE_NAME。
5
+ 缺 webAppName、文件不存在或混淆失败时 process.exit(1),便于 afterInstall.sh 判断。
6
+
7
+ 2. scripts/afterInstall.sh
8
+ 在安装前用 pkg_root=\pwd`记下发布包根目录(与检查${webAppName}` 时一致)。
9
+ cd 到脚本目录后执行:node ../js/confuse.js "${webAppName}" "{{configFileName}}" "$pkg_root"(原先 ./scripts/js/ 在 scripts/<name>/ 下会指错路径,已改为 ../js/)。
10
+
11
+ 3. src/genWebPackage.ts
12
+ 先生成 tplPath、再算 resolvedConfigFileName(与 winner / pro / 自定义 tpl 规则一致),再写脚本和 deploy.xml,避免以前「脚本里的名字」和「实际 template 名」不一致。
13
+ afterInstall 的 lodash 模板增加 configFileName: resolvedConfigFileName,打包后会把 {{configFileName}} 写成具体名字(如 sysconfig、config.local)。
14
+ genDeployXml 改为使用 resolvedConfigFileName。
15
+ 生成 zip 时把 templates/see/bash/scripts/js 拷到 tmp/scripts/js,与 ../js/confuse.js 一致。
16
+ 若你本地只改模板、不跑 genSeePackage,需在发布包里保留 scripts/js/,并保证 afterInstall 里第二段参数与 deploy.xml 里 ${webAppName}/xxx.js 的 xxx 一致。
@@ -15,7 +15,7 @@
15
15
  <system id="{{ name }}" type="{{ type }}" name="{{ name }}" mode="cluster" front="">
16
16
  <scale describe="集群规模" />
17
17
  <scripts describe="集群脚本集">
18
- <script name="beforeInstall" path="" describe="安装前处理"/>
18
+ <script name="beforeInstall" path="./scripts/{{ name }}/beforeInstall.sh" describe="安装前处理"/>
19
19
  <script name="install" path="./scripts/{{ name }}/install.py" describe="部署"/>
20
20
  <script name="afterInstall" path="./scripts/{{ name }}/afterInstall.py" describe="安装后处理"/>
21
21
  <script name="start" path="" describe="启动" />
@@ -1,26 +1,44 @@
1
1
  #!/usr/bin/python
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
- # 为上传之后的 pkg 包赋755权限
5
4
  import os
5
+ import sys
6
6
  import utils
7
7
 
8
8
  # 读取 deploy.xml 配置文件定义的 webAppName
9
9
  webAppName = "${webAppName}"
10
10
  # TIPS: 执行脚本的路径是在 安装目录 下,对应 deploy.xml 里的 workspace 字段
11
11
  pkgPath = os.path.join(os.getcwd(), webAppName)
12
+ pkg_root = os.getcwd()
12
13
 
13
14
  def chmodPkg():
14
15
  for root,dirs,files in os.walk(pkgPath):
15
16
  for file in files:
16
17
  if(not file[0] == "."):
17
- # 生成完整路径
18
18
  fp = os.path.join(root, file)
19
19
  utils.chmod(fp, "755")
20
20
  for dir in dirs:
21
21
  if(not dir[0] == "."):
22
- # 这句话没有起作用,因为walk自己还是会遍历到.dir下面去
23
22
  dp = os.path.join(root, dir)
24
23
  utils.chmod(dp, "755")
25
24
 
25
+ if not os.path.isdir(webAppName):
26
+ sys.stderr.write("错误: 安装检查失败。应用目录 '%s' 不存在。\n" % webAppName)
27
+ sys.exit(1)
28
+
29
+ if len(os.listdir(webAppName)) == 0:
30
+ sys.stderr.write("错误: 安装检查失败。应用目录 '%s' 存在但为空。\n" % webAppName)
31
+ sys.exit(1)
32
+
26
33
  chmodPkg()
34
+
35
+ <% if (enableObfuscation) { %>
36
+ import subprocess
37
+ script_dir = os.path.dirname(os.path.abspath(__file__))
38
+ index_js = os.path.normpath(os.path.join(script_dir, '.', 'js', 'confuse.js'))
39
+ cmd = ['node', index_js, webAppName, '{{configFileName}}', pkg_root]
40
+ ret = subprocess.call(cmd)
41
+ if ret != 0:
42
+ sys.stderr.write("错误: 混淆配置文件失败。\n")
43
+ sys.exit(ret)
44
+ <% } %>
@@ -0,0 +1,85 @@
1
+ #!/bin/bash
2
+
3
+ # 定义图标
4
+ CHECK_ICON="✅"
5
+ ERROR_ICON="❌"
6
+ INFO_ICON="ℹ️"
7
+ WARNING_ICON="⚠️"
8
+
9
+ echo -e "${INFO_ICON} 开始检查 Python 环境..."
10
+
11
+ # 检查 python 命令是否可用(因为实际运行时调用的就是这个命令)
12
+ if command -v python &> /dev/null
13
+ then
14
+ # 尝试获取 Python 版本
15
+ if PYTHON_VERSION=$(python --version 2>&1)
16
+ then
17
+ echo -e "${CHECK_ICON} Python 命令检测成功: ${PYTHON_VERSION}"
18
+
19
+ # 执行一段简单的 Python 脚本来验证环境是否真正可用
20
+ echo -e "${INFO_ICON} 正在验证 Python 环境可执行性..."
21
+
22
+ # 创建一个简单的测试脚本
23
+ TEST_SCRIPT='
24
+ import sys
25
+ import os
26
+ print("Python version:", sys.version.split()[0])
27
+ print("Python executable:", sys.executable)
28
+ print("Platform:", sys.platform)
29
+ try:
30
+ import json
31
+ print("JSON module: OK")
32
+ except ImportError as e:
33
+ print("JSON module: FAILED -", str(e))
34
+ sys.exit(1)
35
+ print("Environment test: PASSED")
36
+ '
37
+
38
+ # 执行测试脚本
39
+ PYTHON_TEST_OUTPUT=$(python -c "$TEST_SCRIPT" 2>&1)
40
+ if [ $? -eq 0 ]; then
41
+ echo -e "${CHECK_ICON} Python 环境验证成功:"
42
+ echo "$PYTHON_TEST_OUTPUT" | while IFS= read -r line; do
43
+ echo -e " ${line}"
44
+ done
45
+ exit 0
46
+ else
47
+ echo -e "${ERROR_ICON} 错误: Python 环境验证失败。详细信息:" >&2
48
+ echo "$PYTHON_TEST_OUTPUT" | while IFS= read -r line; do
49
+ echo -e " ${line}" >&2
50
+ done
51
+ echo -e "${ERROR_ICON} 部署无法继续,请检查您的 Python 环境。" >&2
52
+ exit 1
53
+ fi
54
+ else
55
+ echo -e "${ERROR_ICON} 错误: python 命令存在但无法正常运行。错误信息: ${PYTHON_VERSION}" >&2
56
+ echo -e "${ERROR_ICON} 部署无法继续,请检查您的 Python 安装。" >&2
57
+ exit 1
58
+ fi
59
+ else
60
+ # python 命令不存在,给出操作建议
61
+ echo -e "${ERROR_ICON} 错误: 系统中未找到 'python' 命令。" >&2
62
+ echo -e "${INFO_ICON} 部署需要 'python' 命令才能继续。" >&2
63
+ echo -e "${INFO_ICON} 解决方案:" >&2
64
+ echo -e " 1. 如果您已安装了 Python 3,可以创建软链接: 参考示例" >&2
65
+ echo -e " sudo ln -s \$(which python3) /usr/local/bin/python" >&2
66
+ echo -e "" >&2
67
+ echo -e " 2. 安装 Python 3 (推荐) 参考示例如下:" >&2
68
+ echo -e " # Ubuntu/Debian:" >&2
69
+ echo -e " sudo apt-get update && sudo apt-get install python3 python3-pip" >&2
70
+ echo -e " sudo ln -s /usr/bin/python3 /usr/bin/python" >&2
71
+ echo -e "" >&2
72
+ echo -e " # CentOS/RHEL 8+ 参考示例如下:" >&2
73
+ echo -e " sudo dnf install python3 python3-pip" >&2
74
+ echo -e " sudo alternatives --install /usr/bin/python python /usr/bin/python3 1" >&2
75
+ echo -e "" >&2
76
+ echo -e " # CentOS/RHEL 7 参考示例如下:" >&2
77
+ echo -e " sudo yum install python3 python3-pip" >&2
78
+ echo -e " sudo ln -s /usr/bin/python3 /usr/bin/python" >&2
79
+ echo -e "" >&2
80
+ echo -e " 3. 或者安装 Python 2.7 (不推荐,已停止维护):" >&2
81
+ echo -e " # Ubuntu/Debian: sudo apt-get install python2.7" >&2
82
+ echo -e " # CentOS/RHEL: sudo yum install python2" >&2
83
+ echo -e "${WARNING_ICON} 请安装 Python 后重新运行部署。" >&2
84
+ exit 1
85
+ fi
@@ -12,60 +12,70 @@ import re
12
12
  import sys
13
13
  import utils
14
14
 
15
- try:
16
- reload(sys)
17
- sys.setdefaultencoding("utf8")
18
- except:
19
- print("Failed to perform module reload, continue installation")
20
-
15
+ # 在 Python 2 中导入额外模块
16
+ if sys.version_info[0] == 2:
17
+ try:
18
+ from io import open
19
+ except ImportError:
20
+ pass
21
+ # 仅在Python 2中设置默认编码
22
+ if sys.version_info[0] == 2:
23
+ try:
24
+ reload(sys)
25
+ sys.setdefaultencoding("utf8")
26
+ except Exception as e:
27
+ print("执行模块重载失败,原因:", e)
28
+ print("继续安装...")
21
29
 
22
30
  name = "{{name}}"
23
- type = "{{type}}"
31
+ deploy_type = "{{type}}"
24
32
  # 读取 deploy.xml 配置文件定义的 webAppName
25
33
  webAppName = "${webAppName}"
26
34
 
27
- def install(name, type):
28
- conf = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "conf")
35
+ def copy_source(deploy_type, name):
36
+ if deploy_type == "bizframe":
37
+ os.system("cp -rf ./tmp/source ./" + name)
38
+ elif deploy_type == "subsystem":
39
+ os.system("cp -rf ./tmp/source ./")
29
40
 
41
+ def install(name, deploy_type):
42
+ conf = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "conf")
30
43
  manifest = ""
31
44
 
32
- for file in os.listdir(conf):
33
- if(re.match(r'manifest\.[0-9]+\.json', file)):
34
- manifest = file
45
+ if os.path.exists(conf):
46
+ for file in os.listdir(conf):
47
+ if re.match(r'manifest\.[0-9]+\.json', file):
48
+ manifest = file
49
+ break
35
50
 
36
- if(manifest == ""):
37
- if(type == "bizframe"):
38
- os.popen("cp -rf ./tmp/source ./" + name)
39
- elif(type == "subsystem"):
40
- os.popen("cp -rf ./tmp/source ./")
51
+ if not manifest:
52
+ copy_source(deploy_type, name)
41
53
  else:
42
- file = open(os.path.join(conf, manifest), "rb")
43
- fileJson = json.load(file)
54
+ with open(os.path.join(conf, manifest), "rb") as f:
55
+ fileJson = json.load(f)
44
56
 
45
57
  for x in fileJson:
46
- destinationdir = ""
47
- source = ""
48
-
49
- if(type == "bizframe"):
58
+ if deploy_type == "bizframe":
50
59
  destinationdir = "./" + webAppName + "/" + fileJson[x]["dir"]
51
60
  source = "./tmp/source/" + fileJson[x]["path"]
52
- elif(type == "subsystem"):
61
+ elif deploy_type == "subsystem":
53
62
  destinationdir = "./" + fileJson[x]["dir"]
54
63
  source = "./tmp/source/" + fileJson[x]["path"]
64
+ else:
65
+ continue
55
66
 
56
- if not (os.path.exists(destinationdir)):
67
+ if not os.path.exists(destinationdir):
57
68
  os.makedirs(destinationdir)
58
69
 
59
- if(os.path.exists(source)):
60
- os.popen("cp -rf " + source + ' ' + destinationdir)
61
-
62
- os.popen("rm -rf tmp")
70
+ if os.path.exists(source):
71
+ os.system("cp -rf " + source + ' ' + destinationdir)
63
72
 
73
+ os.system("rm -rf tmp")
64
74
 
65
- utils.clear(webAppName, type)
75
+ utils.clear(webAppName, deploy_type)
66
76
 
67
77
  # SEE 在脚本下发的时候会保留 scripts 目录下的内容,造成 conf 中存在多份 manifest
68
- os.popen("rm -rf ./scripts/" + name)
69
- os.popen("cp -rf ./tmp/scripts/" + name + " ./scripts/" + name)
78
+ os.system("rm -rf ./scripts/" + name)
79
+ os.system("cp -rf ./tmp/scripts/" + name + " ./scripts/" + name)
70
80
 
71
- install(name, type)
81
+ install(name, deploy_type)
@@ -0,0 +1,43 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const JavaScriptObfuscator = require('./obfuscator')
4
+ try {
5
+ const webAppName = process.argv[2] || process.env.WEB_APP_NAME
6
+ const configBase = process.argv[3] || process.env.CONFIG_FILE_NAME || 'sysconfig'
7
+ const pkgRoot = process.argv[4] ? path.resolve(process.argv[4]) : path.resolve(__dirname, '..', '..')
8
+ if (!webAppName) {
9
+ console.error('缺少前端应用目录名:请传入第 1 个参数或设置环境变量 WEB_APP_NAME')
10
+ process.exit(1)
11
+ }
12
+ const filepath = path.join(pkgRoot, webAppName, `${configBase}.js`)
13
+ console.log(`__filename:${__filename}`)
14
+ console.log(`文件路径:${filepath}`)
15
+ if (!fs.existsSync(filepath)) {
16
+ console.error(`文件不存在: ${filepath}`)
17
+ process.exit(1)
18
+ }
19
+ const sourceCode = fs.readFileSync(filepath, 'utf8')
20
+ const obfuscationResult = JavaScriptObfuscator.obfuscate(
21
+ sourceCode,
22
+ {
23
+ compact: true,
24
+ controlFlowFlattening: true,
25
+ controlFlowFlatteningThreshold: 0.75,
26
+ deadCodeInjection: true,
27
+ deadCodeInjectionThreshold: 0.5,
28
+ numbersToExpressions: true,
29
+ simplify: true,
30
+ selfDefending: true,
31
+ shuffleStringArray: true,
32
+ splitStrings: true,
33
+ stringArrayThreshold: 0.75,
34
+ unicodeEscapeSequence: true
35
+ }
36
+ )
37
+ fs.writeFileSync(filepath, obfuscationResult.getObfuscatedCode())
38
+ console.log('代码混淆完成,并已更新成功')
39
+ console.log(`更新路径:${filepath}`)
40
+ } catch (e) {
41
+ console.error(e)
42
+ process.exit(1)
43
+ }