nsbp-cli 0.2.0 → 0.2.2

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/bin/nsbp.js CHANGED
@@ -63,6 +63,12 @@ program
63
63
  '.prettierrc',
64
64
  '.prettierignore',
65
65
  '.gitignore',
66
+ '.dockerignore',
67
+ 'docker-compose.yml',
68
+ 'docker-compose.dev.yml',
69
+ 'Dockerfile',
70
+ 'Dockerfile.dev',
71
+ 'Makefile',
66
72
  'README.md'
67
73
  ];
68
74
 
@@ -76,8 +82,11 @@ program
76
82
  fs.copySync(source, target, {
77
83
  filter: (src) => {
78
84
  // Exclude node_modules, build, .temp_cache, etc.
85
+ // Use relative path to avoid matching parent directory names
86
+ const relativePath = path.relative(source, src);
87
+ const segments = relativePath.split(path.sep);
79
88
  const excluded = ['node_modules', '.temp_cache', 'build', '.git', '.DS_Store', '.serena'];
80
- return !excluded.some(ex => src.includes(ex));
89
+ return !segments.some(seg => excluded.includes(seg));
81
90
  }
82
91
  });
83
92
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsbp-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "CLI tool for creating NSBP (Node React SSR by Webpack) projects",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,56 @@
1
+ # Dependencies
2
+ node_modules
3
+ npm-debug.log
4
+ yarn-error.log
5
+ yarn-debug.log
6
+ pnpm-debug.log
7
+ pnpm-lock.yaml
8
+
9
+ # Build outputs
10
+ build
11
+ public/js
12
+ public/css
13
+ public/client.*
14
+ public/*.js
15
+ public/*.js.map
16
+ public/*.txt
17
+ public/*.json
18
+ .temp_cache
19
+
20
+ # IDE
21
+ .vscode
22
+ .idea
23
+ *.swp
24
+ *.swo
25
+ *~
26
+
27
+ # OS
28
+ .DS_Store
29
+ Thumbs.db
30
+
31
+ # Git
32
+ .git
33
+ .gitignore
34
+
35
+ # Docker
36
+ Dockerfile*
37
+ docker-compose*.yml
38
+ .dockerignore
39
+
40
+ # CI/CD
41
+ .github
42
+ .gitlab-ci.yml
43
+
44
+ # Environment
45
+ .env.local
46
+ .env.*.local
47
+
48
+ # Logs
49
+ logs
50
+ *.log
51
+
52
+ # CLI (for main project only)
53
+ cli
54
+
55
+ # Serena
56
+ .serena
@@ -0,0 +1,65 @@
1
+ # Multi-stage build for production
2
+
3
+ # Stage 1: Build
4
+ FROM node:20-alpine AS builder
5
+
6
+ # Set working directory
7
+ WORKDIR /app
8
+
9
+ # Copy package files
10
+ COPY package*.json ./
11
+
12
+ # Install pnpm and dependencies (including devDependencies for building)
13
+ RUN npm install -g pnpm && pnpm install
14
+
15
+ # Copy source code
16
+ COPY . .
17
+
18
+ # Build application
19
+ RUN npm run build
20
+
21
+ # Stage 2: Production
22
+ FROM node:20-alpine AS production
23
+
24
+ # Install dumb-init for proper signal handling
25
+ RUN apk add --no-cache dumb-init
26
+
27
+ # Create non-root user
28
+ RUN addgroup -g 1001 -S nodejs && \
29
+ adduser -S nodejs -u 1001
30
+
31
+ # Set working directory
32
+ WORKDIR /app
33
+
34
+ # Copy package files
35
+ COPY package*.json ./
36
+
37
+ # Install pnpm and only production dependencies
38
+ RUN npm install -g pnpm && pnpm install --prod && pnpm store prune
39
+
40
+ # Copy build artifacts from builder stage
41
+ COPY --from=builder /app/build ./build
42
+ COPY --from=builder /app/public ./public
43
+
44
+ # Copy scripts and config
45
+ COPY --from=builder /app/scripts ./scripts
46
+ COPY --from=builder /app/tsconfig.json ./
47
+
48
+ # Change ownership
49
+ RUN chown -R nodejs:nodejs /app
50
+
51
+ # Switch to non-root user
52
+ USER nodejs
53
+
54
+ # Expose port
55
+ EXPOSE 3001
56
+
57
+ # Health check
58
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
59
+ CMD node -e "require('http').get('http://localhost:3001', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
60
+
61
+ # Use dumb-init to handle signals properly
62
+ ENTRYPOINT ["dumb-init", "--"]
63
+
64
+ # Start application
65
+ CMD ["node", "./scripts/start.js"]
@@ -0,0 +1,52 @@
1
+ # Development Dockerfile
2
+
3
+ FROM node:20-alpine
4
+
5
+ # Install dumb-init for proper signal handling
6
+ RUN apk add --no-cache dumb-init
7
+
8
+ # Create non-root user
9
+ RUN addgroup -u 1001 -S nodejs && \
10
+ adduser -S nodejs -u 1001
11
+
12
+ # Set working directory
13
+ WORKDIR /app
14
+
15
+ # Copy package files first to leverage Docker cache
16
+ COPY package*.json ./
17
+
18
+ # Install pnpm and all dependencies (including devDependencies)
19
+ RUN npm install -g pnpm && pnpm install && pnpm store prune
20
+
21
+ # Copy application code
22
+ COPY . .
23
+
24
+ # Create build directory with proper permissions
25
+ RUN mkdir -p /app/build && \
26
+ chown -R nodejs:nodejs /app
27
+
28
+ # Create entrypoint script to fix volume permissions
29
+ RUN printf '#!/bin/sh\n\
30
+ # Fix permissions for volume mounts before switching user\n\
31
+ if [ -d "/app/build" ]; then\n\
32
+ chown -R nodejs:nodejs /app/build 2>/dev/null || true\n\
33
+ chmod -R 755 /app/build 2>/dev/null || true\n\
34
+ fi\n\
35
+ if [ -d "/app/node_modules" ]; then\n\
36
+ chown -R nodejs:nodejs /app/node_modules 2>/dev/null || true\n\
37
+ fi\n\
38
+ # Switch to nodejs user and execute command\n\
39
+ exec su-exec nodejs:nodejs "$@"\n' > /entrypoint.sh && \
40
+ chmod +x /entrypoint.sh
41
+
42
+ # Install su-exec for user switching
43
+ RUN apk add --no-cache su-exec
44
+
45
+ # Expose port
46
+ EXPOSE 3001
47
+
48
+ # Use entrypoint (runs as root, fixes perms, then switches to nodejs)
49
+ ENTRYPOINT ["/entrypoint.sh"]
50
+
51
+ # Start development server
52
+ CMD ["dumb-init", "--", "npm", "run", "dev"]
@@ -0,0 +1,54 @@
1
+ .PHONY: help build dev prod down clean logs restart
2
+
3
+ help: ## Show this help message
4
+ @echo 'Usage: make [target]'
5
+ @echo ''
6
+ @echo 'Available targets:'
7
+ @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
8
+
9
+ build: ## Build Docker images for production
10
+ docker-compose build
11
+
12
+ build-dev: ## Build Docker images for development
13
+ docker-compose -f docker-compose.dev.yml build
14
+
15
+ dev: ## Start development environment (removes orphan containers)
16
+ docker-compose -f docker-compose.dev.yml up --build --remove-orphans
17
+
18
+ prod: ## Start production environment (removes orphan containers)
19
+ docker-compose up -d --remove-orphans
20
+
21
+ down: ## Stop and remove containers (including orphan containers)
22
+ docker-compose down --remove-orphans
23
+ docker-compose -f docker-compose.dev.yml down --remove-orphans
24
+
25
+ clean: ## Stop containers, remove images and volumes (including orphan containers)
26
+ docker-compose down -v --rmi all --remove-orphans
27
+ docker-compose -f docker-compose.dev.yml down -v --rmi all --remove-orphans
28
+
29
+ logs: ## View logs
30
+ docker-compose logs -f
31
+
32
+ logs-dev: ## View development logs
33
+ docker-compose -f docker-compose.dev.yml logs -f
34
+
35
+ restart: ## Restart production containers
36
+ docker-compose restart
37
+
38
+ restart-dev: ## Restart development containers
39
+ docker-compose -f docker-compose.dev.yml restart
40
+
41
+ rebuild: ## Rebuild and restart production containers (removes orphan containers)
42
+ docker-compose up -d --build --remove-orphans
43
+
44
+ rebuild-dev: ## Rebuild and restart development containers (removes orphan containers)
45
+ docker-compose -f docker-compose.dev.yml up -d --build --remove-orphans
46
+
47
+ shell: ## Open shell in production container
48
+ docker-compose exec app sh
49
+
50
+ shell-dev: ## Open shell in development container
51
+ docker-compose -f docker-compose.dev.yml exec app sh
52
+
53
+ test: ## Run tests (if configured)
54
+ docker-compose exec app npm test
@@ -0,0 +1,37 @@
1
+ services:
2
+ app:
3
+ build:
4
+ context: .
5
+ dockerfile: Dockerfile.dev
6
+ container_name: nsbp-app-dev
7
+ ports:
8
+ - "3001:3001"
9
+ - "9229:9229" # Node.js debug port
10
+ environment:
11
+ - NODE_ENV=development
12
+ - PORT=3001
13
+ volumes:
14
+ # Mount source code for hot reload
15
+ - ./src:/app/src
16
+ - ./public:/app/public
17
+ - ./scripts:/app/scripts
18
+ - ./webpack.base.js:/app/webpack.base.js
19
+ - ./webpack.client.js:/app/webpack.client.js
20
+ - ./webpack.server.js:/app/webpack.server.js
21
+ - ./tsconfig.json:/app/tsconfig.json
22
+ # Persist node_modules
23
+ - node_modules:/app/node_modules
24
+ # Build output - named volume for persistence
25
+ - build_output:/app/build
26
+ command: ["dumb-init", "--", "npm", "run", "dev"]
27
+ restart: unless-stopped
28
+ networks:
29
+ - nsbp-network
30
+
31
+ volumes:
32
+ node_modules:
33
+ build_output:
34
+
35
+ networks:
36
+ nsbp-network:
37
+ driver: bridge
@@ -0,0 +1,24 @@
1
+ services:
2
+ app:
3
+ build:
4
+ context: .
5
+ dockerfile: Dockerfile
6
+ container_name: nsbp-app
7
+ ports:
8
+ - "3001:3001"
9
+ environment:
10
+ - NODE_ENV=production
11
+ - PORT=3001
12
+ restart: unless-stopped
13
+ healthcheck:
14
+ test: ["CMD", "node", "-e", "require('http').get('http://localhost:3001', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
15
+ interval: 30s
16
+ timeout: 3s
17
+ retries: 3
18
+ start_period: 5s
19
+ networks:
20
+ - nsbp-network
21
+
22
+ networks:
23
+ nsbp-network:
24
+ driver: bridge
@@ -394,7 +394,7 @@ export const getPhotoMenu = (req: any, res: any) => {
394
394
  <PhotoCard>
395
395
  <PhotoImageWrapper>
396
396
  <PhotoImage
397
- src={item.cover}
397
+ src={item.cover || 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='}
398
398
  alt={item.name}
399
399
  loading="lazy"
400
400
  />
@@ -123,7 +123,7 @@ const Photo = ({ query, data, menu, getPhotoMenu }: any) => {
123
123
  <motion.img
124
124
  key={i}
125
125
  className="demo4-photo"
126
- src={useCurrentFlag ? `/images/${photos[i][2]}` : photos[i][2]}
126
+ src={photos[i][2] ? (useCurrentFlag ? `/images/${photos[i][2]}` : photos[i][2]) : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='}
127
127
  initial={false}
128
128
  animate={{
129
129
  left: pos.left,
@@ -5,8 +5,8 @@ import { useCurrentFlag, outPhotoDicPath } from '../utils/config'
5
5
 
6
6
  const app = express()
7
7
 
8
- app.use(express.static('public'))
9
- !useCurrentFlag && app.use(express.static(outPhotoDicPath))
8
+ app.use(express.static('public', { dotfiles: 'allow' }))
9
+ !useCurrentFlag && app.use(express.static(outPhotoDicPath, { dotfiles: 'allow' }))
10
10
 
11
11
  //使用express提供的static中间件,中间件会将所有静态文件的路由指向public文件夹
12
12
 
@@ -47,7 +47,7 @@ const getFileMenu = (dir: string): { name: string; cover?: string; count?: numbe
47
47
  const count = files.length
48
48
 
49
49
  // 在该目录下找 cover.jpg
50
- let cover = undefined
50
+ let cover = ''
51
51
  const coverPath = path.join(fullPath, 'cover.jpg')
52
52
  if (fs.existsSync(coverPath)) {
53
53
  // 转成相对 public 的 URL 路径
@@ -227,11 +227,12 @@ module.exports = ({ mode, entry, server, init }) => {
227
227
  },
228
228
  name(module) {
229
229
  //名字就是包当中的名字
230
- return (
231
- /[\\/]node_modules[\\/](.*)/.exec(module.identifier()) &&
232
- /[\\/]node_modules[\\/](.*)/.exec(module.identifier()).length &&
233
- /[\\/]node_modules[\\/](.*)/.exec(module.identifier())[1].replace(/\/|\\/g, '_')
234
- )
230
+ const match = /[\\/]node_modules[\\/](.*)/.exec(module.identifier())
231
+ if (match && match.length) {
232
+ // 移除开头的点号,避免生成隐藏文件
233
+ return match[1].replace(/\/|\\/g, '_').replace(/^\./, '')
234
+ }
235
+ return false
235
236
  },
236
237
  minChunks: 1, //最小共用次数为1时就使用
237
238
  priority: 30, //权重为30