From 68110698e96855b6f2768141451ee5f778d54f43 Mon Sep 17 00:00:00 2001 From: Kurisu Date: Wed, 24 May 2023 16:16:30 +0800 Subject: [PATCH] 新增一个打包版本指令 --- afterbuild.js | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 10 +++++----- 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 afterbuild.js diff --git a/afterbuild.js b/afterbuild.js new file mode 100644 index 0000000..eb2570d --- /dev/null +++ b/afterbuild.js @@ -0,0 +1,40 @@ +const fs = require("fs"); + +const encoding = "UTF-8"; +/** + * 写入version信息方便判断版本 + */ +function sendfile() { + try { + const pathFolder = "./dist/version.text"; + deleteFolder(pathFolder); + fs.writeFileSync(pathFolder, new Date().getTime().toString(), { encoding }); + } catch (e) { + console.error("sourcemap文件写入失败", e); + } +} + +/**删除文件或文件夹 */ +function deleteFolder(path) { + let files = []; + if (fs.existsSync(path)) { + if (fs.statSync(path).isFile()) { + fs.unlinkSync(path); //删除文件 + } else { + files = fs.readdirSync(path); + files.forEach((file, index) => { + let curPath = path + "/" + file; + if (fs.statSync(curPath).isDirectory()) { + // recurse + deleteFolder(curPath); + } else { + // delete file + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } + } +} + +sendfile(); diff --git a/package.json b/package.json index 5822f6a..5987f86 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "description": "霏微汽车云平台", "scripts": { "analyze": "cross-env ANALYZE=1 umi build", - "build:prod": "cross-env REACT_APP_ENV=prod umi build", - "build:unset": "cross-env REACT_APP_ENV=dev umi build", + "build:prod": "cross-env REACT_APP_ENV=prod umi build && node afterbuild.js", + "build:unset": "cross-env REACT_APP_ENV=dev umi build && node afterbuild.js", "lint": "npm run lint:js && npm run lint:style && npm run lint:prettier", "lint-staged": "lint-staged", "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ", @@ -14,16 +14,16 @@ "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./", "lint:prettier": "check-prettier lint", "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less", + "package": "chmod +x ./build.sh && ./build.sh", "prettier": "prettier -c --write \"**/*\"", "site": "cross-env npm run fetch:blocks && npm run build && npm run functions:build", "start": "cross-env HOST=devlocal.feewee.cn umi dev", "start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_UI=none HOST=devlocal.feewee.cn umi dev", - "start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_UI=none HOST=testlocal.feewee.cn umi dev", "start:prod": "cross-env REACT_APP_ENV=prod MOCK=none UMI_UI=none HOST=local.feewee.cn umi dev", + "start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_UI=none HOST=testlocal.feewee.cn umi dev", "test": "umi test", "test:all": "node ./tests/run-tests.js", - "test:component": "umi test ./src/components", - "package": "chmod +x ./build.sh && ./build.sh" + "test:component": "umi test ./src/components" }, "husky": { "hooks": {} -- libgit2 0.22.2