UNPKG

2.19 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.runYarnAddGdScripts = exports.runYarnCi = exports.runYarnInstall = exports.cloneOrPull = exports.getRepoName = void 0;
5
6var _fsExtra = require("fs-extra");
7
8var _simpleGit = _interopRequireDefault(require("simple-git"));
9
10var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
11
12var _path = require("path");
13
14var _os = require("os");
15
16var _utils = require("../utils");
17
18function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20const fixturePath = (0, _path.join)((0, _os.tmpdir)(), "gd-scripts", "fixtures");
21
22const getRepoName = repo => {
23 const rgxRepoName = /.*github.com\/.*?\/(.*?).git/;
24 const match = rgxRepoName.exec(repo);
25
26 if (!match) {
27 throw new Error("Repo name not found.");
28 }
29
30 const repoName = match[1];
31 return repoName;
32};
33
34exports.getRepoName = getRepoName;
35
36const getFixtureRepoPath = repo => {
37 const repoName = getRepoName(repo);
38 const fixturesRepoPath = (0, _path.join)(fixturePath, repoName);
39 return fixturesRepoPath;
40};
41
42const checkoutLatestTag = fixturesRepoPath => new Promise(resolve => {
43 (0, _simpleGit.default)().cwd(fixturesRepoPath).checkoutLatestTag(resolve);
44});
45
46const clone = repo => new Promise(resolve => {
47 (0, _simpleGit.default)().cwd(fixturePath).clone(repo, resolve);
48});
49
50const cloneOrPull = async repo => {
51 const fixturesRepoPath = getFixtureRepoPath(repo);
52
53 if (!(0, _fsExtra.pathExistsSync)(fixturesRepoPath)) {
54 await clone(repo);
55 }
56
57 await checkoutLatestTag(fixturesRepoPath);
58};
59
60exports.cloneOrPull = cloneOrPull;
61
62const runYarnInstall = repo => _crossSpawn.default.sync("yarn", ["install"], {
63 stdio: "inherit",
64 cwd: getFixtureRepoPath(repo)
65});
66
67exports.runYarnInstall = runYarnInstall;
68
69const runYarnCi = repo => _crossSpawn.default.sync("yarn", ["ci"], {
70 stdio: "inherit",
71 cwd: getFixtureRepoPath(repo)
72});
73
74exports.runYarnCi = runYarnCi;
75
76const runYarnAddGdScripts = repo => _crossSpawn.default.sync("yarn", ["add", `file:${(0, _utils.fromRoot)(".")}`, "-D"], {
77 stdio: "inherit",
78 cwd: getFixtureRepoPath(repo)
79});
80
81exports.runYarnAddGdScripts = runYarnAddGdScripts;
82//# sourceMappingURL=utils.js.map
\No newline at end of file