spicy-koa-cli
v1.0.6
Published
koa setup
Downloads
1
Readme
koa-cli开发
开发
- 用
fs
模块 创建dir
以及index.js
、package.json
- 使用
ejs
进行条件渲染js代码 - 生成
inputconfig
数据结构来控制ejs
代码生成 - 使用
inquirer
库让用户自定义inputconfig - 使用
execa
来安装依赖
execa("yarn", {
cwd: getRoot(), //getroot()为项目的根路径
stdio: [2, 2, 2], // 显示安装进度条
});
- 引入
prettier
来格式化代码
prettier.format(r, { //r 为将要被格式化的代码, 指定代码解析器
parser: "babel",
});
注意点
- 如果使用esm 来开发 nodejs 需要在package.json 设置type:"module"
- 如果需要使用到__dirname 需要自己拼接一个
import { fileURLToPath } from "url";
const __dirname = fileURLToPath(import.meta.url);
//此时的__dirname为文件路径. 需要../出去
发布
- 在package.json 中配置bin 以及 files
"files": [ //指定上传到npm上的文件
"bin",
"package.json"
],
"bin": "./bin/index.js",
- 把项目代码移到bin目录下
- 项目执行文件index.js的顶部需要配置
#!/usr/bin/env node
来告诉系统用node来解析 - npm link
- npm login --registry http://registry.npmjs.org
- npm publish --registry http://registry.npmjs.org