Browse Source

append npm run init to initialize depedent environment

ZhangXK 9 months ago
parent
commit
759ccff8b8
3 changed files with 57 additions and 10 deletions
  1. 8 7
      comx_sdk.node/package.json
  2. 48 0
      comx_sdk.node/utils/init.js
  3. 1 3
      readme.md

+ 8 - 7
comx_sdk.node/package.json

@@ -11,13 +11,14 @@
       "js_ext": "./utils/js_ext.js"
    },
    "scripts": {
-      "js_ext_lnx": "./js_ext.sh",
-      "js_ext": "node ./utils/js_ext.js",
-      "dev-lnx": "./linux.sh",
-      "dev-mac": "./mac.sh",
-      "dev-win": "node ./js/dev.js",
-      "ws": "node ./utils/ws.js",
-      "apply": "node ./utils/apply.js"
+       "js_ext_lnx": "./js_ext.sh",
+       "js_ext": "node ./utils/js_ext.js",
+       "dev-lnx": "./linux.sh",
+       "dev-mac": "./mac.sh",
+       "dev-win": "node ./js/dev.js",
+       "ws": "node ./utils/ws.js",
+       "apply": "node ./utils/apply.js",
+       "init": "node ./utils/init.js"
    },
    "keywords": [],
    "author": "",

+ 48 - 0
comx_sdk.node/utils/init.js

@@ -0,0 +1,48 @@
+const { spawn } = require('child_process');
+const path = require('path');
+
+/**
+ * 运行批处理文件并传递压缩文件名作为参数
+ * @param {string} batFilePath - 批处理文件的路径
+ * @param {string} zipFileName - 压缩文件名
+ * @param {function} callback - 回调函数,用于处理输出和错误
+ */
+function runBatchFileWithZip(batFilePath, zipFileName, callback) {
+    // 使用spawn方法启动命令行,并指定批处理文件的路径和参数
+    const child = spawn('cmd.exe', ['/c', batFilePath, zipFileName]);
+
+    // 监听标准输出
+    child.stdout.on('data', (data) => {
+        if (callback) {
+            callback(null, data);
+        }
+    });
+
+    // 监听标准错误输出
+    child.stderr.on('data', (data) => {
+        //console.error(`错误输出: ${data}`);
+        if (callback) {
+            callback(new Error(data));
+        }
+    });
+
+    // 监听进程退出事件
+    child.on('close', (code) => {
+        if (callback) {
+            callback(code === 0 ? null : new Error(`子进程退出码 ${code}`));
+        }
+    });
+}
+
+if(process.platform === 'win32')
+{
+    let cmd = path.join(__dirname, '../dependences/windows/', 'extract.bat');
+    let gz  = path.join(__dirname, '../dependences/windows/', 'windows.tar.gz');
+
+    process.chdir(path.join(__dirname, '../dependences/windows/'));
+    process.stdout.write('Dependent environment initialization ...');
+    runBatchFileWithZip(cmd, gz, (error, data) => {
+        if(!error && !data)console.log('\b\b\bcompleted.');
+    });
+}
+                       

+ 1 - 3
readme.md

@@ -20,9 +20,7 @@
 > 5. git clone http://qnap.zxklyh.cn:2030/dcip/dcip.git ./
 > 5. cd comx_sdk.node
 > 
-> 6. cd .\dependences\windows\
-> 6. .\extract.bat .\windows.tar.gz
->
+> 6. 初始化依赖环境:npm run init
 > 7. 配置远程服务器:npm run ws [web_address],目前使用的服务器地址为:qnap.zxklyh.cn
 >
 > 8. **用户授权申请**: