/
clone.js
executable file
·31 lines (26 loc) · 999 Bytes
/
clone.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/user/bin/env node
const _ = require('lodash');
const chalk = require('chalk');
const path = require('path');
const shell = require('shelljs');
const repos = [
{ dir: 'app-api-template', repo: 'git@github.com/dcarrsf/app-api-template.git' },
{ dir: 'app-ui-template', repo: 'git@github.com/dcarrsf/app-ui-template.git' }
];
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
const localRepos = _.filter(shell.ls('.'), item => shell.test('-d', item) && shell.test('-e', path.join(item, '.git')));
const neededRepos = _.filter(repos, repo => localRepos.includes(repo.dir));
_.forEach(neededRepos, repo => {
const { dir, repo: remote } = repo;
shell.exec(`git clone --quiet ${remote}`);
console.log(chalk.orange(`Cloning complete for ${remote}...`));
if (shell.test('-e', path.join(dir, 'package.json'))) {
console.log(chalk.orange('Yarn install...'));
shell.pushd('-q', dir);
shell.exec('yarn');
shell.popd('-q');
}
});