-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (40 loc) · 1.26 KB
/
index.js
File metadata and controls
53 lines (40 loc) · 1.26 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
#!/usr/bin/env node
"use strict"
const fs = require("fs-extra")
const path = require("path")
const { spawnSync, spawn } = require("child_process")
const os = require("os")
const { html, css, generatePackageJson } = require("./config")
let folderName
let root
function addDependencies() {
let dependencies = ["lite-server@2.5.4"]
let command = "yarnpkg"
let args = ["add", ...dependencies, "--exact", "--save-dev"]
args.push("--cwd")
args.push(root)
spawnSync(command, args, { stdio: "inherit" })
}
function addTemplateFiles() {
const packageJson = generatePackageJson(folderName)
fs.writeFileSync(
path.join(root, "package.json"),
JSON.stringify(packageJson, null, 2) + os.EOL
)
fs.writeFileSync(path.join(root, "index.html"), html + os.EOL)
fs.writeFileSync(path.join(root, "normalize.css"), css + os.EOL)
fs.writeFileSync(path.join(root, "styles.css"), "" + os.EOL)
fs.writeFileSync(path.join(root, "index.js"), "" + os.EOL)
fs.writeFileSync(path.join(root, ".gitignore"), "node_modules/" + os.EOL)
}
function init() {
folderName = process.argv[2] || "html-website"
root = path.resolve(folderName)
// clean up
fs.removeSync(root)
// create folder
fs.ensureDirSync(folderName)
addTemplateFiles()
addDependencies()
}
init()