@druid-ui/build 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +42 -11
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/src/cmd/index.ts +51 -10
- package/src/index.ts +2 -2
package/bin/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { build } from "esbuild";
|
|
|
6
6
|
import fs3 from "node:fs/promises";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
|
-
import { basename as basename2 } from "node:path";
|
|
9
|
+
import { dirname, basename as basename2 } from "node:path";
|
|
10
10
|
|
|
11
11
|
// src/utils.ts
|
|
12
12
|
import path from "node:path";
|
|
@@ -117,7 +117,7 @@ async function buildWasm(entryFile2, outfolder2 = "./dist", witExtension) {
|
|
|
117
117
|
async function buildRaw(entryFile2, outfolder2 = "./dist") {
|
|
118
118
|
const outfilename = getBundleFileName(entryFile2, "-raw");
|
|
119
119
|
const outfile = outfolder2 + "/" + outfilename;
|
|
120
|
-
const rawPath = require2.resolve("@druid-ui/component/raw");
|
|
120
|
+
const rawPath = dirname(require2.resolve("@druid-ui/component/raw"));
|
|
121
121
|
await build({
|
|
122
122
|
entryPoints: [entryFile2],
|
|
123
123
|
bundle: true,
|
|
@@ -132,16 +132,23 @@ async function buildRaw(entryFile2, outfolder2 = "./dist") {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// src/cmd/index.ts
|
|
135
|
+
import { watch } from "node:fs";
|
|
136
|
+
import { resolve as resolve2 } from "node:path";
|
|
135
137
|
console.log("Druid UI Build Tool");
|
|
136
138
|
var args = process.argv;
|
|
137
139
|
var duBuildRaw = false;
|
|
138
140
|
var worldName = "druid-ui";
|
|
141
|
+
var watchMode = false;
|
|
139
142
|
var witFiles = [];
|
|
140
143
|
args = args.filter((arg) => {
|
|
141
144
|
if (arg === "--raw") {
|
|
142
145
|
duBuildRaw = true;
|
|
143
146
|
return false;
|
|
144
147
|
}
|
|
148
|
+
if (arg === "--watch" || arg === "-w") {
|
|
149
|
+
watchMode = true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
145
152
|
if (arg.startsWith("--wit=")) {
|
|
146
153
|
witFiles.push(arg.slice(6));
|
|
147
154
|
return false;
|
|
@@ -155,18 +162,42 @@ args = args.filter((arg) => {
|
|
|
155
162
|
var entryFile = args[2];
|
|
156
163
|
if (!entryFile) {
|
|
157
164
|
console.error(
|
|
158
|
-
"Usage: ./cli <entry-file> [out-folder] [--world-name=<name>] [--wit=<file>] [--raw]"
|
|
165
|
+
"Usage: ./cli <entry-file> [out-folder] [--world-name=<name>] [--wit=<file>] [--raw] [--watch|-w]"
|
|
159
166
|
);
|
|
160
167
|
process.exit(1);
|
|
161
168
|
}
|
|
162
169
|
var outfolder = args[3] || "./dist";
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
async function doBuild() {
|
|
171
|
+
console.log(`Building ${entryFile} to ${outfolder}...`);
|
|
172
|
+
try {
|
|
173
|
+
if (duBuildRaw) {
|
|
174
|
+
await buildRaw(entryFile, outfolder);
|
|
175
|
+
} else {
|
|
176
|
+
await buildWasm(entryFile, outfolder, {
|
|
177
|
+
worldName,
|
|
178
|
+
files: witFiles
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
console.log("Build complete.");
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error("Build failed:", error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
await doBuild();
|
|
187
|
+
if (watchMode) {
|
|
188
|
+
console.log("Watching for changes...");
|
|
189
|
+
const srcDir = resolve2(entryFile, "..");
|
|
190
|
+
let building = false;
|
|
191
|
+
watch(srcDir, { recursive: true }, async (_eventType, filename) => {
|
|
192
|
+
if (filename && (filename.endsWith(".tsx") || filename.endsWith(".ts") || filename.endsWith(".jsx") || filename.endsWith(".js"))) {
|
|
193
|
+
if (building) return;
|
|
194
|
+
building = true;
|
|
195
|
+
console.log(`
|
|
196
|
+
File changed: ${filename}`);
|
|
197
|
+
await doBuild();
|
|
198
|
+
building = false;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
await new Promise(() => {
|
|
170
202
|
});
|
|
171
203
|
}
|
|
172
|
-
console.log("Build complete.");
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { build } from "esbuild";
|
|
|
4
4
|
import fs3 from "node:fs/promises";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
|
-
import { basename as basename2 } from "node:path";
|
|
7
|
+
import { dirname as dirname2, basename as basename2 } from "node:path";
|
|
8
8
|
|
|
9
9
|
// src/utils.ts
|
|
10
10
|
import path from "node:path";
|
|
@@ -137,7 +137,7 @@ async function buildWasm(entryFile, outfolder = "./dist", witExtension) {
|
|
|
137
137
|
async function buildRaw(entryFile, outfolder = "./dist") {
|
|
138
138
|
const outfilename = getBundleFileName(entryFile, "-raw");
|
|
139
139
|
const outfile = outfolder + "/" + outfilename;
|
|
140
|
-
const rawPath = require2.resolve("@druid-ui/component/raw");
|
|
140
|
+
const rawPath = dirname2(require2.resolve("@druid-ui/component/raw"));
|
|
141
141
|
await build({
|
|
142
142
|
entryPoints: [entryFile],
|
|
143
143
|
bundle: true,
|
package/package.json
CHANGED
package/src/cmd/index.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { buildWasm, buildRaw } from "../";
|
|
4
|
+
import { watch } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
|
|
4
7
|
console.log("Druid UI Build Tool");
|
|
5
8
|
let args = process.argv;
|
|
6
9
|
|
|
7
10
|
let duBuildRaw = false;
|
|
8
11
|
let worldName = "druid-ui";
|
|
12
|
+
let watchMode = false;
|
|
9
13
|
const witFiles: string[] = [];
|
|
10
14
|
|
|
11
15
|
args = args.filter((arg) => {
|
|
@@ -13,6 +17,10 @@ args = args.filter((arg) => {
|
|
|
13
17
|
duBuildRaw = true;
|
|
14
18
|
return false;
|
|
15
19
|
}
|
|
20
|
+
if (arg === "--watch" || arg === "-w") {
|
|
21
|
+
watchMode = true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
16
24
|
if (arg.startsWith("--wit=")) {
|
|
17
25
|
witFiles.push(arg.slice(6));
|
|
18
26
|
return false;
|
|
@@ -28,20 +36,53 @@ const entryFile = args[2];
|
|
|
28
36
|
|
|
29
37
|
if (!entryFile) {
|
|
30
38
|
console.error(
|
|
31
|
-
"Usage: ./cli <entry-file> [out-folder] [--world-name=<name>] [--wit=<file>] [--raw]",
|
|
39
|
+
"Usage: ./cli <entry-file> [out-folder] [--world-name=<name>] [--wit=<file>] [--raw] [--watch|-w]",
|
|
32
40
|
);
|
|
33
41
|
process.exit(1);
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
const outfolder = args[3] || "./dist";
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
async function doBuild() {
|
|
47
|
+
console.log(`Building ${entryFile} to ${outfolder}...`);
|
|
48
|
+
try {
|
|
49
|
+
if (duBuildRaw) {
|
|
50
|
+
await buildRaw(entryFile, outfolder);
|
|
51
|
+
} else {
|
|
52
|
+
await buildWasm(entryFile, outfolder, {
|
|
53
|
+
worldName,
|
|
54
|
+
files: witFiles,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
console.log("Build complete.");
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("Build failed:", error);
|
|
60
|
+
}
|
|
45
61
|
}
|
|
46
62
|
|
|
47
|
-
|
|
63
|
+
await doBuild();
|
|
64
|
+
|
|
65
|
+
if (watchMode) {
|
|
66
|
+
console.log("Watching for changes...");
|
|
67
|
+
const srcDir = resolve(entryFile, "..");
|
|
68
|
+
let building = false;
|
|
69
|
+
|
|
70
|
+
watch(srcDir, { recursive: true }, async (_eventType, filename) => {
|
|
71
|
+
if (
|
|
72
|
+
filename &&
|
|
73
|
+
(filename.endsWith(".tsx") ||
|
|
74
|
+
filename.endsWith(".ts") ||
|
|
75
|
+
filename.endsWith(".jsx") ||
|
|
76
|
+
filename.endsWith(".js"))
|
|
77
|
+
) {
|
|
78
|
+
if (building) return;
|
|
79
|
+
building = true;
|
|
80
|
+
console.log(`\nFile changed: ${filename}`);
|
|
81
|
+
await doBuild();
|
|
82
|
+
building = false;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Keep the process running
|
|
87
|
+
await new Promise(() => {});
|
|
88
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ const getBundleFileName = (entryFile, suffix = "") => {
|
|
|
25
25
|
export async function buildWasm(
|
|
26
26
|
entryFile,
|
|
27
27
|
outfolder = "./dist",
|
|
28
|
-
witExtension?: WitExtension
|
|
28
|
+
witExtension?: WitExtension,
|
|
29
29
|
) {
|
|
30
30
|
await fs.mkdir(outfolder, { recursive: true });
|
|
31
31
|
|
|
@@ -70,7 +70,7 @@ export async function buildRaw(entryFile, outfolder = "./dist") {
|
|
|
70
70
|
|
|
71
71
|
const outfile = outfolder + "/" + outfilename;
|
|
72
72
|
|
|
73
|
-
const rawPath = require.resolve("@druid-ui/component/raw");
|
|
73
|
+
const rawPath = dirname(require.resolve("@druid-ui/component/raw"));
|
|
74
74
|
await build({
|
|
75
75
|
entryPoints: [entryFile],
|
|
76
76
|
bundle: true,
|