-
Notifications
You must be signed in to change notification settings - Fork 1
/
clone_utils.js
65 lines (65 loc) · 2.94 KB
/
clone_utils.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.clone = void 0;
const fs_1 = __importDefault(require("fs"));
const config_1 = require("./config");
const utils_1 = require("./utils");
function clone(struct, name) {
return __awaiter(this, void 0, void 0, function* () {
try {
(0, utils_1.output)(`Cloning ${name}...`);
fs_1.default.mkdirSync(`${name}/.mist`, { recursive: true });
let orgFile = { name };
fs_1.default.writeFileSync(`${name}/.mist/conf.json`, JSON.stringify(orgFile));
yield (0, utils_1.execPromise)(`git clone -q "${config_1.GIT_HOST}/${name}/event-catalogue" event-catalogue`, name);
Object.keys(struct).forEach((team) => {
fs_1.default.mkdirSync(`${name}/${team}`, { recursive: true });
createFolderStructure(struct[team], `${name}/${team}`, name, team);
});
}
catch (e) {
throw e;
}
});
}
exports.clone = clone;
function createFolderStructure(struct, prefix, org, team) {
Object.keys(struct).forEach((k) => __awaiter(this, void 0, void 0, function* () {
if (struct[k] instanceof Object)
createFolderStructure(struct[k], prefix + "/" + k, org, team);
else {
// output(`git clone "${HOST}/${org}/${team}/${k}" "${prefix}/${k}"`);
let repo = `"${config_1.GIT_HOST}/${org}/${team}/${k}"`;
let dir = `${prefix}/${k}`;
try {
fs_1.default.mkdirSync(dir, { recursive: true });
yield (0, utils_1.execPromise)(`git init --initial-branch=main`, dir);
yield (0, utils_1.execPromise)(`git remote add origin ${repo}`, dir);
yield fs_1.default.writeFile(dir + "/fetch.bat", `@echo off
git fetch
git reset --hard origin/main
del fetch.sh
(goto) 2>nul & del fetch.bat`, () => { });
yield fs_1.default.writeFile(dir + "/fetch.sh", `#!/bin/sh
git fetch
git reset --hard origin/main
rm fetch.bat fetch.sh`, () => { });
}
catch (e) {
console.log(e);
}
}
}));
}