-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.js
More file actions
70 lines (63 loc) · 1.7 KB
/
generator.js
File metadata and controls
70 lines (63 loc) · 1.7 KB
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
const fs = require('fs')
const slug = process.argv.slice(2)[0]
if (!slug) {
console.error('You should provide a slug.')
return
}
const htmlContent = `<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="${slug}" />
<meta property="og:description" content="${slug}" />
<link rel="icon" href="../favicon.ico" />
<link rel="stylesheet" href="../global.css" />
<link rel="stylesheet" href="./styles.css" />
<script src="./index.js"></script>
<title>${slug}</title>
</head>
<body>
<!--
To do:
- Update meta tags.
- Remove <link> or <script> tags in needed.
-->
<h1>${slug}</h1>
</body>
</html>
`
// Create folder `./${slug}`
try {
if (!fs.existsSync(`web/${slug}`)) {
fs.mkdirSync(`web/${slug}`)
console.log(`Successfully created \`web/${slug}\` folder`)
}
} catch (err) {
console.error(err)
}
// Create index.html
fs.writeFile(`./web/${slug}/index.html`, htmlContent, (err) => {
if (err) {
console.error('Error while creating "index.html": ', err)
return
}
console.log('Successfully created `index.html` file')
})
// Create styles.css
fs.writeFile(`./web/${slug}/styles.css`, '', (err) => {
if (err) {
console.error('Error while creating "styles.css": ', err)
return
}
console.log('Successfully created `styles.css` file')
})
// Create index.js
fs.writeFile(`./web/${slug}/index.js`, '', (err) => {
if (err) {
console.error('Error while creating "index.js": ', err)
return
}
console.log('Successfully created `index.js` file')
})