From c003e11b8044bfdf1ff7151f04f9c03fea777095 Mon Sep 17 00:00:00 2001 From: chu fan Date: Wed, 6 Sep 2023 19:24:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=AD=A3=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 +- scripts/.exec | 25 +----- scripts/docker | 203 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/lint | 16 +--- scripts/network | 99 ----------------------- scripts/release | 13 +--- 6 files changed, 213 insertions(+), 149 deletions(-) create mode 100755 scripts/docker delete mode 100755 scripts/network diff --git a/package.json b/package.json index 7ccb6ac..cc1c563 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ "deploy:ali": "bash scripts/deploy.sh ali $npm_package_version", "deploy:github": "bash scripts/deploy.sh github $npm_package_version", "deploy:vercel": "vercel --prod", - "release": "bumpp --preid alpha --execute=\"pnpm commit-and-tag-version && git add CHANGELOG.md\" --commit \"chore(release): publish v%s\" --all --tag --push", - "lint": "eslint --ext .js,.vue,.ts --ignore-path .gitignore .", - "lintfix": "eslint --fix --ext .js,.ts,.vue --ignore-path .gitignore .", + "release": "./scripts/release", + "lint": "./scripts/lint", + "lintfix": "./scripts/lint --fix", "clean": "find . -name \"node_modules\" -type d -exec rm -rf '{}' + " }, "scripts-info": { diff --git a/scripts/.exec b/scripts/.exec index b1ef1aa..2a1f11a 100755 --- a/scripts/.exec +++ b/scripts/.exec @@ -16,27 +16,6 @@ process.on('exit', () => { exit() }) -async function syncExec(command){ - let size=100 - let count = 0; - const intervalId = setInterval(async () => { - console.log('执行中'+'.'.repeat(count),size,count); - count++; - size = await new Promise((resolve,reject)=>{ - exec(command,(code)=>{ - console.log(code) - console.log('Exit code:', code); - resolve() - }) - }) - console.log(size) - if (count > size) { - clearInterval(intervalId); // 停止打印 - } - }, 1000); - -} - /** * 执行shell指令 * @param commands @@ -55,11 +34,11 @@ exports.execShell = async commands => { for (let index=0;index>>command--${count}:\n ${command} \n<<>>command(${count}):\n${command} \n<<{ + const command=getCommand(scriptName) + await execShell(command) +})() \ No newline at end of file diff --git a/scripts/lint b/scripts/lint index ebdf6dd..0d933c3 100755 --- a/scripts/lint +++ b/scripts/lint @@ -1,14 +1,10 @@ #!/usr/bin/env node /** * - * 将应用程序打包成可部署的包、文件、镜像 + * 格式化代码 * 例如: - * - ./scripts/bundle build 基础部署打包 - * - ./scripts/bundle build_proxy 用于三方平台部署打包 - * - ./scripts/bundle image 构建容器镜像 - * - ./scripts/bundle image_faster 本地build,快速构建容器镜像 - * - ./scripts/bundle xxx 其他参数,默认执行build命令 - * - ./scripts/bundle 交互式选择执行的命令 + * - ./scripts/lint + * - ./scripts/lint --fix */ const { execShell } = require("./.exec"); @@ -20,8 +16,4 @@ if(scriptName!=null){ fixed='--fix' } -;(async ()=>{ - const scriptCommand= `eslint ${fixed} --ext .js,.ts,.vue --ignore-path .gitignore .` - // 执行 - await execShell(scriptCommand) -})() \ No newline at end of file +;(async ()=>await execShell(`eslint ${fixed} --ext .js,.ts,.vue --ignore-path .gitignore .`))() \ No newline at end of file diff --git a/scripts/network b/scripts/network deleted file mode 100755 index 78ab5d5..0000000 --- a/scripts/network +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env node - -/** - * - * 例如: - * - ./scripts/network create - * - ./scripts/network inspect - * - ./scripts/network rm - */ -const { execShell, BaseSetting} = require("./.exec"); -const scriptName=process.argv[2]; - - -/** - * 网络基础信息 - * - 网络名称 - * - 子网掩码 - * - 网关地址 - */ -const dockerNetworkInfo={ - defaultName:'service_env_net', - subnet:'172.30.0.0/24', - gateway:'172.30.0.1', -} - -// 支持的命令 -const SupportScripts={ - ls:'docker network ls', - create:[ - // 创建网关 - ` - docker network create - --subnet=${dockerNetworkInfo.subnet} - --gateway=${dockerNetworkInfo.gateway} - ${dockerNetworkInfo.defaultName} - `, - // 查看创建后基本信息 - ` - docker network inspect ${dockerNetworkInfo.defaultName} - ` - ].join(' && '), - rm:[ - // 参数校验 - ` - if test -z "${dockerNetworkInfo.defaultName}";then - echo "参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称" - fi - `, - // 判断网络是否存在 - ` - docker network ls | grep -w "${dockerNetworkInfo.defaultName}" - if [ $? -eq 1 ] ;then - echo "容器网络:${dockerNetworkInfo.defaultName} 不存在,删除无效" - exit 0; - fi - `, - // 删除网络 - ` - docker network rm "${dockerNetworkInfo.defaultName}" - ` - ].join(''), - inspect: - ` - docker network inspect ${dockerNetworkInfo.defaultName} - ` -} - -/** - * 获取需要执行的shell命令 - * @param scriptName - * @returns {string} - */ -function getCommand(scriptName){ - let deployCommand=SupportScripts.ls - - // 部署到阿里云服务器 - if(scriptName==='ls'){ - deployCommand=SupportScripts.ls - } - - // 部署到Github - if(scriptName==='rm'){ - deployCommand=SupportScripts.rm - } - if(scriptName==='create'){ - deployCommand=SupportScripts.create - } - if(scriptName==='inspect'){ - deployCommand=SupportScripts.inspect - } - return deployCommand -} - - -// 执行 -;(async ()=>{ - const command=getCommand(scriptName) - await execShell(command) -})() \ No newline at end of file diff --git a/scripts/release b/scripts/release index 496cf96..20a7aac 100755 --- a/scripts/release +++ b/scripts/release @@ -13,15 +13,4 @@ const generateChangeLog='pnpm commit-and-tag-version && git add CHANGELOG.md' // git提交信息 const commitInfo='chore(release): publish v%s' -const releaseCommands= - "bumpp " + - "--preid alpha "+ - `--execute= "${generateChangeLog}" `+ - `--commit "${commitInfo}" `+ - "--all "+ - "--tag "+ - "--push " - -;(async ()=>{ - await execShell(releaseCommands) -})() \ No newline at end of file +;(async ()=>await execShell(`bumpp --preid alpha --execute="${generateChangeLog}" --commit "${commitInfo}" --all --tag --push`))() \ No newline at end of file