-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
44 lines (38 loc) · 1.04 KB
/
init.js
File metadata and controls
44 lines (38 loc) · 1.04 KB
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
const clone = require('git-clone/promise');
const fs = require('fs');
const path = require('path')
const deploy = require("./deploy");
const del = require('del');
// taken from express-git-hook's source
function buildFileTree(rootDir) {
var dir = {}
fs.readdirSync(rootDir).forEach(file => {
if (file == ".git")
return
let filePath = path.resolve(rootDir, file)
if (fs.lstatSync(filePath).isDirectory()) {
dir[file] = buildFileTree(filePath)
} else {
dir[file] = filePath
}
})
return dir
}
const clonePath = "cloned-repo";
(async () => {
del.sync([clonePath+"/**", clonePath+"/.**", "!"+clonePath])
let cloneUrl
const pat = process.env.PAT
if(pat){
cloneUrl = `https://user:${pat}@github.com/${process.env.REPOSITORY}`
}else{
cloneUrl = `https://github.com/${process.env.REPOSITORY}`
}
try {
await clone(cloneUrl, clonePath, {args: ["--recursive", "-j8"]})
} catch (e) {
console.error(e)
return
}
deploy(buildFileTree(clonePath)["compose"], () => console.log("Done!"))
})()