-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (38 loc) · 1.35 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
const unified = require('unified');
const markdown = require('remark-parse');
const { select } = require('unist-util-select');
const remarkToChan = require('@geut/remark-chan');
const stringify = require('@geut/chan-stringify');
const {
initialize: transformerInitialize,
addChanges: transformerAddChanges,
addRelease: transformerAddRelease
} = require('./transformer');
const preset = (plugin, opts = {}) => [
[markdown, remarkToChan, [plugin, opts], stringify],
{ settings: { position: false } }
];
exports.initialize = function initialize(from, opts, cb) {
return unified()
.use(...preset(transformerInitialize, opts))
.process(from, cb);
};
exports.addChanges = function addChanges(from, opts, cb) {
return unified()
.use(...preset(transformerAddChanges, opts))
.process(from, cb);
};
exports.addRelease = function addRelease(from, opts, cb) {
return unified()
.use(...preset(transformerAddRelease, opts))
.process(from, cb);
};
exports.getMarkdownRelease = function getMarkdownRelease(from, { version }) {
const markdownTree = unified()
.use(markdown)
.parse(from);
const chanTree = remarkToChan()(markdownTree);
const release = select(`release[identifier=${version}]`, chanTree);
const compile = new stringify({ withPreface: false });
return compile.Compiler({ type: 'root', children: [release] }, from);
};