2018-04-04 20:25:13 +00:00
|
|
|
import * as plugins from './mod.plugins';
|
|
|
|
import { bash } from '../npmci.bash';
|
|
|
|
import { repo } from '../npmci.env';
|
2017-08-28 15:11:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* handle cli input
|
|
|
|
* @param argvArg
|
|
|
|
*/
|
2018-04-04 20:25:13 +00:00
|
|
|
export let handleCli = async argvArg => {
|
2017-08-28 15:11:47 +00:00
|
|
|
if (argvArg._.length >= 2) {
|
2018-04-04 20:25:13 +00:00
|
|
|
let action: string = argvArg._[1];
|
2017-08-28 15:11:47 +00:00
|
|
|
switch (action) {
|
|
|
|
case 'mirror':
|
2018-04-04 20:25:13 +00:00
|
|
|
await mirror();
|
|
|
|
break;
|
2017-08-28 15:11:47 +00:00
|
|
|
default:
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.error(`>>npmci git ...<< action >>${action}<< not supported`);
|
2017-08-28 15:11:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.log(
|
|
|
|
`>>npmci git ...<< cli arguments invalid... Please read the documentation.`
|
|
|
|
);
|
2017-08-28 15:11:47 +00:00
|
|
|
}
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|
2017-08-28 15:11:47 +00:00
|
|
|
|
|
|
|
export let mirror = async () => {
|
2018-04-04 20:25:13 +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;
|
2017-09-08 12:58:44 +00:00
|
|
|
if (githubToken) {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.info('found github token.');
|
|
|
|
plugins.beautylog.log('attempting the mirror the repository to GitHub');
|
2017-09-08 12:58:44 +00:00
|
|
|
// add the mirror
|
2018-04-04 20:25:13 +00:00
|
|
|
await bash(
|
|
|
|
`git remote add mirror https://${githubToken}@github.com/${githubUser}/${githubRepo}.git`
|
|
|
|
);
|
|
|
|
await bash(`git push mirror --all`);
|
|
|
|
plugins.beautylog.ok('pushed all branches to mirror!');
|
|
|
|
await bash(`git push mirror --tags`);
|
|
|
|
plugins.beautylog.ok('pushed all tags to mirror!');
|
2017-09-08 13:00:43 +00:00
|
|
|
} else {
|
2018-04-04 20:25:13 +00:00
|
|
|
plugins.beautylog.error(`cannot find NPMCI_GIT_GITHUBTOKEN env var!`);
|
|
|
|
process.exit(1);
|
2017-09-08 12:58:44 +00:00
|
|
|
}
|
2018-04-04 20:25:13 +00:00
|
|
|
};
|