From a2dafcc3a8bb79daf9e11d4436a75d69f4e7b3de Mon Sep 17 00:00:00 2001 From: Cheney Date: Tue, 13 Aug 2024 17:54:20 +0800 Subject: [PATCH] init --- .idea/.gitignore | 8 ++++++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 ++++++ .idea/vcs.xml | 6 ++++ Readme.md | 6 ++++ package.json | 11 ++++++++ src/Config.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++ src/GitUtil.js | 37 ++++++++++++++++++++++++ src/index.js | 32 +++++++++++++++++++++ sydmark.iml | 8 ++++++ test/sydmark.txt | 32 +++++++++++++++++++++ 11 files changed, 225 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Readme.md create mode 100644 package.json create mode 100644 src/Config.js create mode 100644 src/GitUtil.js create mode 100644 src/index.js create mode 100644 sydmark.iml create mode 100644 test/sydmark.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9715c22 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..60e4288 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..9661ac7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..a607596 --- /dev/null +++ b/Readme.md @@ -0,0 +1,6 @@ +# sydmark + +## 功能 +- 获取 git hash +- 获取目标文件 md5 +- [feature] 从文件中读取自动分析,默认为当前路径下的 sydmark.txt \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6cf3675 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "sydmark", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/src/Config.js b/src/Config.js new file mode 100644 index 0000000..348460d --- /dev/null +++ b/src/Config.js @@ -0,0 +1,71 @@ +/** + * 配置项 + * windows 默认存储在用户 home 目录的 AppData\Local 下的 sydmark 目录 + * linux 默认存贮在用户 home 目录的 .sydmark 目录 + */ + +const os = require('os'); +const path = require('path'); +const fs = require('fs'); + + +// 默认配置 +let configMap = { + gitAuth : "qian.huang%40sunyard.com:qian.huang", + docAuth : "" +} + +// 获取操作系统的名称 +const platform = os.platform(); +let baseDir = undefined +const userHomeDir = os.homedir(); + +// 检查操作系统类型 +if (platform === 'win32') { + console.log('操作系统是 Windows'); + baseDir = path.resolve(userHomeDir, "AppData/Local/sydmark") +} else if (platform === 'linux') { + console.log('操作系统是 Linux'); + baseDir = path.resolve(userHomeDir, ".sydmark") +} else { + console.log('暂不支持操作系统 ' + platform ); + process.exit(-1) +} + +// 检查目录是否存在 +// 如果目录不存在创建目录 +if (!fs.existsSync(baseDir)) { + // 使用递归创建目录 + fs.mkdirSync(baseDir, { recursive: true }); + console.log(`目录 ${resolvedPath} 创建成功`); +} else { + console.log(`目录 ${resolvedPath} 已存在,无需创建`); +} + +const configFile = path.resolve(baseDir, "config.json"); +// 判断文件是否存在 +// 如果存在读取 +try { + if ( fs.existsSync( configFile ) ) { + let json = fs.readFileSync(configFile, "UTF-8") + configMap = JSON.parse(json); + } else { + throw "unexists" + } +} catch ( e ) { + // 如果 不存在/读取异常 用默认值填充 + fs.writeFileSync(configFile, JSON.stringify( configMap, null, 4 )) +} + +module.exports = { + + getConfig(key) { + return configMap[key] + }, + + setConfig(key, value) { + configMap[key] = value + fs.writeFileSync(configFile, JSON.stringify( configMap, null, 4 )) + } + +} \ No newline at end of file diff --git a/src/GitUtil.js b/src/GitUtil.js new file mode 100644 index 0000000..3b14b05 --- /dev/null +++ b/src/GitUtil.js @@ -0,0 +1,37 @@ +const regex = /^(http:\/\/.+\)[.+]$/gm; // 使用 'm' 标志启用多行匹配 + +module.exports = { + findGits : function (txt) { + const gits = [] + + // 执行正则匹配 + const matches = txt.match(regex); + if (matches) { + matches.forEach((match, index) => { + let ms = regex.exec(match) + gits.push({ + url : ms[1], + branch : ms[2] + }) + }); + } else { + return gits + } + } + + , getHash : function (url, branch, auth){ + let pos = 0; + if ( url.startsWith("http://") ) { + pos = 7 + } else if ( url.startsWith("https://") ) { + pos = 8 + } else if ( url.startsWith("git://") ) { + pos = 6 + } + + git ls-remote --heads http://qian.huang%40sunyard.com:qian.huang@172.1.4.32:3000/SSP/CollaborativeComputingFuture dev-1.2 + + } +} + + diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..ae19c03 --- /dev/null +++ b/src/index.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const GitUtil= require("./GitUtil") + +let filePath = "./sydmark.txt" + +// 提取命令行参数 +const args = process.argv.slice(2); // 忽略前两个参数 +if( args.length !== 0 ) { + filePath = args[0] +} + +// 确认文件是否存在 +if ( ! fs.existsSync(filePath) ) { + console.error("输入文件不存在 " + filePath) + process.exit(-1) +} + +// 读取文件内容 +const txt = fs.readFileSync(filePath, "utf-8") + +// 分析 git 和分支 +const gits = GitUtil.findGits(txt) +// 获取 git 指定分支的随后一个 hash + + + +// 分析 doc 文件路径, 以 Sunyard/ 开头 + + + + + diff --git a/sydmark.iml b/sydmark.iml new file mode 100644 index 0000000..3d48a82 --- /dev/null +++ b/sydmark.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/sydmark.txt b/test/sydmark.txt new file mode 100644 index 0000000..ce978dd --- /dev/null +++ b/test/sydmark.txt @@ -0,0 +1,32 @@ +【服务端】 +http://172.1.4.32:3000/SSP/CollaborativeComputingFuture.git[dev-1.2] + + +【java 客户端】 +http://172.1.4.32:3000/SSP/CollaborativeComputing[dev-dm] + + +【CIPS 客户端】 +http://172.1.4.32:3000/SSP/coapi[dev-1.0] + + +【Linux 客户端】 + +【Windows 客户端】 + + +【Android 客户端 - SKF 】 +http://172.1.4.32:3000/SSP/skftest.git[skf_bld_1.00]d5f3cf7941 + +【Android 客户端 - 期货 】 +http://172.1.4.32:3000/SSP/gatewaysoltest.git[gatewaysoltest_bld_1.00]e044206d60 + +【iOS 客户端】 +http://172.1.4.32:3000/SSP/SunyardSKF_iOS.git[SunyardSKF_iOS_bld_1.00]5a691e2440 + +【Android 客户端】 +Sunyard/Dev/产品/信息安全产品/交付项目/协同签名验签服务器(国密版)/03 软件发布/SDK包/android/skf_test_1.00.apk + + +【iOS 客户端】 +Sunyard/Dev/产品/信息安全产品/交付项目/协同签名验签服务器(国密版)/03 软件发布/01 目标代码/iOS/SunardSKFAndBusiness_1.0.0.ipa (目标代码无意义,每3 天过期) \ No newline at end of file