Skip to content

Commit

Permalink
chore: 添加windows平台运行脚本时的提示
Browse files Browse the repository at this point in the history
  • Loading branch information
xugaoyi committed Nov 23, 2023
1 parent 77bdf60 commit 26fbc5a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions utils/check.js
Original file line number Diff line number Diff line change
@@ -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')
}
}

1 comment on commit 26fbc5a

@vercel
Copy link

@vercel vercel bot commented on 26fbc5a Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.