-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplateJSONGenerator.js
45 lines (38 loc) · 1020 Bytes
/
templateJSONGenerator.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
// File to generate template.json
const execSync = require('child_process').execSync
const fs = require('fs')
// Packages to be added to template.json
const packages = [
'@material-ui/core',
'@material-ui/icons',
'@testing-library/jest-dom',
'@testing-library/react',
'@testing-library/user-event',
'fontsource-roboto',
'react',
'react-dom',
'react-redux',
'react-router-dom',
'react-scripts',
'redux',
'redux-devtools-extension',
'redux-thunk',
]
const templateFile = 'template.json'
const writeToFile = (string, flag = 'a') => {
fs.writeFileSync(templateFile, string, { flag })
}
const index = packages.length - 1
writeToFile('{\n\t"package": {\n\t\t"dependencies": {\n', 'w')
for (let t in packages.slice(0, index))
writeToFile(
execSync(
`echo '\t\t\t"'${packages[t]}'": "^'$(npm view ${packages[t]} version)'",'`
).toString()
)
writeToFile(
execSync(
`echo '\t\t\t"'${packages[index]}'": "^'$(npm view ${packages[index]} version)'"'`
).toString()
)
writeToFile('\t\t}\n\t}\n}\n')