-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
104 lines (94 loc) · 2.65 KB
/
build.ts
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
import { fromFileUrl } from "jsr:@std/path";
import { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.9.0/mod.ts";
import {
build as esBuild,
type Plugin,
} from "https://deno.land/x/esbuild@v0.20.2/mod.js";
import { ensureFile } from "jsr:@std/fs";
import { viewType } from "./lib.ts";
export const writeTextFileWithLog = async (
path: URL,
content: string
): Promise<void> => {
console.log(path.toString() + " に書き込み中... " + content.length + "文字");
await ensureFile(path);
await Deno.writeTextFile(path, content);
console.log(path.toString() + " に書き込み完了!");
};
const distributionPath = new URL(
"../vscodeExtensionDistribution/",
import.meta.url
);
const build = async (url: URL, format: "cjs" | "esm"): Promise<string> => {
const esbuildResult = await esBuild({
entryPoints: [fromFileUrl(url)],
plugins: denoPlugins() as Plugin[],
write: false,
bundle: true,
format,
target: ["node18", "chrome115"],
});
for (const esbuildResultFile of esbuildResult.outputFiles ?? []) {
if (esbuildResultFile.path === "<stdout>") {
console.log("js 発見");
const scriptContent = new TextDecoder().decode(
esbuildResultFile.contents
);
return scriptContent;
}
}
throw new Error("esbuild で <stdout> の出力を取得できなかった...");
};
const scriptRelativePath = "./main.js";
writeTextFileWithLog(
new URL(scriptRelativePath, distributionPath),
await build(new URL("./main.ts", import.meta.url), "cjs")
);
writeTextFileWithLog(
new URL("client.js", distributionPath),
await build(new URL("../client/main.tsx", import.meta.url), "esm")
);
writeTextFileWithLog(
new URL("./package.json", distributionPath),
JSON.stringify({
name: "bson editor",
version: "0.0.1",
description: "bson editor VSCode extension",
repository: {
url: "git+https://github.com/narumincho/bson-editor.git",
type: "git",
},
license: "MIT",
homepage: "https://github.com/narumincho/bson-editor",
author: "narumincho",
engines: {
vscode: "^1.76.0",
},
dependencies: {},
activationEvents: [],
/**
* https://code.visualstudio.com/api/references/contribution-points
*/
contributes: {
customEditors: [
{
viewType,
displayName: "bson editor",
selector: [
{
filenamePattern: "*.bson",
},
],
priority: "default",
},
],
},
browser: scriptRelativePath,
publisher: "narumincho",
})
);
writeTextFileWithLog(
new URL("README.md", distributionPath),
`bson-editor VSCode extension
`
);