Created
February 23, 2022 08:52
-
-
Save mshk/3d5ec8cda8a4105e2292495bb268caf3 to your computer and use it in GitHub Desktop.
Backlog Wiki exporter
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
import * as backlogjs from 'backlog-js'; | |
import 'dotenv/config'; | |
import 'cross-fetch/polyfill'; | |
import * as fs from 'fs'; | |
type Wiki = { | |
name: string; | |
content: string | |
} | |
const backlog = new backlogjs.Backlog({ | |
host: process.env.BACKLOG_HOST || '', | |
apiKey: process.env.BACKLOG_API_KEY, | |
}); | |
const getWikis = async (projectIdOrKey: string, keyword: string = '') => { | |
return backlog | |
.getWikis({ | |
projectIdOrKey, | |
keyword, | |
}) | |
.catch((err) => { | |
console.log('error:', err.message); | |
}); | |
}; | |
const main = async () => { | |
const wikis = await getWikis(process.env.BACKLOG_PROJECT || '', process.env.BACKLOG_WIKI_CATEGORY); | |
fs.writeFileSync('docs/SUMMARY.md', '#一覧\n\n'); | |
wikis.forEach((wiki: Wiki) => { | |
const fileName = `${wiki.name.split('/').slice(-1)[0]}`; | |
const dirName = wiki.name.replace(`/${fileName}`, ''); | |
const filePath = `${dirName}/${fileName}.md`; | |
console.log(filePath); | |
if (!fs.existsSync(dirName)) { | |
fs.mkdirSync(`docs/${dirName}`, { recursive: true}); | |
fs.writeFileSync(`docs/${dirName}/README.md`, 'readme'); | |
} | |
fs.writeFileSync(`docs/${filePath}`, wiki.content); | |
fs.appendFileSync('docs/SUMMARY.md', `* [${dirName}/${fileName}](${filePath})\n`); | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment