nodebbs 0.0.2 → 0.0.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.
Files changed (62) hide show
  1. package/README.md +103 -111
  2. package/bin/dev.js +6 -1
  3. package/bin/run.js +6 -1
  4. package/dist/commands/clean/index.d.ts +11 -0
  5. package/dist/commands/clean/index.js +93 -0
  6. package/dist/commands/db/backup.d.ts +9 -0
  7. package/dist/commands/db/backup.js +78 -0
  8. package/dist/commands/db/generate.d.ts +3 -0
  9. package/dist/commands/db/generate.js +9 -3
  10. package/dist/commands/db/migrate.d.ts +3 -0
  11. package/dist/commands/db/migrate.js +8 -2
  12. package/dist/commands/db/push.d.ts +3 -0
  13. package/dist/commands/db/push.js +8 -2
  14. package/dist/commands/db/reset.d.ts +3 -0
  15. package/dist/commands/db/reset.js +10 -4
  16. package/dist/commands/db/seed.d.ts +3 -0
  17. package/dist/commands/db/seed.js +9 -3
  18. package/dist/commands/logs/api.d.ts +3 -0
  19. package/dist/commands/logs/api.js +8 -2
  20. package/dist/commands/logs/db.d.ts +3 -0
  21. package/dist/commands/logs/db.js +8 -2
  22. package/dist/commands/logs/index.d.ts +3 -0
  23. package/dist/commands/logs/index.js +8 -2
  24. package/dist/commands/logs/redis.d.ts +3 -0
  25. package/dist/commands/logs/redis.js +8 -2
  26. package/dist/commands/logs/web.d.ts +3 -0
  27. package/dist/commands/logs/web.js +9 -3
  28. package/dist/commands/{db → rebuild}/index.d.ts +2 -1
  29. package/dist/commands/rebuild/index.js +11 -0
  30. package/dist/commands/restart/index.d.ts +3 -0
  31. package/dist/commands/restart/index.js +10 -2
  32. package/dist/commands/shell/api.d.ts +3 -0
  33. package/dist/commands/shell/api.js +9 -3
  34. package/dist/commands/shell/db.d.ts +3 -0
  35. package/dist/commands/shell/db.js +9 -3
  36. package/dist/commands/shell/redis.d.ts +3 -0
  37. package/dist/commands/shell/redis.js +9 -3
  38. package/dist/commands/shell/web.d.ts +3 -0
  39. package/dist/commands/shell/web.js +9 -3
  40. package/dist/commands/{dev → start}/index.d.ts +2 -2
  41. package/dist/commands/start/index.js +111 -0
  42. package/dist/commands/status/index.d.ts +3 -0
  43. package/dist/commands/status/index.js +8 -2
  44. package/dist/commands/stop/index.d.ts +1 -0
  45. package/dist/commands/stop/index.js +9 -1
  46. package/dist/interactive.d.ts +1 -0
  47. package/dist/interactive.js +171 -0
  48. package/dist/templates/env +61 -0
  49. package/dist/utils/docker.js +10 -18
  50. package/dist/utils/env.js +20 -10
  51. package/dist/utils/selection.d.ts +7 -0
  52. package/dist/utils/selection.js +68 -0
  53. package/dist/utils/template.d.ts +11 -0
  54. package/dist/utils/template.js +18 -0
  55. package/oclif.manifest.json +367 -90
  56. package/package.json +30 -25
  57. package/dist/commands/db/index.js +0 -11
  58. package/dist/commands/deploy/index.d.ts +0 -8
  59. package/dist/commands/deploy/index.js +0 -95
  60. package/dist/commands/dev/index.js +0 -59
  61. package/dist/commands/setup/index.d.ts +0 -5
  62. package/dist/commands/setup/index.js +0 -12
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class DbPush extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,10 +1,16 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { execCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class DbPush extends Command {
5
- static description = '推送数据库 schema';
6
+ static description = '推送数据库 schema (db:push)';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
11
+ const { flags } = await this.parse(DbPush);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
8
14
  logger.info('正在推送数据库 schema...');
9
15
  await execCompose(files, 'api', ['npm', 'run', 'db:push'], isBuiltIn);
10
16
  logger.success('Schema 推送完成');
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class DbReset extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,12 +1,18 @@
1
1
  import { Command } from '@oclif/core';
2
+ import { confirm } from '@inquirer/prompts';
2
3
  import { execCompose, getComposeFiles } from '../../utils/docker.js';
3
4
  import { logger } from '../../utils/logger.js';
4
- import { confirm } from '@inquirer/prompts';
5
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
5
6
  export default class DbReset extends Command {
6
- static description = '重置并重新初始化数据';
7
+ static description = '重置数据库 (db:reset) - 危险操作!';
8
+ static flags = {
9
+ env: EnvFlag,
10
+ };
7
11
  async run() {
8
- const { files, isBuiltIn } = await getComposeFiles('basic');
9
- logger.warning('警告:这将清空数据库并重新初始化!');
12
+ const { flags } = await this.parse(DbReset);
13
+ const env = await selectEnvironment(flags.env);
14
+ const { files, isBuiltIn } = await getComposeFiles(env);
15
+ logger.warning('警告:这将清除所有数据!');
10
16
  const confirmReset = await confirm({
11
17
  message: '确认继续?',
12
18
  default: false
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class DbSeed extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { execCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class DbSeed extends Command {
5
- static description = '初始化数据库数据';
6
+ static description = '填充种子数据 (db:seed)';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('正在初始化数据库数据...');
11
+ const { flags } = await this.parse(DbSeed);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在填充种子数据...');
9
15
  await execCompose(files, 'api', ['npm', 'run', 'seed'], isBuiltIn);
10
16
  logger.success('数据初始化完成');
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class LogsApi extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class LogsApi extends Command {
5
6
  static description = '查看 API 服务日志';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('正在显示 API 服务日志...');
11
+ const { flags } = await this.parse(LogsApi);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在获取 API 服务日志...');
9
15
  await runCompose(files, ['logs', '-f', 'api'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class LogsDb extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class LogsDb extends Command {
5
6
  static description = '查看数据库日志';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('正在显示数据库日志...');
11
+ const { flags } = await this.parse(LogsDb);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在获取数据库日志...');
9
15
  await runCompose(files, ['logs', '-f', 'postgres'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class Logs extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class Logs extends Command {
5
6
  static description = '查看所有服务日志';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('正在显示所有服务日志...');
11
+ const { flags } = await this.parse(Logs);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在获取所有服务日志 (按 Ctrl+C 退出)...');
9
15
  await runCompose(files, ['logs', '-f'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class LogsRedis extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class LogsRedis extends Command {
5
6
  static description = '查看 Redis 日志';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('正在显示 Redis 日志...');
11
+ const { flags } = await this.parse(LogsRedis);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在获取 Redis 日志...');
9
15
  await runCompose(files, ['logs', '-f', 'redis'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class LogsWeb extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class LogsWeb extends Command {
5
- static description = '查看 Web 服务日志';
6
+ static description = '查看 Web 前端日志';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('正在显示 Web 服务日志...');
11
+ const { flags } = await this.parse(LogsWeb);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在获取 Web 前端日志...');
9
15
  await runCompose(files, ['logs', '-f', 'web'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,6 @@
1
1
  import { Command } from '@oclif/core';
2
- export default class Db extends Command {
2
+ export default class Rebuild extends Command {
3
3
  static description: string;
4
+ static strict: boolean;
4
5
  run(): Promise<void>;
5
6
  }
@@ -0,0 +1,11 @@
1
+ import { Command } from '@oclif/core';
2
+ import Start from '../start/index.js';
3
+ export default class Rebuild extends Command {
4
+ static description = '重新构建并启动服务 (start --build)';
5
+ // Allow passing flags like -e to the underlying start command
6
+ static strict = false;
7
+ async run() {
8
+ // Invoke Start command with --build flag and any other arguments
9
+ await Start.run(['--build', ...this.argv]);
10
+ }
11
+ }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class Restart extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,19 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class Restart extends Command {
5
- static description = '重启所有服务';
6
+ static description = '重启所有服务 (docker compose restart)';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
11
+ const { flags } = await this.parse(Restart);
12
+ // 1. 选择环境
13
+ const env = await selectEnvironment(flags.env);
14
+ const { files, isBuiltIn } = await getComposeFiles(env);
8
15
  logger.info('正在重启服务...');
16
+ logger.info('环境: ' + env);
9
17
  await runCompose(files, ['restart'], isBuiltIn);
10
18
  logger.success('服务已重启');
11
19
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class ShellApi extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class ShellApi extends Command {
5
- static description = '进入 API 容器';
6
+ static description = '进入 API 服务 shell';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('进入 API 容器...');
11
+ const { flags } = await this.parse(ShellApi);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在进入 API 服务 shell...');
9
15
  await runCompose(files, ['exec', 'api', 'sh'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class ShellDb extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class ShellDb extends Command {
5
- static description = '进入数据库';
6
+ static description = '进入数据库 shell (psql)';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('进入数据库...');
11
+ const { flags } = await this.parse(ShellDb);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在进入数据库 shell...');
9
15
  await runCompose(files, ['exec', 'postgres', 'psql', '-U', 'postgres', '-d', 'nodebbs'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class ShellRedis extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class ShellRedis extends Command {
5
- static description = '进入 Redis';
6
+ static description = '进入 Redis shell (redis-cli)';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('进入 Redis...');
11
+ const { flags } = await this.parse(ShellRedis);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在进入 Redis shell...');
9
15
  await runCompose(files, ['exec', 'redis', 'redis-cli'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class ShellWeb extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class ShellWeb extends Command {
5
- static description = '进入 Web 容器';
6
+ static description = '进入 Web 前端 shell';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('进入 Web 容器...');
11
+ const { flags } = await this.parse(ShellWeb);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在进入 Web 前端 shell...');
9
15
  await runCompose(files, ['exec', 'web', 'sh'], isBuiltIn);
10
16
  }
11
17
  }
@@ -1,9 +1,9 @@
1
1
  import { Command } from '@oclif/core';
2
- export default class Dev extends Command {
2
+ export default class Start extends Command {
3
3
  static description: string;
4
4
  static flags: {
5
5
  env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
- rebuild: import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
+ build: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
7
  };
8
8
  run(): Promise<void>;
9
9
  }
@@ -0,0 +1,111 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import { confirm } from '@inquirer/prompts';
3
+ import { checkDocker, runCompose, waitForHealth, execCompose, getComposeFiles } from '../../utils/docker.js';
4
+ import { initEnv, checkEnv } from '../../utils/env.js';
5
+ import { logger } from '../../utils/logger.js';
6
+ import dotenv from 'dotenv';
7
+ import { EnvFlag, selectEnvironment, setStoredEnv } from '../../utils/selection.js';
8
+ export default class Start extends Command {
9
+ static description = '开始部署';
10
+ static flags = {
11
+ env: EnvFlag,
12
+ build: Flags.boolean({
13
+ char: 'b',
14
+ description: '重新构建并启动服务 (跳过健康检查和数据初始化)',
15
+ default: false,
16
+ }),
17
+ };
18
+ async run() {
19
+ const { flags } = await this.parse(Start);
20
+ if (flags.build) {
21
+ logger.header('NodeBBS 重新构建启动');
22
+ }
23
+ else {
24
+ logger.header('NodeBBS Docker 部署');
25
+ }
26
+ // 1. 选择环境
27
+ const env = await selectEnvironment(flags.env);
28
+ await setStoredEnv(env);
29
+ // 2. 获取 Compose 文件
30
+ const { files: composeFiles, isBuiltIn } = await getComposeFiles(env);
31
+ if (isBuiltIn) {
32
+ logger.info('使用内置 Docker Compose 模板...');
33
+ }
34
+ else {
35
+ logger.info('使用项目 Docker Compose 文件...');
36
+ }
37
+ if (env === 'production') {
38
+ logger.success('已选择:标准生产环境');
39
+ }
40
+ else if (env === 'lowmem') {
41
+ logger.success('已选择:低配环境');
42
+ }
43
+ else {
44
+ logger.success('已选择:基础环境');
45
+ if (!flags.build) {
46
+ logger.warning('注意:无资源限制,不推荐用于生产环境。');
47
+ }
48
+ }
49
+ // 3. 检查 Docker 和环境变量
50
+ await checkDocker();
51
+ // initEnv 保证 .env 存在(或退出)
52
+ await initEnv();
53
+ await checkEnv(env);
54
+ if (!flags.build) {
55
+ const continueDeploy = await confirm({
56
+ message: '是否继续启动?',
57
+ default: true
58
+ });
59
+ if (!continueDeploy) {
60
+ logger.info('操作已取消。');
61
+ this.exit(0);
62
+ }
63
+ }
64
+ // 4. 构建并启动服务
65
+ if (flags.build) {
66
+ logger.info('正在重新构建并启动服务...');
67
+ await runCompose(composeFiles, ['up', '-d', '--build'], isBuiltIn);
68
+ logger.success('服务已重新构建并启动');
69
+ }
70
+ else {
71
+ logger.info('正在构建 Docker 镜像...');
72
+ await runCompose(composeFiles, ['build', '--no-cache'], isBuiltIn);
73
+ logger.success('镜像构建完成');
74
+ logger.info('正在启动服务...');
75
+ await runCompose(composeFiles, ['up', '-d'], isBuiltIn);
76
+ logger.success('服务启动指令已发送');
77
+ }
78
+ // 5. 启动后操作 (仅完整部署)
79
+ if (!flags.build) {
80
+ await waitForHealth(composeFiles, isBuiltIn);
81
+ const pushDb = await confirm({
82
+ message: '是否推送数据库 schema?',
83
+ default: false
84
+ });
85
+ if (pushDb) {
86
+ logger.info('正在推送数据库 schema...');
87
+ await execCompose(composeFiles, 'api', ['npm', 'run', 'db:push'], isBuiltIn);
88
+ logger.success('数据库 schema 推送完成');
89
+ }
90
+ const seedDb = await confirm({
91
+ message: '是否初始化种子数据?',
92
+ default: false
93
+ });
94
+ if (seedDb) {
95
+ logger.info('正在初始化数据...');
96
+ await execCompose(composeFiles, 'api', ['npm', 'run', 'seed'], isBuiltIn);
97
+ logger.success('数据初始化完成');
98
+ }
99
+ }
100
+ logger.header(flags.build ? '启动成功!' : 'NodeBBS 启动成功!');
101
+ // 6. 显示信息
102
+ logger.info(`环境: ${env}`);
103
+ const envConfig = dotenv.config().parsed || {};
104
+ const webPort = envConfig.WEB_PORT || '3100';
105
+ const apiPort = envConfig.API_PORT || '7100';
106
+ console.log(` Web 前端: http://localhost:${webPort}`);
107
+ console.log(` API 服务: http://localhost:${apiPort}`);
108
+ console.log(` API 文档: http://localhost:${apiPort}/docs`);
109
+ console.log(` 健康检查: http://localhost:${apiPort}/api`);
110
+ }
111
+ }
@@ -1,5 +1,8 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class Status extends Command {
3
3
  static description: string;
4
+ static flags: {
5
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ };
4
7
  run(): Promise<void>;
5
8
  }
@@ -1,11 +1,17 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
+ import { EnvFlag, selectEnvironment } from '../../utils/selection.js';
4
5
  export default class Status extends Command {
5
6
  static description = '查看服务状态';
7
+ static flags = {
8
+ env: EnvFlag,
9
+ };
6
10
  async run() {
7
- const { files, isBuiltIn } = await getComposeFiles('basic');
8
- logger.info('服务状态:');
11
+ const { flags } = await this.parse(Status);
12
+ const env = await selectEnvironment(flags.env);
13
+ const { files, isBuiltIn } = await getComposeFiles(env);
14
+ logger.info('正在获取服务状态...');
9
15
  await runCompose(files, ['ps'], isBuiltIn);
10
16
  }
11
17
  }
@@ -3,6 +3,7 @@ export default class Stop extends Command {
3
3
  static description: string;
4
4
  static flags: {
5
5
  volumes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
7
  };
7
8
  run(): Promise<void>;
8
9
  }
@@ -2,6 +2,7 @@ import { Command, Flags } from '@oclif/core';
2
2
  import { runCompose, getComposeFiles } from '../../utils/docker.js';
3
3
  import { logger } from '../../utils/logger.js';
4
4
  import { confirm } from '@inquirer/prompts';
5
+ import { EnvFlag, selectEnvironment, clearStoredEnv } from '../../utils/selection.js';
5
6
  export default class Stop extends Command {
6
7
  static description = '停止服务';
7
8
  static flags = {
@@ -10,10 +11,15 @@ export default class Stop extends Command {
10
11
  description: '同时删除数据卷(危险!)',
11
12
  default: false,
12
13
  }),
14
+ env: EnvFlag,
13
15
  };
14
16
  async run() {
15
17
  const { flags } = await this.parse(Stop);
16
- const { files, isBuiltIn } = await getComposeFiles('basic');
18
+ // 1. 选择环境
19
+ const env = await selectEnvironment(flags.env, {
20
+ prompt: '请选择运行环境(停止服务需匹配启动环境):'
21
+ });
22
+ const { files, isBuiltIn } = await getComposeFiles(env);
17
23
  if (flags.volumes) {
18
24
  logger.warning('警告:这将删除所有数据!');
19
25
  const confirmDelete = await confirm({
@@ -26,11 +32,13 @@ export default class Stop extends Command {
26
32
  }
27
33
  logger.info('正在停止服务并删除数据卷...');
28
34
  await runCompose(files, ['down', '-v'], isBuiltIn);
35
+ await clearStoredEnv();
29
36
  logger.success('服务已停止,数据卷已删除');
30
37
  }
31
38
  else {
32
39
  logger.info('正在停止服务...');
33
40
  await runCompose(files, ['down'], isBuiltIn);
41
+ await clearStoredEnv();
34
42
  logger.success('服务已停止');
35
43
  }
36
44
  }
@@ -0,0 +1 @@
1
+ export declare function runInteractive(root: string): Promise<void>;