160 lines
4.2 KiB
Bash
Executable File
160 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# 脚本名称:build.sh
|
||
# 描述:快速构建deb脚本,用于解析参数、调用命令和显示帮助。
|
||
# 作者:wangpenglong
|
||
# 创建日期:2024年05月10日
|
||
|
||
# 开启调试模式,显示脚本执行过程 -x;
|
||
# 开启错误处理,脚本执行出错时退出 -e;
|
||
# set -ex
|
||
set -e
|
||
|
||
VERSION="1.0.0"
|
||
AUTHOR="wangpenglong"
|
||
DATE="2024年05月10日"
|
||
|
||
# 帮助信息
|
||
help_info() {
|
||
echo "使用方法:$0 [选项]"
|
||
echo " -h, --help 显示帮助信息"
|
||
echo " -v, --version 显示脚本版本信息"
|
||
echo " -c, --clean 清空构建的文件"
|
||
echo " -r, --replace_url 替换url为内网url"
|
||
echo " -b, --build 构建软件包"
|
||
}
|
||
|
||
# 版本信息
|
||
version_info() {
|
||
echo "脚本版本:${VERSION}"
|
||
echo "作者:${AUTHOR}"
|
||
echo "创建日期:${DATE}"
|
||
}
|
||
|
||
#添加参数clean,清理编译出的所有内容
|
||
function clean() {
|
||
git clean -fdx -e '*.deb' -e '*.rpm' #清除新建or添加的文件
|
||
rm -rf ../VSCode-linux-*
|
||
# git reset --hard #清除修改的文件
|
||
}
|
||
|
||
#替换url为内网url
|
||
function replace_url() {
|
||
#修改yarn.lock中地址
|
||
NPM_URL='https://registry.yarnpkg.com'
|
||
NPM_LOCAL_SEVER="http://kylinos.zz.gitea.com:3000"
|
||
|
||
for i in $(find -name yarn.lock); do
|
||
sed -i "s#${NPM_URL}#${NPM_LOCAL_SEVER}#g" $i
|
||
done
|
||
|
||
#替换calculate-deps.ts中地址
|
||
calculate_deps_files=("build/linux/debian/calculate-deps.ts" "build/linux/debian/calculate-deps.js")
|
||
dpkgShlibdepsUrl="https://raw.githubusercontent.com/chromium"
|
||
dpkgShlibdepsUrl_local="http://127.0.0.1:9099"
|
||
for calculate_deps_file in ${calculate_deps_files[@]}; do
|
||
echo "替换${calculate_deps_file}中的地址"
|
||
sed -i "s#${dpkgShlibdepsUrl}#${dpkgShlibdepsUrl_local}#g" ${calculate_deps_file}
|
||
sed -i "s/\/third_party//" ${calculate_deps_file}
|
||
done
|
||
|
||
install_sysroot_files=("build/linux/debian/install-sysroot.ts" "build/linux/debian/install-sysroot.js")
|
||
URL_PREFIX="https://msftelectron.blob.core.windows.net"
|
||
URL_PREFIX_local="http://127.0.0.1:9099"
|
||
sysrootJSONUrl="https://raw.githubusercontent.com/electron"
|
||
sysrootJSONUrl_local="http://127.0.0.1:9099/sysroots"
|
||
for install_sysroot_file in ${install_sysroot_files[@]}; do
|
||
echo "替换${install_sysroot_file}中的地址"
|
||
sed -i "s#${URL_PREFIX}#${URL_PREFIX_local}#g" ${install_sysroot_file}
|
||
sed -i "s#${sysrootJSONUrl}#${sysrootJSONUrl_local}#g" ${install_sysroot_file}
|
||
sed -i "s/https/http/g" ${install_sysroot_file}
|
||
done
|
||
echo "electron_mirror=http://127.0.0.1:9099/electron/" > .npmrc
|
||
ELECTRON_URL="https://electronjs.org"
|
||
sed -i "s#${ELECTRON_URL}#${URL_PREFIX_local}#g" .yarnrc
|
||
echo "[done] replace local url end."
|
||
}
|
||
|
||
function build(){
|
||
#start build
|
||
echo "[start] build start."
|
||
set -ex
|
||
|
||
#设置环境变量,构建软件包时,可不下载 electron二进制和 playwright browser包
|
||
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
|
||
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
||
|
||
#CHILD_CONCURRENCY 控制并行运行以构建节点模块的子进程的数量。
|
||
#将此数字设置为 1 将导致节点模块按顺序构建,这可以避免使用 node-gyp 的 Windows 上的链接器错误。
|
||
# CHILD_CONCURRENCY=1 yarn --frozen-lockfile --check-files --network-timeout 180000
|
||
# yarn --frozen-lockfile --check-files --network-timeout 180000
|
||
yarn
|
||
|
||
#关闭telemetry,node_modules也会有地址
|
||
./close_telemetry.sh
|
||
#检查
|
||
yarn monaco-compile-check
|
||
yarn valid-layers-check
|
||
#编译
|
||
yarn gulp compile-build
|
||
yarn gulp compile-extension-media
|
||
yarn gulp compile-extensions-build
|
||
#压缩代码
|
||
yarn gulp minify-vscode
|
||
yarn gulp "vscode-linux-x64-min-ci" #this will download electron,need change code.
|
||
#打包
|
||
yarn gulp "vscode-linux-x64-build-deb"
|
||
cp .build/linux/deb/*/deb/*.deb .
|
||
|
||
echo "[done] build end."
|
||
}
|
||
|
||
# 解析参数
|
||
parse_args() {
|
||
while [[ $# -gt 0 ]]; do
|
||
key="$1"
|
||
|
||
case $key in
|
||
-h|--help)
|
||
help_info
|
||
exit 0
|
||
;;
|
||
-v|--version)
|
||
version_info
|
||
exit 0
|
||
;;
|
||
-c|--clean)
|
||
clean
|
||
exit 0
|
||
;;
|
||
-r|--replace_url)
|
||
replace_url
|
||
exit 0
|
||
;;
|
||
-b|--build)
|
||
build
|
||
exit 0
|
||
;;
|
||
*)
|
||
echo "未知选项:$1"
|
||
help_info
|
||
exit 1
|
||
;;
|
||
esac
|
||
shift
|
||
done
|
||
# 没有选项时,显示帮助信息
|
||
if [ $# -eq 0 ]; then
|
||
help_info
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
# 主函数
|
||
main() {
|
||
parse_args "$@"
|
||
}
|
||
|
||
# 调用主函数
|
||
main "$@"
|