Skip to content

Instantly share code, notes, and snippets.

@mshk
Created February 23, 2022 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshk/3d5ec8cda8a4105e2292495bb268caf3 to your computer and use it in GitHub Desktop.
Save mshk/3d5ec8cda8a4105e2292495bb268caf3 to your computer and use it in GitHub Desktop.
Backlog Wiki exporter
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