From f7caaa8f6510d60e3c29f822a35107ad781ec726 Mon Sep 17 00:00:00 2001 From: Burt <1020103647@qq.com> Date: Wed, 24 Jan 2024 13:50:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20windows=E4=B8=8Bshell=20=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=89=A7=E8=A1=8C=EF=BC=8C=E6=94=B9=E7=94=A8=20nodejs?= =?UTF-8?q?=20=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- shell/postinstall.js | 20 ++++++++++++++++++++ shell/postinstall.sh | 8 ++++---- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 shell/postinstall.js diff --git a/package.json b/package.json index be63257..3ade026 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pnpm": ">=7.30" }, "scripts": { - "postinstall": "sh ./shell/postinstall.sh", + "postinstall": "node ./shell/postinstall.js", "dev:app": "uni -p app", "dev:app-android": "uni -p app-android", "dev:app-ios": "uni -p app-ios", diff --git a/shell/postinstall.js b/shell/postinstall.js new file mode 100644 index 0000000..a32d04c --- /dev/null +++ b/shell/postinstall.js @@ -0,0 +1,20 @@ +/** + * 本文件会在依赖包安装时执行,用以生成 `src/manifest.json` + * 如果不存在 `src/manifest.json` 会运行报错,提示找不到 `src/manifest.json` + * 如果中途自己删除了 'src/manifest.json' 文件,记得手动执行本文件,可以右键 `Run Code` 快速执行 + */ + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const fs = require('fs') + +const filePath = './src/manifest.json' +console.log(filePath) + +if (fs.existsSync(filePath)) { + console.log(`${filePath}存在`) +} else { + console.log(`${filePath}不存在,需要创建`) + fs.writeFile(filePath, '{}\n', {}, () => { + console.log(`${filePath}已经成功创建,并写入{}`) + }) +} diff --git a/shell/postinstall.sh b/shell/postinstall.sh index a222e17..be33812 100644 --- a/shell/postinstall.sh +++ b/shell/postinstall.sh @@ -1,10 +1,10 @@ +# 本文件会在依赖包安装时执行,用以生成 `src/manifest.json` +# 如果不存在 `src/manifest.json` 会运行报错,提示找不到 `src/manifest.json` +# 如果中途自己删除了 'src/manifest.json' 文件,记得手动执行本文件,可以右键 `Run Code` 快速执行 + if test -f ./src/manifest.json; then echo ./src/manifest.json 存在 else touch ./src/manifest.json echo "{}" >./src/manifest.json fi - -# 本文件会在依赖包安装时执行,用以生成 `src/manifest.json` -# 如果不存在 `src/manifest.json` 会运行报错,提示找不到 `src/manifest.json` -# 如果中途自己删除了 'src/manifest.json' 文件,记得手动执行本文件,可以右键 `Run Code` 快速执行