-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatch.js
executable file
·38 lines (32 loc) · 1.28 KB
/
watch.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
const esbuild = require('esbuild');
const { options, generate_declarations } = require("./builder");
options.plugins.unshift({
name: "regenerate-localization",
setup(build) {
const properties = require("dot-properties");
const fs = require("fs");
const path = require("path");
build.onResolve({ filter: /\.properties$/ }, (args) => {
const full_path = path.join(args.resolveDir, "messages", args.path);
const filename = path.relative(path.join(args.resolveDir, "messages"), full_path);
const property_tree = properties.parse(fs.readFileSync(full_path, "utf8"), true);
const module_content = generate_declarations(filename, property_tree);
fs.writeFileSync(path.join(args.resolveDir, "messages", `${filename}.d.ts`), module_content);
});
}
});
esbuild.build({
...options,
watch: {
onRebuild(error, result) {
if (error) console.error('watch build failed:', error)
else console.log('watch build succeeded:', result)
},
},
}).then(result => {
console.log("Build ok", result);
const messages = esbuild.formatMessagesSync(result.warnings, { kind: "warning" });
for (const message of messages) {
console.log(message);
}
})