forked from Protofy-xyz/Protofy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.js
53 lines (42 loc) · 1.72 KB
/
prepare.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
const fs = require('fs')
const { execSync } = require('child_process');
const isLatest = process.argv.length > 2 && process.argv[2] == '--latest'
const modules = JSON.parse(fs.readFileSync('./modules.json').toString())
// console.log('modules', modules)
function isEmpty(path) {
return fs.readdirSync(path).length === 0;
}
const storeLibVersion = (moduleDir, moduleName) => {
//console.log('store lib version executed for: ', moduleDir, moduleName)
const currentRevision = exec('cd '+moduleDir+' && git rev-parse HEAD')
if(modules[moduleName].revision !== currentRevision) {
console.log('Updating revision for library '+moduleName+'. Setting revision to: '+currentRevision)
modules[moduleName].revision = currentRevision
fs.writeFileSync('./modules.json', JSON.stringify(modules, null, 4))
}
}
const exec = (cmd) => {
//console.log('[*] Executing: ', cmd)
return execSync(cmd).toString().trim()
}
if(!fs.existsSync("./data")) {
fs.mkdirSync('./data')
}
if(!fs.existsSync("./data/databases")) {
fs.mkdirSync('./data/databases')
}
Object.keys(modules).forEach((moduleName) => {
//console.log('Preparing', moduleName, '...')
const moduleDir = "packages/"+moduleName
if(!fs.existsSync(moduleDir) || isEmpty(moduleDir) ) {
console.log(moduleName+ ' not found, cloning into', moduleDir)
exec('git clone '+modules[moduleName].url+' '+moduleDir)
}
if(!isLatest) {
exec('cd '+moduleDir+' && git checkout '+modules[moduleName].revision)
} else {
console.log('[*] Warning: --latest flag was specified. Using the latest version of', moduleName)
exec('cd '+moduleDir+' && git checkout main')
}
storeLibVersion(moduleDir, moduleName)
})