keystonemc 1.0.0 → 1.1.0

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.
@@ -0,0 +1,11 @@
1
+ import { Plugin } from 'vite';
2
+ type PluginConfig = {
3
+ name: string;
4
+ uuid?: string;
5
+ description?: string;
6
+ authors?: string[];
7
+ version?: number[];
8
+ embedSourceMap?: boolean;
9
+ };
10
+ declare const behaviorPacker: ({ name, uuid, description, authors, version, embedSourceMap, }?: PluginConfig) => Plugin;
11
+ export default behaviorPacker;
@@ -0,0 +1,120 @@
1
+ import { resolve } from "path";
2
+ import * as crypto from "node:crypto";
3
+ import * as fs from "node:fs";
4
+ const behaviorPacker = ({
5
+ name = "my first plugin",
6
+ uuid,
7
+ description = "",
8
+ authors = [],
9
+ version = [1, 0, 0],
10
+ embedSourceMap = true
11
+ } = {
12
+ name: "my first plugin",
13
+ description: "",
14
+ authors: [],
15
+ version: [1, 0, 0],
16
+ embedSourceMap: true
17
+ }) => ({
18
+ name: "BehaviorPacker",
19
+ config: (config) => {
20
+ return {
21
+ ...config,
22
+ build: {
23
+ sourcemap: true,
24
+ minify: false,
25
+ outDir: "./dist_behavior_pack/scripts",
26
+ emptyOutDir: true,
27
+ assetsDir: "",
28
+ rollupOptions: {
29
+ external: [
30
+ "@minecraft/server",
31
+ "@minecraft/server-net",
32
+ "@minecraft/server-ui"
33
+ ],
34
+ input: {
35
+ index: resolve(process.cwd(), "./src/index.ts")
36
+ }
37
+ }
38
+ }
39
+ };
40
+ },
41
+ generateBundle(options, bundle) {
42
+ if (!embedSourceMap) return;
43
+ for (const [fileName, file] of Object.entries(bundle)) {
44
+ if (file.type === "chunk" && file.map) {
45
+ const sourceMapData = file.map;
46
+ const embeddedSourceMap = {
47
+ version: sourceMapData.version,
48
+ sources: sourceMapData.sources,
49
+ sourcesContent: sourceMapData.sourcesContent,
50
+ mappings: sourceMapData.mappings,
51
+ names: sourceMapData.names
52
+ };
53
+ const sourceMapEmbed = `// ========== Embedded Source Map ==========
54
+ globalThis.__SOURCE_MAP__ = ${JSON.stringify(embeddedSourceMap)};
55
+ // ========== End of Embedded Source Map ==========
56
+
57
+ `;
58
+ const originalCode = file.code;
59
+ const modifiedCode = sourceMapEmbed + originalCode;
60
+ file.code = modifiedCode.replace(/\/\/# sourceMappingURL=.+$/gm, "");
61
+ file.map = null;
62
+ }
63
+ }
64
+ for (const fileName in bundle) {
65
+ if (fileName.endsWith(".map")) {
66
+ delete bundle[fileName];
67
+ }
68
+ }
69
+ },
70
+ writeBundle: async (_options, bundle) => {
71
+ const entryFile = Object.values(bundle).find(
72
+ (file) => file.type === "chunk" && file.isEntry
73
+ );
74
+ if (!entryFile || entryFile.type !== "chunk") {
75
+ throw new Error("No entry file found");
76
+ }
77
+ const behaviorUUID = uuid ?? crypto.randomUUID();
78
+ const manifestStub = {
79
+ "format_version": 2,
80
+ "header": {
81
+ "name": name,
82
+ "description": description,
83
+ "uuid": behaviorUUID,
84
+ "version": version,
85
+ "min_engine_version": [1, 21, 120]
86
+ },
87
+ "modules": [
88
+ {
89
+ "description": "script",
90
+ "type": "script",
91
+ "language": "javascript",
92
+ "uuid": crypto.randomUUID(),
93
+ "version": [1, 0, 0],
94
+ "entry": `scripts/${entryFile.fileName}`
95
+ }
96
+ ],
97
+ "dependencies": [
98
+ {
99
+ "module_name": "@minecraft/server",
100
+ "version": "beta"
101
+ },
102
+ {
103
+ "module_name": "@minecraft/server-ui",
104
+ "version": "beta"
105
+ },
106
+ {
107
+ "module_name": "@minecraft/server-net",
108
+ "version": "beta"
109
+ }
110
+ ],
111
+ "metadata": {
112
+ "authors": authors
113
+ }
114
+ };
115
+ fs.writeFileSync("./dist_behavior_pack/manifest.json", JSON.stringify(manifestStub, null, 2));
116
+ }
117
+ });
118
+ export {
119
+ behaviorPacker as default
120
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keystonemc",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "ScriptAPI Wrapper",
5
5
  "type": "module",
6
6
  "scripts": {