-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (32 loc) · 1.68 KB
/
index.js
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
const { program } = require('commander');
const { parseCommand } = require('./lib/parse-command');
const { findNote, findNotesUnderChannel } = require('./lib/slite/find-slite-note');
const { fetchSliteNoteContent } = require('./lib/slite/fetch-slite-note-content');
const { createConfluencePage } = require('./lib/confluence/create-confluence-page');
(async function() {
const { slite: sliteCxt, confluence: confluenceCxt, dryRun, recursive, bypassDuplicateError } = parseCommand();
const notes = sliteCxt.channelId != null
? await findNotesUnderChannel(sliteCxt.origin, sliteCxt.token, sliteCxt.channelId, recursive)
: await findNote(sliteCxt.origin, sliteCxt.token, sliteCxt.noteId, recursive);
if (dryRun) {
console.log(`The following Slite notes are migrated under ${program.to}`);
for (const note of notes) {
console.log(`noteId: ${note.id}, noteTitle: ${note.title}`);
await fetchSliteNoteContent(note.publicShareToken, note.title, sliteCxt);
}
return;
}
const createdPages = {};
for (const note of notes) {
console.log(`\nMigrating note (noteId: ${note.id}, noteTitle: ${note.title}) ...`);
const xhtml = await fetchSliteNoteContent(note.publicShareToken, note.title, sliteCxt);
const parentPageId = note.parentNoteId ? createdPages[note.parentNoteId] : confluenceCxt.pageId;
const pageId = await createConfluencePage(note.title, xhtml, parentPageId, bypassDuplicateError, confluenceCxt);
if (pageId) {
console.log(`Successfully migrated (pageId: ${pageId})`);
createdPages[note.id] = pageId;
} else {
throw new Error(`Failed to migrate slite note (noteId: ${note.id}, noteTitle: ${note.title})`);
}
}
})();