diff --git a/configGit.js b/configGit.js deleted file mode 100644 index 64ba192..0000000 --- a/configGit.js +++ /dev/null @@ -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 -} diff --git a/deploy.js b/deploy.js index 66a6b7a..6420a07 100644 --- a/deploy.js +++ b/deploy.js @@ -147,7 +147,6 @@ function deployToGit(){ const moment = require('moment') const Promise = require('bluebird') const spawn = require('hexo-util/lib/spawn') - const parseConfig = require('./configGit') const swigHelpers = { 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() { const baseDir = '' 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 += '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) return @@ -275,13 +318,13 @@ function deployToGit(){ concurrency: 2 }) }).then(() => { - return parseConfig(connection) + return parseConnection(connection) }).each(function(repo) { console.log('########## repo ###########') console.log(repo) return push(repo) }) - } + } // end of function exec function commitMessage(connection) { const message = connection.m || connection.msg || connection.message || 'Site updated: {{ now(\'YYYY-MM-DD HH:mm:ss\') }}'