jax-hono 1.0.20 → 1.0.21

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,20 +1,20 @@
1
- import { mkdirSync } from 'node:fs'
2
- import { cwd } from 'node:process'
3
- import { join, resolve } from 'node:path'
4
-
5
- export const packageDir = join(import.meta.dir, '..')
6
- export const projectDir = cwd()
7
-
8
- export function getGeneratedDir() {
9
- const configuredDir = Bun.env.JAX_HONO_GENERATED_DIR
10
-
11
- return configuredDir
12
- ? resolve(projectDir, configuredDir)
13
- : join(projectDir, '.jax-hono')
14
- }
15
-
16
- export const generatedDir = getGeneratedDir()
17
-
18
- export function ensureGeneratedDir() {
19
- mkdirSync(generatedDir, { recursive: true })
20
- }
1
+ import { mkdirSync } from 'node:fs'
2
+ import { cwd } from 'node:process'
3
+ import { join, resolve } from 'node:path'
4
+
5
+ export const packageDir = join(import.meta.dir, '..')
6
+ export const projectDir = cwd()
7
+
8
+ export function getGeneratedDir() {
9
+ const configuredDir = Bun.env.JAX_HONO_GENERATED_DIR
10
+
11
+ return configuredDir
12
+ ? resolve(projectDir, configuredDir)
13
+ : join(projectDir, '.jax-hono')
14
+ }
15
+
16
+ export const generatedDir = getGeneratedDir()
17
+
18
+ export function ensureGeneratedDir() {
19
+ mkdirSync(generatedDir, { recursive: true })
20
+ }
package/config.ts CHANGED
@@ -5,35 +5,35 @@ import { config as loadDotenv } from 'dotenv';
5
5
  import minimist from 'minimist';
6
6
  import { getProjectDir, requireGeneratedModule, type GeneratedProjectConfig } from './core/generated';
7
7
  import type { JaxConfig } from './types/config';
8
-
9
- type PlainConfig = Record<string, unknown>;
10
- type ProjectConfig = GeneratedProjectConfig;
11
- type ConfigModuleItem = {
12
- name: string;
13
- stage: string;
14
- config: unknown;
15
- };
16
- export type { JaxConfig } from './types/config';
17
- export type Config = JaxConfig & ProjectConfig;
18
-
8
+
9
+ type PlainConfig = Record<string, unknown>;
10
+ type ProjectConfig = GeneratedProjectConfig;
11
+ type ConfigModuleItem = {
12
+ name: string;
13
+ stage: string;
14
+ config: unknown;
15
+ };
16
+ export type { JaxConfig } from './types/config';
17
+ export type Config = JaxConfig & ProjectConfig;
18
+
19
19
  const { configModules } = requireGeneratedModule<{ configModules: readonly ConfigModuleItem[] }>('config.ts');
20
20
  const projectDir = getProjectDir();
21
-
22
- loadDotenvFile('.env');
23
-
24
- const argv = minimist(Bun.argv.slice(2), {
25
- string: ['env'],
26
- alias: {
27
- env: 'e'
28
- }
29
- });
30
-
31
- const env = argv.env || Bun.env.APP_ENV || Bun.env.NODE_ENV || 'prod';
32
-
33
- console.log('env', env);
34
-
35
- loadDotenvFile(`.env.${env}`);
36
-
21
+
22
+ loadDotenvFile('.env');
23
+
24
+ const argv = minimist(Bun.argv.slice(2), {
25
+ string: ['env'],
26
+ alias: {
27
+ env: 'e'
28
+ }
29
+ });
30
+
31
+ const env = argv.env || Bun.env.APP_ENV || Bun.env.NODE_ENV || 'prod';
32
+
33
+ console.log('env', env);
34
+
35
+ loadDotenvFile(`.env.${env}`);
36
+
37
37
  function loadDotenvFile(file: string) {
38
38
  const path = join(projectDir, file);
39
39
 
@@ -41,46 +41,46 @@ function loadDotenvFile(file: string) {
41
41
  loadDotenv({ path, override: true });
42
42
  }
43
43
  }
44
-
45
- function isPlainConfig(value: unknown): value is PlainConfig {
46
- return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
47
- }
48
-
49
- function shouldUseConfigStage(stage: string) {
50
- return stage === 'base' || stage === 'default' || stage === env;
51
- }
52
-
53
- function parsePort(value: string | undefined) {
54
- const port = Number(value);
55
-
56
- return Number.isInteger(port) && port > 0 ? port : 3000;
57
- }
58
-
59
- export function loadConfig(): Config {
44
+
45
+ function isPlainConfig(value: unknown): value is PlainConfig {
46
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
47
+ }
48
+
49
+ function shouldUseConfigStage(stage: string) {
50
+ return stage === 'base' || stage === 'default' || stage === env;
51
+ }
52
+
53
+ function parsePort(value: string | undefined) {
54
+ const port = Number(value);
55
+
56
+ return Number.isInteger(port) && port > 0 ? port : 3000;
57
+ }
58
+
59
+ export function loadConfig(): Config {
60
60
  const jaxConfig: JaxConfig = {
61
61
  rootDir: projectDir,
62
- port: parsePort(Bun.env.PORT),
63
- env
64
- };
65
-
66
- const configs = configModules
67
- .filter((item) => shouldUseConfigStage(item.stage))
68
- .map((item) => {
69
- if (!isPlainConfig(item.config)) {
70
- throw new TypeError(`Config file ${item.name} must export a plain object.`);
71
- }
72
-
73
- return item.config;
74
- });
75
-
76
- return merge.all<PlainConfig>([jaxConfig, ...configs], {
77
- arrayMerge: (_destination, source) => source
78
- }) as Config;
79
- }
80
-
81
- const config = loadConfig();
82
-
83
- console.log('port', config.port);
84
-
85
- export { env };
86
- export default config;
62
+ port: parsePort(Bun.env.PORT),
63
+ env
64
+ };
65
+
66
+ const configs = configModules
67
+ .filter((item) => shouldUseConfigStage(item.stage))
68
+ .map((item) => {
69
+ if (!isPlainConfig(item.config)) {
70
+ throw new TypeError(`Config file ${item.name} must export a plain object.`);
71
+ }
72
+
73
+ return item.config;
74
+ });
75
+
76
+ return merge.all<PlainConfig>([jaxConfig, ...configs], {
77
+ arrayMerge: (_destination, source) => source
78
+ }) as Config;
79
+ }
80
+
81
+ const config = loadConfig();
82
+
83
+ console.log('port', config.port);
84
+
85
+ export { env };
86
+ export default config;