@gravito/satellite-news 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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +51 -0
- package/package.json +28 -0
- package/src/Domain/Entities/News.ts +26 -0
- package/src/index.ts +52 -0
- package/tsconfig.json +21 -0
package/CHANGELOG.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { ServiceProvider } from "@gravito/core";
|
|
3
|
+
var NewsServiceProvider = class extends ServiceProvider {
|
|
4
|
+
register(_container) {
|
|
5
|
+
}
|
|
6
|
+
boot() {
|
|
7
|
+
const core = this.core;
|
|
8
|
+
if (!core) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
core.logger.info("\u{1F4F0} News Satellite is live");
|
|
12
|
+
core.router.prefix("/api/admin/v1/news").group((router) => {
|
|
13
|
+
router.get(
|
|
14
|
+
"/",
|
|
15
|
+
(ctx) => ctx.json([
|
|
16
|
+
{
|
|
17
|
+
id: "news-1",
|
|
18
|
+
title: "Gravito 2.0 \u6B63\u5F0F\u7248\u767C\u5E03\uFF1A\u9081\u5411\u5168\u65B0\u7684\u63D2\u4EF6\u5316\u6642\u4EE3",
|
|
19
|
+
slug: "gravito-2-launch",
|
|
20
|
+
category: "\u7522\u54C1\u66F4\u65B0",
|
|
21
|
+
status: "PUBLISHED",
|
|
22
|
+
publishedAt: "2025-01-10"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "news-2",
|
|
26
|
+
title: "\u5E74\u5EA6\u958B\u767C\u8005\u5927\u6703 2025 \u5831\u540D\u958B\u59CB",
|
|
27
|
+
slug: "gravito-dev-conf-2025",
|
|
28
|
+
category: "\u54C1\u724C\u6D3B\u52D5",
|
|
29
|
+
status: "DRAFT",
|
|
30
|
+
publishedAt: null
|
|
31
|
+
}
|
|
32
|
+
])
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
core.router.get(
|
|
36
|
+
"/api/v1/news",
|
|
37
|
+
(ctx) => ctx.json({
|
|
38
|
+
data: [
|
|
39
|
+
{
|
|
40
|
+
title: "Gravito 2.0 \u6B63\u5F0F\u7248\u767C\u5E03",
|
|
41
|
+
slug: "gravito-2-launch",
|
|
42
|
+
excerpt: "\u6211\u5011\u5E36\u4F86\u4E86\u6578\u767E\u9805\u66F4\u65B0..."
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
NewsServiceProvider
|
|
51
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gravito/satellite-news",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
8
|
+
"typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck"
|
|
9
|
+
},
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@gravito/enterprise": "workspace:*",
|
|
13
|
+
"@gravito/atlas": "workspace:*",
|
|
14
|
+
"@gravito/core": "workspace:*"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"tsup": "^8.3.5",
|
|
18
|
+
"typescript": "^5.9.3"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/gravito-framework/gravito.git",
|
|
26
|
+
"directory": "satellites/news"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Entity } from '@gravito/enterprise'
|
|
2
|
+
|
|
3
|
+
export interface NewsProps {
|
|
4
|
+
title: string
|
|
5
|
+
slug: string
|
|
6
|
+
excerpt: string
|
|
7
|
+
content: string
|
|
8
|
+
thumbnail?: string
|
|
9
|
+
category: string
|
|
10
|
+
status: 'DRAFT' | 'PUBLISHED'
|
|
11
|
+
publishedAt?: Date
|
|
12
|
+
createdAt: Date
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class News extends Entity<string> {
|
|
16
|
+
private _props: NewsProps
|
|
17
|
+
|
|
18
|
+
constructor(props: NewsProps, id?: string) {
|
|
19
|
+
super(id || crypto.randomUUID())
|
|
20
|
+
this._props = props
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
unpack() {
|
|
24
|
+
return { ...this._props }
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Container, ServiceProvider } from '@gravito/core'
|
|
2
|
+
|
|
3
|
+
export class NewsServiceProvider extends ServiceProvider {
|
|
4
|
+
register(_container: Container): void {
|
|
5
|
+
// 註冊服務
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
override boot(): void {
|
|
9
|
+
const core = this.core
|
|
10
|
+
if (!core) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
core.logger.info('📰 News Satellite is live')
|
|
15
|
+
|
|
16
|
+
core.router.prefix('/api/admin/v1/news').group((router) => {
|
|
17
|
+
router.get('/', (ctx) =>
|
|
18
|
+
ctx.json([
|
|
19
|
+
{
|
|
20
|
+
id: 'news-1',
|
|
21
|
+
title: 'Gravito 2.0 正式版發布:邁向全新的插件化時代',
|
|
22
|
+
slug: 'gravito-2-launch',
|
|
23
|
+
category: '產品更新',
|
|
24
|
+
status: 'PUBLISHED',
|
|
25
|
+
publishedAt: '2025-01-10',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'news-2',
|
|
29
|
+
title: '年度開發者大會 2025 報名開始',
|
|
30
|
+
slug: 'gravito-dev-conf-2025',
|
|
31
|
+
category: '品牌活動',
|
|
32
|
+
status: 'DRAFT',
|
|
33
|
+
publishedAt: null,
|
|
34
|
+
},
|
|
35
|
+
])
|
|
36
|
+
)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// 公開 API
|
|
40
|
+
core.router.get('/api/v1/news', (ctx) =>
|
|
41
|
+
ctx.json({
|
|
42
|
+
data: [
|
|
43
|
+
{
|
|
44
|
+
title: 'Gravito 2.0 正式版發布',
|
|
45
|
+
slug: 'gravito-2-launch',
|
|
46
|
+
excerpt: '我們帶來了數百項更新...',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"types": ["bun-types"],
|
|
8
|
+
"paths": {
|
|
9
|
+
"@gravito/core": ["../../packages/core/src/index.ts"],
|
|
10
|
+
"@gravito/*": ["../../packages/*/src/index.ts"]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src/**/*"
|
|
15
|
+
],
|
|
16
|
+
"exclude": [
|
|
17
|
+
"node_modules",
|
|
18
|
+
"dist",
|
|
19
|
+
"**/*.test.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|