From 26fbc5a078b5318d31e2d4a19d6d201c5983136d Mon Sep 17 00:00:00 2001 From: xugaoyi <894072666@qq.com> Date: Thu, 23 Nov 2023 12:43:04 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0windows=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E8=BF=90=E8=A1=8C=E8=84=9A=E6=9C=AC=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- utils/check.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 utils/check.js diff --git a/package.json b/package.json index 3090576..2bc4858 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "scripts": { "dev": "export NODE_OPTIONS=--openssl-legacy-provider && node --max_old_space_size=4096 ./node_modules/vuepress/cli.js dev docs", "build": "export NODE_OPTIONS=--openssl-legacy-provider && node --max_old_space_size=4096 ./node_modules/vuepress/cli.js build docs", - "predev": "vdoing", - "prebuild": "vdoing", + "predev": "node utils/check.js dev && vdoing", + "prebuild": "node utils/check.js build && vdoing", "deploy": "bash deploy.sh", "editFm": "node utils/editFrontmatter.js", "baiduPush": "node utils/baiduPush.js https://xugaoyi.com && bash baiduPush.sh", diff --git a/utils/check.js b/utils/check.js new file mode 100644 index 0000000..73769f6 --- /dev/null +++ b/utils/check.js @@ -0,0 +1,26 @@ +const isWin = process.platform === 'win32'; + +// 如果是 windows 平台 +if (isWin) { + const {dev: devScriptStr, build: buildScriptStr} = require('../package.json').scripts + const args = process.argv.slice(2) + const scriptType = args[0] + const fRed = "\x1b[31m" + + const warnFn = (type) => { + console.log(fRed, + `\n[vdoing] 提示:因为您使用的是 windows 系统,请手动将 package.json 文件中的 ${type} 脚本内的 export 改为 set,否则运行失败。 \n` + ) + process.exit(1) + } + + // 当前运行的是dev脚本 且 脚本前端是'export' + if (scriptType === 'dev' && devScriptStr.startsWith('export')) { + warnFn('dev') + } + + // 当前运行的是build脚本 且 脚本前端是'export' + if (scriptType === 'build' && buildScriptStr.startsWith('export')) { + warnFn('build') + } +} \ No newline at end of file