298 - 《Node 项目初始化 SOP》
发布于 2023年5月10日
傍晚准备写个脚本,实现用 ChatGPT 写书。在开始写代码之前,摆在面前的一个问题就是如何初始化项目。虽然做过 N 遍,但由于步骤比较多,从头来一遍还是挺费时间的。于是就想着把这个步骤也 SOP 化。
1、初始化项目。完成包含 TypeScript、Father、Prettier、ZX、Release 脚本等的初始化代码和配置。完成后可以用 pnpm dev 启动、pnpm build 构建、pnpm release 发布等。
mkdir src && touch src/index.ts
mkdir scripts
cat <<EOF >package.json
{
"name": "myapp",
"version": "0.0.0-alpha.0",
"homepage": "https://github.com/sorrycc/myapp",
"bugs": "https://github.com/sorrycc/myapp/issues",
"repository": {
"type": "git",
"url": "https://github.com/sorrycc/myapp"
},
"license": "MIT",
"files": [
"bin",
"dist"
],
"scripts": {
"build": "father build",
"dev": "father dev",
"doctor": "father doctor",
"release": "father doctor && esno scripts/release.ts"
},
"devDependencies": {
}
}
EOF
cat <<EOF >tsconfig.json
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"skipLibCheck": true,
"target": "es2019",
"jsx": "react",
"paths": {
}
},
"exclude": [
"**/node_modules",
]
}
EOF
cat <<EOF >.prettierrc
{
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "never",
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }],
"plugins": [
"prettier-plugin-organize-imports",
"prettier-plugin-packagejson"
]
}
EOF
cat <<EOF >.gitignore
/node_modules
/dist
EOF
cat <<EOF >.editorconfig
# 🎨 http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf