-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
119 lines (100 loc) · 3.23 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
const { build, context } = require("esbuild");
const fs = require("fs");
//@ts-check
/** @typedef {import('esbuild').BuildOptions} BuildOptions **/
console.log("Building extension..");
var productionBuild = process.env.NODE_ENV?.trim() === "production";
console.log("Environment:", productionBuild ? "production" : "development");
/** @type BuildOptions */
const baseConfig = {
bundle: true,
minify: productionBuild,
sourcemap: !productionBuild,
external: ["vscode"],
define: {
// This is not defined in the browser environment, so we need to provide a polyfill.
'global': 'globalThis'
},
plugins: [
{
name: 'rebuild-notify',
setup(build) {
build.onStart(() => {
console.log("Build started..");
});
build.onEnd(result => {
console.log(`Build ended.`);
})
},
}],
};
console.log("Options:", baseConfig);
// Config for extension source code (to be run in a Node-based context)
/** @type BuildOptions */
const extensionConfig = {
...baseConfig,
format: "cjs",
target: "es2020",
mainFields: ["module", "main"],
entryPoints: ["./src/extension.ts"],
outfile: "./out/extension.js",
tsconfig: "./tsconfig.json"
};
// Note: The platform 'node' is required for the 'vscode-languageserver' functions to work.
const getLanguageConfig = (type, language) => {
const file = language ? `${language}-language-${type}` : `language-${type}`;
return {
...baseConfig,
format: "cjs",
target: "es2020",
entryPoints: [`./src/languages/${file}.ts`],
outfile: `./out/${file}.js`
}
}
(async () => {
try {
if (fs.existsSync('./out')) {
console.log("Deleting existing out directory..");
fs.rmSync('./out', { recursive: true });
// Note: Uncomment this if you want to use SVG icons directly.
console.log("Copying media files to out directory..");
fs.mkdirSync('./out/media/glyphs', { recursive: true });
for (const file of fs.readdirSync('./media/glyphs')) {
fs.copyFileSync(`./media/glyphs/${file}`, `./out/media/glyphs/${file}`);
}
// Copy the language config files to the out directory.
for (const file of fs.readdirSync('./src/languages/')) {
if (file.endsWith('.json')) {
fs.copyFileSync(`./src/languages/${file}`, `./out/${file}`);
}
}
}
const args = process.argv.slice(2);
const configs = [
extensionConfig,
getLanguageConfig('server'),
getLanguageConfig('server', 'turtle'),
getLanguageConfig('server', 'trig'),
getLanguageConfig('server', 'sparql'),
getLanguageConfig('client'),
getLanguageConfig('client', 'turtle'),
getLanguageConfig('client', 'trig'),
getLanguageConfig('client', 'sparql'),
]
if (args.includes("--watch")) {
// This is the advanced long-running form of "build" that supports additional
// features such as watch mode and a local development server.
for (const config of configs) {
(await context(config)).watch();
}
} else {
for (const config of configs) {
build(config);
}
}
} catch (err) {
console.log("Extension config:", extensionConfig);
process.stderr.write(err.stderr);
process.exit(1);
}
})();