-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (26 loc) · 1.16 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
const exec = require('util').promisify(require('child_process').exec)
const { readFile, writeFile } = require('fs').promises
import path from 'path'
import remark from 'remark'
import html from 'remark-html'
import { green } from 'ansi-colors'
export const change = async({ config, filepath }) => {
const markdown = await readFile(path.join(process.cwd(), `/${config.remark.input}/${filepath}`), 'utf8')
const filename = `${filepath.replace(config.remark.filter, '')}.svelte`
const writePath = `/${config.remark.outputSvelte}/${filename}`
const parsed = (await remark().use(html).process(markdown)).contents
await writeFile(path.join(process.cwd(), writePath), parsed, 'utf8')
console.log('~>', green('Finished converting markdown to svelte:'), writePath)
console.log()
}
export const remove = async({ config, filepath }) => {
try {
const filename = `${filepath.replace(config.remark.filter, '')}.svelte`
const { stdout } = await exec(`rm -f ${config.remark.outputSvelte}/${filename}`)
if (stdout) { console.log(stdout) }
} catch (error) {
console.error(`error: ${error}`)
}
console.log('~>', green('Finished removing markdown file:'), filepath)
console.log()
}