UNPKG

1.52 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const utils_fs_1 = require("@ionic/utils-fs");
4const path = require("path");
5async function isGitInstalled({ shell }) {
6 return Boolean(await shell.cmdinfo('git', ['--version']));
7}
8exports.isGitInstalled = isGitInstalled;
9async function getTopLevel({ shell }) {
10 return shell.cmdinfo('git', ['rev-parse', '--show-toplevel']);
11}
12exports.getTopLevel = getTopLevel;
13async function isRepoInitialized(dir) {
14 return utils_fs_1.pathExists(path.join(dir, '.git'));
15}
16exports.isRepoInitialized = isRepoInitialized;
17async function initializeRepo({ shell }, dir) {
18 await shell.run('git', ['init'], { cwd: dir });
19}
20exports.initializeRepo = initializeRepo;
21async function getIonicRemote({ shell }, dir) {
22 const regex = /ionic\t(.+) \(\w+\)/;
23 // would like to use get-url, but not available in git 2.0.0
24 const remotes = await shell.output('git', ['remote', '-v'], { cwd: dir });
25 for (const line of remotes.split('\n')) {
26 const match = regex.exec(line.trim());
27 if (match) {
28 return match[1];
29 }
30 }
31}
32exports.getIonicRemote = getIonicRemote;
33async function addIonicRemote({ shell }, dir, url) {
34 await shell.run('git', ['remote', 'add', 'ionic', url], { cwd: dir });
35}
36exports.addIonicRemote = addIonicRemote;
37async function setIonicRemote({ shell }, dir, url) {
38 await shell.run('git', ['remote', 'set-url', 'ionic', url], { cwd: dir });
39}
40exports.setIonicRemote = setIonicRemote;