Created
July 3, 2020 23:20
-
-
Save gengue/495ab8977142a0066285af6ffe15855f to your computer and use it in GitHub Desktop.
Import trello list to wikijs
This file contains hidden or 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
/* | |
* Get started | |
* 1. create a folder and run `npm init` | |
* 2. run `npm install graphql-request slugify` | |
* 3. copy this file inside the folder | |
* 4. edit config (trello json, API_KEY, SOURCE_LIST, TARGET_PATH, etc...) | |
* 5. run `node index.js` | |
*/ | |
const { GraphQLClient } = require("graphql-request"); | |
const slugify = require("slugify"); | |
const trelloData = require("./vAll.json"); // your trello board https://help.trello.com/article/747-exporting-data-from-trello-1 | |
const API_KEY = `WIKIJS-API-KEY-HERE`; // get/create from Administration > System > Api Access | |
const SOURCE_LIST = "Trainings"; // trello column. must match exactly | |
const TARGET_PATH = "vAll/General/Trainings"; // wikijs target base path | |
const ENDPOINT = "https://vhelp.venturatravel.org/graphql"; | |
const graphQLClient = new GraphQLClient(ENDPOINT, { | |
headers: { | |
authorization: `Bearer ${API_KEY}`, | |
}, | |
}); | |
const CREATE_PAGE_MUTATION = ` | |
mutation CreatePage( | |
$path: String! | |
$title: String! | |
$content: String! | |
$desc: String! | |
$tags: [String!] | |
) { | |
pages { | |
create( | |
path: $path | |
title: $title | |
content: $content | |
editor: "markdown" | |
description: $desc | |
isPublished: true | |
isPrivate: true | |
locale: "en" | |
tags: $tags | |
) { | |
responseResult { | |
succeeded | |
message | |
} | |
page { | |
path | |
title | |
} | |
} | |
} | |
} | |
`; | |
async function main() { | |
const list = trelloData.lists.find((i) => i.name === SOURCE_LIST); | |
if (!list) return "List not found"; | |
const cards = trelloData.cards.filter((i) => i.idList === list.id); | |
const createPage = (c) => { | |
const variables = { | |
path: `${TARGET_PATH}/${slugify(c.name, { lower: true })}`, | |
title: c.name, | |
content: c.desc, | |
tags: ["test"], | |
desc: "", | |
}; | |
console.log(variables.path); | |
return graphQLClient.request(CREATE_PAGE_MUTATION, variables); | |
}; | |
const data = await Promise.all(cards.map(createPage)); | |
console.log(JSON.stringify(data, undefined, 2)); | |
return true; | |
} | |
main().catch((error) => console.error(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment