-
Notifications
You must be signed in to change notification settings - Fork 290
/
create_a_new_student.js
129 lines (117 loc) · 3.1 KB
/
create_a_new_student.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* 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 {
firstName,
lastName,
title,
year,
quarter,
groupNumber,
paperUrl,
posterPdf,
posterImg,
repositoryUrl,
} = createCLIArgs()
const posterFolder = path.join(__dirname, "content", "posters", `${year}`)
if (!fs.existsSync(posterFolder)) {
fs.mkdirSync(posterFolder)
}
const groupsFolder = path.join(posterFolder, `Q${quarter}`)
if (!fs.existsSync(groupsFolder)) {
fs.mkdirSync(groupsFolder)
}
const groupFolder = path.join(groupsFolder, `Group ${groupNumber}`)
if (!fs.existsSync(groupFolder)) {
fs.mkdirSync(groupFolder)
}
const studentsFolder = path.join(groupFolder, "students")
if (!fs.existsSync(studentsFolder)) {
fs.mkdirSync(studentsFolder)
}
const root = path.join(studentsFolder, `${firstName} ${lastName}`)
if (!fs.existsSync(root)) {
fs.mkdirSync(root)
}
const data = {
thesisTitle: title,
paperUrl,
firstName,
lastName,
repositoryUrl,
}
fs.writeFileSync(
path.join(root, `student_info.yaml`),
yaml.dump(data, { lineWidth: -1 }),
)
if (posterPdf) {
fs.copyFileSync(posterPdf, path.join(root, `poster.pdf`))
} else {
console.log(
"[WARNING] 'posterPdf' flag was not provided! Manual additon of 'poster.pdf' is needed!",
)
}
if (posterImg) {
fs.copyFileSync(posterImg, path.join(root, `poster.jpg`))
} else {
console.log(
"[WARNING] 'posterImg' flag was not provided! Manual additon of 'poster.jpg' is needed!",
)
}
}
const createCLIArgs = () => {
const parser = new ArgumentParser({})
parser.addArgument("--title", {
help: "The title of the thesis.",
type: "string",
})
parser.addArgument("--firstName", {
help: "The first name of the student",
type: "string",
required: true,
})
parser.addArgument("--lastName", {
help: "The last name of the student",
type: "string",
required: true,
})
parser.addArgument("--paperUrl", {
help: "A link to the TU Delft repository version of your paper",
defaultValue: "",
type: "string",
})
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.",
type: "int",
defaultValue: new Date().getFullYear(),
})
parser.addArgument("--groupNumber", {
help: "Your group number on BrightSpace.",
type: "int",
required: true,
})
parser.addArgument("--posterPdf", {
help: "An absolute path to the location of your poster.",
type: "string",
})
parser.addArgument("--posterImg", {
help: "An absolute path to the location of your poster.",
type: "string",
})
parser.addArgument("--repositoryUrl", {
help: "If applicable, link to the repository with your code.",
defaultValue: "",
type: "string",
})
return parser.parseArgs()
}
main()