@xfilecom/create-xframe 0.1.0 → 0.1.1
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/create-xframe.js +1 -0
- package/package.json +12 -3
- package/template/shared/README.md +8 -0
- package/template/shared/config/api/application-development.yml +2 -0
- package/template/shared/config/api/application-production.yml +2 -0
- package/template/shared/config/api/application-staging.yml +2 -0
- package/template/shared/config/api/application.yml +21 -0
- package/template/shared/endpoint/.gitkeep +0 -0
- package/template/shared/endpoint/README.md +1 -0
- package/template/shared/schema/.gitkeep +0 -0
- package/template/shared/schema/README.md +1 -0
- package/template/shared/sql/.gitkeep +0 -0
- package/template/shared/sql/README.md +1 -0
- package/template/src/app.module.ts +24 -6
- package/template/src/config.loader.ts +43 -0
- package/template/src/main.ts +18 -0
package/bin/create-xframe.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfilecom/create-xframe",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Scaffold a Nest app wired to @xfilecom/backend-core (xframe)",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"bin": {
|
|
7
7
|
"create-xframe": "bin/create-xframe.js"
|
|
8
8
|
},
|
|
9
|
-
"files": [
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"template"
|
|
12
|
+
],
|
|
10
13
|
"engines": {
|
|
11
14
|
"node": ">=18"
|
|
12
15
|
},
|
|
@@ -14,5 +17,11 @@
|
|
|
14
17
|
"registry": "https://registry.npmjs.org/",
|
|
15
18
|
"access": "public"
|
|
16
19
|
},
|
|
17
|
-
"keywords": [
|
|
20
|
+
"keywords": [
|
|
21
|
+
"xframe",
|
|
22
|
+
"nestjs",
|
|
23
|
+
"xfilecom",
|
|
24
|
+
"scaffold",
|
|
25
|
+
"create-xframe"
|
|
26
|
+
]
|
|
18
27
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# `shared/` — 설정·도메인 자산
|
|
2
|
+
|
|
3
|
+
| 경로 | 용도 |
|
|
4
|
+
|------|------|
|
|
5
|
+
| **`config/api`** | Nest API YAML (`loadApplicationYamlSync` → `src/config.loader.ts`) |
|
|
6
|
+
| **`schema/`** | Drizzle 스키마 등 (TS는 `tsconfig.build.json`에 경로 포함 필요) |
|
|
7
|
+
| **`sql/`** | 마이그레이션·시드 SQL |
|
|
8
|
+
| **`endpoint/`** | OpenAPI·공유 DTO·라우트 규칙 |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
server:
|
|
2
|
+
port: 3000
|
|
3
|
+
|
|
4
|
+
cors:
|
|
5
|
+
enabled: true
|
|
6
|
+
origin: true
|
|
7
|
+
|
|
8
|
+
core:
|
|
9
|
+
database:
|
|
10
|
+
auto: false
|
|
11
|
+
interceptors:
|
|
12
|
+
logging: true
|
|
13
|
+
errorHandling: true
|
|
14
|
+
responseTransform: true
|
|
15
|
+
databaseCheck: true
|
|
16
|
+
response:
|
|
17
|
+
commonResponse: true
|
|
18
|
+
filters:
|
|
19
|
+
exception: true
|
|
20
|
+
guards:
|
|
21
|
+
jwt: false
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
OpenAPI·공유 endpoint 계약.
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Drizzle 등 DB 스키마. `AppModule`에서 import 후 `database: { auto: true, schema }`에 연결. TS 파일을 여기 두면 `tsconfig.build.json`의 `include`에 `shared/schema/**/*.ts`를 추가하세요.
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
마이그레이션·시드 SQL 보관.
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
|
-
import { CoreModule } from '@xfilecom/backend-core';
|
|
2
|
+
import { CoreModule, type CoreModuleOptions } from '@xfilecom/backend-core';
|
|
3
|
+
import { appConfig } from './config.loader';
|
|
3
4
|
import { AppController } from './app.controller';
|
|
5
|
+
// import { schema } from '../shared/schema';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
function coreOptionsFromYaml(): CoreModuleOptions {
|
|
8
|
+
const c = appConfig.core;
|
|
9
|
+
if (!c) {
|
|
10
|
+
return {
|
|
8
11
|
database: { auto: false },
|
|
9
12
|
guards: { jwt: false },
|
|
10
|
-
}
|
|
11
|
-
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
database: {
|
|
17
|
+
auto: c.database?.auto === true,
|
|
18
|
+
// schema,
|
|
19
|
+
},
|
|
20
|
+
interceptors: c.interceptors,
|
|
21
|
+
response: c.response,
|
|
22
|
+
filters: c.filters,
|
|
23
|
+
guards: c.guards,
|
|
24
|
+
jwt: c.jwt,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Module({
|
|
29
|
+
imports: [CoreModule.forHttpApi(coreOptionsFromYaml())],
|
|
12
30
|
controllers: [AppController],
|
|
13
31
|
})
|
|
14
32
|
export class AppModule {}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import {
|
|
3
|
+
loadApplicationYamlSync,
|
|
4
|
+
type ConfigSource,
|
|
5
|
+
} from '@xfilecom/backend-core';
|
|
6
|
+
|
|
7
|
+
const configDir = resolve(process.cwd(), 'shared', 'config', 'api');
|
|
8
|
+
const nodeEnv = process.env.NODE_ENV || 'development';
|
|
9
|
+
const configSource =
|
|
10
|
+
(process.env.CONFIG_SOURCE as ConfigSource | undefined) ?? 'yamlWithEnvOverrides';
|
|
11
|
+
|
|
12
|
+
export const appConfig = loadApplicationYamlSync({
|
|
13
|
+
rootDir: configDir,
|
|
14
|
+
env: nodeEnv,
|
|
15
|
+
configSource,
|
|
16
|
+
syncEnvKeys: {
|
|
17
|
+
PORT: 'server.port',
|
|
18
|
+
APP_ENV: 'app.env',
|
|
19
|
+
},
|
|
20
|
+
}) as AppConfigShape;
|
|
21
|
+
|
|
22
|
+
export type AppConfigShape = {
|
|
23
|
+
server?: { port?: number };
|
|
24
|
+
app?: { env?: string };
|
|
25
|
+
cors?: {
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
origin?: boolean | string | string[];
|
|
28
|
+
credentials?: boolean;
|
|
29
|
+
};
|
|
30
|
+
core?: {
|
|
31
|
+
database?: { auto?: boolean };
|
|
32
|
+
interceptors?: {
|
|
33
|
+
logging?: boolean | Record<string, unknown>;
|
|
34
|
+
errorHandling?: boolean;
|
|
35
|
+
responseTransform?: boolean;
|
|
36
|
+
databaseCheck?: boolean;
|
|
37
|
+
};
|
|
38
|
+
response?: { commonResponse?: boolean };
|
|
39
|
+
filters?: { exception?: boolean | Record<string, unknown> };
|
|
40
|
+
guards?: { jwt?: boolean };
|
|
41
|
+
jwt?: { secret?: string; expiresIn?: string };
|
|
42
|
+
};
|
|
43
|
+
};
|
package/template/src/main.ts
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
+
import './config.loader';
|
|
1
2
|
import 'reflect-metadata';
|
|
2
3
|
import { NestFactory } from '@nestjs/core';
|
|
4
|
+
import type { INestApplication } from '@nestjs/common';
|
|
3
5
|
import { AppModule } from './app.module';
|
|
6
|
+
import { appConfig } from './config.loader';
|
|
7
|
+
|
|
8
|
+
function applyCors(app: INestApplication): void {
|
|
9
|
+
const cors = appConfig.cors;
|
|
10
|
+
if (cors?.enabled === false) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const origin = cors?.origin ?? true;
|
|
14
|
+
const credentials = cors?.credentials === true;
|
|
15
|
+
if (Array.isArray(origin) || typeof origin === 'string') {
|
|
16
|
+
app.enableCors({ origin, credentials });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
app.enableCors({ origin: origin === true, credentials });
|
|
20
|
+
}
|
|
4
21
|
|
|
5
22
|
async function bootstrap() {
|
|
6
23
|
const app = await NestFactory.create(AppModule);
|
|
24
|
+
applyCors(app);
|
|
7
25
|
const port = Number(process.env.PORT) || 3000;
|
|
8
26
|
await app.listen(port);
|
|
9
27
|
}
|