Skip to content

Commit a9f2f9d

Browse files
committed
chore: test code 추가
1 parent db54de1 commit a9f2f9d

File tree

6 files changed

+2223
-8
lines changed

6 files changed

+2223
-8
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { writeFileSync, readFileSync } from 'fs';
2+
import { join, resolve, dirname } from 'path';
3+
import { Client } from 'notion-to-utils';
4+
import dotenv from 'dotenv';
5+
import { fileURLToPath } from 'url';
6+
7+
// ES 모듈에서 __dirname 대체
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = dirname(__filename);
10+
11+
// 환경 변수 로드
12+
dotenv.config({ path: resolve(__dirname, '../.env.local') });
13+
14+
// 페이지 ID
15+
const PAGE_ID = '76318ec3-9f83-4cc2-af54-7d81daab0131';
16+
17+
// ? using this script : pnpx tsx scripts/fetchNotionProperties.ts
18+
async function fetchNotionPage() {
19+
try {
20+
// Notion API 키 확인
21+
let apiKey = process.env.NOTION_API_KEY;
22+
23+
// 환경 변수에서 API 키를 가져오지 못한 경우 .env.local 파일에서 직접 읽기 시도
24+
if (!apiKey) {
25+
try {
26+
const envPath = resolve(__dirname, '../.env.local');
27+
console.log(
28+
`환경 변수에서 API 키를 찾을 수 없어 ${envPath} 파일에서 직접 읽습니다.`
29+
);
30+
const envContent = readFileSync(envPath, 'utf8');
31+
const match = envContent.match(/NOTION_API_KEY=(.+)/);
32+
if (match && match[1]) {
33+
apiKey = match[1];
34+
console.log('API 키를 파일에서 성공적으로 읽었습니다.');
35+
}
36+
} catch (err) {
37+
console.error('.env.local 파일 읽기 실패:', err);
38+
}
39+
}
40+
41+
if (!apiKey) {
42+
console.error(
43+
'NOTION_API_KEY를 찾을 수 없습니다. .env.local 파일에 NOTION_API_KEY=your_key 형식으로 설정해주세요.'
44+
);
45+
process.exit(1);
46+
}
47+
48+
console.log('Notion API에서 페이지 속성 데이터를 가져오는 중...');
49+
50+
// Notion 클라이언트 생성
51+
const client = new Client({ auth: apiKey });
52+
53+
const blocks = await client.getPageBlocks(PAGE_ID);
54+
55+
// JSON 파일로 저장
56+
const outputPath = join(__dirname, '../src/sample-data/notionPage.json');
57+
console.log(`저장 경로: ${outputPath}`);
58+
writeFileSync(outputPath, JSON.stringify(blocks, null, 2), 'utf8');
59+
60+
console.log(`페이지 데이터가 성공적으로 저장되었습니다: ${outputPath}`);
61+
} catch (error) {
62+
console.error('페이지 데이터 가져오기 실패:', error);
63+
process.exit(1);
64+
}
65+
}
66+
67+
// 스크립트 실행
68+
fetchNotionPage();

apps/renderer-storybook/src/sample-data/notionBlocks.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"type": "file",
7070
"file": {
7171
"url": "https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fcd7314a5-d906-43b0-81e7-42eff82c02a3%2F566f127b-9e73-491d-bee6-5afd075653a2%2Fimage.png?table=block&id=17f9c6bf-2b17-8016-bf79-dc83ab79fb78&cache=v2",
72-
"expiry_time": "2025-03-20T12:10:05.408Z"
72+
"expiry_time": "2025-04-10T13:24:52.481Z"
7373
},
7474
"format": {
7575
"block_width": 2998,
@@ -850,7 +850,7 @@
850850
"page_id": "1239c6bf-2b17-8076-a838-d17ca1c89783"
851851
},
852852
"created_time": "2024-10-18T08:07:00.000Z",
853-
"last_edited_time": "2025-03-19T14:10:00.000Z",
853+
"last_edited_time": "2025-04-10T12:12:00.000Z",
854854
"created_by": {
855855
"object": "user",
856856
"id": "5146391e-8b65-47f2-83b6-2bfe81194f32"
@@ -4548,7 +4548,7 @@
45484548
"page_id": "1239c6bf-2b17-8076-a838-d17ca1c89783"
45494549
},
45504550
"created_time": "2025-01-19T10:53:00.000Z",
4551-
"last_edited_time": "2025-01-19T10:53:00.000Z",
4551+
"last_edited_time": "2025-04-10T12:19:00.000Z",
45524552
"created_by": {
45534553
"object": "user",
45544554
"id": "5146391e-8b65-47f2-83b6-2bfe81194f32"
@@ -4566,7 +4566,7 @@
45664566
"type": "file",
45674567
"file": {
45684568
"url": "https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fcd7314a5-d906-43b0-81e7-42eff82c02a3%2F10d9f59d-d3e2-429a-ad72-c8b15b1f536b%2Fimage.png?table=block&id=1809c6bf-2b17-8096-aaf4-d89c3850bed0&cache=v2",
4569-
"expiry_time": "2025-03-20T12:10:05.632Z"
4569+
"expiry_time": "2025-04-10T13:24:52.634Z"
45704570
},
45714571
"format": {
45724572
"block_width": 721,

0 commit comments

Comments
 (0)