npmci/ts/mod_git/index.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-08-28 15:11:47 +00:00
import * as plugins from './mod.plugins'
2017-09-08 12:58:44 +00:00
import { bash } from '../npmci.bash'
import { repo } from '../npmci.env'
2017-08-28 15:11:47 +00:00
/**
* handle cli input
* @param argvArg
*/
export let handleCli = async (argvArg) => {
if (argvArg._.length >= 2) {
let action: string = argvArg._[ 1 ]
switch (action) {
case 'mirror':
await mirror()
break
default:
plugins.beautylog.error(`>>npmci git ...<< action >>${action}<< not supported`)
}
} else {
plugins.beautylog.log(`>>npmci git ...<< cli arguments invalid... Please read the documentation.`)
}
}
export let mirror = async () => {
2017-09-08 12:58:44 +00:00
let githubToken = process.env.NPMCI_GIT_GITHUBTOKEN
let githubUser = process.env.NPMCI_GIT_GITHUBGROUP || repo.user
let githubRepo = process.env.NPMCI_GIT_GITHUB || repo.repo
if (githubToken) {
plugins.beautylog.info('found github token.')
plugins.beautylog.log('attempting the mirror the repository to GitHub')
// add the mirror
bash(`git remote add mirror https://${githubToken}@github.com/${githubUser}/${githubRepo}.git`)
bash(`git push mirror`)
}
2017-08-28 15:11:47 +00:00
}