forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-subject.js
executable file
·82 lines (62 loc) · 1.43 KB
/
create-subject.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
#!/usr/bin/env node
/* Create a new subject folder
Output looks like:
src/
xsubject/
README.md
docs/
gitkeep
lib/
middleware/
pages/
components/
stylesheets/
scripts/
tests/
*/
import fs from 'fs/promises'
import { program } from 'commander'
program
.description('Scaffold a new subject folder under the src/ directory.')
.option('-n, --name <string>', 'Name of subject.')
.parse(process.argv)
const name = program.opts().name
if (!name) {
throw new Error('No subject name provided.')
}
const src = 'src/'
const subfolders = [
'docs',
'lib',
'middleware',
'pages',
'components',
'stylesheets',
'scripts',
'tests',
]
const files = [
[
'README.md',
`# ${name.toUpperCase()}
TBD what is ${name.toUpperCase()}
## What ${name.toUpperCase()} does
TBD why is ${name.toUpperCase()} on the docs
## How ${name.toUpperCase()} works
TBD step-by-step instructions to work on ${name.toUpperCase()}
## How to work on ${name.toUpperCase()}
TBD step-by-step instructions on how to work on ${name.toUpperCase()}
## How to get help for ${name.toUpperCase()}
TBD reference material
`,
],
]
const path = `${src}${name.toLowerCase()}/`
await fs.mkdir(path)
for (const subfolder of subfolders) {
await fs.mkdir(`${path}${subfolder}/`)
await fs.writeFile(`${path}${subfolder}/gitkeep`, '')
}
for (const [file, content] of files) {
await fs.writeFile(`${path}${file}`, content)
}