1 | const fs = require('fs-extra')
|
2 | const fsOpts = { encoding: 'utf8' }
|
3 | const { promisify } = require('util')
|
4 | const xml2js = require('xml2js')
|
5 | const parseXML = promisify(xml2js.parseString)
|
6 |
|
7 | module.exports = async (snippetPath) => {
|
8 | const snippetXml = await fs.readFile(snippetPath, fsOpts)
|
9 | const snippetObj = await parseXML(snippetXml)
|
10 | const blinkSnippets = snippetObj.CodeSnippets.snippets[0].category.filter((category) => {
|
11 | return category.$.title.startsWith('Blink')
|
12 | })
|
13 | if (!blinkSnippets.length) return Promise.reject(new Error('Blink Snippets not found'))
|
14 | const match = blinkSnippets[0].$.title.match(/v.+$/)
|
15 | if (!match) return Promise.reject(new Error('No version specified in Blink Snippets'))
|
16 | return match[0]
|
17 | }
|