赞
踩
npm init -y
- #!/usr/bin/env node
-
- import prompts from "prompts";
- import path from "node:path";
- import fs from "node:fs";
- const bootstrap = async () => {
- const result = await prompts([
- {
- type: "text",
- name: "projectName",
- message: "请输入项目名称:"
- },
- ]);
- const targetPath = path.resolve(process.cwd(), result.projectName);
- const sourcePath = path.resolve(__dirname, "../template");
- console.log(targetPath);
- fs.cpSync(sourcePath, targetPath,{
- recursive: true,
- });
- fs.renameSync(
- path.resolve(targetPath, "_gitignore"),
- path.resolve(targetPath, ".gitignore")
- );
- console.log(`
- 项目创建成功!!
- cd ${result.projectName}
- npm install
- npm run dev
- `)
- };
- bootstrap();
npm i -D typescript tsup prompts @types/prompts
根目录下创建tsconfig.json
- {
- "include": ["src"],
- "compilerOptions": {
- "target": "ES2022",
- "module": "ES2022",
- "moduleResolution": "Bundler",
- "outDir": "dist",
- "skipLibCheck": true,
- "declaration": false,
- "strict": true,
- "rootDir": "src"
- }
- }
根目录下创建tsup.config.ts
- import { defineConfig } from 'tsup'
-
- export default defineConfig({
- target:"node18",
- entry:["src/index.ts"],
- clean: true,
- format:["cjs"],
- minify: true,
- platform: "node",
- outDir: "dist",
- })
名字起create-xxx
- {
- "name": "create-cocobin",
- "version": "1.0.0",
- "description": "",
- "bin": {
- "create-cocobin": "dist/index.js"
- },
- "file": [
- "dist",
- "template"
- ],
- "scripts": {
- "dev": "tsup --watch",
- "build": "tsup",
- "typecheck": "tsc --noEmit",
- "release": "release-it"
- },
- "keywords": [],
- "author": "",
- "license": "MIT",
- "devDependencies": {
- "@types/prompts": "^2.4.9",
- "prompts": "^2.4.2",
- "release-it": "^17.2.1",
- "tsup": "^8.0.2",
- "typescript": "^5.4.5"
- },
- "release-it": {
- "hooks": {
- "after:bump": "npm run build"
- }
- }
- }
里面把.gitignore文件改成_gitignore --> 避免影响文件
不要node_module文件夹
不要pnpm-lock.yaml文件
npm init release-it
- # Logs
- logs
- *.log
- npm-debug.log*
- yarn-debug.log*
- yarn-error.log*
- pnpm-debug.log*
- lerna-debug.log*
-
- node_modules
- dist
- dist-ssr
- *.local
-
- # Editor directories and files
- .vscode/*
- !.vscode/extensions.json
- .idea
- .DS_Store
- *.suo
- *.ntvs*
- *.njsproj
- *.sln
- *.sw?
npm run dev
git init
npm config set registry https://registry.npmjs.org/
npm login
提交到github
npm run release
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。