forked from ionic-team/ionic-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.ts
More file actions
40 lines (35 loc) · 1.22 KB
/
Copy pathgit.ts
File metadata and controls
40 lines (35 loc) · 1.22 KB
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
32
33
34
35
36
37
38
39
40
import * as fs from 'fs';
import * as semver from 'semver';
import * as config from './config';
import { execp, vlog } from './utils';
export async function ensureLatestMaster(
dir: string,
url: string,
branch = 'master'
): Promise<void> {
if (!fs.existsSync(dir)) {
// console.log(`Cloning repo ${url}\r\nThis may take a few mins...`);
await execp(`git clone ${url} ${dir}`);
if (branch !== 'master') {
await checkout(dir, branch);
}
// console.log('Clone complete');
} else {
// console.log(dir);
vlog(`${dir} Repo exists - Updating`);
await execp('git --git-dir=.git reset --hard', { cwd: dir });
await execp(`git --git-dir=.git checkout ${branch}`, { cwd: dir });
await execp(`git --git-dir=.git pull --ff-only origin ${branch}`, { cwd: dir });
}
}
export async function getVersions(dir: string): Promise<semver.SemVer[]> {
// get a list of version tags
const { stdout: tags } = await execp(`git --git-dir=.git tag`, { cwd: dir });
return tags
.split('\n')
.map(tag => semver.parse(tag))
.filter(tag => semver.valid(tag));
}
export async function checkout(dir: string, ref: string): Promise<void> {
await execp(`git --git-dir=.git checkout ${ref}`, { cwd: dir });
}