-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
55 lines (41 loc) · 1.68 KB
/
build.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
48
49
50
51
52
53
54
55
const fs = require('fs-extra')
const jsyaml = require('js-yaml')
const livescript = require('livescript2')
const stylus = require('stylus2')
const { JSDOM } = require('jsdom')
const terser = require('terser')
const minify = require('minify')
;(async () => {
const dom = await JSDOM.fromFile('dev.html')
const { document } = dom.window
for (const el of document.querySelectorAll('[data-dev]')) {
el.remove()
}
let css, js, html, code, json
css = fs.readFileSync('index.styl', 'utf8')
css = stylus.render(css, { compress: true })
const cssEl = document.querySelector('[data-css]')
cssEl.outerHTML = `<style>${css}</style>`
js = fs.readFileSync('index.ls', 'utf8')
js = livescript.compile(js)
const jsEl = document.querySelector('[data-js]')
jsEl.outerHTML = `<script>${js}</script>`
html = dom.serialize()
html = await minify.html(html)
fs.writeFileSync('index.html', html)
fs.ensureDirSync('vscode-ext/dist')
fs.emptyDirSync('vscode-ext/dist')
const pack = fs.readJsonSync('vscode-ext/package.json')
fs.outputJsonSync('vscode-ext/dist/package.json', pack)
const yaml = fs.readFileSync('vscode-ext/syntaxes/taxon.tmLanguage.yaml', 'utf8')
json = jsyaml.load(yaml)
fs.outputJsonSync('vscode-ext/dist/syntaxes/taxon.tmLanguage.json', json)
code = fs.readFileSync('vscode-ext/extension.js', 'utf8')
code = (await terser.minify(code)).code
fs.outputFileSync('vscode-ext/dist/extension.js', code)
json = fs.readJsonSync('vscode-ext/language-configuration.json')
fs.outputJsonSync('vscode-ext/dist/language-configuration.json', json)
fs.copyFileSync('icon.png', 'vscode-ext/dist/icon.png')
fs.copyFileSync('vscode-ext/LICENSE', 'vscode-ext/dist/LICENSE')
console.log('Built')
})()