forked from todogroup/repolinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_markup.js
34 lines (31 loc) · 1.09 KB
/
github_markup.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
// Copyright 2018 TODO Group. All rights reserved.
// Licensed under the Apache License, Version 2.0.
const { commandExists } = require('./command_exists')
const spawnSync = require('child_process').spawnSync
class GitHubMarkup {
/**
* Returns a rendered version of a given README file, or null if the document
* cannot be rendered. Supports all formats used by github_markup.
*
* Throws 'GitHub Markup not installed' error if command line of 'github_markup' is not available.
*
* @param {string} targetFile The file to render
* @returns {Promise<string|null>} The rendered markup, or null if it cannot be rendered
*/
async renderMarkup(targetFile) {
// TODO: windows?
const command = await commandExists(['github-markup'])
if (command === null) {
throw new Error('GitHub markup not installed')
}
const gitHubMarkupRes = spawnSync(
`${__dirname}/github_markup_check_and_render`,
[targetFile]
)
if (gitHubMarkupRes.status !== 0) {
return null
}
return gitHubMarkupRes.stdout.toString()
}
}
module.exports = new GitHubMarkup()