-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
executable file
·136 lines (112 loc) · 3.3 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env node
const esbuild = require('esbuild');
const {sassPlugin} = require('esbuild-sass-plugin');
const {rmSync, readFileSync, writeFileSync} = require('fs');
const {basename} = require('path')
const glob = require('glob').sync;
//
// Args ...
//
const prod = process.argv.slice(2).includes('--prod');
const watch = process.argv.slice(2).includes('--watch')
//
// Cleanup first ...
//
rmSync('./pkg/webserver/static/assets', {
recursive: true,
force: true
});
//
// Go package ...
//
let monacoGoCode = `package monaco
// revive:disable:line-length-limit
// Languages ...
var Languages = map[string]Language{
\t"plain": {
\t\tID: "plain",
\t\tName: "Plain text",
\t\tAliases: []string{},
\t\tExtensions: []string{".txt"},
\t\tFilenames: []string{},
\t},
`
glob('./node_modules/monaco-editor/esm/vs/basic-languages/*/*.contribution.js').sort().forEach((file) => {
const content = readFileSync(file).toString();
const regexp = /registerLanguage(\(.*?^}\));/gms;
const matches = content.matchAll(regexp);
for (const match of matches) {
let language = {}
try {
language = eval(match[1]);
} catch (e) {
console.log('--------\n'+match[1]+'\n--------');
process.exit(0);
}
if (!language.aliases) { // PLA?
return;
}
let name = language.aliases[0];
switch (name) {
case 'abap': /* fix case */ name = 'ABAP'; break;
case 'eeStructuredText': /* do nothing */ break;
case 'sol': /* fix name */ name = 'Solidity'; break;
case 'aes': /* fix name */ name = 'Sophia'; break;
case 'sparql': /* fix case */ name = 'SPARQL'; break;
default: /* capitalize */ name = name[0].toUpperCase() + name.slice(1); break;
}
language.extensions = language.extensions || [];
language.filenames = language.filenames || [];
monacoGoCode += `\t"${language.id}": {
\t\tID: "${language.id}",
\t\tName: "${name}",
\t\tAliases: []string{${JSON.stringify(language.aliases.slice(1)).replace(/,/g, ', ').slice(1, -1)}},
\t\tExtensions: []string{${JSON.stringify(language.extensions).replace(/,/g, ', ').slice(1, -1)}},
\t\tFilenames: []string{${JSON.stringify(language.filenames).replace(/,/g, ', ').slice(1, -1)}},
\t},
`
}
});
monacoGoCode += `}
`
writeFileSync('./pkg/monaco/languages.go', monacoGoCode);
//
// Monaco ...
//
esbuild.build({
entryPoints: [
'./node_modules/monaco-editor/esm/vs/language/json/json.worker.js',
'./node_modules/monaco-editor/esm/vs/language/css/css.worker.js',
'./node_modules/monaco-editor/esm/vs/language/html/html.worker.js',
'./node_modules/monaco-editor/esm/vs/language/typescript/ts.worker.js',
'./node_modules/monaco-editor/esm/vs/editor/editor.worker.js',
],
bundle: true,
minify: prod,
format: 'iife',
outbase: './node_modules/monaco-editor/esm',
outdir: './pkg/webserver/static/assets'
});
//
// Application
//
const appContext = {
entryPoints: [
'./web/app/app.js'
],
bundle: true,
minify: prod,
format: 'iife',
outbase: './web/app',
outdir: './pkg/webserver/static/assets',
loader: {
'.ttf': 'file'
},
plugins: [sassPlugin()]
};
esbuild.build(appContext);
if (watch) {
esbuild.context(appContext).then(function(ctx) {
ctx.watch();
});
}