chore: 添加windows平台运行脚本时的提示

This commit is contained in:
xugaoyi 2023-11-23 12:43:04 +08:00
parent 77bdf60a33
commit 26fbc5a078
2 changed files with 28 additions and 2 deletions

View File

@ -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",

26
utils/check.js Normal file
View File

@ -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')
}
}