create-skweb 3.3.1 → 3.3.3

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.
@@ -1,16 +1,17 @@
1
-
2
- > create-skweb@3.3.0 prebuild
3
- > tsc --outDir dist --rootDir src
4
-
5
-
6
- > create-skweb@3.3.0 build
7
- > rollup -c rollup.config.mjs && node scripts/inject-shebang.mjs && chmod +x dist/cli.js
8
-
9
- 
10
- src/index.ts → dist/index.js...
11
- (!) [plugin typescript] @rollup/plugin-typescript: outputToFilesystem option is defaulting to true.
12
- created dist/index.js in 396ms
13
- 
14
- src/cli.ts → dist/cli.js...
15
- created dist/cli.js in 186ms
16
- [inject-shebang] Shebang added to /Users/stayknight/projects/skweb-mono/tools/create-skweb/dist/cli.js
1
+
2
+ > create-skweb@3.3.3 prebuild
3
+ > tsc --outDir dist --rootDir src
4
+
5
+ ⠙
6
+ > create-skweb@3.3.3 build
7
+ > rollup -c rollup.config.mjs && node scripts/inject-shebang.mjs && chmod +x dist/cli.js
8
+
9
+ ⠙
10
+ src/index.ts → dist/index.js...
11
+ (!) [plugin typescript] @rollup/plugin-typescript: outputToFilesystem option is defaulting to true.
12
+ created dist/index.js in 361ms
13
+ 
14
+ src/cli.ts → dist/cli.js...
15
+ created dist/cli.js in 185ms
16
+ [inject-shebang] Shebang added to /Users/stayknight/projects/skweb-mono/tools/create-skweb/dist/cli.js
17
+ ⠙
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # create-skweb
2
2
 
3
+ ## 3.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - chore(create-skweb): v3.3.3 - 抽取共享配置模块,统一数据库和 Redis 连接配置
8
+
9
+ ## 3.3.2
10
+
11
+ ### Patch Changes
12
+
13
+ - chore(create-skweb): v3.3.2 - 移除 ecosystem.config 中的 NODE_ENV/PORT,移除 database 默认 underscored
14
+
3
15
  ## 3.3.1
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-skweb",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "description": "Create a new SKWeb project with TypeScript, CJS, or MJS support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -5,10 +5,6 @@ module.exports = {
5
5
  script: 'src/web-app.js',
6
6
  instances: 'max',
7
7
  exec_mode: 'cluster',
8
- env: {
9
- NODE_ENV: 'production',
10
- PORT: 3000
11
- },
12
8
  max_memory_restart: '512M',
13
9
  error_file: 'logs/web-err.log',
14
10
  out_file: 'logs/web-out.log',
@@ -20,9 +16,6 @@ module.exports = {
20
16
  instances: 1,
21
17
  exec_mode: 'fork',
22
18
  autorestart: true,
23
- env: {
24
- NODE_ENV: 'production'
25
- },
26
19
  max_memory_restart: '512M',
27
20
  error_file: 'logs/cron-err.log',
28
21
  out_file: 'logs/cron-out.log',
@@ -3,19 +3,13 @@ require('dotenv/config')
3
3
  const path = require('path')
4
4
  const { Database } = require('skweb-sequelize')
5
5
  const { logger } = require('../utils/logger.js')
6
+ const { getDatabaseConfig } = require('../config/database.js')
6
7
 
7
8
  async function runMigrate() {
8
9
  logger.info('[migrate] Running database migrations...')
9
10
 
10
11
  const db = new Database({
11
- host: process.env.DB_HOST || '127.0.0.1',
12
- port: Number(process.env.DB_PORT) || 3306,
13
- username: process.env.DB_USER || 'root',
14
- password: process.env.DB_PASS || '',
15
- database: process.env.DB_NAME || 'test-project',
16
- dialect: process.env.DB_DIALECT || 'mysql',
17
- charset: process.env.DB_CHARSET || 'utf8mb4',
18
- underscored: true,
12
+ ...getDatabaseConfig(),
19
13
  logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
20
14
  })
21
15
 
@@ -32,4 +26,4 @@ if (require.main === module) {
32
26
  })
33
27
  }
34
28
 
35
- module.exports = { runMigrate }
29
+ module.exports = { runMigrate }
@@ -4,19 +4,13 @@ const path = require('path')
4
4
  const fs = require('fs')
5
5
  const { Database } = require('skweb-sequelize')
6
6
  const { logger } = require('../utils/logger.js')
7
+ const { getDatabaseConfig } = require('../config/database.js')
7
8
 
8
9
  async function runSeed() {
9
10
  logger.info('[seed] Initializing database with seed data...')
10
11
 
11
12
  const db = new Database({
12
- host: process.env.DB_HOST || '127.0.0.1',
13
- port: Number(process.env.DB_PORT) || 3306,
14
- username: process.env.DB_USER || 'root',
15
- password: process.env.DB_PASS || '',
16
- database: process.env.DB_NAME || 'test-project',
17
- dialect: process.env.DB_DIALECT || 'mysql',
18
- charset: process.env.DB_CHARSET || 'utf8mb4',
19
- underscored: true,
13
+ ...getDatabaseConfig(),
20
14
  logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
21
15
  })
22
16
 
@@ -0,0 +1,13 @@
1
+ function getDatabaseConfig() {
2
+ return {
3
+ host: process.env.DB_HOST || '127.0.0.1',
4
+ port: Number(process.env.DB_PORT) || 3306,
5
+ username: process.env.DB_USER || 'root',
6
+ password: process.env.DB_PASS || '',
7
+ database: process.env.DB_NAME || 'test-project',
8
+ dialect: process.env.DB_DIALECT || 'mysql',
9
+ charset: process.env.DB_CHARSET || 'utf8mb4'
10
+ }
11
+ }
12
+
13
+ module.exports = { getDatabaseConfig }
@@ -0,0 +1,9 @@
1
+ function getRedisConfig() {
2
+ return {
3
+ host: process.env.REDIS_HOST || '127.0.0.1',
4
+ port: Number(process.env.REDIS_PORT) || 6379,
5
+ password: process.env.REDIS_PASSWORD || undefined
6
+ }
7
+ }
8
+
9
+ module.exports = { getRedisConfig }
@@ -1,24 +1,15 @@
1
1
  // @ts-nocheck
2
2
  const { CronFramework } = require('skweb-framework')
3
3
  const { logger } = require('./utils/logger.js')
4
+ const { getDatabaseConfig } = require('./config/database.js')
5
+ const { getRedisConfig } = require('./config/redis.js')
4
6
 
5
7
  const framework = new CronFramework({
6
8
  db: {
7
- host: process.env.DB_HOST || '127.0.0.1',
8
- port: Number(process.env.DB_PORT) || 3306,
9
- username: process.env.DB_USER || 'root',
10
- password: process.env.DB_PASS || '',
11
- database: process.env.DB_NAME || 'test-project',
12
- dialect: process.env.DB_DIALECT || 'mysql',
13
- charset: process.env.DB_CHARSET || 'utf8mb4',
14
- underscored: true,
9
+ ...getDatabaseConfig(),
15
10
  logging: process.env.DEBUG_DB === 'true'
16
11
  },
17
- redis: {
18
- host: process.env.REDIS_HOST || '127.0.0.1',
19
- port: Number(process.env.REDIS_PORT) || 6379,
20
- password: process.env.REDIS_PASSWORD || undefined
21
- },
12
+ redis: getRedisConfig(),
22
13
  channel: 'cron:task:cmd',
23
14
  logger,
24
15
  onSaveTask: async (taskData) => {
@@ -41,4 +32,4 @@ const framework = new CronFramework({
41
32
  }
42
33
  })
43
34
 
44
- module.exports = { framework }
35
+ module.exports = { framework }
@@ -1,23 +1,14 @@
1
1
  // @ts-nocheck
2
2
  const { WebFramework } = require('skweb-framework')
3
+ const { getDatabaseConfig } = require('./config/database.js')
4
+ const { getRedisConfig } = require('./config/redis.js')
3
5
 
4
6
  const framework = new WebFramework({
5
7
  db: {
6
- host: process.env.DB_HOST || '127.0.0.1',
7
- port: Number(process.env.DB_PORT) || 3306,
8
- username: process.env.DB_USER || 'root',
9
- password: process.env.DB_PASS || '',
10
- database: process.env.DB_NAME || 'test-project',
11
- dialect: process.env.DB_DIALECT || 'mysql',
12
- charset: process.env.DB_CHARSET || 'utf8mb4',
13
- underscored: true,
8
+ ...getDatabaseConfig(),
14
9
  logging: process.env.DEBUG_DB === 'true'
15
10
  },
16
- redis: {
17
- host: process.env.REDIS_HOST || '127.0.0.1',
18
- port: Number(process.env.REDIS_PORT) || 6379,
19
- password: process.env.REDIS_PASSWORD || undefined
20
- }
11
+ redis: getRedisConfig()
21
12
  })
22
13
 
23
- module.exports = { framework }
14
+ module.exports = { framework }
@@ -5,10 +5,6 @@ module.exports = {
5
5
  script: 'src/web-app.js',
6
6
  instances: 'max',
7
7
  exec_mode: 'cluster',
8
- env: {
9
- NODE_ENV: 'production',
10
- PORT: 3000
11
- },
12
8
  max_memory_restart: '512M',
13
9
  error_file: 'logs/web-err.log',
14
10
  out_file: 'logs/web-out.log',
@@ -20,9 +16,6 @@ module.exports = {
20
16
  instances: 1,
21
17
  exec_mode: 'fork',
22
18
  autorestart: true,
23
- env: {
24
- NODE_ENV: 'production'
25
- },
26
19
  max_memory_restart: '512M',
27
20
  error_file: 'logs/cron-err.log',
28
21
  out_file: 'logs/cron-out.log',
@@ -4,6 +4,7 @@ import path from 'path'
4
4
  import { fileURLToPath } from 'url'
5
5
  import { Database } from 'skweb-sequelize'
6
6
  import logger from '../utils/logger.js'
7
+ import { getDatabaseConfig } from '../config/database.js'
7
8
 
8
9
  const __filename = fileURLToPath(import.meta.url)
9
10
  const __dirname = path.dirname(__filename)
@@ -12,14 +13,7 @@ async function runMigrate() {
12
13
  logger.info('[migrate] Running database migrations...')
13
14
 
14
15
  const db = new Database({
15
- host: process.env.DB_HOST || '127.0.0.1',
16
- port: Number(process.env.DB_PORT) || 3306,
17
- username: process.env.DB_USER || 'root',
18
- password: process.env.DB_PASS || '',
19
- database: process.env.DB_NAME || 'test-project',
20
- dialect: process.env.DB_DIALECT || 'mysql',
21
- charset: process.env.DB_CHARSET || 'utf8mb4',
22
- underscored: true,
16
+ ...getDatabaseConfig(),
23
17
  logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
24
18
  })
25
19
 
@@ -35,4 +29,4 @@ if (isMainModule) {
35
29
  logger.error('[migrate] Fatal error:', err)
36
30
  process.exit(1)
37
31
  })
38
- }
32
+ }
@@ -4,6 +4,7 @@ import path from 'path'
4
4
  import { fileURLToPath } from 'url'
5
5
  import { Database } from 'skweb-sequelize'
6
6
  import logger from '../utils/logger.js'
7
+ import { getDatabaseConfig } from '../config/database.js'
7
8
 
8
9
  const __filename = fileURLToPath(import.meta.url)
9
10
  const __dirname = path.dirname(__filename)
@@ -12,14 +13,7 @@ async function runSeed() {
12
13
  logger.info('[seed] Initializing database with seed data...')
13
14
 
14
15
  const db = new Database({
15
- host: process.env.DB_HOST || '127.0.0.1',
16
- port: Number(process.env.DB_PORT) || 3306,
17
- username: process.env.DB_USER || 'root',
18
- password: process.env.DB_PASS || '',
19
- database: process.env.DB_NAME || 'test-project',
20
- dialect: process.env.DB_DIALECT || 'mysql',
21
- charset: process.env.DB_CHARSET || 'utf8mb4',
22
- underscored: true,
16
+ ...getDatabaseConfig(),
23
17
  logging: process.env.DEBUG_DB === 'true' ? (msg) => logger.debug(msg) : false
24
18
  })
25
19
 
@@ -0,0 +1,11 @@
1
+ export function getDatabaseConfig() {
2
+ return {
3
+ host: process.env.DB_HOST || '127.0.0.1',
4
+ port: Number(process.env.DB_PORT) || 3306,
5
+ username: process.env.DB_USER || 'root',
6
+ password: process.env.DB_PASS || '',
7
+ database: process.env.DB_NAME || 'test-project',
8
+ dialect: process.env.DB_DIALECT || 'mysql',
9
+ charset: process.env.DB_CHARSET || 'utf8mb4'
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+ export function getRedisConfig() {
2
+ return {
3
+ host: process.env.REDIS_HOST || '127.0.0.1',
4
+ port: Number(process.env.REDIS_PORT) || 6379,
5
+ password: process.env.REDIS_PASSWORD || undefined
6
+ }
7
+ }
@@ -1,24 +1,15 @@
1
1
  // @ts-nocheck
2
2
  import { CronFramework } from 'skweb-framework'
3
3
  import logger from './utils/logger.js'
4
+ import { getDatabaseConfig } from './config/database.js'
5
+ import { getRedisConfig } from './config/redis.js'
4
6
 
5
7
  const framework = new CronFramework({
6
8
  db: {
7
- host: process.env.DB_HOST || '127.0.0.1',
8
- port: Number(process.env.DB_PORT) || 3306,
9
- username: process.env.DB_USER || 'root',
10
- password: process.env.DB_PASS || '',
11
- database: process.env.DB_NAME || 'test-project',
12
- dialect: process.env.DB_DIALECT || 'mysql',
13
- charset: process.env.DB_CHARSET || 'utf8mb4',
14
- underscored: true,
9
+ ...getDatabaseConfig(),
15
10
  logging: process.env.DEBUG_DB === 'true'
16
11
  },
17
- redis: {
18
- host: process.env.REDIS_HOST || '127.0.0.1',
19
- port: Number(process.env.REDIS_PORT) || 6379,
20
- password: process.env.REDIS_PASSWORD || undefined
21
- },
12
+ redis: getRedisConfig(),
22
13
  channel: 'cron:task:cmd',
23
14
  logger,
24
15
  onSaveTask: async (taskData) => {
@@ -41,4 +32,4 @@ const framework = new CronFramework({
41
32
  }
42
33
  })
43
34
 
44
- export { framework }
35
+ export { framework }
@@ -1,23 +1,14 @@
1
1
  // @ts-nocheck
2
2
  import { WebFramework } from 'skweb-framework'
3
+ import { getDatabaseConfig } from './config/database.js'
4
+ import { getRedisConfig } from './config/redis.js'
3
5
 
4
6
  const framework = new WebFramework({
5
7
  db: {
6
- host: process.env.DB_HOST || '127.0.0.1',
7
- port: Number(process.env.DB_PORT) || 3306,
8
- username: process.env.DB_USER || 'root',
9
- password: process.env.DB_PASS || '',
10
- database: process.env.DB_NAME || 'test-project',
11
- dialect: process.env.DB_DIALECT || 'mysql',
12
- charset: process.env.DB_CHARSET || 'utf8mb4',
13
- underscored: true,
8
+ ...getDatabaseConfig(),
14
9
  logging: process.env.DEBUG_DB === 'true'
15
10
  },
16
- redis: {
17
- host: process.env.REDIS_HOST || '127.0.0.1',
18
- port: Number(process.env.REDIS_PORT) || 6379,
19
- password: process.env.REDIS_PASSWORD || undefined
20
- }
11
+ redis: getRedisConfig()
21
12
  })
22
13
 
23
- export { framework }
14
+ export { framework }
@@ -7,10 +7,6 @@ module.exports = {
7
7
  interpreter_args: 'tsx',
8
8
  instances: 'max',
9
9
  exec_mode: 'cluster',
10
- env: {
11
- NODE_ENV: 'production',
12
- PORT: 3000
13
- },
14
10
  max_memory_restart: '512M',
15
11
  error_file: 'logs/web-err.log',
16
12
  out_file: 'logs/web-out.log',
@@ -24,9 +20,6 @@ module.exports = {
24
20
  instances: 1,
25
21
  exec_mode: 'fork',
26
22
  autorestart: true,
27
- env: {
28
- NODE_ENV: 'production'
29
- },
30
23
  max_memory_restart: '512M',
31
24
  error_file: 'logs/cron-err.log',
32
25
  out_file: 'logs/cron-out.log',
@@ -4,6 +4,7 @@ import path from 'path'
4
4
  import { fileURLToPath } from 'url'
5
5
  import { Database } from 'skweb-sequelize'
6
6
  import logger from '../utils/logger.js'
7
+ import { getDatabaseConfig } from '../config/database.js'
7
8
 
8
9
  const __filename = fileURLToPath(import.meta.url)
9
10
  const __dirname = path.dirname(__filename)
@@ -12,14 +13,7 @@ async function runMigrate(): Promise<void> {
12
13
  logger.info('[migrate] Running database migrations...')
13
14
 
14
15
  const db = new Database({
15
- host: process.env.DB_HOST || '127.0.0.1',
16
- port: Number(process.env.DB_PORT) || 3306,
17
- username: process.env.DB_USER || 'root',
18
- password: process.env.DB_PASS || '',
19
- database: process.env.DB_NAME || 'test-project',
20
- dialect: (process.env.DB_DIALECT as 'mysql' | 'postgres' | 'sqlite' | 'mariadb') || 'mysql',
21
- charset: process.env.DB_CHARSET || 'utf8mb4',
22
- underscored: true,
16
+ ...getDatabaseConfig(),
23
17
  logging: process.env.DEBUG_DB === 'true' ? (msg: string) => logger.debug(msg) : false
24
18
  })
25
19
 
@@ -35,4 +29,4 @@ if (isMainModule) {
35
29
  logger.error('[migrate] Fatal error:', err)
36
30
  process.exit(1)
37
31
  })
38
- }
32
+ }
@@ -4,6 +4,7 @@ import path from 'path'
4
4
  import { fileURLToPath } from 'url'
5
5
  import { Database } from 'skweb-sequelize'
6
6
  import logger from '../utils/logger.js'
7
+ import { getDatabaseConfig } from '../config/database.js'
7
8
 
8
9
  const __filename = fileURLToPath(import.meta.url)
9
10
  const __dirname = path.dirname(__filename)
@@ -12,14 +13,7 @@ async function runSeed(): Promise<void> {
12
13
  logger.info('[seed] Initializing database with seed data...')
13
14
 
14
15
  const db = new Database({
15
- host: process.env.DB_HOST || '127.0.0.1',
16
- port: Number(process.env.DB_PORT) || 3306,
17
- username: process.env.DB_USER || 'root',
18
- password: process.env.DB_PASS || '',
19
- database: process.env.DB_NAME || 'test-project',
20
- dialect: (process.env.DB_DIALECT as 'mysql' | 'postgres' | 'sqlite' | 'mariadb') || 'mysql',
21
- charset: process.env.DB_CHARSET || 'utf8mb4',
22
- underscored: true,
16
+ ...getDatabaseConfig(),
23
17
  logging: process.env.DEBUG_DB === 'true' ? (msg: string) => logger.debug(msg) : false
24
18
  })
25
19
 
@@ -0,0 +1,13 @@
1
+ import type { DatabaseConfig } from 'skweb-sequelize'
2
+
3
+ export function getDatabaseConfig(): DatabaseConfig {
4
+ return {
5
+ host: process.env.DB_HOST || '127.0.0.1',
6
+ port: Number(process.env.DB_PORT) || 3306,
7
+ username: process.env.DB_USER || 'root',
8
+ password: process.env.DB_PASS || '',
9
+ database: process.env.DB_NAME || 'test-project',
10
+ dialect: (process.env.DB_DIALECT as any) || 'mysql',
11
+ charset: process.env.DB_CHARSET || 'utf8mb4'
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { RedisOptions } from 'skweb-redis'
2
+
3
+ export function getRedisConfig(): RedisOptions {
4
+ return {
5
+ host: process.env.REDIS_HOST || '127.0.0.1',
6
+ port: Number(process.env.REDIS_PORT) || 6379,
7
+ password: process.env.REDIS_PASSWORD || undefined
8
+ }
9
+ }
@@ -1,24 +1,15 @@
1
1
  // @ts-nocheck
2
2
  import { CronFramework } from 'skweb-framework'
3
3
  import logger from './utils/logger.js'
4
+ import { getDatabaseConfig } from './config/database.js'
5
+ import { getRedisConfig } from './config/redis.js'
4
6
 
5
7
  const framework = new CronFramework({
6
8
  db: {
7
- host: process.env.DB_HOST || '127.0.0.1',
8
- port: Number(process.env.DB_PORT) || 3306,
9
- username: process.env.DB_USER || 'root',
10
- password: process.env.DB_PASS || '',
11
- database: process.env.DB_NAME || 'test-project',
12
- dialect: (process.env.DB_DIALECT as any) || 'mysql',
13
- charset: process.env.DB_CHARSET || 'utf8mb4',
14
- underscored: true,
9
+ ...getDatabaseConfig(),
15
10
  logging: process.env.DEBUG_DB === 'true'
16
11
  },
17
- redis: {
18
- host: process.env.REDIS_HOST || '127.0.0.1',
19
- port: Number(process.env.REDIS_PORT) || 6379,
20
- password: process.env.REDIS_PASSWORD || undefined
21
- },
12
+ redis: getRedisConfig(),
22
13
  channel: 'cron:task:cmd',
23
14
  logger,
24
15
  onSaveTask: async (taskData: { taskId: string; cache: unknown; data: unknown }) => {
@@ -41,4 +32,4 @@ const framework = new CronFramework({
41
32
  }
42
33
  })
43
34
 
44
- export { framework }
35
+ export { framework }
@@ -1,23 +1,14 @@
1
1
  // @ts-nocheck
2
2
  import { WebFramework } from 'skweb-framework'
3
+ import { getDatabaseConfig } from './config/database.js'
4
+ import { getRedisConfig } from './config/redis.js'
3
5
 
4
6
  const framework = new WebFramework({
5
7
  db: {
6
- host: process.env.DB_HOST || '127.0.0.1',
7
- port: Number(process.env.DB_PORT) || 3306,
8
- username: process.env.DB_USER || 'root',
9
- password: process.env.DB_PASS || '',
10
- database: process.env.DB_NAME || 'test-project',
11
- dialect: (process.env.DB_DIALECT as any) || 'mysql',
12
- charset: process.env.DB_CHARSET || 'utf8mb4',
13
- underscored: true,
8
+ ...getDatabaseConfig(),
14
9
  logging: process.env.DEBUG_DB === 'true'
15
10
  },
16
- redis: {
17
- host: process.env.REDIS_HOST || '127.0.0.1',
18
- port: Number(process.env.REDIS_PORT) || 6379,
19
- password: process.env.REDIS_PASSWORD || undefined
20
- }
11
+ redis: getRedisConfig()
21
12
  })
22
13
 
23
- export { framework }
14
+ export { framework }