-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-documentation-database.js
More file actions
278 lines (242 loc) · 7.39 KB
/
Copy pathcreate-documentation-database.js
File metadata and controls
278 lines (242 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Import the MCP Notion functionality
const mcp = require('/Users/kk/code/kk-mcp/src/notion-power.ts');
const DATABASE_NAME = "BC AI Ecosystem Documentation";
const DATABASE_PROPERTIES = {
"Title": { type: "title" },
"Type": {
type: "select",
options: [
{ name: "Documentation", color: "blue" },
{ name: "Report", color: "green" },
{ name: "Data", color: "orange" }
]
},
"Date Created": { type: "date" },
"Category": {
type: "select",
options: [
{ name: "Project Management", color: "purple" },
{ name: "Intelligence", color: "red" },
{ name: "Funding", color: "yellow" },
{ name: "Database", color: "pink" },
{ name: "Analysis", color: "brown" }
]
},
"Content": { type: "rich_text" }
};
// Files to migrate
const FILES_TO_MIGRATE = [
{
path: '/Users/kk/ecosystem-map-bc-ai/FUNDING_DATABASE_MASTER_PLAN.md',
type: 'Documentation',
category: 'Funding'
},
{
path: '/Users/kk/ecosystem-map-bc-ai/FUNDING_DATABASE_AUDIT_2025-08-09.md',
type: 'Report',
category: 'Database'
},
{
path: '/Users/kk/ecosystem-map-bc-ai/FUNDING_DB_ENRICHMENT_REPORT.md',
type: 'Report',
category: 'Funding'
},
{
path: '/Users/kk/ecosystem-map-bc-ai/PROJECT_STATUS_2025_08_10.md',
type: 'Report',
category: 'Project Management'
},
{
path: '/Users/kk/ecosystem-map-bc-ai/FINAL_CLEANUP_SUMMARY.md',
type: 'Report',
category: 'Project Management'
},
{
path: '/Users/kk/ecosystem-map-bc-ai/docs/project-management/FINAL_CLEANUP_SUMMARY.md',
type: 'Report',
category: 'Project Management'
}
];
// Intelligence reports
const INTELLIGENCE_FILES = [
'BC_AI_TOP_10_PEOPLE_INTELLIGENCE_REPORT.md',
'BC_INVESTOR_ECOSYSTEM_MAPPING.md',
'BC_MAJOR_EXITS_FINANCIAL_INTELLIGENCE_REPORT.md',
'COMPLETE_INTELLIGENCE_REPORT.md',
'FINANCIAL_PEOPLE_INTELLIGENCE_RESULTS.md',
'FINANCIAL_PEOPLE_INTELLIGENCE_STRATEGY.md',
'PROPRIETARY_INTELLIGENCE_ENHANCEMENT_SUMMARY.md'
].map(filename => ({
path: `/Users/kk/ecosystem-map-bc-ai/data/intelligence/${filename}`,
type: 'Report',
category: 'Intelligence'
}));
async function createNotionDatabase() {
console.log(`Creating Notion database: ${DATABASE_NAME}`);
try {
// Create the database using MCP Notion
const database = await mcp.createDatabase({
title: DATABASE_NAME,
properties: DATABASE_PROPERTIES,
parent: { type: 'workspace', workspace: true }
});
console.log(`✅ Database created successfully!`);
console.log(`Database ID: ${database.id}`);
return database.id;
} catch (error) {
console.error('❌ Error creating database:', error);
throw error;
}
}
async function readFileContent(filePath) {
try {
const content = fs.readFileSync(filePath, 'utf8');
return content;
} catch (error) {
console.log(`⚠️ Could not read file: ${filePath} - ${error.message}`);
return null;
}
}
function extractTitle(filePath) {
const filename = path.basename(filePath, '.md');
return filename.replace(/_/g, ' ').replace(/-/g, ' ');
}
function extractDateFromFilename(filePath) {
const dateMatch = path.basename(filePath).match(/(\d{4}-\d{2}-\d{2})/);
if (dateMatch) {
return dateMatch[1];
}
// Check file stats as fallback
try {
const stats = fs.statSync(filePath);
return stats.mtime.toISOString().split('T')[0];
} catch {
return new Date().toISOString().split('T')[0];
}
}
async function migrateFile(databaseId, fileInfo) {
const content = await readFileContent(fileInfo.path);
if (!content) {
return null;
}
const title = extractTitle(fileInfo.path);
const dateCreated = extractDateFromFilename(fileInfo.path);
console.log(`📝 Migrating: ${title}`);
try {
const page = await mcp.createPage({
parent: { database_id: databaseId },
properties: {
"Title": {
title: [{ text: { content: title } }]
},
"Type": {
select: { name: fileInfo.type }
},
"Date Created": {
date: { start: dateCreated }
},
"Category": {
select: { name: fileInfo.category }
},
"Content": {
rich_text: [{ text: { content: content.substring(0, 2000) } }] // Notion has limits
}
},
children: [
{
object: 'block',
type: 'code',
code: {
language: 'markdown',
rich_text: [{ text: { content: content } }]
}
}
]
});
console.log(`✅ Successfully migrated: ${title}`);
return page.id;
} catch (error) {
console.error(`❌ Error migrating ${title}:`, error);
return null;
}
}
async function main() {
console.log('🚀 Starting BC AI Ecosystem Documentation Migration');
try {
// Create the database
const databaseId = await createNotionDatabase();
// Combine all files to migrate
const allFiles = [...FILES_TO_MIGRATE, ...INTELLIGENCE_FILES];
console.log(`\n📄 Migrating ${allFiles.length} files...`);
const results = {
successful: [],
failed: [],
skipped: []
};
for (const fileInfo of allFiles) {
const pageId = await migrateFile(databaseId, fileInfo);
if (pageId) {
results.successful.push({
file: fileInfo.path,
title: extractTitle(fileInfo.path),
pageId
});
} else {
if (fs.existsSync(fileInfo.path)) {
results.failed.push(fileInfo.path);
} else {
results.skipped.push(fileInfo.path);
}
}
// Small delay to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 500));
}
// Final summary
console.log('\n📊 MIGRATION COMPLETE');
console.log('='.repeat(50));
console.log(`Database ID: ${databaseId}`);
console.log(`✅ Successfully migrated: ${results.successful.length} files`);
console.log(`❌ Failed migrations: ${results.failed.length} files`);
console.log(`⏭️ Skipped (not found): ${results.skipped.length} files`);
if (results.successful.length > 0) {
console.log('\n📝 Successfully migrated files:');
results.successful.forEach(item => {
console.log(` • ${item.title}`);
});
}
if (results.failed.length > 0) {
console.log('\n❌ Failed migrations:');
results.failed.forEach(file => {
console.log(` • ${path.basename(file)}`);
});
}
if (results.skipped.length > 0) {
console.log('\n⏭️ Skipped files (not found):');
results.skipped.forEach(file => {
console.log(` • ${path.basename(file)}`);
});
}
// Save results to file
const resultsSummary = {
databaseId,
timestamp: new Date().toISOString(),
results
};
fs.writeFileSync(
'/Users/kk/ecosystem-map-bc-ai/documentation-migration-results.json',
JSON.stringify(resultsSummary, null, 2)
);
console.log('\n💾 Results saved to: documentation-migration-results.json');
console.log(`\n🎉 Database URL: https://notion.so/${databaseId.replace(/-/g, '')}`);
} catch (error) {
console.error('💥 Migration failed:', error);
process.exit(1);
}
}
if (require.main === module) {
main();
}
module.exports = { createNotionDatabase, migrateFile };