vue
1、安裝 gogsnode
一、拉取鏡像git
docker pull gogs/gogs
二、建立數據目錄vue-cli
mkdir -p /var/gogs
三、建立窗口並運行docker
docker run --privileged=true -d --name=git-gogs -p 10022:22 -p 13000:3000 -v /var/gogs:/data gogs/gogs
四、配置 gogsnpm
瀏覽器輸入 url : http://ip:13000json
...windows
配置保存路徑:centos
/var/gogs/gogs/conf/app.ini瀏覽器
2、提交代碼檢查
提交代碼檢查主要是利用 git hooks 來運行腳本,對代碼進行提交前的檢查,若是檢查不經過,則禁止提交。
本交使用的是客戶端鉤子,工程是用 vue-cli 建立的。
一、安裝 pre-git
yarn add pre-git@3.17.0 --dev
二、配置 pre-git
在 package.json 中插入下列代碼
"scripts": { "lint": "eslint --ext .js,.vue src test/unit test/e2e/specs", "pre-check": "node verify/commit-check.js && npm run lint" }, "config": { "pre-git": { "enabled": true, "commit-msg": "simple", "pre-commit": [ "npm run pre-check" ], "pre-push": [], "post-commit": [], "post-checkout": [], "post-merge": [] } }
三、編寫自定義代碼檢查腳本
在項目根目錄下建立 verify/commit-check.js,這次檢查主要實現:強制使用 eslint ,強制文件頭部添加註釋說明。commit-check.js 內容以下:
1 const fs = require('fs') 2 const path = require('path') 3 const config = require('../config') 4 5 // 彩色輸出錯誤信息 6 // 開始時使用 chalk 7 // windows 下無效 8 // 有更好的方法歡迎留言 9 function ConsoleLog () {} 10 ConsoleLog.prototype.white = function (info) { 11 console.log('\x1B[37m', info) 12 } 13 ConsoleLog.prototype.green = function (info) { 14 console.log('\x1B[32m', info) 15 } 16 ConsoleLog.prototype.red = function (info) { 17 console.log('\x1B[31m', info) 18 } 19 20 const consoleLog = new ConsoleLog() 21 22 // 檢查 eslint 是否打開 23 if (!config.dev.useEslint) { 24 consoleLog.green('###########################') 25 consoleLog.red('ERROR: ' + 'Set config.dev.useEslint = true.') 26 consoleLog.red('請設置 config.dev.useEslint = true.') 27 consoleLog.white('\n') 28 process.exit(1) 29 } else { 30 readDirSync(path.join(__dirname, '../src')) 31 } 32 33 // 檢查文件頭是否含有註釋 34 function checkComments (file) { 35 const extname = path.extname(file) 36 if (extname === '.vue' || extname === '.js') { 37 const lines = fs.readFileSync(file).toString().replace(/(^\s*)|(\s*$)/g, '') 38 if (lines.startsWith('<!--') || lines.startsWith('/*')) { 39 40 } else { 41 consoleLog.green('###########################') 42 consoleLog.red('ERROR: ' + 'Add file header comments.') 43 consoleLog.red('請添加文件頭部註釋.') 44 consoleLog.white('\n') 45 process.exit(1) 46 } 47 } 48 } 49 // 遍歷文件夾 50 function readDirSync (path) { 51 let pa = fs.readdirSync(path) 52 pa.forEach(function (ele) { 53 let info = fs.statSync(path + '/' + ele) 54 if (info.isDirectory()) { 55 readDirSync(path + '/' + ele) 56 } else { 57 checkComments(path + '/' + ele) 58 } 59 }) 60 }
3、測試下
git add . git commit -m "test"
至些,一個簡單的提交代碼檢查腳本就完成了。