瀏覽代碼

fix: node版本切换

林韬明 8 月之前
父節點
當前提交
0b5e21d6c0
共有 3 個文件被更改,包括 19 次插入1 次删除
  1. 1 0
      .nvmrc
  2. 16 0
      lvnvm.js
  3. 2 1
      package.json

+ 1 - 0
.nvmrc

@@ -0,0 +1 @@
+v14.21.3

+ 16 - 0
lvnvm.js

@@ -0,0 +1,16 @@
+const fs = require('fs');
+const os = require('os');
+const { execSync } = require('child_process');
+
+if (fs.existsSync('.nvmrc')) {
+  const nvmrcContent = fs.readFileSync('.nvmrc', 'utf8').trim();
+  const nvmVersion = os.platform() === 'win32' ? execSync('type .nvmrc', { encoding: 'utf8' }).trim() : nvmrcContent;
+  try {
+    execSync(`nvm use ${nvmVersion}`, { stdio: 'inherit' });
+    console.log('\x1b[32m%s\x1b[0m', `${nvmVersion} Node.js 版本切换成功`);
+  } catch (error) {
+    console.error('\x1b[31m%s\x1b[0m','Node.js 版本切换失败 Check installation nvm');
+  }
+} else {
+  console.error('\x1b[31m%s\x1b[0m', '.nvmrc 文件不存在');
+}

+ 2 - 1
package.json

@@ -16,7 +16,8 @@
     "test:unit": "jest --clearCache && vue-cli-service test:unit",
     "test:ci": "npm run lint && npm run test:unit",
     "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml",
-    "new": "plop"
+    "new": "plop",
+    "nvm": "node lvnvm.js"
   },
   "husky": {
     "hooks": {