sapdon 3.1.0 → 3.2.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.
Files changed (220) hide show
  1. package/README.md +8 -1
  2. package/doc/api.md +2 -2
  3. package/package.json +18 -19
  4. package/{dist → prod}/cli/index.d.ts +1 -1
  5. package/prod/cli/index.js +1 -0
  6. package/{dist → prod}/cli/start.js +997 -967
  7. package/{dist → prod}/core/index.d.ts +2155 -1652
  8. package/prod/core/index.js +59017 -0
  9. package/prod/utils/index.d.ts +41 -0
  10. package/prod/utils/index.js +1 -0
  11. package/dist/cli/build.d.ts +0 -7
  12. package/dist/cli/build.js +0 -236
  13. package/dist/cli/dev-server/client.d.ts +0 -2
  14. package/dist/cli/dev-server/client.js +0 -21
  15. package/dist/cli/dev-server/config.d.ts +0 -3
  16. package/dist/cli/dev-server/config.js +0 -3
  17. package/dist/cli/dev-server/handles.d.ts +0 -4
  18. package/dist/cli/dev-server/handles.js +0 -5
  19. package/dist/cli/dev-server/hmr.d.ts +0 -1
  20. package/dist/cli/dev-server/hmr.js +0 -13
  21. package/dist/cli/dev-server/index.d.ts +0 -4
  22. package/dist/cli/dev-server/index.js +0 -17
  23. package/dist/cli/dev-server/server.d.ts +0 -14
  24. package/dist/cli/dev-server/server.js +0 -59
  25. package/dist/cli/dev-server/syncFiles.d.ts +0 -3
  26. package/dist/cli/dev-server/syncFiles.js +0 -45
  27. package/dist/cli/index.js +0 -90
  28. package/dist/cli/init.d.ts +0 -9
  29. package/dist/cli/init.js +0 -80
  30. package/dist/cli/load.d.ts +0 -3
  31. package/dist/cli/load.js +0 -94
  32. package/dist/cli/start.d.ts +0 -2
  33. package/dist/cli/tools/textureSet.d.ts +0 -13
  34. package/dist/cli/tools/textureSet.js +0 -103
  35. package/dist/cli/utils.d.ts +0 -13
  36. package/dist/cli/utils.js +0 -89
  37. package/dist/core/addon/biome.d.ts +0 -22
  38. package/dist/core/addon/biome.js +0 -27
  39. package/dist/core/addon/block/block.d.ts +0 -41
  40. package/dist/core/addon/block/block.js +0 -46
  41. package/dist/core/addon/controllers/animationController.d.ts +0 -43
  42. package/dist/core/addon/controllers/animationController.js +0 -73
  43. package/dist/core/addon/controllers/render_controllers.js +0 -162
  44. package/dist/core/addon/entity/clientEntity.d.ts +0 -107
  45. package/dist/core/addon/entity/clientEntity.js +0 -149
  46. package/dist/core/addon/entity/entity.d.ts +0 -42
  47. package/dist/core/addon/entity/entity.js +0 -50
  48. package/dist/core/addon/feature/oreFeature.d.ts +0 -19
  49. package/dist/core/addon/feature/oreFeature.js +0 -24
  50. package/dist/core/addon/featureRule.d.ts +0 -20
  51. package/dist/core/addon/featureRule.js +0 -25
  52. package/dist/core/addon/item/attachable.d.ts +0 -94
  53. package/dist/core/addon/item/attachable.js +0 -134
  54. package/dist/core/addon/item/item.d.ts +0 -19
  55. package/dist/core/addon/item/item.js +0 -26
  56. package/dist/core/addon/manifest.d.ts +0 -49
  57. package/dist/core/addon/manifest.js +0 -65
  58. package/dist/core/addon/menuCategory.d.ts +0 -6
  59. package/dist/core/addon/menuCategory.js +0 -7
  60. package/dist/core/addon/recipe/baseRecipe.d.ts +0 -12
  61. package/dist/core/addon/recipe/baseRecipe.js +0 -23
  62. package/dist/core/addon/recipe/data.d.ts +0 -66
  63. package/dist/core/addon/recipe/data.js +0 -74
  64. package/dist/core/addon/recipe/furnace.d.ts +0 -17
  65. package/dist/core/addon/recipe/furnace.js +0 -43
  66. package/dist/core/addon/recipe/shaped.d.ts +0 -26
  67. package/dist/core/addon/recipe/shaped.js +0 -53
  68. package/dist/core/addon/recipe/shapeless.d.ts +0 -18
  69. package/dist/core/addon/recipe/shapeless.js +0 -36
  70. package/dist/core/biome/biome.d.ts +0 -14
  71. package/dist/core/biome/biome.js +0 -23
  72. package/dist/core/biome/biomeComponent.d.ts +0 -46
  73. package/dist/core/biome/biomeComponent.js +0 -77
  74. package/dist/core/block/basicBlock.d.ts +0 -48
  75. package/dist/core/block/basicBlock.js +0 -105
  76. package/dist/core/block/block.d.ts +0 -32
  77. package/dist/core/block/block.js +0 -92
  78. package/dist/core/block/blockComponent.d.ts +0 -187
  79. package/dist/core/block/blockComponent.js +0 -500
  80. package/dist/core/block/cropBlock.d.ts +0 -4
  81. package/dist/core/block/cropBlock.js +0 -27
  82. package/dist/core/block/geometryBlock.d.ts +0 -12
  83. package/dist/core/block/geometryBlock.js +0 -16
  84. package/dist/core/block/oreBlock.d.ts +0 -9
  85. package/dist/core/block/oreBlock.js +0 -25
  86. package/dist/core/block/rotatableBlock.d.ts +0 -27
  87. package/dist/core/block/rotatableBlock.js +0 -107
  88. package/dist/core/block/tileBlock.d.ts +0 -17
  89. package/dist/core/block/tileBlock.js +0 -125
  90. package/dist/core/entity/basicEntity.d.ts +0 -111
  91. package/dist/core/entity/basicEntity.js +0 -170
  92. package/dist/core/entity/behavior/followMob.d.ts +0 -12
  93. package/dist/core/entity/behavior/followMob.js +0 -35
  94. package/dist/core/entity/behavior/followParent.d.ts +0 -7
  95. package/dist/core/entity/behavior/followParent.js +0 -15
  96. package/dist/core/entity/behavior/randomStroll.d.ts +0 -31
  97. package/dist/core/entity/behavior/randomStroll.js +0 -63
  98. package/dist/core/entity/behavior/tempt.d.ts +0 -73
  99. package/dist/core/entity/behavior/tempt.js +0 -134
  100. package/dist/core/entity/bundles/BasicMoveBundle.js +0 -8
  101. package/dist/core/entity/bundles/basicBundle.d.ts +0 -13
  102. package/dist/core/entity/bundles/basicBundle.js +0 -38
  103. package/dist/core/entity/clientEntity.d.ts +0 -20
  104. package/dist/core/entity/clientEntity.js +0 -37
  105. package/dist/core/entity/componets/entityComponet.d.ts +0 -202
  106. package/dist/core/entity/componets/entityComponet.js +0 -354
  107. package/dist/core/entity/data/nativeEntityData.d.ts +0 -9
  108. package/dist/core/entity/data/nativeEntityData.js +0 -38
  109. package/dist/core/entity/dummyEntity.js +0 -14
  110. package/dist/core/entity/entity.d.ts +0 -15
  111. package/dist/core/entity/entity.js +0 -11
  112. package/dist/core/entity/nativeEntity.d.ts +0 -8
  113. package/dist/core/entity/nativeEntity.js +0 -28
  114. package/dist/core/entity/navigation/walk.d.ts +0 -23
  115. package/dist/core/entity/navigation/walk.js +0 -56
  116. package/dist/core/entity/projectile.d.ts +0 -3
  117. package/dist/core/entity/projectile.js +0 -7
  118. package/dist/core/factory/biomeFactory.d.ts +0 -4
  119. package/dist/core/factory/biomeFactory.js +0 -13
  120. package/dist/core/factory/blockFactory.d.ts +0 -34
  121. package/dist/core/factory/blockFactory.js +0 -143
  122. package/dist/core/factory/entityFactory.d.ts +0 -17
  123. package/dist/core/factory/entityFactory.js +0 -75
  124. package/dist/core/factory/featureFactory.d.ts +0 -6
  125. package/dist/core/factory/featureFactory.js +0 -23
  126. package/dist/core/factory/itemExtra.d.ts +0 -8
  127. package/dist/core/factory/itemExtra.js +0 -9
  128. package/dist/core/factory/itemFactory.d.ts +0 -27
  129. package/dist/core/factory/itemFactory.js +0 -112
  130. package/dist/core/factory/recipeFactory.d.ts +0 -18
  131. package/dist/core/factory/recipeFactory.js +0 -39
  132. package/dist/core/factory/uiFactory.d.ts +0 -12
  133. package/dist/core/factory/uiFactory.js +0 -32
  134. package/dist/core/feature/oreFeature.d.ts +0 -10
  135. package/dist/core/feature/oreFeature.js +0 -11
  136. package/dist/core/feature-rule/condition/biomeFilter.d.ts +0 -26
  137. package/dist/core/feature-rule/condition/biomeFilter.js +0 -36
  138. package/dist/core/feature-rule/condition/featureConditions.d.ts +0 -27
  139. package/dist/core/feature-rule/condition/featureConditions.js +0 -37
  140. package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +0 -17
  141. package/dist/core/feature-rule/distribution/coordinateDistribution.js +0 -23
  142. package/dist/core/feature-rule/distribution/featureDistribution.d.ts +0 -31
  143. package/dist/core/feature-rule/distribution/featureDistribution.js +0 -41
  144. package/dist/core/feature-rule/featureRule.d.ts +0 -17
  145. package/dist/core/feature-rule/featureRule.js +0 -26
  146. package/dist/core/index.js +0 -1
  147. package/dist/core/item/armor.d.ts +0 -21
  148. package/dist/core/item/armor.js +0 -90
  149. package/dist/core/item/attachable.d.ts +0 -6
  150. package/dist/core/item/attachable.js +0 -26
  151. package/dist/core/item/food.d.ts +0 -24
  152. package/dist/core/item/food.js +0 -38
  153. package/dist/core/item/item.d.ts +0 -36
  154. package/dist/core/item/item.js +0 -69
  155. package/dist/core/item/itemComponents.d.ts +0 -113
  156. package/dist/core/item/itemComponents.js +0 -225
  157. package/dist/core/registry.d.ts +0 -12
  158. package/dist/core/registry.js +0 -17
  159. package/dist/core/texture.d.ts +0 -18
  160. package/dist/core/texture.js +0 -38
  161. package/dist/core/ui/buttonMapping.d.ts +0 -97
  162. package/dist/core/ui/buttonMapping.js +0 -132
  163. package/dist/core/ui/dataBindingObject.d.ts +0 -97
  164. package/dist/core/ui/dataBindingObject.js +0 -134
  165. package/dist/core/ui/elements/button.d.ts +0 -21
  166. package/dist/core/ui/elements/button.js +0 -101
  167. package/dist/core/ui/elements/collectionPanel.d.ts +0 -12
  168. package/dist/core/ui/elements/collectionPanel.js +0 -53
  169. package/dist/core/ui/elements/grid.d.ts +0 -8
  170. package/dist/core/ui/elements/grid.js +0 -33
  171. package/dist/core/ui/elements/image.d.ts +0 -13
  172. package/dist/core/ui/elements/image.js +0 -55
  173. package/dist/core/ui/elements/label.d.ts +0 -14
  174. package/dist/core/ui/elements/label.js +0 -61
  175. package/dist/core/ui/elements/panel.d.ts +0 -11
  176. package/dist/core/ui/elements/panel.js +0 -49
  177. package/dist/core/ui/elements/scrollingPanel.d.ts +0 -14
  178. package/dist/core/ui/elements/scrollingPanel.js +0 -59
  179. package/dist/core/ui/elements/stackPanel.d.ts +0 -14
  180. package/dist/core/ui/elements/stackPanel.js +0 -37
  181. package/dist/core/ui/elements/uiElement.d.ts +0 -53
  182. package/dist/core/ui/elements/uiElement.js +0 -129
  183. package/dist/core/ui/properties/control.d.ts +0 -214
  184. package/dist/core/ui/properties/control.js +0 -286
  185. package/dist/core/ui/properties/dataBinding.d.ts +0 -6
  186. package/dist/core/ui/properties/dataBinding.js +0 -16
  187. package/dist/core/ui/properties/factory.d.ts +0 -37
  188. package/dist/core/ui/properties/factory.js +0 -62
  189. package/dist/core/ui/properties/gridProp.d.ts +0 -65
  190. package/dist/core/ui/properties/gridProp.js +0 -90
  191. package/dist/core/ui/properties/input.d.ts +0 -97
  192. package/dist/core/ui/properties/input.js +0 -134
  193. package/dist/core/ui/properties/layout.d.ts +0 -105
  194. package/dist/core/ui/properties/layout.js +0 -145
  195. package/dist/core/ui/properties/scrollView.d.ts +0 -105
  196. package/dist/core/ui/properties/scrollView.js +0 -145
  197. package/dist/core/ui/properties/sound.d.ts +0 -47
  198. package/dist/core/ui/properties/sound.js +0 -66
  199. package/dist/core/ui/properties/sprite.d.ts +0 -161
  200. package/dist/core/ui/properties/sprite.js +0 -222
  201. package/dist/core/ui/properties/text.d.ts +0 -135
  202. package/dist/core/ui/properties/text.js +0 -187
  203. package/dist/core/ui/registry/uiSystemRegistry.d.ts +0 -8
  204. package/dist/core/ui/registry/uiSystemRegistry.js +0 -26
  205. package/dist/core/ui/systems/chest.d.ts +0 -5
  206. package/dist/core/ui/systems/chest.js +0 -21
  207. package/dist/core/ui/systems/containerUISystem.d.ts +0 -67
  208. package/dist/core/ui/systems/containerUISystem.js +0 -214
  209. package/dist/core/ui/systems/guidebook.d.ts +0 -9
  210. package/dist/core/ui/systems/guidebook.js +0 -206
  211. package/dist/core/ui/systems/serverForm.d.ts +0 -13
  212. package/dist/core/ui/systems/serverForm.js +0 -116
  213. package/dist/core/ui/systems/system.d.ts +0 -16
  214. package/dist/core/ui/systems/system.js +0 -37
  215. package/dist/oc/actor.js +0 -44
  216. package/dist/oc/core.js +0 -201
  217. package/dist/oc/input.js +0 -67
  218. package/dist/oc/optional.js +0 -31
  219. /package/{dist → prod}/oc/index.d.ts +0 -0
  220. /package/{dist → prod}/oc/index.js +0 -0
@@ -0,0 +1,41 @@
1
+ declare function getMetadata(target: any): any;
2
+ declare function getOrCreateMetadata(target: any): any;
3
+
4
+ interface ISerializer {
5
+ (instance: any): object;
6
+ }
7
+ declare function jsonEncoderReplacer(_: string, v: any): any;
8
+ declare const defaultSerializer: ISerializer;
9
+ declare function Serializable(serializer?: ISerializer): (_: any, ctx: DecoratorContext) => void;
10
+ /**
11
+ * 只能应用一个 Serializer
12
+ *
13
+ * 重复的 Serializer 会被覆盖
14
+ * @param target
15
+ * @param ctx
16
+ */
17
+ declare const Serializer: MethodDecorator;
18
+ declare function serialize<R, T extends object>(inst: T): R;
19
+ declare const jsonEncodeDecoder: EncodeDecoder<any, string>;
20
+ declare function encode<Base, Trans>(value: Base, encodeDecoder?: EncodeDecoder<Base, Trans>): Trans;
21
+ declare function decode<Trans, Base>(value: Trans, encodeDecoder?: EncodeDecoder<Base, Trans>): Base;
22
+ interface EncodeDecoder<Base, Trans> {
23
+ encode: (data: Base) => Trans;
24
+ decode: (chunk: Trans) => Base;
25
+ }
26
+
27
+ type ConstructorOf<T, Arg extends unknown[] = []> = new (...args: Arg) => T;
28
+
29
+ type FloatLiteral = `${number}.${number}`;
30
+ interface RawType<T> extends RawJSON {
31
+ valueOf(): T;
32
+ }
33
+ declare const IS_RAW_SYMBOL: unique symbol;
34
+ declare const f64: (literal: FloatLiteral) => {
35
+ [IS_RAW_SYMBOL]: boolean;
36
+ rawJSON: string;
37
+ valueOf(): number;
38
+ };
39
+ declare function isRawJSON(v: any): boolean;
40
+
41
+ export { type ConstructorOf, type EncodeDecoder, type FloatLiteral, type ISerializer, type RawType, Serializable, Serializer, decode, defaultSerializer, encode, f64, getMetadata, getOrCreateMetadata, isRawJSON, jsonEncodeDecoder, jsonEncoderReplacer, serialize };
@@ -0,0 +1 @@
1
+ function n(n){return n?.[Symbol.metadata]}function t(n){if(null==n)return;return n?.[Symbol.metadata]??(n[Symbol.metadata]={})}Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));const e=Symbol("isRawJSON"),r=n=>{const t=JSON.rawJSON(n).rawJSON;return{[e]:!0,rawJSON:t,valueOf:()=>parseFloat(n)}};function o(n){return!0===n?.[e]}const a=["boolean","number"],c=["string","undefined"];function i(n,t){const e=typeof t;if(null===e)return null;if(c.includes(e))return t;if(a.includes(e))return JSON.rawJSON(t);if("object"===e)return JSON.isRawJSON(t)?t:o(t)?JSON.rawJSON(t.rawJSON):t;if("bigint"===e)return JSON.rawJSON(t.toString());throw new Error("Unexpected value")}const s=n=>structuredClone(n),u=Symbol("serializer"),l=new WeakMap;function S(n=s){return(e,r)=>{if("class"!==r.kind)throw new Error("Serializable decorator can only be applied to classes");t(r)[u]=n}}const f=(n,t)=>{const e=n.constructor;if(!e)throw new Error("Cannot serialize an instance of an anonymous class");l.set(e,n[t])};function d(t){const e=Reflect.getPrototypeOf(t)?.constructor;if(!e)throw new Error("Cannot serialize an instance of an anonymous class");return(n(e)?.[u]??l.get(e)??s).call(t,t)}const w={encode:n=>JSON.stringify(n,i),decode:JSON.parse};function O(n,t=w){return t.encode(n)}function m(n,t=w){return t.decode(n)}export{S as Serializable,f as Serializer,m as decode,s as defaultSerializer,O as encode,r as f64,n as getMetadata,t as getOrCreateMetadata,o as isRawJSON,w as jsonEncodeDecoder,i as jsonEncoderReplacer,d as serialize};
@@ -1,7 +0,0 @@
1
- export function projectCanBuild(projectPath: any, projectName: any): boolean;
2
- export namespace scriptBundler {
3
- let __projectPath: string;
4
- function js(source: any, target: any): void;
5
- function ts(source: any, target: any, tname?: string, sname?: string): Promise<void>;
6
- }
7
- export function buildProject(projectPath: string, projectName: string): Promise<void>;
package/dist/cli/build.js DELETED
@@ -1,236 +0,0 @@
1
- import path from 'path';
2
- import { pathNotExist, readFile, generateUUID, saveFile, copyFileSync, copyFolder, asyncImport } from "./utils.js";
3
- import { generateAddonClient } from './load.js';
4
- import { AddonManifestHeader, AddonManifestModule, AddonManifest, AddonManifestMetadata } from '../core/addon/manifest.js';
5
- import { fileURLToPath } from 'url';
6
- import fs from 'fs';
7
- import { rollup } from 'rollup';
8
- import commonjs from '@rollup/plugin-commonjs';
9
- import { nodeResolve } from '@rollup/plugin-node-resolve';
10
- import ts from '@rollup/plugin-typescript';
11
- import { typescriptPaths as paths } from 'rollup-plugin-typescript-paths';
12
- import json from '@rollup/plugin-json';
13
- import { visualizer } from 'rollup-plugin-visualizer';
14
- import { syncDevFilesClient } from './dev-server/syncFiles.js';
15
- import { hmr } from './dev-server/hmr.js';
16
- import cp from 'child_process';
17
- // 获取当前文件的目录路径
18
- const __filename = fileURLToPath(import.meta.url);
19
- const __dirname = path.dirname(__filename);
20
- //读取配置文件
21
- // const pathConfig = JSON.parse(readFile(path.join(__dirname, "./build.config")))
22
- const rollupIgnores = [
23
- 'rollup',
24
- 'typescript',
25
- '@sapdon/core',
26
- '@sapdon/cli',
27
- '@minecraft',
28
- ];
29
- //脚本打包器
30
- export const scriptBundler = {
31
- __projectPath: path.join(__dirname, '../../'),
32
- js: (source, target) => {
33
- copyFolder(source, target);
34
- },
35
- //ts先通过rollup处理后再复制
36
- ts: async (source, target, tname = 'index.js', sname = 'index.ts') => {
37
- // console.log(source, target, tname)
38
- const tmpFile = path.join(scriptBundler.__projectPath, '.tmp', `sapdon-${crypto.randomUUID()}.js`);
39
- try {
40
- const bundle = await rollup({
41
- input: path.join(source, sname),
42
- plugins: [
43
- paths(),
44
- nodeResolve({
45
- preferBuiltins: true
46
- }),
47
- //@ts-ignore
48
- ts({
49
- tsconfig: path.join(scriptBundler.__projectPath, 'tsconfig.json'),
50
- }),
51
- //@ts-ignore
52
- commonjs(),
53
- //@ts-ignore
54
- json(),
55
- // visualizer({ open: true }), //可视化分析, 打包出问题取消注释这一行
56
- ],
57
- external(name) {
58
- for (const candidate of rollupIgnores) {
59
- if (name.includes(candidate)) {
60
- return true;
61
- }
62
- }
63
- return false;
64
- }
65
- });
66
- await bundle.write({
67
- file: tmpFile,
68
- format: 'esm',
69
- });
70
- bundle.close();
71
- fs.cpSync(tmpFile, path.join(target, tname));
72
- }
73
- catch (e) {
74
- console.error(e);
75
- }
76
- finally {
77
- fs.rmSync(tmpFile, {
78
- recursive: true,
79
- force: true
80
- });
81
- }
82
- }
83
- };
84
- async function bundleScripts(projectPath, scriptPath, element) {
85
- const sourcePath = path.join(projectPath, element.path);
86
- const elementType = element.type || 'js';
87
- scriptBundler.__projectPath = projectPath;
88
- scriptBundler[elementType](sourcePath, scriptPath);
89
- }
90
- function preload(filePath) {
91
- fs.appendFileSync(filePath, `
92
- ;(async () => {
93
- const { startDevServer } = await import('@sapdon/cli')
94
- const { GRegistry, UISystemRegistry } = await import('@sapdon/core')
95
- startDevServer(GRegistry, UISystemRegistry)
96
- })();
97
- `);
98
- }
99
- async function runOnChild(targetFilePath) {
100
- const { promise, resolve } = Promise.withResolvers();
101
- const child = cp.fork(targetFilePath, { stdio: 'inherit' });
102
- child.once('message', message => {
103
- if (message !== 'initialized') {
104
- child.kill();
105
- }
106
- resolve();
107
- });
108
- await promise;
109
- }
110
- async function runScript(src) {
111
- if (src.endsWith('.ts')) {
112
- const randomName = crypto.randomUUID() + '.js';
113
- const sourceDir = path.dirname(src);
114
- const sourceFileName = src.replace(sourceDir, '');
115
- const targetFilePath = path.join(sourceDir, randomName);
116
- await scriptBundler.ts(sourceDir, sourceDir, randomName, sourceFileName);
117
- preload(targetFilePath);
118
- try {
119
- await runOnChild(targetFilePath);
120
- }
121
- finally {
122
- fs.rmSync(targetFilePath, { force: true });
123
- }
124
- return;
125
- }
126
- await runOnChild(src);
127
- }
128
- export function projectCanBuild(projectPath, projectName) {
129
- console.log("开始构建项目");
130
- console.log("项目路径:" + projectPath);
131
- //检查项目是否存在
132
- if (pathNotExist(projectPath)) {
133
- console.log("项目不存在");
134
- return false;
135
- }
136
- //检查项目是否有build.config文件
137
- if (pathNotExist(path.join(projectPath, "build.config"))) {
138
- console.log("项目没有build.config文件");
139
- return false;
140
- }
141
- return true;
142
- }
143
- //构建项目
144
- /**
145
- * `client`
146
- *
147
- * 在使用前使用 `projectCanBuild` 确保项目可以构建
148
- * @param {string} projectPath
149
- * @param {string} projectName
150
- */
151
- export const buildProject = async (projectPath, projectName) => {
152
- //读取build.config文件
153
- const buildConfigPath = path.join(projectPath, "build.config");
154
- const buildConfig = JSON.parse(readFile(buildConfigPath));
155
- //console.log(buildConfig)
156
- //读取mod.info文件
157
- const modInfoPath = path.join(projectPath, "mod.info");
158
- const modInfo = JSON.parse(readFile(modInfoPath));
159
- const min_engine_version = versionStringToArray(modInfo.min_engine_version);
160
- const buildDirPath = path.join(projectPath, buildConfig.defaultConfig.buildDir);
161
- const buildBehDirPath = path.join(buildDirPath, `${projectName}_BP/`);
162
- const buildResDirPath = path.join(buildDirPath, `${projectName}_RP/`);
163
- //生成manifest.json文件
164
- //判断manifest.json是否已经生成过了,生成过了就不用生成
165
- const manifestPath = path.join(buildBehDirPath, "manifest.json");
166
- if (pathNotExist(manifestPath)) {
167
- const behManifest = generateBehManifest(modInfo.name, modInfo.description, modInfo.version, {
168
- min_engine_version: min_engine_version,
169
- }, buildConfig.defaultConfig.dependencies, buildConfig.defaultConfig.scriptEntry);
170
- const resManifest = generateResManifest(modInfo.name, modInfo.description, modInfo.version, {
171
- min_engine_version: min_engine_version,
172
- }, []);
173
- //BP
174
- saveFile(path.join(buildBehDirPath, "manifest.json"), behManifest);
175
- //RP
176
- saveFile(path.join(buildResDirPath, "manifest.json"), resManifest);
177
- }
178
- //复制pack_icon.png
179
- const packIconPath = path.join(projectPath, "pack_icon.png");
180
- copyFileSync(packIconPath, path.join(buildBehDirPath, "pack_icon.png"));
181
- copyFileSync(packIconPath, path.join(buildResDirPath, "pack_icon.png"));
182
- const resources = buildConfig.resources;
183
- resources.forEach(element => {
184
- const sourcePath = path.join(projectPath, element.path);
185
- copyFolder(sourcePath, buildResDirPath);
186
- });
187
- const scripts = buildConfig.scripts;
188
- const scriptPath = path.join(buildBehDirPath, "scripts/");
189
- for (const element of scripts) {
190
- await bundleScripts(projectPath, scriptPath, element);
191
- }
192
- const absoluteModPath = path.join(projectPath, buildConfig.defaultConfig.buildEntry);
193
- await runScript(absoluteModPath);
194
- //只有当buildMode为development时才加载用户modjs文件
195
- if (buildConfig.defaultConfig.buildMode === "development") {
196
- //动态加载用户modjs文件
197
- await generateAddonClient(absoluteModPath, buildDirPath, projectName);
198
- }
199
- syncDevFilesClient(projectPath, projectName);
200
- if (buildConfig.useHMR === true) {
201
- hmr(projectPath, projectName);
202
- }
203
- };
204
- function versionStringToArray(versionString) {
205
- // 使用 split 方法将字符串按 '.' 分割成数组
206
- const parts = versionString.split('.');
207
- // 使用 map 方法将每个部分转换为数字
208
- const versionArray = parts.map(part => Number(part));
209
- return versionArray;
210
- }
211
- const generateBehManifest = (name, description, version, options = {}, dependencies = [], entry) => {
212
- console.log("开始生成behavior_packs/manifest.json");
213
- console.log("Entry:", entry);
214
- const header = new AddonManifestHeader((name + "_BP"), description, versionStringToArray(version), generateUUID(), options);
215
- const module = new AddonManifestModule("行为模块", "data", generateUUID(), versionStringToArray(version));
216
- const script_module = new AddonManifestModule("脚本模块", "script", generateUUID(), versionStringToArray(version));
217
- if (entry) {
218
- script_module.entry = entry;
219
- }
220
- const metadata = new AddonManifestMetadata(["@sapdon"], "MIT", {
221
- "sapdon": ["1.0.0"]
222
- }, "addon", "https://github.com/junjun260/sapdon");
223
- const manifest = new AddonManifest(2, //格式版本
224
- header, [module, script_module], dependencies, null, metadata);
225
- return JSON.stringify(manifest, null, 2);
226
- };
227
- const generateResManifest = (name, description, version, options = {}, dependencies = []) => {
228
- const header = new AddonManifestHeader((name + "_RP"), description, versionStringToArray(version), generateUUID(), options);
229
- const module = new AddonManifestModule("资源模块", "resources", generateUUID(), versionStringToArray(version));
230
- const metadata = new AddonManifestMetadata(["@sapdon"], "MIT", {
231
- "sapdon": ["1.0.0"]
232
- }, "addon", "https://github.com/junjun260/sapdon");
233
- const manifest = new AddonManifest(2, //格式版本
234
- header, [module], [], null, metadata);
235
- return JSON.stringify(manifest, null, 2);
236
- };
@@ -1,2 +0,0 @@
1
- export function cliRequest(path: any, ...params: any[]): Promise<void>;
2
- export function writeAddon(modPath: any, buildPath: any, projectName: any): Promise<void>;
@@ -1,21 +0,0 @@
1
- import { devServerConfig } from './config.js';
2
- import { ServerHandles } from './handles.js';
3
- const { port } = devServerConfig;
4
- export async function cliRequest(path, ...params) {
5
- try {
6
- await fetch(`http://localhost:${port}/${path}`, {
7
- method: 'POST',
8
- headers: {
9
- 'Content-Type': 'application/json'
10
- },
11
- body: JSON.stringify(params)
12
- });
13
- }
14
- catch (error) {
15
- console.error(error);
16
- console.error('尝试在构建脚本中使用 server.startDevServer() 启动开发服务器');
17
- }
18
- }
19
- export async function writeAddon(modPath, buildPath, projectName) {
20
- await cliRequest(ServerHandles.WRITE_ADDON, modPath, buildPath, projectName);
21
- }
@@ -1,3 +0,0 @@
1
- export namespace devServerConfig {
2
- let port: number;
3
- }
@@ -1,3 +0,0 @@
1
- export const devServerConfig = {
2
- port: 49037
3
- };
@@ -1,4 +0,0 @@
1
- export declare enum ServerHandles {
2
- WRITE_ADDON = "write-addon",
3
- WRITE_GAME_DEV = "write-dev"
4
- }
@@ -1,5 +0,0 @@
1
- export var ServerHandles;
2
- (function (ServerHandles) {
3
- ServerHandles["WRITE_ADDON"] = "write-addon";
4
- ServerHandles["WRITE_GAME_DEV"] = "write-dev";
5
- })(ServerHandles || (ServerHandles = {}));
@@ -1 +0,0 @@
1
- export function hmr(projectPath: any, projectName: any): void;
@@ -1,13 +0,0 @@
1
- import fs from 'fs';
2
- import lodash from 'lodash';
3
- import { buildProject } from '../build.js';
4
- const debounce = lodash.debounce;
5
- export function hmr(projectPath, projectName) {
6
- // fs.watch(projectPath, { recursive: true }, debounce(async (eventType, filename) => {
7
- // if (filename.endsWith('.js') || filename.endsWith('.ts')) {
8
- // process.stdout.write(`File ${filename} changed, reloading...\r`)
9
- // await buildProject(projectPath, projectName)
10
- // console.log(`Reloaded ${filename}`)
11
- // }
12
- // }), 1000)
13
- }
@@ -1,4 +0,0 @@
1
- import { ServerHandles } from "./handles.js";
2
- import { server } from "./server.js";
3
- export declare function startDevServer(GRegistry: any, UIRegistry: any): void;
4
- export { server, ServerHandles, };
@@ -1,17 +0,0 @@
1
- import { generateAddon } from "../load.js";
2
- import { ServerHandles } from "./handles.js";
3
- import { server } from "./server.js";
4
- import { syncDevFilesServer } from "./syncFiles.js";
5
- function startup(GRegistry, UIRegistry) {
6
- server.bootstrap();
7
- server.handle(ServerHandles.WRITE_ADDON, generateAddon(GRegistry, UIRegistry));
8
- server.handle(ServerHandles.WRITE_GAME_DEV, syncDevFilesServer);
9
- }
10
- export function startDevServer(GRegistry, UIRegistry) {
11
- if (server.isListening()) {
12
- return;
13
- }
14
- startup(GRegistry, UIRegistry);
15
- process.send('initialized');
16
- }
17
- export { server, ServerHandles, };
@@ -1,14 +0,0 @@
1
- import http from 'http';
2
- type ServerHandler = (...args: Transferable[]) => void;
3
- type HandlerInterceptor = (handler: ServerHandler) => ServerHandler;
4
- declare class DevelopmentServer {
5
- readonly cliServerHandlers: Map<string, ServerHandler>;
6
- listening: boolean;
7
- isListening(): boolean;
8
- bootstrap(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
9
- handle(url: string, handler: ServerHandler): void;
10
- getHandler(url: string): ServerHandler | undefined;
11
- interceptHandler(url: string, interceptor: HandlerInterceptor): ServerHandler;
12
- }
13
- export declare const server: DevelopmentServer;
14
- export {};
@@ -1,59 +0,0 @@
1
- import http from 'http';
2
- import { devServerConfig } from './config.js';
3
- const { port } = devServerConfig;
4
- class DevelopmentServer {
5
- cliServerHandlers = new Map();
6
- listening = false;
7
- isListening() {
8
- return this.listening;
9
- }
10
- bootstrap() {
11
- this.listening = true;
12
- const svr = http.createServer(async (req, res) => {
13
- const handler = this.cliServerHandlers.get((req.url ?? '/').slice(1));
14
- if (handler) {
15
- try {
16
- const { promise, resolve, reject } = Promise.withResolvers();
17
- let buf = Buffer.alloc(0);
18
- req.on('data', chunk => buf = Buffer.concat([buf, chunk]));
19
- req.on('end', () => {
20
- try {
21
- resolve(JSON.parse(buf));
22
- }
23
- catch (error) {
24
- reject(error);
25
- }
26
- });
27
- await handler(...await promise);
28
- }
29
- catch (error) {
30
- console.error(error);
31
- res.writeHead(500);
32
- res.end();
33
- return;
34
- }
35
- res.writeHead(200);
36
- res.end();
37
- }
38
- else {
39
- res.writeHead(404);
40
- res.end();
41
- }
42
- }).listen(port, () => console.log(`Dev Server listening on port ${port}`));
43
- svr.on('error', () => this.listening = false);
44
- return svr;
45
- }
46
- handle(url, handler) {
47
- this.cliServerHandlers.set(url, handler);
48
- }
49
- getHandler(url) {
50
- return this.cliServerHandlers.get(url);
51
- }
52
- interceptHandler(url, interceptor) {
53
- const currentHandler = this.getHandler(url) ?? Function.prototype;
54
- const newHandler = interceptor(currentHandler);
55
- this.cliServerHandlers.set(url, newHandler);
56
- return newHandler;
57
- }
58
- }
59
- export const server = new DevelopmentServer();
@@ -1,3 +0,0 @@
1
- export function syncDevFilesClient(projectPath: any, projectName: any): Promise<void>;
2
- export function syncDevFilesServer(projectPath: any, projectName: any): Promise<void>;
3
- export function writeLib(projectPath: any): Promise<void>;
@@ -1,45 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import { cliRequest } from "./client.js";
3
- import { copyFolder, dirname } from "../utils.js";
4
- import path from "path";
5
- import fs from 'fs';
6
- import { ServerHandles } from "./handles.js";
7
- export async function syncDevFilesClient(projectPath, projectName) {
8
- await cliRequest(ServerHandles.WRITE_GAME_DEV, projectPath, projectName);
9
- }
10
- export async function syncDevFilesServer(projectPath, projectName) {
11
- const buildConfig = JSON.parse(readFileSync(path.join(projectPath, "build.config")));
12
- const buildDir = path.join(projectPath, buildConfig.defaultConfig.buildDir);
13
- const buildBehDirPath = path.join(buildDir, `${projectName}_BP`);
14
- const buildResDirPath = path.join(buildDir, `${projectName}_RP`);
15
- copyFolder(buildBehDirPath, path.join(buildConfig.mojangPath, "development_behavior_packs/", `${projectName}_BP/`));
16
- copyFolder(buildResDirPath, path.join(buildConfig.mojangPath, "development_resource_packs/", `${projectName}_RP/`));
17
- }
18
- export async function writeLib(projectPath) {
19
- const projectModules = path.join(projectPath, "node_modules");
20
- const rootDir = path.join(dirname(import.meta), '../');
21
- const corePath = path.join(rootDir, 'core');
22
- const cliPath = path.join(rootDir, 'cli');
23
- const ocPath = path.join(rootDir, 'oc');
24
- const targetCorePath = path.join(projectModules, '@sapdon/core');
25
- const targetCliPath = path.join(projectModules, '@sapdon/cli');
26
- const targetOcPath = path.join(projectModules, '@sapdon/oc');
27
- fs.cpSync(corePath, targetCorePath, { recursive: true, force: true });
28
- fs.cpSync(cliPath, targetCliPath, { recursive: true, force: true });
29
- fs.cpSync(ocPath, targetOcPath, { recursive: true, force: true });
30
- fs.writeFileSync(path.join(targetCorePath, 'package.json'), JSON.stringify({
31
- name: '@sapdon/core',
32
- main: 'index.js',
33
- version: '1.0.0',
34
- }));
35
- fs.writeFileSync(path.join(targetCliPath, 'package.json'), JSON.stringify({
36
- name: '@sapdon/cli',
37
- main: 'index.js',
38
- version: '1.0.0',
39
- }));
40
- fs.writeFileSync(path.join(targetOcPath, 'package.json'), JSON.stringify({
41
- name: '@sapdon/oc',
42
- main: 'index.js',
43
- version: '1.0.0',
44
- }));
45
- }
package/dist/cli/index.js DELETED
@@ -1,90 +0,0 @@
1
- import http from 'http';
2
-
3
- const devServerConfig = {
4
- port: 49037
5
- };
6
-
7
- const {
8
- port: port$1
9
- } = devServerConfig;
10
-
11
- async function cliRequest(path, ...params) {
12
- try {
13
- await fetch(`http://localhost:${port$1}/${path}`, {
14
- method: 'POST',
15
- headers: {
16
- 'Content-Type': 'application/json'
17
- },
18
- body: JSON.stringify(params)
19
- });
20
- } catch (error) {
21
- console.error(error);
22
- console.error('尝试在构建脚本中使用 server.startDevServer() 启动开发服务器');
23
- }
24
- }
25
-
26
- const { port } = devServerConfig;
27
- class DevelopmentServer {
28
- cliServerHandlers = new Map();
29
- listening = false;
30
- isListening() {
31
- return this.listening;
32
- }
33
- bootstrap() {
34
- this.listening = true;
35
- const svr = http.createServer(async (req, res) => {
36
- const handler = this.cliServerHandlers.get((req.url ?? '/').slice(1));
37
- if (handler) {
38
- try {
39
- const { promise, resolve, reject } = Promise.withResolvers();
40
- let buf = Buffer.alloc(0);
41
- req.on('data', chunk => buf = Buffer.concat([buf, chunk]));
42
- req.on('end', () => {
43
- try {
44
- resolve(JSON.parse(buf));
45
- }
46
- catch (error) {
47
- reject(error);
48
- }
49
- });
50
- await handler(...await promise);
51
- }
52
- catch (error) {
53
- console.error(error);
54
- res.writeHead(500);
55
- res.end();
56
- return;
57
- }
58
- res.writeHead(200);
59
- res.end();
60
- }
61
- else {
62
- res.writeHead(404);
63
- res.end();
64
- }
65
- }).listen(port, () => console.log(`Dev Server listening on port ${port}`));
66
- svr.on('error', () => this.listening = false);
67
- return svr;
68
- }
69
- handle(url, handler) {
70
- this.cliServerHandlers.set(url, handler);
71
- }
72
- getHandler(url) {
73
- return this.cliServerHandlers.get(url);
74
- }
75
- interceptHandler(url, interceptor) {
76
- const currentHandler = this.getHandler(url) ?? Function.prototype;
77
- const newHandler = interceptor(currentHandler);
78
- this.cliServerHandlers.set(url, newHandler);
79
- return newHandler;
80
- }
81
- }
82
- const server = new DevelopmentServer();
83
-
84
- const client = {
85
- call: async (name, ...args) => {
86
- return await cliRequest(name, ...args)
87
- }
88
- };
89
-
90
- export { client, server as devServer };
@@ -1,9 +0,0 @@
1
- export function initMojangPath(projectPath: any): void;
2
- export function initProject(projectPath: any, data: any): void;
3
- export function initNPMProject(projectPath: any, data: any): void;
4
- export function readPackageJson(dir: any): {
5
- name: string;
6
- description: any;
7
- author: any;
8
- version: any;
9
- } | null;