From 450108d6ac922a18b2500662db3bdb4736cbd7a8 Mon Sep 17 00:00:00 2001 From: Jason <5340635+wen-jason@user.noreply.gitee.com> Date: Mon, 15 Aug 2022 15:47:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=93=E5=8C=85=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/package.json | 4 +++- admin/release.sh | 17 ----------------- admin/scripts/build.mjs | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 18 deletions(-) delete mode 100755 admin/release.sh create mode 100644 admin/scripts/build.mjs diff --git a/admin/package.json b/admin/package.json index a6a13faf..32468d85 100644 --- a/admin/package.json +++ b/admin/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "preview": "vite preview --port 4173", - "build": "vite build", + "build": "node ./scripts/build.mjs", "type-check": "vue-tsc --noEmit", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" }, @@ -42,6 +42,8 @@ "consola": "^2.15.3", "eslint": "^8.5.0", "eslint-plugin-vue": "^9.0.0", + "execa": "^6.1.0", + "fs-extra": "^10.1.0", "postcss": "^8.4.14", "prettier": "^2.5.1", "sass": "^1.53.0", diff --git a/admin/release.sh b/admin/release.sh deleted file mode 100755 index 1d238e36..00000000 --- a/admin/release.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# 文件原路径 -srcPath="./dist/" -# 发布路径文件夹 -releasePath="../server/public/admin" - -#删除发布目录下的mobile文件 -rm -r $releasePath -echo "已删除 ==> $releasePath 下的目录文件" -mkdir $releasePath -echo "已新建 ==> $releasePath 目录" - -# 复制打包目录内的文件到发布目录 -cp -r $srcPath/* $releasePath -echo "已复制 $srcPath/* ==> $releasePath" - -cp $releasePath/../favicon.ico $releasePath \ No newline at end of file diff --git a/admin/scripts/build.mjs b/admin/scripts/build.mjs new file mode 100644 index 00000000..e0154844 --- /dev/null +++ b/admin/scripts/build.mjs @@ -0,0 +1,37 @@ +import { execaCommand } from 'execa' +import path from 'path' +import fsExtra from 'fs-extra' +const { existsSync, remove, copy } = fsExtra +const cwd = process.cwd() +//打包发布路径,谨慎改动 +const releaseRelativePath = '../frontend' +const distPath = path.resolve(cwd, 'dist') +const releasePath = path.resolve(cwd, releaseRelativePath) + +async function build() { + await execaCommand('vite build', { stdio: 'inherit', encoding: 'utf-8', cwd }) + if (existsSync(releasePath)) { + await remove(releasePath) + } + console.log(`文件正在复制 ==> ${releaseRelativePath}`) + try { + await copyFile(distPath, releasePath) + } catch (error) { + console.log(`\n ${error}`) + } + console.log(`文件已复制 ==> ${releaseRelativePath}`) +} + +function copyFile(sourceDir, targetDir) { + return new Promise((resolve, reject) => { + copy(sourceDir, targetDir, (err) => { + if (err) { + reject(err) + } else { + resolve() + } + }) + }) +} + +build()