1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.runYarnAddGdScripts = exports.runYarnCi = exports.runYarnInstall = exports.cloneOrPull = exports.getRepoName = void 0;
|
5 |
|
6 | var _fsExtra = require("fs-extra");
|
7 |
|
8 | var _simpleGit = _interopRequireDefault(require("simple-git"));
|
9 |
|
10 | var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
|
11 |
|
12 | var _path = require("path");
|
13 |
|
14 | var _os = require("os");
|
15 |
|
16 | var _utils = require("../utils");
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 | const fixturePath = (0, _path.join)((0, _os.tmpdir)(), "gd-scripts", "fixtures");
|
21 |
|
22 | const 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 |
|
34 | exports.getRepoName = getRepoName;
|
35 |
|
36 | const getFixtureRepoPath = repo => {
|
37 | const repoName = getRepoName(repo);
|
38 | const fixturesRepoPath = (0, _path.join)(fixturePath, repoName);
|
39 | return fixturesRepoPath;
|
40 | };
|
41 |
|
42 | const checkoutLatestTag = fixturesRepoPath => new Promise(resolve => {
|
43 | (0, _simpleGit.default)().cwd(fixturesRepoPath).checkoutLatestTag(resolve);
|
44 | });
|
45 |
|
46 | const clone = repo => new Promise(resolve => {
|
47 | (0, _simpleGit.default)().cwd(fixturePath).clone(repo, resolve);
|
48 | });
|
49 |
|
50 | const 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 |
|
60 | exports.cloneOrPull = cloneOrPull;
|
61 |
|
62 | const runYarnInstall = repo => _crossSpawn.default.sync("yarn", ["install"], {
|
63 | stdio: "inherit",
|
64 | cwd: getFixtureRepoPath(repo)
|
65 | });
|
66 |
|
67 | exports.runYarnInstall = runYarnInstall;
|
68 |
|
69 | const runYarnCi = repo => _crossSpawn.default.sync("yarn", ["ci"], {
|
70 | stdio: "inherit",
|
71 | cwd: getFixtureRepoPath(repo)
|
72 | });
|
73 |
|
74 | exports.runYarnCi = runYarnCi;
|
75 |
|
76 | const runYarnAddGdScripts = repo => _crossSpawn.default.sync("yarn", ["add", `file:${(0, _utils.fromRoot)(".")}`, "-D"], {
|
77 | stdio: "inherit",
|
78 | cwd: getFixtureRepoPath(repo)
|
79 | });
|
80 |
|
81 | exports.runYarnAddGdScripts = runYarnAddGdScripts;
|
82 |
|
\ | No newline at end of file |