文章目录
  1. 1. ref

写一个自己的 CLI

1
2
3
4
5
6
7
mkdir jinit

头部写
#!/usr/bin/env node

npm i -g

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

#!/usr/bin/env node
const path = require("path");
const fs = require("fs");

const currentBaseName = path.basename(process.cwd());

console.log("当前文件名", currentBaseName);

fs.writeFile("README.md", `# ${currentBaseName}`, "utf8", function(error) {
if (error) {
console.log(error);
return false;
}
console.log("写入成功");
});

fs.writeFile("index.js", `# import react from "react"`, "utf8", function(
error
) {
if (error) {
console.log(error);
return false;
}
console.log("写入成功");
});

ref

https://www.jianshu.com/p/1c5d086c68fa

文章目录
  1. 1. ref
Fork me on GitHub