-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathload-repos.js
64 lines (58 loc) · 1.93 KB
/
load-repos.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
import execa from 'execa'
import path from 'path'
import versions from '../content/versions.json'
import { cleanDir, createDir, execaOptions, info, log, main } from './utils'
const MASTER_DIR = path.join(__dirname, '../content/documentation')
const DATA_DIR = path.join(__dirname, '../data')
const REPO = 'spring-io/dataflow.spring.io'
const ANAME = 'dataflow.spring.io'
const AEXT = '.tar.gz'
const url = version => `https://github.com/${REPO}/archive/${version}${AEXT}`
const loadRepos = async () => {
info('Loading')
cleanDir(DATA_DIR)
createDir(DATA_DIR)
for (let versionId of Object.keys(versions)) {
info(versionId)
const version = versions[versionId]
if (version.branch === 'main') {
info(`Link version ${versionId} (name: ${version.name})`)
linkFile(MASTER_DIR, path.join(DATA_DIR, versionId))
} else {
info(`Loading version ${versionId} (name: ${version.name})`)
const archive = path.join(DATA_DIR, `${versionId}${AEXT}`)
downloadVersion(url(versionId), archive)
extractVersion(archive, versionId)
cleanDir(archive)
}
}
}
const downloadVersion = (url, dest) => {
log('Downloading', url, 'to', dest)
const { failed } = execa.sync('curl', ['-fLs', url, '-o', dest], execaOptions)
if (failed) throw new Error(`Couldn't download ${url} to ${dest}`)
}
const extractVersion = (file, version) => {
log('Extracting', file)
const dest = `${DATA_DIR}/${version}`
createDir(dest)
const { failed } = execa.sync(
'tar',
[
'-C',
dest,
'--strip-components=3',
'-xvzf',
file,
`${ANAME}-${version}/content/documentation`,
],
execaOptions
)
if (failed) throw new Error(`Couldn't extract ${file}`)
}
const linkFile = (src, dest) => {
log('Linking', src, 'to', dest)
const { failed } = execa.sync('ln', ['-s', src, dest], execaOptions)
if (failed) throw new Error(`Couldn't link ${src} to ${dest}`)
}
main('load-repos', loadRepos)