-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
48 lines (39 loc) · 1.17 KB
/
demo.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
#!/usr/bin/env node
var fs = require('fs')
var dirName = process.argv[2] // 你传的参数是从第 2 个开始的
if (!fs.existsSync(dirName)) {
fs.mkdirSync("./" + dirName) // mkdir $1
process.chdir("./" + dirName) // cd $1
fs.mkdirSync('css') // mkdir css
fs.mkdirSync('js') // mkdir js
fs.writeFileSync("./index.html", '<!DOCTYPE> \n<title>Hello</title> \n<h1>Hi</h1>')
fs.writeFileSync("./css/style.css", 'h1{color: red;}')
fs.writeFileSync("./js/main.js", 'var string = "Hello World" \nalert(string)')
console.log('新生成了目录,返回 0');
process.exit(0)
} else {
console.log('要生成的目录已经存在,返回 1');
process.exit(1)
}
/*
➜ local ls
demo.js demo.sh
➜ local ./demo.js xxx
新生成了目录,返回 0
➜ local ./demo.js xxx
要生成的目录已经存在,返回 1
➜ local ./demo.js xxx
➜ local tree xxx
xxx
├── css
│ └── style.css
├── index.html
└── js
└── main.js
➜ local cat xxx/index.html
<!DOCTYPE>
<title>Hello</title>
<h1>Hi</h1>%
➜ local
有点奇怪为什么后面都带了`%` ?
*/