nsbp-cli 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,149 +4,156 @@ Command-line interface for creating NSBP (Node React SSR by Webpack) projects.
4
4
 
5
5
  📦 **Published on npm**: [https://www.npmjs.com/package/nsbp-cli](https://www.npmjs.com/package/nsbp-cli)
6
6
 
7
- ## Installation from npm
7
+ ## Installation
8
8
 
9
- Install globally from npm registry:
10
-
11
- \`\`\`bash
12
- # Install globally
9
+ ### Global Installation (npm)
10
+ ```bash
13
11
  npm install -g nsbp-cli
12
+ ```
14
13
 
15
- # Or use npx (no installation required)
14
+ ### Using npx (No Installation)
15
+ ```bash
16
16
  npx nsbp-cli create my-app
17
+ ```
17
18
 
18
- # Verify installation
19
- nsbp-cli --version
20
- \`\`\`
21
-
22
- ## Local Usage
23
-
24
- The CLI is also located in \`cli/\` directory of the NSBP project. Run it locally for development:
25
-
26
- \`\`\`bash
27
- # Navigate to CLI directory
28
- cd cli
29
-
30
- # Show help
31
- node ./bin/nsbp-cli.js --help
19
+ ### Verify Installation
20
+ ```bash
21
+ nsbp --version
22
+ ```
32
23
 
33
- # Show NSBP information
34
- node ./bin/nsbp-cli.js info
24
+ ## Quick Start
35
25
 
36
- # Create a new project
37
- node ./bin/nsbp-cli.js create my-app
26
+ Create a new NSBP project with a single command:
38
27
 
39
- # Skip npm install
40
- node ./bin/nsbp-cli.js create my-app --skip-install
41
- \`\`\`
28
+ ```bash
29
+ nsbp create my-app
30
+ cd my-app
31
+ npm install
32
+ npm run dev
33
+ ```
42
34
 
43
- ## Usage
35
+ For development with Docker (recommended):
36
+ ```bash
37
+ cd my-app
38
+ make dev # Starts development environment with hot reload
39
+ ```
44
40
 
45
- ### Create a new project
41
+ ## Command Reference
46
42
 
47
- \`\`\`bash
48
- # From npm (after global install)
49
- nsbp-cli create my-app
43
+ ### Create a New Project
44
+ ```bash
45
+ nsbp create <app-name> [options]
50
46
 
51
- # From npx
52
- npx nsbp-cli create my-app
47
+ # Examples
48
+ nsbp create my-app
49
+ nsbp create my-app --skip-install # Skip npm install
50
+ nsbp create my-app --template basic # Specify template (basic is default)
51
+ ```
53
52
 
54
- # From local CLI directory
55
- node ./bin/nsbp-cli.js create my-app
53
+ ### Display Framework Information
54
+ ```bash
55
+ nsbp info
56
+ ```
56
57
 
57
- # Skip npm install
58
- nsbp-cli create my-app --skip-install
58
+ ### Help
59
+ ```bash
60
+ nsbp --help # Show all commands
61
+ nsbp create --help # Show create command options
62
+ ```
59
63
 
60
- # Specify template (currently only basic is available)
61
- nsbp-cli create my-app --template basic
62
- \`\`\`
64
+ ## Templates
63
65
 
64
- ### Display information
66
+ The CLI provides project templates to get started quickly:
65
67
 
66
- \`\`\`bash
67
- # Show NSBP framework information
68
- nsbp-cli info
69
- \`\`\`
68
+ - **basic** (default) - Complete NSBP stack with React SSR, TypeScript, and Webpack
69
+ - Includes full Docker support for development and production
70
+ - Pre-configured with Makefile for easy Docker operations
71
+ - Ready-to-use project structure
70
72
 
71
- ### Help
73
+ - **blog** - Blog-focused template with article layouts (coming soon)
74
+ - **ecommerce** - E-commerce template with product pages (coming soon)
72
75
 
73
- \`\`\`bash
74
- # Show all commands
75
- nsbp-cli --help
76
+ ## Docker Support
76
77
 
77
- # Show create command help
78
- nsbp-cli create --help
79
- \`\`\`
78
+ The **basic** template includes comprehensive Docker configuration:
80
79
 
81
- ## Templates
80
+ ### Docker Files Included
81
+ - `.dockerignore` - Docker build ignore rules
82
+ - `docker-compose.yml` - Production environment configuration
83
+ - `docker-compose.dev.yml` - Development environment with hot reload
84
+ - `Dockerfile` - Multi-stage production build
85
+ - `Dockerfile.dev` - Development build
86
+ - `Makefile` - Convenient Docker commands
82
87
 
83
- - **basic**: Default template with core NSBP features (currently available)
84
- - **blog**: Blog-focused template with article layouts (coming soon)
85
- - **ecommerce**: E-commerce template with product pages (coming soon)
88
+ ### Available Make Commands
89
+ ```bash
90
+ make dev # Start development environment (hot reload)
91
+ make prod # Start production environment
92
+ make rebuild # Rebuild and restart production containers
93
+ make logs # View container logs
94
+ make down # Stop and remove containers
95
+ make shell # Open shell in production container
96
+ make shell-dev # Open shell in development container
97
+ ```
86
98
 
87
- ## How it works
99
+ ## How It Works
88
100
 
89
- The CLI copies NSBP project structure from \`templates/basic/\` to your target directory and creates a new \`package.json\` with appropriate dependencies. You get a fully functional NSBP project ready for development.
101
+ The CLI copies the NSBP project structure from `templates/basic/` to your target directory and creates a new `package.json` with appropriate dependencies. You get a fully functional NSBP project ready for development, including complete Docker support.
90
102
 
91
103
  ## Template Synchronization
92
104
 
93
105
  The CLI includes a synchronization script that keeps built-in templates up-to-date with the main NSBP project code.
94
106
 
95
107
  ### Sync Script
96
- Location: \`cli/scripts/sync-template.js\`
108
+ Location: `cli/scripts/sync-template.js`
97
109
 
98
110
  ### Usage
99
- \`\`\`bash
100
- # From CLI directory
101
- cd /path/to/nsbp-cli/cli
102
-
103
- # Run sync script
104
- pnpm run sync-template
105
- # or
106
- npm run sync-template
107
-
108
- # Or use to update shortcut
109
- pnpm run update
110
- # or
111
- npm run update
112
- \`\`\`
111
+ ```bash
112
+ cd cli
113
+ npm run update # Runs sync-template script
114
+ ```
113
115
 
114
116
  ### Features
115
- - **Smart copying**: Copies only source code and configuration files
116
- - **Build artifact filtering**: Automatically excludes .js.map, .css.map, .txt, .json, and .LICENSE.txt files from the public directory
117
- - **Template transformation**: Converts main project's package.json to template format (name: "nsbp-cli-template")
118
- - **Integrity verification**: Checks for required files like src/Routers.tsx, scripts/start.js, and package.json
119
-
120
- ### What gets synchronized
121
- - \`src/\` - React components and routing
122
- - \`public/\` - Static assets (images, favicon.ico)
123
- - \`scripts/\` - Startup and utility scripts
124
- - \`webpack.*.js\` - Webpack configuration files
125
- - \`tsconfig.json\` - TypeScript configuration
126
- - \`postcss.config.js\` - PostCSS configuration
127
- - \`package.json\` - Project configuration (automatically templatized)
128
- - \`.gitignore\`, \`.prettierrc\`, \`.prettierignore\`, \`README.md\`
117
+ - **Smart copying** - Copies only source code and configuration files
118
+ - **Build artifact filtering** - Automatically excludes build artifacts from the public directory
119
+ - **Template transformation** - Converts main project's package.json to template format
120
+ - **Integrity verification** - Checks for required files before synchronization
121
+
122
+ ### Synchronized Files
123
+ - `src/` - React components and routing
124
+ - `public/` - Static assets
125
+ - `scripts/` - Startup and utility scripts
126
+ - `webpack.*.js` - Webpack configuration
127
+ - `tsconfig.json` - TypeScript configuration
128
+ - `postcss.config.js` - PostCSS configuration
129
+ - `package.json` - Project configuration (templatized)
130
+ - `.gitignore`, `.prettierrc`, `.prettierignore`, `README.md`
131
+ - **Docker files**: `.dockerignore`, `docker-compose.yml`, `docker-compose.dev.yml`, `Dockerfile`, `Dockerfile.dev`, `Makefile`
129
132
 
130
133
  ## Development
131
134
 
132
135
  To work on the CLI locally:
133
136
 
134
- \`\`\`bash
137
+ ```bash
135
138
  cd cli
136
- pnpm install
137
- # or
138
139
  npm install
139
- node ./bin/nsbp-cli.js create test-app
140
- \`\`\`
140
+ node ./bin/nsbp.js --help # Test CLI locally
141
+ ```
142
+
143
+ ### Publishing Updates
144
+ From the NSBP project root:
145
+ ```bash
146
+ make publish-cli # Syncs templates, updates version, publishes to npm
147
+ ```
141
148
 
142
149
  ## Package Information
143
150
 
144
- - **Package Name**: \`nsbp-cli\`
145
- - **Bin Command**: \`nsbp-cli\`
146
- - **Version**: \`0.1.0\`
151
+ - **Package Name**: `nsbp-cli`
152
+ - **Bin Command**: `nsbp` (install globally and run `nsbp --help`)
153
+ - **Version**: `0.2.3`
147
154
  - **Dependencies**: chalk, commander, fs-extra, inquirer
148
- - **Package Manager**: Supports both npm and pnpm
155
+ - **Node Version**: >=16.0.0
149
156
 
150
157
  ## License
151
158
 
152
- ISC
159
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsbp-cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "CLI tool for creating NSBP (Node React SSR by Webpack) projects",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -53,4 +53,4 @@ logs
53
53
  cli
54
54
 
55
55
  # Serena
56
- .serena
56
+ .serena
@@ -62,4 +62,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
62
62
  ENTRYPOINT ["dumb-init", "--"]
63
63
 
64
64
  # Start application
65
- CMD ["node", "./scripts/start.js"]
65
+ CMD ["node", "./scripts/start.js"]
@@ -6,7 +6,7 @@ FROM node:20-alpine
6
6
  RUN apk add --no-cache dumb-init
7
7
 
8
8
  # Create non-root user
9
- RUN addgroup -u 1001 -S nodejs && \
9
+ RUN addgroup -g 1001 -S nodejs && \
10
10
  adduser -S nodejs -u 1001
11
11
 
12
12
  # Set working directory
@@ -49,4 +49,4 @@ EXPOSE 3001
49
49
  ENTRYPOINT ["/entrypoint.sh"]
50
50
 
51
51
  # Start development server
52
- CMD ["dumb-init", "--", "npm", "run", "dev"]
52
+ CMD ["dumb-init", "--", "npm", "run", "dev"]
@@ -1,4 +1,4 @@
1
- .PHONY: help build dev prod down clean logs restart
1
+ .PHONY: help build dev prod down clean logs restart publish-cli
2
2
 
3
3
  help: ## Show this help message
4
4
  @echo 'Usage: make [target]'
@@ -51,4 +51,23 @@ shell-dev: ## Open shell in development container
51
51
  docker-compose -f docker-compose.dev.yml exec app sh
52
52
 
53
53
  test: ## Run tests (if configured)
54
- docker-compose exec app npm test
54
+ docker-compose exec app npm test
55
+
56
+ publish-cli: ## Publish CLI to npm registry
57
+ @echo "🚀 Starting CLI publish process..."
58
+ cd cli && npm run update
59
+ @echo "📦 Template updated, committing changes..."
60
+ git add .
61
+ git diff --quiet && git diff --cached --quiet || git commit -m "chore: update cli template"
62
+ @echo "🔖 Updating version..."
63
+ cd cli && npm version patch --no-git-tag-version
64
+ @echo "📝 Committing version bump..."
65
+ git add cli/package.json
66
+ git commit -m "chore: bump version to v$$(cd cli && node -p "require('./package.json').version")"
67
+ @echo "🏷️ Creating git tag..."
68
+ git tag -a "v$$(cd cli && node -p "require('./package.json').version")" -m "Version $$(cd cli && node -p "require('./package.json').version")"
69
+ @echo "📤 Publishing to npm..."
70
+ cd cli && npm publish
71
+ @echo "📤 Pushing to git repository..."
72
+ git push --follow-tags
73
+ @echo "✅ CLI published successfully!"
@@ -1,6 +1,6 @@
1
1
  # 开发
2
2
  - npm run dev (开发运行)
3
- - npm run build (生产编译)
3
+ - npm run build (生产编译)
4
4
  - npm start (生产运行)
5
5
 
6
6
  客户端渲染
@@ -10,4 +10,128 @@ http://localhost:3001/
10
10
  http://localhost:3001/?seo=1
11
11
 
12
12
  服务端渲染不成功,改为客户端渲染
13
- http://localhost:3001/?seo=1&from=link
13
+ http://localhost:3001/?seo=1&from=link
14
+
15
+ ## Docker 部署
16
+
17
+ **权限问题已修复!** 详细说明见下面的开发环境说明。
18
+
19
+ ### 生产环境
20
+
21
+ 使用 Makefile (推荐):
22
+
23
+ ```bash
24
+ # 构建并启动
25
+ make prod
26
+
27
+ # 或分步执行
28
+ make build
29
+ make prod
30
+
31
+ # 查看日志
32
+ make logs
33
+
34
+ # 重启
35
+ make restart
36
+
37
+ # 进入容器
38
+ make shell
39
+
40
+ # 停止
41
+ make down
42
+
43
+ # 完全清理(删除镜像和卷)
44
+ make clean
45
+ ```
46
+
47
+ 或直接使用 Docker Compose:
48
+
49
+ ```bash
50
+ # 构建镜像
51
+ docker-compose build
52
+
53
+ # 启动服务(后台运行)
54
+ docker-compose up -d
55
+
56
+ # 查看日志
57
+ docker-compose logs -f
58
+
59
+ # 停止服务
60
+ docker-compose down
61
+ ```
62
+
63
+ 访问: http://localhost:3001
64
+
65
+ ### 开发环境
66
+
67
+ ⚠️ **重要提示**:
68
+ 1. 首次启动开发环境需要等待构建完成,期间可能看到 `Cannot find module` 错误,这是正常的
69
+ 2. 开发环境使用 volume 挂载,遇到权限问题时会自动修复
70
+ 3. 如果遇到权限错误(EACCES),容器会自动修复权限(通过 entrypoint.sh)
71
+
72
+ ```bash
73
+ # 启动开发环境(带热重载)
74
+ make dev
75
+
76
+ # 查看日志
77
+ make logs-dev
78
+
79
+ # 进入容器
80
+ make shell-dev
81
+
82
+ # 重启开发环境
83
+ make restart-dev
84
+
85
+ # 重新构建并启动
86
+ make rebuild-dev
87
+ ```
88
+
89
+ 或直接使用 Docker Compose:
90
+
91
+ ```bash
92
+ # 构建并启动开发环境
93
+ docker-compose -f docker-compose.dev.yml up --build
94
+
95
+ # 后台运行
96
+ docker-compose -f docker-compose.dev.yml up -d --build
97
+
98
+ # 查看日志
99
+ docker-compose -f docker-compose.dev.yml logs -f
100
+
101
+ # 停止
102
+ docker-compose -f docker-compose.dev.yml down
103
+ ```
104
+
105
+ ### Docker 命令速查
106
+
107
+ ```bash
108
+ # 查看所有可用命令
109
+ make help
110
+
111
+ # 生产环境
112
+ make build # 构建镜像
113
+ make prod # 启动生产环境
114
+ make logs # 查看日志
115
+ make restart # 重启容器
116
+ make shell # 进入容器
117
+ make down # 停止容器
118
+
119
+ # 开发环境
120
+ make build-dev # 构建开发镜像
121
+ make dev # 启动开发环境
122
+ make logs-dev # 查看开发日志
123
+ make restart-dev # 重启开发容器
124
+ make shell-dev # 进入开发容器
125
+
126
+ # 通用命令
127
+ make clean # 清理所有资源(镜像、卷等)
128
+ make rebuild # 重新构建并启动生产环境
129
+ make rebuild-dev # 重新构建并启动开发环境
130
+ ```
131
+
132
+ ### 环境变量
133
+
134
+ 可在 `docker-compose.yml` 或 `docker-compose.dev.yml` 中配置环境变量:
135
+
136
+ - `NODE_ENV`: 运行环境 (production/development)
137
+ - `PORT`: 服务端口 (默认 3001)
@@ -34,4 +34,4 @@ volumes:
34
34
 
35
35
  networks:
36
36
  nsbp-network:
37
- driver: bridge
37
+ driver: bridge
@@ -21,4 +21,4 @@ services:
21
21
 
22
22
  networks:
23
23
  nsbp-network:
24
- driver: bridge
24
+ driver: bridge
@@ -0,0 +1,77 @@
1
+ #!/bin/bash
2
+
3
+ # 开发环境验证脚本
4
+
5
+ echo "========================================="
6
+ echo "Docker 开发环境验证"
7
+ echo "========================================="
8
+ echo ""
9
+
10
+ GREEN='\033[0;32m'
11
+ RED='\033[0;31m'
12
+ NC='\033[0m'
13
+
14
+ # 检查容器状态
15
+ echo "1. 检查容器状态..."
16
+ if docker ps | grep -q "nsbp-app-dev"; then
17
+ echo -e "${GREEN}✅ 容器正在运行${NC}"
18
+ else
19
+ echo -e "${RED}❌ 容器未运行${NC}"
20
+ echo ""
21
+ echo "启动命令:"
22
+ echo " make dev"
23
+ echo " docker-compose -f docker-compose.dev.yml up -d --build"
24
+ exit 1
25
+ fi
26
+
27
+ echo ""
28
+ echo "2. 检查服务是否可访问..."
29
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3001)
30
+ if [ "$HTTP_CODE" = "200" ]; then
31
+ echo -e "${GREEN}✅ 服务可访问 (HTTP $HTTP_CODE)${NC}"
32
+ else
33
+ echo -e "${RED}❌ 服务不可访问 (HTTP $HTTP_CODE)${NC}"
34
+ fi
35
+
36
+ echo ""
37
+ echo "3. 检查权限错误..."
38
+ if docker-compose -f docker-compose.dev.yml logs 2>&1 | grep -q "EACCES"; then
39
+ echo -e "${RED}❌ 发现权限错误${NC}"
40
+ echo ""
41
+ echo "最近的权限错误:"
42
+ docker-compose -f docker-compose.dev.yml logs | grep "EACCES" | tail -3
43
+ else
44
+ echo -e "${GREEN}✅ 未发现权限错误${NC}"
45
+ fi
46
+
47
+ echo ""
48
+ echo "4. 检查构建状态..."
49
+ if docker-compose -f docker-compose.dev.yml logs 2>&1 | grep -q "compiled successfully"; then
50
+ echo -e "${GREEN}✅ 构建完成${NC}"
51
+ else
52
+ echo -e "${YELLOW}⚠️ 构建中或未开始${NC}"
53
+ fi
54
+
55
+ echo ""
56
+ echo "5. 检查服务器监听..."
57
+ if docker-compose -f docker-compose.dev.yml logs 2>&1 | grep -q "listening"; then
58
+ echo -e "${GREEN}✅ 服务器正在监听${NC}"
59
+ else
60
+ echo -e "${YELLOW}⚠️ 服务器尚未启动监听${NC}"
61
+ fi
62
+
63
+ echo ""
64
+ echo "========================================="
65
+ echo -e "${GREEN}验证完成!${NC}"
66
+ echo "========================================="
67
+ echo ""
68
+ echo "访问应用:"
69
+ echo " http://localhost:3001"
70
+ echo ""
71
+ echo "查看日志:"
72
+ echo " docker-compose -f docker-compose.dev.yml logs -f"
73
+ echo ""
74
+ echo "停止服务:"
75
+ echo " make down"
76
+ echo " docker-compose -f docker-compose.dev.yml down"
77
+ echo ""
@@ -347,7 +347,7 @@ export const getPhotoMenu = (req: any, res: any) => {
347
347
  <QuickStartGrid>
348
348
  <QuickStartCard>
349
349
  <QuickStartTitle>1️⃣ 创建项目</QuickStartTitle>
350
- <QuickStartCode>$ npx nsbp create my-app</QuickStartCode>
350
+ <QuickStartCode>$ npx nsbp-cli create my-app</QuickStartCode>
351
351
  <QuickStartDescription>
352
352
  使用 CLI 工具创建新项目
353
353
  </QuickStartDescription>