-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_a_new_group.js
69 lines (60 loc) · 1.75 KB
/
create_a_new_group.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
/* eslint-disable @typescript-eslint/no-var-requires */
const { ArgumentParser } = require("argparse")
const fs = require("fs")
const yaml = require("js-yaml")
const path = require("path")
const main = () => {
const { title, year, supervisors, quarter, groupNumber } = createCLIArgs()
const root = path.join(__dirname, "content", "posters", `${year}`)
if (!fs.existsSync(root)) {
fs.mkdirSync(root)
}
const groupsRoot = path.join(root, `Q${quarter}`)
if (!fs.existsSync(groupsRoot)) {
fs.mkdirSync(groupsRoot)
}
const groupRoot = path.join(groupsRoot, `Group ${groupNumber}`)
if (!fs.existsSync(groupRoot)) {
fs.mkdirSync(groupRoot)
}
const studentsRoot = path.join(groupRoot, "students")
if (!fs.existsSync(studentsRoot)) {
fs.mkdirSync(studentsRoot)
}
fs.writeFileSync(
path.join(groupRoot, `group_info.yaml`),
yaml.dump({ projectTitle: title, year, supervisors, quarter }),
)
}
const createCLIArgs = () => {
const parser = new ArgumentParser({})
parser.addArgument("--title", {
help: "The title of the project.",
type: "string",
required: true,
})
parser.addArgument("--quarter", {
help: "The quarter in which project was run.",
type: "int",
choices: [1, 2, 3, 4],
required: true,
})
parser.addArgument("--year", {
help: "The year in which project was run. If not specified we assume the current year.",
type: "int",
defaultValue: new Date().getFullYear(),
})
parser.addArgument("--supervisors", {
help: "A list of supervisor names.",
type: "string",
nargs: "+",
defaultValue: [],
})
parser.addArgument("--groupNumber", {
help: "Your group number on BrightSpace.",
type: "int",
required: true,
})
return parser.parseArgs()
}
main()