-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52ae95f
commit 0180a38
Showing
10 changed files
with
234 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@dandori/core": patch | ||
"@dandori/ui": patch | ||
--- | ||
|
||
add notion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,12 @@ | ||
import { DandoriTask } from "@dandori/core"; | ||
import { loadEnvFile } from "@dandori/libs"; | ||
import { generateDandoriMiroCards } from "@dandori/ui"; | ||
import { tasks } from "./mock"; | ||
|
||
// set environment variables like miro access token | ||
// set environment variables like access token | ||
loadEnvFile(); | ||
|
||
const boardId = "Your board ID"; | ||
|
||
// customize tasks as you like | ||
const tasks: DandoriTask[] = [ | ||
{ | ||
id: "1", | ||
name: "task1", | ||
deadline: "2021-01-01", | ||
description: "task1-description", | ||
fromTaskIdList: [], | ||
}, | ||
{ | ||
id: "2", | ||
name: "task2", | ||
deadline: "2021-01-02", | ||
description: "task2-description", | ||
fromTaskIdList: ["1"], | ||
}, | ||
{ | ||
id: "3", | ||
name: "task3", | ||
deadline: "2021-01-03", | ||
description: "task3-description", | ||
fromTaskIdList: ["1"], | ||
}, | ||
{ | ||
id: "4", | ||
name: "task4", | ||
deadline: "2021-01-04", | ||
description: "task4-description", | ||
fromTaskIdList: ["2", "3"], | ||
}, | ||
{ | ||
id: "5", | ||
name: "task5", | ||
deadline: "2021-01-05", | ||
description: "task5-description", | ||
fromTaskIdList: [], | ||
}, | ||
{ | ||
id: "6", | ||
name: "task6", | ||
deadline: "2021-01-06", | ||
description: "task6-description", | ||
fromTaskIdList: ["5"], | ||
}, | ||
{ | ||
id: "7", | ||
name: "task7", | ||
deadline: "2021-01-07", | ||
description: "task7-description", | ||
fromTaskIdList: ["5"], | ||
}, | ||
{ | ||
id: "8", | ||
name: "task8", | ||
deadline: "2021-01-08", | ||
description: "task8-description", | ||
fromTaskIdList: ["6", "7"], | ||
}, | ||
]; | ||
|
||
await generateDandoriMiroCards(tasks, { | ||
boardId, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { loadEnvFile } from "@dandori/libs"; | ||
import { tasks } from "./mock"; | ||
import generateDandoriNotionPages from "../src/notion"; | ||
|
||
// set environment variables like access token | ||
loadEnvFile(); | ||
|
||
// set notion settings | ||
const databaseId = ""; | ||
const databasePropertiesMap = { | ||
deadline: "", | ||
description: "", | ||
status: "", | ||
"status.todo": "", | ||
"status.doing": "", | ||
"status.done": "", | ||
}; | ||
|
||
await generateDandoriNotionPages(tasks, { | ||
databaseId, | ||
databasePropertiesMap, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { DandoriTask } from "@dandori/core/src"; | ||
|
||
// customize tasks as you like | ||
export const tasks: DandoriTask[] = [ | ||
{ | ||
id: "1", | ||
name: "task1", | ||
deadline: "2021-01-01", | ||
description: "task1-description", | ||
fromTaskIdList: [], | ||
status: "done", | ||
}, | ||
{ | ||
id: "2", | ||
name: "task2", | ||
deadline: "2021-01-02", | ||
description: "task2-description", | ||
fromTaskIdList: ["1"], | ||
status: "doing", | ||
}, | ||
{ | ||
id: "3", | ||
name: "task3", | ||
deadline: "2021-01-03", | ||
description: "task3-description", | ||
fromTaskIdList: ["1"], | ||
status: "doing", | ||
}, | ||
{ | ||
id: "4", | ||
name: "task4", | ||
deadline: "2021-01-04", | ||
description: "task4-description", | ||
fromTaskIdList: ["2", "3"], | ||
status: "todo", | ||
}, | ||
{ | ||
id: "5", | ||
name: "task5", | ||
deadline: "2021-01-05", | ||
description: "task5-description", | ||
fromTaskIdList: [], | ||
}, | ||
{ | ||
id: "6", | ||
name: "task6", | ||
deadline: "2021-01-06", | ||
description: "task6-description", | ||
fromTaskIdList: ["5"], | ||
status: "doing", | ||
}, | ||
{ | ||
id: "7", | ||
name: "task7", | ||
deadline: "2021-01-07", | ||
description: "task7-description", | ||
fromTaskIdList: ["5"], | ||
status: "doing", | ||
}, | ||
{ | ||
id: "8", | ||
name: "task8", | ||
deadline: "2021-01-08", | ||
description: "task8-description", | ||
fromTaskIdList: ["6", "7"], | ||
status: "done", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { | ||
DandoriTask, | ||
DandoriTaskOptionalProperty, | ||
DandoriTaskRequiredProperty, | ||
DandoriTaskStatus, | ||
} from "@dandori/core"; | ||
import { Client } from "@notionhq/client"; | ||
import { runPromisesSequentially } from "@dandori/libs"; | ||
import { CreatePageParameters } from "@notionhq/client/build/src/api-endpoints"; | ||
|
||
type SupportNotionTaskOptionalProperty = | ||
| Exclude<DandoriTaskOptionalProperty, "assignee"> | ||
| `${Extract<DandoriTaskOptionalProperty, "status">}.${DandoriTaskStatus}`; | ||
|
||
type DatabasePropertiesMap = { | ||
[key in SupportNotionTaskOptionalProperty]?: string; | ||
} & { [key in Extract<DandoriTaskRequiredProperty, "name">]?: string }; | ||
|
||
export type GenerateDandoriNotionDatabaseItemsOptions = { | ||
databaseId: string; | ||
databasePropertiesMap: DatabasePropertiesMap; | ||
}; | ||
|
||
const createPageParams = ( | ||
task: DandoriTask, | ||
options: GenerateDandoriNotionDatabaseItemsOptions, | ||
): CreatePageParameters => { | ||
const propsMap = options.databasePropertiesMap; | ||
const { deadline, description, status, name } = task; | ||
const { | ||
deadline: deadlineProp, | ||
description: descriptionProp, | ||
status: statusProp, | ||
name: nameProp = "Name", | ||
} = propsMap; | ||
const pageProperties: Record<string, any> = { | ||
[nameProp]: { | ||
title: [ | ||
{ | ||
text: { | ||
content: name, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
if (descriptionProp) { | ||
pageProperties[descriptionProp] = { | ||
rich_text: [ | ||
{ | ||
text: { | ||
content: description, | ||
}, | ||
}, | ||
], | ||
}; | ||
} | ||
if (deadline && deadlineProp) { | ||
// start date must be before end date in Notion | ||
const today = new Date(); | ||
if (today < new Date(deadline)) { | ||
pageProperties[deadlineProp] = { | ||
date: { | ||
start: today.toISOString(), | ||
end: deadline, | ||
}, | ||
}; | ||
} | ||
} | ||
if (status && statusProp) { | ||
const statusName = propsMap[`status.${status}`]; | ||
if (statusName) { | ||
pageProperties[statusProp] = { | ||
select: { | ||
name: statusName, | ||
}, | ||
}; | ||
} | ||
} | ||
return { | ||
parent: { | ||
database_id: options.databaseId, | ||
}, | ||
properties: pageProperties, | ||
}; | ||
}; | ||
|
||
export default async function generateDandoriNotionPages( | ||
tasks: DandoriTask[], | ||
options: GenerateDandoriNotionDatabaseItemsOptions, | ||
): Promise<void> { | ||
const client = new Client({ | ||
auth: process.env.NOTION_TOKEN, | ||
}); | ||
const createPages = tasks.map((task) => () => { | ||
const pageParams = createPageParams(task, options); | ||
return client.pages.create(pageParams); | ||
}); | ||
await runPromisesSequentially(createPages, "Creating Notion Pages"); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.