diff --git a/bin/gh-pages.js b/bin/gh-pages.js index e73f706..caf22a0 100755 --- a/bin/gh-pages.js +++ b/bin/gh-pages.js @@ -39,20 +39,25 @@ console.log('"'+'git@github.com:[github-id]/[github-id].github.com.git'.red +'"' rl.question(' > ', function(repo) { var user, regx, branch, project; + var isGithub = true; - if(repo.indexOf('https') >= 0) { - regx = /github.com\/([^\/]+)/; + if (repo.indexOf('github') >= 0) { + if(repo.indexOf('https') >= 0) { + regx = /github.com\/([^\/]+)/; + } else { + regx = /:([^\/]+)/; + } + user = repo.match(regx)[1]; + branch = (repo.match(/\/[\w-]+.github.com/) == null) ? 'gh-pages' : 'master'; + project = (branch == 'gh-pages') ? repo.match(/\/([^\.]+)/)[1] : ''; } else { - regx = /:([^\/]+)/; + isGithub = false; } - user = repo.match(regx)[1]; - branch = (repo.match(/\/[\w-]+.github.com/) == null) ? 'gh-pages' : 'master'; - project = (branch == 'gh-pages') ? repo.match(/\/([^\.]+)/)[1] : ''; console.log('haroo> git remote -v¶'.yellow); exec('git remote -v', function(code, stdout, stderr) { console.log(stdout); - if (stdout.match(/origin.+?\/haroopress/) != null) { + if (isGithub && stdout.match(/origin.+?\/haroopress/) != null) { step( function gitInit() { console.log('haroo> Start setting github pages branch ¶'.yellow); @@ -123,6 +128,61 @@ rl.question(' > ', function(repo) { console.log('haroo> completed'.cyan); } ); + } else { // for other repository + step( + function gitInit(code, stdout, stderr) { + console.log('haroo> Start setting github pages branch ¶'.yellow); + exec('git init', this); + }, + function gitRemoteAdd(code, stdout, stderr) { + console.log(stdout); + console.log('haroo> Git remote add to origin ¶'.red); + exec('git remote add origin '+ repo, this) + }, + function gitPull(code, stdout, stderr) { + console.log(stdout); + console.log('haroo > Trying git pull from remote ¶'.yellow); + exec('git pull origin master', this); + }, + function gitPullResult(code, stdout, stderr) { + console.log(stdout); + if (stderr.indexOf('FATAL:') >= 0) { + step( + function setGitConfig(code, stdout, stderr) { + console.log(stdout); + console.log('haroo> Added remote %s as origin ¶'.yellow, repo); + exec('git config branch.master.remote origin', this); + }, + function initHaroog(code, stdout, stderr) { + console.log(stdout); + console.log('haroo> Created inex.html ¶'.yellow); + exec('echo "" > index.html', this); + }, + function gitAdd(code, stdout, stderr) { + console.log(stdout); + console.log('haroo> git add . ¶'.yellow); + exec('git add .', this); + }, + function gitCommit(code, stdout, stderr) { + console.log(stdout); + console.log('haroo> git commit -m "init site" ¶'.yellow); + exec('git commit -m "init site"', this); + }, + function gitPush(code, stdout, stderr) { + console.log(stdout); + console.log('haroo> git push origin master ¶'.yellow) + exec('git push origin master', this); + }, + function end(code, stdout, stderr) { + console.log(stdout); + console.log('haroo> completed'.cyan); + } + ); + } else { + console.log('haroo> completed'.cyan); + } + } + ); } });