UNPKG

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