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
51 lines (44 loc) · 1.59 KB
/
Copy pathgit.ts
File metadata and controls
51 lines (44 loc) · 1.59 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
41
42
43
44
45
46
47
48
49
50
51
import { existsSync } from 'fs';
import * as semver from 'semver';
import { join } from 'path';
import { GIT_URL } from './config';
import { deleteFolderRecursive, execp, vlog } from './utils';
export async function ensureLatestMaster(
dir: string,
url: string,
branch = 'master'
): Promise<void> {
// make sure dir, if exists, is a valid git project
if (existsSync(dir) && !existsSync(join(dir, '.git'))) {
vlog('Removing non-git directory in sources');
deleteFolderRecursive(dir);
}
if (!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 -f ${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 -f ${ref}`, { cwd: dir });
}
export async function updateSubmodules(): Promise<void> {
await execp(`git submodule update --init --remote`);
}