-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainings.js
72 lines (52 loc) · 1.83 KB
/
trainings.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
66
67
68
69
70
71
72
const fs = require('fs')
const sh = require("shelljs")
const config = require('./config')
const utils = require('./utils');
const spawn = require('child_process').spawn;
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
const lg = console.log
const WORK_DIR = './work'
const TRAINING_DIR = './public/formation'
const cleanAllDirs = () => {
sh.rm('-rf', WORK_DIR);
sh.mkdir('-p', WORK_DIR);
sh.rm('-rf', TRAINING_DIR);
sh.mkdir('-p', TRAINING_DIR);
}
const importOneTraining = (gitUrl) => {
lg('...Importing', gitUrl)
const repoName = utils.findRepoName(gitUrl)
const repoDir =`${WORK_DIR}/${repoName}`
const cmds = [
`cd ${WORK_DIR} && git clone ${gitUrl}`,
`cd ${repoDir} && ../../node_modules/.bin/gitbook install && ../../node_modules/.bin/gitbook build`,
`cp -r ${repoDir}/_book ./${TRAINING_DIR}/${repoName}`]
cmds.forEach(sh.exec)
}
const updateOneTraining = (gitUrl) => {
lg('...Updating from ', gitUrl)
const repoName = utils.findRepoName(gitUrl)
const cmds = [
`cd ${WORK_DIR} && git pull ${gitUrl}`,
`cd ${repoDir} && ../../node_modules/.bin/gitbook install && ../../node_modules/.bin/gitbook build`,
`rm -rf ./${TRAINING_DIR}/${repoName}`,
`cp -r ${repoDir}/_book ./${TRAINING_DIR}/${repoName}`]
cmds.forEach(sh.exec)
}
function importAllTrainings() {
cleanAllDirs();
const gitUrls = [].concat.apply([],
config.cursusList.map(c => c.trainings))
.map(t => t.git)
gitUrls.forEach(importOneTraining)
}
module.exports = { importAllTrainings, importOneTraining, updateOneTraining }