把 configGit.js 合并入 deploy.js

This commit is contained in:
陆柯 2019-11-24 13:26:32 +08:00
parent da8cbca952
commit 43073a9350
2 changed files with 47 additions and 49 deletions

View File

@ -1,45 +0,0 @@
'use strict'
const rRepoURL = /^(?:(?:git|https?|git\+https|git\+ssh):\/\/)?(?:[^@]+@)?([^\/]+?)[\/:](.+?)\.git$/ // eslint-disable-line no-useless-escape
const rGithubPage = /\.github\.(io|com)$/
function parseRepo(repo) {
const split = repo.split(',')
const url = split.shift()
let branch = split[0]
if (!branch && rRepoURL.test(url)) {
const match = url.match(rRepoURL)
const host = match[1]
const path = match[2]
if (host === 'github.com') {
branch = rGithubPage.test(path) ? 'master' : 'gh-pages'
} else if (host === 'coding.net') {
branch = 'coding-pages'
}
}
return {
url: url,
branch: branch || 'master'
}
}
module.exports = function(args) {
const repo = args.repo || args.repository
if (!repo) throw new TypeError('repo is required!')
if (typeof repo === 'string') {
const data = parseRepo(repo)
data.branch = args.branch || data.branch
return [data]
}
const result = Object.keys(repo).map(key => {
return parseRepo(repo[key])
})
return result
}

View File

@ -147,7 +147,6 @@ function deployToGit(){
const moment = require('moment') const moment = require('moment')
const Promise = require('bluebird') const Promise = require('bluebird')
const spawn = require('hexo-util/lib/spawn') const spawn = require('hexo-util/lib/spawn')
const parseConfig = require('./configGit')
const swigHelpers = { const swigHelpers = {
now: function(format) { now: function(format) {
@ -155,6 +154,50 @@ function deployToGit(){
} }
} }
const rRepoURL = /^(?:(?:git|https?|git\+https|git\+ssh):\/\/)?(?:[^@]+@)?([^\/]+?)[\/:](.+?)\.git$/ // eslint-disable-line no-useless-escape
const rGithubPage = /\.github\.(io|com)$/
function parseRepo(repo) {
const split = repo.split(',')
const url = split.shift()
let branch = split[0]
if (!branch && rRepoURL.test(url)) {
const match = url.match(rRepoURL)
const host = match[1]
const path = match[2]
if (host === 'github.com') {
branch = rGithubPage.test(path) ? 'master' : 'gh-pages'
} else if (host === 'coding.net') {
branch = 'coding-pages'
}
}
return {
url: url,
branch: branch || 'master'
}
}
function parseConnection(args) {
const repo = args.repo || args.repository
if (!repo) throw new TypeError('repo is required!')
if (typeof repo === 'string') {
const data = parseRepo(repo)
data.branch = args.branch || data.branch
return [data]
}
const result = Object.keys(repo).map(key => {
return parseRepo(repo[key])
})
return result
}
function exec() { function exec() {
const baseDir = '' const baseDir = ''
const deployDir = pathFn.join(baseDir, '.deploy_git') const deployDir = pathFn.join(baseDir, '.deploy_git')
@ -174,7 +217,7 @@ function deployToGit(){
help += 'You have to configure the deployment settings in config files or command line first!\n\n' help += 'You have to configure the deployment settings in config files or command line first!\n\n'
help += 'Example:\n' help += 'Example:\n'
help += ' node deploy.js -t git -r https://github.com/log-home/log-home.github.io -b master -l ../../project/public' help += ' node deploy.js -t git -r https://github.com/OWNER/OWNER.github.io -b master -f ./dist'
console.log(help) console.log(help)
return return
@ -275,13 +318,13 @@ function deployToGit(){
concurrency: 2 concurrency: 2
}) })
}).then(() => { }).then(() => {
return parseConfig(connection) return parseConnection(connection)
}).each(function(repo) { }).each(function(repo) {
console.log('########## repo ###########') console.log('########## repo ###########')
console.log(repo) console.log(repo)
return push(repo) return push(repo)
}) })
} } // end of function exec
function commitMessage(connection) { function commitMessage(connection) {
const message = connection.m || connection.msg || connection.message || 'Site updated: {{ now(\'YYYY-MM-DD HH:mm:ss\') }}' const message = connection.m || connection.msg || connection.message || 'Site updated: {{ now(\'YYYY-MM-DD HH:mm:ss\') }}'