nodebbs 0.0.2 → 0.0.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.
Files changed (57) hide show
  1. package/README.md +83 -99
  2. package/dist/commands/clean/index.d.ts +11 -0
  3. package/dist/commands/clean/index.js +93 -0
  4. package/dist/commands/db/backup.d.ts +9 -0
  5. package/dist/commands/db/backup.js +78 -0
  6. package/dist/commands/db/generate.d.ts +3 -0
  7. package/dist/commands/db/generate.js +9 -3
  8. package/dist/commands/db/index.d.ts +3 -0
  9. package/dist/commands/db/index.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/restart/index.d.ts +3 -0
  29. package/dist/commands/restart/index.js +10 -2
  30. package/dist/commands/shell/api.d.ts +3 -0
  31. package/dist/commands/shell/api.js +9 -3
  32. package/dist/commands/shell/db.d.ts +3 -0
  33. package/dist/commands/shell/db.js +9 -3
  34. package/dist/commands/shell/redis.d.ts +3 -0
  35. package/dist/commands/shell/redis.js +9 -3
  36. package/dist/commands/shell/web.d.ts +3 -0
  37. package/dist/commands/shell/web.js +9 -3
  38. package/dist/commands/{dev → start}/index.d.ts +2 -2
  39. package/dist/commands/start/index.js +110 -0
  40. package/dist/commands/status/index.d.ts +3 -0
  41. package/dist/commands/status/index.js +8 -2
  42. package/dist/commands/stop/index.d.ts +1 -0
  43. package/dist/commands/stop/index.js +7 -1
  44. package/dist/templates/env +61 -0
  45. package/dist/utils/docker.js +3 -11
  46. package/dist/utils/env.js +19 -9
  47. package/dist/utils/selection.d.ts +5 -0
  48. package/dist/utils/selection.js +24 -0
  49. package/dist/utils/template.d.ts +11 -0
  50. package/dist/utils/template.js +18 -0
  51. package/oclif.manifest.json +380 -89
  52. package/package.json +21 -21
  53. package/dist/commands/deploy/index.d.ts +0 -8
  54. package/dist/commands/deploy/index.js +0 -95
  55. package/dist/commands/dev/index.js +0 -59
  56. package/dist/commands/setup/index.d.ts +0 -5
  57. package/dist/commands/setup/index.js +0 -12
package/dist/utils/env.js CHANGED
@@ -4,6 +4,7 @@ import { promisify } from 'node:util';
4
4
  import { logger } from './logger.js';
5
5
  import { confirm } from '@inquirer/prompts';
6
6
  import dotenv from 'dotenv';
7
+ import { getTemplatePath } from './template.js';
7
8
  const fileExists = promisify(exists);
8
9
  export async function initEnv() {
9
10
  if (await fileExists('.env')) {
@@ -11,8 +12,24 @@ export async function initEnv() {
11
12
  return;
12
13
  }
13
14
  logger.info('正在创建 .env 文件...');
15
+ let sourceFile = '';
16
+ let isBuiltIn = false;
14
17
  if (await fileExists('.env.docker.example')) {
15
- await fs.copyFile('.env.docker.example', '.env');
18
+ sourceFile = '.env.docker.example';
19
+ }
20
+ else {
21
+ // Use built-in template
22
+ sourceFile = getTemplatePath('env');
23
+ isBuiltIn = true;
24
+ }
25
+ if (sourceFile) {
26
+ await fs.copyFile(sourceFile, '.env');
27
+ if (isBuiltIn) {
28
+ logger.success('已使用内置模板创建 .env');
29
+ }
30
+ else {
31
+ logger.success(`已从 ${sourceFile} 复制 .env`);
32
+ }
16
33
  logger.warning('请编辑 .env 文件并修改以下配置:');
17
34
  logger.warning(' - POSTGRES_PASSWORD (数据库密码)');
18
35
  logger.warning(' - REDIS_PASSWORD (Redis 密码)');
@@ -27,14 +44,7 @@ export async function initEnv() {
27
44
  }
28
45
  }
29
46
  else {
30
- // If .env.docker.example doesn't exist, maybe we are in the wrong directory or need to look in project/
31
- if (await fileExists('project/.env.docker.example')) {
32
- await fs.copyFile('project/.env.docker.example', '.env');
33
- logger.success('已从 project/.env.docker.example 复制 .env');
34
- }
35
- else {
36
- logger.warning('未找到 .env.docker.example!跳过 .env 创建。');
37
- }
47
+ logger.warning('未找到 .env.docker.example 或内置模板!跳过 .env 创建。');
38
48
  }
39
49
  }
40
50
  export async function checkEnv(envType) {
@@ -0,0 +1,5 @@
1
+ export type EnvType = 'production' | 'lowmem' | 'basic';
2
+ export declare const EnvFlag: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
3
+ export declare function selectEnvironment(env?: string, options?: {
4
+ prompt?: string;
5
+ }): Promise<EnvType>;
@@ -0,0 +1,24 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { select } from '@inquirer/prompts';
3
+ import { logger } from './logger.js';
4
+ export const EnvFlag = Flags.string({
5
+ char: 'e',
6
+ description: '部署环境 (production, lowmem, basic)',
7
+ options: ['production', 'lowmem', 'basic'],
8
+ });
9
+ export async function selectEnvironment(env, options = {}) {
10
+ if (env) {
11
+ // oclif options validation handles valid values, but type casting is needed
12
+ return env;
13
+ }
14
+ const selected = await select({
15
+ message: options.prompt || '请选择运行环境:',
16
+ choices: [
17
+ { name: '标准生产环境 (2C4G+) [推荐]', value: 'production' },
18
+ { name: '低配环境 (1C1G/1C2G)', value: 'lowmem' },
19
+ { name: '基础环境 (仅用于测试)', value: 'basic' },
20
+ ],
21
+ });
22
+ logger.info(`已选择环境: ${selected}`);
23
+ return selected;
24
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Get the absolute path to the templates directory.
3
+ * In production (dist/utils), templates are in dist/templates.
4
+ * In development (src/utils), templates are in src/templates.
5
+ */
6
+ export declare function getTemplateDir(): string;
7
+ /**
8
+ * Get the absolute path to a specific template file.
9
+ * @param fileName The name of the template file (e.g., 'env', 'docker-compose.yml')
10
+ */
11
+ export declare function getTemplatePath(fileName: string): string;
@@ -0,0 +1,18 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
4
+ /**
5
+ * Get the absolute path to the templates directory.
6
+ * In production (dist/utils), templates are in dist/templates.
7
+ * In development (src/utils), templates are in src/templates.
8
+ */
9
+ export function getTemplateDir() {
10
+ return path.join(__dirname, '..', 'templates');
11
+ }
12
+ /**
13
+ * Get the absolute path to a specific template file.
14
+ * @param fileName The name of the template file (e.g., 'env', 'docker-compose.yml')
15
+ */
16
+ export function getTemplatePath(fileName) {
17
+ return path.join(getTemplateDir(), fileName);
18
+ }