forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-subject.js
executable file
·72 lines (52 loc) · 1.41 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
#!/usr/bin/env node
/* Create a new subject folder
Output looks like:
src/
xsubject/
README.md
components/
gitkeep
lib/
tests/
scripts/
stylesheets/
pages/
docs/
*/
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 = ['components', 'lib', 'tests', 'scripts', 'stylesheets', 'pages', 'docs']
const files = [
[
'README.md',
`# ${name.toUpperCase()}
TBD what is ${name.toUpperCase()}
## Why ${name.toUpperCase()}
TBD why is ${name.toUpperCase()} on the docs, include metrics if applicable
## How to view ${name.toUpperCase()}
TBD step-by-step instructions to view/experience ${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)
}