sapdon 3.0.1 → 3.0.2
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/README.md +3 -1
- package/doc/cli.md +24 -0
- package/doc/sapdon-ts.md +17 -5
- package/package.json +2 -2
- package/dist/cli/build.d.ts +0 -7
- package/dist/cli/build.js +0 -232
- package/dist/cli/dev-server/client.d.ts +0 -2
- package/dist/cli/dev-server/client.js +0 -20
- package/dist/cli/dev-server/config.d.ts +0 -3
- package/dist/cli/dev-server/config.js +0 -3
- package/dist/cli/dev-server/hmr.d.ts +0 -1
- package/dist/cli/dev-server/hmr.js +0 -13
- package/dist/cli/dev-server/index.d.ts +0 -3
- package/dist/cli/dev-server/index.js +0 -11
- package/dist/cli/dev-server/server.d.ts +0 -6
- package/dist/cli/dev-server/server.js +0 -50
- package/dist/cli/dev-server/syncFiles.d.ts +0 -3
- package/dist/cli/dev-server/syncFiles.js +0 -36
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -1
- package/dist/cli/init.d.ts +0 -9
- package/dist/cli/init.js +0 -80
- package/dist/cli/load.d.ts +0 -3
- package/dist/cli/load.js +0 -94
- package/dist/cli/start.d.ts +0 -2
- package/dist/cli/start.js +0 -156
- package/dist/cli/tools/textureSet.d.ts +0 -13
- package/dist/cli/tools/textureSet.js +0 -103
- package/dist/cli/utils.d.ts +0 -13
- package/dist/cli/utils.js +0 -89
- package/dist/core/addon/biome.d.ts +0 -22
- package/dist/core/addon/biome.js +0 -27
- package/dist/core/addon/block/block.d.ts +0 -41
- package/dist/core/addon/block/block.js +0 -46
- package/dist/core/addon/controllers/animationController.d.ts +0 -43
- package/dist/core/addon/controllers/animationController.js +0 -73
- package/dist/core/addon/entity/clientEntity.d.ts +0 -107
- package/dist/core/addon/entity/clientEntity.js +0 -149
- package/dist/core/addon/entity/entity.d.ts +0 -42
- package/dist/core/addon/entity/entity.js +0 -50
- package/dist/core/addon/feature/oreFeature.d.ts +0 -19
- package/dist/core/addon/feature/oreFeature.js +0 -24
- package/dist/core/addon/featureRule.d.ts +0 -20
- package/dist/core/addon/featureRule.js +0 -25
- package/dist/core/addon/item/attachable.d.ts +0 -94
- package/dist/core/addon/item/attachable.js +0 -134
- package/dist/core/addon/item/item.d.ts +0 -19
- package/dist/core/addon/item/item.js +0 -26
- package/dist/core/addon/manifest.d.ts +0 -49
- package/dist/core/addon/manifest.js +0 -65
- package/dist/core/addon/menuCategory.d.ts +0 -6
- package/dist/core/addon/menuCategory.js +0 -7
- package/dist/core/addon/recipe/baseRecipe.d.ts +0 -12
- package/dist/core/addon/recipe/baseRecipe.js +0 -23
- package/dist/core/addon/recipe/data.d.ts +0 -66
- package/dist/core/addon/recipe/data.js +0 -74
- package/dist/core/addon/recipe/furnace.d.ts +0 -17
- package/dist/core/addon/recipe/furnace.js +0 -43
- package/dist/core/addon/recipe/shaped.d.ts +0 -26
- package/dist/core/addon/recipe/shaped.js +0 -53
- package/dist/core/addon/recipe/shapeless.d.ts +0 -18
- package/dist/core/addon/recipe/shapeless.js +0 -36
- package/dist/core/biome/biome.d.ts +0 -14
- package/dist/core/biome/biome.js +0 -23
- package/dist/core/biome/biomeComponent.d.ts +0 -46
- package/dist/core/biome/biomeComponent.js +0 -77
- package/dist/core/block/basicBlock.d.ts +0 -48
- package/dist/core/block/basicBlock.js +0 -105
- package/dist/core/block/block.d.ts +0 -32
- package/dist/core/block/block.js +0 -92
- package/dist/core/block/blockComponent.d.ts +0 -187
- package/dist/core/block/blockComponent.js +0 -500
- package/dist/core/block/cropBlock.d.ts +0 -4
- package/dist/core/block/cropBlock.js +0 -27
- package/dist/core/block/geometryBlock.d.ts +0 -12
- package/dist/core/block/geometryBlock.js +0 -16
- package/dist/core/block/oreBlock.d.ts +0 -9
- package/dist/core/block/oreBlock.js +0 -25
- package/dist/core/block/rotatableBlock.d.ts +0 -27
- package/dist/core/block/rotatableBlock.js +0 -107
- package/dist/core/block/tileBlock.d.ts +0 -17
- package/dist/core/block/tileBlock.js +0 -125
- package/dist/core/entity/basicEntity.d.ts +0 -111
- package/dist/core/entity/basicEntity.js +0 -170
- package/dist/core/entity/behavior/followMob.d.ts +0 -12
- package/dist/core/entity/behavior/followMob.js +0 -35
- package/dist/core/entity/behavior/followParent.d.ts +0 -7
- package/dist/core/entity/behavior/followParent.js +0 -15
- package/dist/core/entity/behavior/randomStroll.d.ts +0 -31
- package/dist/core/entity/behavior/randomStroll.js +0 -63
- package/dist/core/entity/behavior/tempt.d.ts +0 -73
- package/dist/core/entity/behavior/tempt.js +0 -134
- package/dist/core/entity/bundles/basicBundle.d.ts +0 -13
- package/dist/core/entity/bundles/basicBundle.js +0 -45
- package/dist/core/entity/clientEntity.d.ts +0 -20
- package/dist/core/entity/clientEntity.js +0 -37
- package/dist/core/entity/componets/entityComponet.d.ts +0 -202
- package/dist/core/entity/componets/entityComponet.js +0 -347
- package/dist/core/entity/data/nativeEntityData.d.ts +0 -9
- package/dist/core/entity/data/nativeEntityData.js +0 -38
- package/dist/core/entity/entity.d.ts +0 -15
- package/dist/core/entity/entity.js +0 -18
- package/dist/core/entity/nativeEntity.d.ts +0 -8
- package/dist/core/entity/nativeEntity.js +0 -28
- package/dist/core/entity/navigation/walk.d.ts +0 -23
- package/dist/core/entity/navigation/walk.js +0 -56
- package/dist/core/entity/projectile.d.ts +0 -3
- package/dist/core/entity/projectile.js +0 -7
- package/dist/core/factory/biomeFactory.d.ts +0 -4
- package/dist/core/factory/biomeFactory.js +0 -13
- package/dist/core/factory/blockFactory.d.ts +0 -34
- package/dist/core/factory/blockFactory.js +0 -143
- package/dist/core/factory/entityFactory.d.ts +0 -17
- package/dist/core/factory/entityFactory.js +0 -75
- package/dist/core/factory/featureFactory.d.ts +0 -6
- package/dist/core/factory/featureFactory.js +0 -23
- package/dist/core/factory/itemExtra.d.ts +0 -8
- package/dist/core/factory/itemExtra.js +0 -9
- package/dist/core/factory/itemFactory.d.ts +0 -27
- package/dist/core/factory/itemFactory.js +0 -112
- package/dist/core/factory/recipeFactory.d.ts +0 -18
- package/dist/core/factory/recipeFactory.js +0 -39
- package/dist/core/factory/uiFactory.d.ts +0 -11
- package/dist/core/factory/uiFactory.js +0 -32
- package/dist/core/feature/oreFeature.d.ts +0 -10
- package/dist/core/feature/oreFeature.js +0 -11
- package/dist/core/feature-rule/condition/biomeFilter.d.ts +0 -26
- package/dist/core/feature-rule/condition/biomeFilter.js +0 -36
- package/dist/core/feature-rule/condition/featureConditions.d.ts +0 -27
- package/dist/core/feature-rule/condition/featureConditions.js +0 -37
- package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +0 -17
- package/dist/core/feature-rule/distribution/coordinateDistribution.js +0 -23
- package/dist/core/feature-rule/distribution/featureDistribution.d.ts +0 -31
- package/dist/core/feature-rule/distribution/featureDistribution.js +0 -41
- package/dist/core/feature-rule/featureRule.d.ts +0 -17
- package/dist/core/feature-rule/featureRule.js +0 -26
- package/dist/core/index.d.ts +0 -24
- package/dist/core/index.js +0 -21
- package/dist/core/item/armor.d.ts +0 -21
- package/dist/core/item/armor.js +0 -90
- package/dist/core/item/attachable.d.ts +0 -6
- package/dist/core/item/attachable.js +0 -26
- package/dist/core/item/food.d.ts +0 -24
- package/dist/core/item/food.js +0 -38
- package/dist/core/item/item.d.ts +0 -36
- package/dist/core/item/item.js +0 -69
- package/dist/core/item/itemComponents.d.ts +0 -113
- package/dist/core/item/itemComponents.js +0 -225
- package/dist/core/registry.d.ts +0 -12
- package/dist/core/registry.js +0 -16
- package/dist/core/texture.d.ts +0 -18
- package/dist/core/texture.js +0 -38
- package/dist/core/ui/buttonMapping.d.ts +0 -97
- package/dist/core/ui/buttonMapping.js +0 -132
- package/dist/core/ui/dataBindingObject.d.ts +0 -97
- package/dist/core/ui/dataBindingObject.js +0 -134
- package/dist/core/ui/elements/button.d.ts +0 -21
- package/dist/core/ui/elements/button.js +0 -101
- package/dist/core/ui/elements/collectionPanel.d.ts +0 -12
- package/dist/core/ui/elements/collectionPanel.js +0 -53
- package/dist/core/ui/elements/grid.d.ts +0 -8
- package/dist/core/ui/elements/grid.js +0 -33
- package/dist/core/ui/elements/image.d.ts +0 -13
- package/dist/core/ui/elements/image.js +0 -55
- package/dist/core/ui/elements/label.d.ts +0 -14
- package/dist/core/ui/elements/label.js +0 -61
- package/dist/core/ui/elements/panel.d.ts +0 -11
- package/dist/core/ui/elements/panel.js +0 -49
- package/dist/core/ui/elements/scrollingPanel.d.ts +0 -14
- package/dist/core/ui/elements/scrollingPanel.js +0 -59
- package/dist/core/ui/elements/stackPanel.d.ts +0 -14
- package/dist/core/ui/elements/stackPanel.js +0 -37
- package/dist/core/ui/elements/uiElement.d.ts +0 -53
- package/dist/core/ui/elements/uiElement.js +0 -129
- package/dist/core/ui/properties/control.d.ts +0 -214
- package/dist/core/ui/properties/control.js +0 -286
- package/dist/core/ui/properties/dataBinding.d.ts +0 -6
- package/dist/core/ui/properties/dataBinding.js +0 -16
- package/dist/core/ui/properties/factory.d.ts +0 -37
- package/dist/core/ui/properties/factory.js +0 -62
- package/dist/core/ui/properties/gridProp.d.ts +0 -65
- package/dist/core/ui/properties/gridProp.js +0 -90
- package/dist/core/ui/properties/input.d.ts +0 -97
- package/dist/core/ui/properties/input.js +0 -134
- package/dist/core/ui/properties/layout.d.ts +0 -105
- package/dist/core/ui/properties/layout.js +0 -145
- package/dist/core/ui/properties/scrollView.d.ts +0 -105
- package/dist/core/ui/properties/scrollView.js +0 -145
- package/dist/core/ui/properties/sound.d.ts +0 -47
- package/dist/core/ui/properties/sound.js +0 -66
- package/dist/core/ui/properties/sprite.d.ts +0 -161
- package/dist/core/ui/properties/sprite.js +0 -222
- package/dist/core/ui/properties/text.d.ts +0 -135
- package/dist/core/ui/properties/text.js +0 -187
- package/dist/core/ui/registry/uiSystemRegistry.d.ts +0 -8
- package/dist/core/ui/registry/uiSystemRegistry.js +0 -26
- package/dist/core/ui/systems/chest.d.ts +0 -4
- package/dist/core/ui/systems/chest.js +0 -21
- package/dist/core/ui/systems/containerUISystem.d.ts +0 -64
- package/dist/core/ui/systems/containerUISystem.js +0 -206
- package/dist/core/ui/systems/guidebook.d.ts +0 -8
- package/dist/core/ui/systems/guidebook.js +0 -206
- package/dist/core/ui/systems/serverForm.d.ts +0 -12
- package/dist/core/ui/systems/serverForm.js +0 -116
- package/dist/core/ui/systems/system.d.ts +0 -16
- package/dist/core/ui/systems/system.js +0 -37
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ hello_sapdon/
|
|
|
61
61
|
1. 打开 `main.mjs` 文件。
|
|
62
62
|
2. 写入以下内容以创建一个基础物品:
|
|
63
63
|
```javascript
|
|
64
|
-
import { ItemAPI } from "
|
|
64
|
+
import { ItemAPI } from "@sapdon/core";
|
|
65
65
|
|
|
66
66
|
ItemAPI.createItem("hello_sapdon:my_item", "items", "masterball");
|
|
67
67
|
```
|
|
@@ -109,3 +109,5 @@ npm update sapdon
|
|
|
109
109
|
|
|
110
110
|
- 官方 QQ 群:`810904181`
|
|
111
111
|
|
|
112
|
+
## ts支持
|
|
113
|
+
[quick start](./doc/sapdon-ts.md)
|
package/doc/cli.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# `@sapdon/cli` 包
|
|
2
|
+
|
|
3
|
+
## 自定义处理器
|
|
4
|
+
```ts
|
|
5
|
+
import { devServer } from '@sapdon/cli'
|
|
6
|
+
devServer.handle('ping', () => {
|
|
7
|
+
console.log('pong')
|
|
8
|
+
})
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 拦截cli处理器
|
|
12
|
+
```ts
|
|
13
|
+
import { devServer, ServerHandles } from '@sapdon/cli'
|
|
14
|
+
|
|
15
|
+
devServer.interceptHandler(ServerHandles.WRITE_ADDON, handler => {
|
|
16
|
+
return (...args: any[]) => {
|
|
17
|
+
const now = peformance.now()
|
|
18
|
+
handler.apply(args)
|
|
19
|
+
const dt = peformance.now() - now
|
|
20
|
+
console.log(`执行耗时 ${dt}ms.`)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
package/doc/sapdon-ts.md
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
# sapdon with typescript
|
|
2
2
|
在使用脚手架创建项目时,默认使用的语言将会是 `ts`
|
|
3
3
|
|
|
4
|
-
但这并不意味着你需要手动去调整 tsconfig 和打包工具,我们提供了一套默认能用的ts
|
|
4
|
+
但这并不意味着你需要手动去调整 tsconfig 和打包工具,我们提供了一套默认能用的ts设置
|
|
5
5
|
|
|
6
6
|
## 和 js 版本相比有什么区别?
|
|
7
|
-
ts
|
|
7
|
+
ts版本拥有更好的类型提示,更严格的类型检查,也可以直接使用node_modules里的库(只能是js/ts)
|
|
8
8
|
|
|
9
9
|
## 听起来太酷了我们开始吧!
|
|
10
|
-
比如我们需要注册一个物品,可能你会想去找它在哪,但在ts版本中,你只需要 `@core` 就可以了
|
|
10
|
+
比如我们需要注册一个物品,可能你会想去找它在哪,但在ts版本中,你只需要 `@sapdon/core` 就可以了
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import { ItemAPI } from '@core
|
|
13
|
+
import { ItemAPI } from '@sapdon/core.js'
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
如果你需要更高级的功能,比如你需要一个ts打包器,或者添加命令行的功能,你可以使用 `@cli`
|
|
16
|
+
如果你需要更高级的功能,比如你需要一个ts打包器,或者添加命令行的功能,你可以使用 `@sapdon/cli`
|
|
17
|
+
|
|
18
|
+
## 从js迁移到ts
|
|
19
|
+
js 的 `main.mjs` 包含了一些预定义的代码:
|
|
20
|
+
```js
|
|
21
|
+
import { startDevServer } from '@sapdon/cli'
|
|
22
|
+
import { GRegistry, UISystemRegistry } from '@sapdon/core'
|
|
23
|
+
|
|
24
|
+
// 开启开发服务器, 不开启开发服务器无法使用文件同步和热更新
|
|
25
|
+
startDevServer(GRegistry, UISystemRegistry)
|
|
26
|
+
```
|
|
27
|
+
如果需要从js迁移到ts,删除 `startDevServer` 那行即可(不删也没事)
|
|
28
|
+
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sapdon",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"main": "dist/core/index.js",
|
|
5
5
|
"types": "dist/core/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"sapdon": "node dist/cli/index.js",
|
|
8
8
|
"create": "node dist/cli/index.js create",
|
|
9
9
|
"build": "node dist/cli/index.js build",
|
|
10
|
-
"
|
|
10
|
+
"pub": "tsc && npm publish"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"bedrock",
|
package/dist/cli/build.d.ts
DELETED
|
@@ -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,232 +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',
|
|
26
|
-
];
|
|
27
|
-
//脚本打包器
|
|
28
|
-
export const scriptBundler = {
|
|
29
|
-
__projectPath: path.join(__dirname, '../../'),
|
|
30
|
-
js: (source, target) => {
|
|
31
|
-
copyFolder(source, target);
|
|
32
|
-
},
|
|
33
|
-
//ts先通过rollup处理后再复制
|
|
34
|
-
ts: async (source, target, tname = 'index.js', sname = 'index.ts') => {
|
|
35
|
-
// console.log(source, target, tname)
|
|
36
|
-
const tmpFile = path.join(scriptBundler.__projectPath, '.tmp', `sapdon-${crypto.randomUUID()}.js`);
|
|
37
|
-
try {
|
|
38
|
-
const bundle = await rollup({
|
|
39
|
-
input: path.join(source, sname),
|
|
40
|
-
plugins: [
|
|
41
|
-
paths(),
|
|
42
|
-
nodeResolve({
|
|
43
|
-
preferBuiltins: true
|
|
44
|
-
}),
|
|
45
|
-
ts({
|
|
46
|
-
tsconfig: path.join(scriptBundler.__projectPath, 'tsconfig.json'),
|
|
47
|
-
}),
|
|
48
|
-
commonjs(),
|
|
49
|
-
json(),
|
|
50
|
-
// visualizer({ open: true }), //可视化分析, 打包出问题取消注释这一行
|
|
51
|
-
],
|
|
52
|
-
external(name) {
|
|
53
|
-
for (const candidate of rollupIgnores) {
|
|
54
|
-
if (name.includes(candidate)) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
await bundle.write({
|
|
62
|
-
file: tmpFile,
|
|
63
|
-
format: 'esm',
|
|
64
|
-
});
|
|
65
|
-
bundle.close();
|
|
66
|
-
fs.cpSync(tmpFile, path.join(target, tname));
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
console.error(e);
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
fs.rmSync(tmpFile, {
|
|
73
|
-
recursive: true,
|
|
74
|
-
force: true
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
async function bundleScripts(projectPath, scriptPath, element) {
|
|
80
|
-
const sourcePath = path.join(projectPath, element.path);
|
|
81
|
-
const elementType = element.type || 'js';
|
|
82
|
-
scriptBundler.__projectPath = projectPath;
|
|
83
|
-
scriptBundler[elementType](sourcePath, scriptPath);
|
|
84
|
-
}
|
|
85
|
-
function preload(filePath) {
|
|
86
|
-
fs.appendFileSync(filePath, `
|
|
87
|
-
;(async () => {
|
|
88
|
-
const { startDevServer } = await import('@sapdon/cli')
|
|
89
|
-
const { GRegistry, UISystemRegistry } = await import('@sapdon/core')
|
|
90
|
-
startDevServer(GRegistry, UISystemRegistry)
|
|
91
|
-
process.send('initialized')
|
|
92
|
-
})();
|
|
93
|
-
`);
|
|
94
|
-
}
|
|
95
|
-
async function runOnChild(targetFilePath) {
|
|
96
|
-
const { promise, resolve } = Promise.withResolvers();
|
|
97
|
-
const child = cp.fork(targetFilePath, { stdio: 'inherit' });
|
|
98
|
-
child.once('message', message => {
|
|
99
|
-
if (message !== 'initialized') {
|
|
100
|
-
child.kill();
|
|
101
|
-
}
|
|
102
|
-
resolve();
|
|
103
|
-
});
|
|
104
|
-
await promise;
|
|
105
|
-
}
|
|
106
|
-
async function runScript(src) {
|
|
107
|
-
if (src.endsWith('.ts')) {
|
|
108
|
-
const randomName = crypto.randomUUID() + '.js';
|
|
109
|
-
const sourceDir = path.dirname(src);
|
|
110
|
-
const sourceFileName = src.replace(sourceDir, '');
|
|
111
|
-
const targetFilePath = path.join(sourceDir, randomName);
|
|
112
|
-
await scriptBundler.ts(sourceDir, sourceDir, randomName, sourceFileName);
|
|
113
|
-
preload(targetFilePath);
|
|
114
|
-
try {
|
|
115
|
-
await runOnChild(targetFilePath);
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
fs.rmSync(targetFilePath, { force: true });
|
|
119
|
-
}
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
await runOnChild(src);
|
|
123
|
-
}
|
|
124
|
-
export function projectCanBuild(projectPath, projectName) {
|
|
125
|
-
console.log("开始构建项目");
|
|
126
|
-
console.log("项目路径:" + projectPath);
|
|
127
|
-
//检查项目是否存在
|
|
128
|
-
if (pathNotExist(projectPath)) {
|
|
129
|
-
console.log("项目不存在");
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
//检查项目是否有build.config文件
|
|
133
|
-
if (pathNotExist(path.join(projectPath, "build.config"))) {
|
|
134
|
-
console.log("项目没有build.config文件");
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
//构建项目
|
|
140
|
-
/**
|
|
141
|
-
* `client`
|
|
142
|
-
*
|
|
143
|
-
* 在使用前使用 `projectCanBuild` 确保项目可以构建
|
|
144
|
-
* @param {string} projectPath
|
|
145
|
-
* @param {string} projectName
|
|
146
|
-
*/
|
|
147
|
-
export const buildProject = async (projectPath, projectName) => {
|
|
148
|
-
//读取build.config文件
|
|
149
|
-
const buildConfigPath = path.join(projectPath, "build.config");
|
|
150
|
-
const buildConfig = JSON.parse(readFile(buildConfigPath));
|
|
151
|
-
//console.log(buildConfig)
|
|
152
|
-
//读取mod.info文件
|
|
153
|
-
const modInfoPath = path.join(projectPath, "mod.info");
|
|
154
|
-
const modInfo = JSON.parse(readFile(modInfoPath));
|
|
155
|
-
const min_engine_version = versionStringToArray(modInfo.min_engine_version);
|
|
156
|
-
const buildDirPath = path.join(projectPath, buildConfig.defaultConfig.buildDir);
|
|
157
|
-
const buildBehDirPath = path.join(buildDirPath, `${projectName}_BP/`);
|
|
158
|
-
const buildResDirPath = path.join(buildDirPath, `${projectName}_RP/`);
|
|
159
|
-
//生成manifest.json文件
|
|
160
|
-
//判断manifest.json是否已经生成过了,生成过了就不用生成
|
|
161
|
-
const manifestPath = path.join(buildBehDirPath, "manifest.json");
|
|
162
|
-
if (pathNotExist(manifestPath)) {
|
|
163
|
-
const behManifest = generateBehManifest(modInfo.name, modInfo.description, modInfo.version, {
|
|
164
|
-
min_engine_version: min_engine_version,
|
|
165
|
-
}, buildConfig.defaultConfig.dependencies, buildConfig.defaultConfig.scriptEntry);
|
|
166
|
-
const resManifest = generateResManifest(modInfo.name, modInfo.description, modInfo.version, {
|
|
167
|
-
min_engine_version: min_engine_version,
|
|
168
|
-
}, []);
|
|
169
|
-
//BP
|
|
170
|
-
saveFile(path.join(buildBehDirPath, "manifest.json"), behManifest);
|
|
171
|
-
//RP
|
|
172
|
-
saveFile(path.join(buildResDirPath, "manifest.json"), resManifest);
|
|
173
|
-
}
|
|
174
|
-
//复制pack_icon.png
|
|
175
|
-
const packIconPath = path.join(projectPath, "pack_icon.png");
|
|
176
|
-
copyFileSync(packIconPath, path.join(buildBehDirPath, "pack_icon.png"));
|
|
177
|
-
copyFileSync(packIconPath, path.join(buildResDirPath, "pack_icon.png"));
|
|
178
|
-
const resources = buildConfig.resources;
|
|
179
|
-
resources.forEach(element => {
|
|
180
|
-
const sourcePath = path.join(projectPath, element.path);
|
|
181
|
-
copyFolder(sourcePath, buildResDirPath);
|
|
182
|
-
});
|
|
183
|
-
const scripts = buildConfig.scripts;
|
|
184
|
-
const scriptPath = path.join(buildBehDirPath, "scripts/");
|
|
185
|
-
for (const element of scripts) {
|
|
186
|
-
await bundleScripts(projectPath, scriptPath, element);
|
|
187
|
-
}
|
|
188
|
-
const absoluteModPath = path.join(projectPath, buildConfig.defaultConfig.buildEntry);
|
|
189
|
-
await runScript(absoluteModPath);
|
|
190
|
-
//只有当buildMode为development时才加载用户modjs文件
|
|
191
|
-
if (buildConfig.defaultConfig.buildMode === "development") {
|
|
192
|
-
//动态加载用户modjs文件
|
|
193
|
-
await generateAddonClient(absoluteModPath, buildDirPath, projectName);
|
|
194
|
-
}
|
|
195
|
-
syncDevFilesClient(projectPath, projectName);
|
|
196
|
-
if (buildConfig.useHMR === true) {
|
|
197
|
-
hmr(projectPath, projectName);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
function versionStringToArray(versionString) {
|
|
201
|
-
// 使用 split 方法将字符串按 '.' 分割成数组
|
|
202
|
-
const parts = versionString.split('.');
|
|
203
|
-
// 使用 map 方法将每个部分转换为数字
|
|
204
|
-
const versionArray = parts.map(part => Number(part));
|
|
205
|
-
return versionArray;
|
|
206
|
-
}
|
|
207
|
-
const generateBehManifest = (name, description, version, options = {}, dependencies = [], entry) => {
|
|
208
|
-
console.log("开始生成behavior_packs/manifest.json");
|
|
209
|
-
console.log("Entry:", entry);
|
|
210
|
-
const header = new AddonManifestHeader((name + "_BP"), description, versionStringToArray(version), generateUUID(), options);
|
|
211
|
-
const module = new AddonManifestModule("行为模块", "data", generateUUID(), versionStringToArray(version));
|
|
212
|
-
const script_module = new AddonManifestModule("脚本模块", "script", generateUUID(), versionStringToArray(version));
|
|
213
|
-
if (entry) {
|
|
214
|
-
script_module.entry = entry;
|
|
215
|
-
}
|
|
216
|
-
const metadata = new AddonManifestMetadata(["@sapdon"], "MIT", {
|
|
217
|
-
"sapdon": ["1.0.0"]
|
|
218
|
-
}, "addon", "https://github.com/junjun260/sapdon");
|
|
219
|
-
const manifest = new AddonManifest(2, //格式版本
|
|
220
|
-
header, [module, script_module], dependencies, null, metadata);
|
|
221
|
-
return JSON.stringify(manifest, null, 2);
|
|
222
|
-
};
|
|
223
|
-
const generateResManifest = (name, description, version, options = {}, dependencies = []) => {
|
|
224
|
-
const header = new AddonManifestHeader((name + "_RP"), description, versionStringToArray(version), generateUUID(), options);
|
|
225
|
-
const module = new AddonManifestModule("资源模块", "resources", generateUUID(), versionStringToArray(version));
|
|
226
|
-
const metadata = new AddonManifestMetadata(["@sapdon"], "MIT", {
|
|
227
|
-
"sapdon": ["1.0.0"]
|
|
228
|
-
}, "addon", "https://github.com/junjun260/sapdon");
|
|
229
|
-
const manifest = new AddonManifest(2, //格式版本
|
|
230
|
-
header, [module], [], null, metadata);
|
|
231
|
-
return JSON.stringify(manifest, null, 2);
|
|
232
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { devServerConfig } from './config.js';
|
|
2
|
-
const { port } = devServerConfig;
|
|
3
|
-
export async function cliRequest(path, ...params) {
|
|
4
|
-
try {
|
|
5
|
-
await fetch(`http://localhost:${port}/${path}`, {
|
|
6
|
-
method: 'POST',
|
|
7
|
-
headers: {
|
|
8
|
-
'Content-Type': 'application/json'
|
|
9
|
-
},
|
|
10
|
-
body: JSON.stringify(params)
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
console.error(error);
|
|
15
|
-
console.error('尝试在构建脚本中使用 server.startDevServer() 启动开发服务器');
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export async function writeAddon(modPath, buildPath, projectName) {
|
|
19
|
-
await cliRequest('write-addon', modPath, buildPath, projectName);
|
|
20
|
-
}
|
|
@@ -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,11 +0,0 @@
|
|
|
1
|
-
import { generateAddon } from "../load.js";
|
|
2
|
-
import { bootstrap, isListening, server } from "./server.js";
|
|
3
|
-
import { syncDevFilesServer } from "./syncFiles.js";
|
|
4
|
-
export function startDevServer(GRegistry, UIRegistry) {
|
|
5
|
-
if (!isListening()) {
|
|
6
|
-
bootstrap();
|
|
7
|
-
server.handle('write-addon', generateAddon(GRegistry, UIRegistry));
|
|
8
|
-
server.handle('sync-files', syncDevFilesServer);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export { server, };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import http from 'http';
|
|
2
|
-
import { devServerConfig } from './config.js';
|
|
3
|
-
const { port } = devServerConfig;
|
|
4
|
-
const cliServerHandlers = new Map();
|
|
5
|
-
let listening = false;
|
|
6
|
-
export function isListening() {
|
|
7
|
-
return listening;
|
|
8
|
-
}
|
|
9
|
-
// server
|
|
10
|
-
export function bootstrap() {
|
|
11
|
-
listening = true;
|
|
12
|
-
const svr = http.createServer(async (req, res) => {
|
|
13
|
-
const handler = 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', () => listening = false);
|
|
44
|
-
return svr;
|
|
45
|
-
}
|
|
46
|
-
export const server = {
|
|
47
|
-
handle(url, handler) {
|
|
48
|
-
cliServerHandlers.set(url, handler);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
@@ -1,36 +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
|
-
export async function syncDevFilesClient(projectPath, projectName) {
|
|
7
|
-
await cliRequest('sync-files', projectPath, projectName);
|
|
8
|
-
}
|
|
9
|
-
export async function syncDevFilesServer(projectPath, projectName) {
|
|
10
|
-
const buildConfig = JSON.parse(readFileSync(path.join(projectPath, "build.config")));
|
|
11
|
-
const buildDir = path.join(projectPath, buildConfig.defaultConfig.buildDir);
|
|
12
|
-
const buildBehDirPath = path.join(buildDir, `${projectName}_BP`);
|
|
13
|
-
const buildResDirPath = path.join(buildDir, `${projectName}_RP`);
|
|
14
|
-
copyFolder(buildBehDirPath, path.join(buildConfig.mojangPath, "development_behavior_packs/", `${projectName}_BP/`));
|
|
15
|
-
copyFolder(buildResDirPath, path.join(buildConfig.mojangPath, "development_resource_packs/", `${projectName}_RP/`));
|
|
16
|
-
}
|
|
17
|
-
export async function writeLib(projectPath) {
|
|
18
|
-
const projectModules = path.join(projectPath, "node_modules");
|
|
19
|
-
const rootDir = path.join(dirname(import.meta), '../../');
|
|
20
|
-
const corePath = path.join(rootDir, 'core');
|
|
21
|
-
const cliPath = path.join(rootDir, 'cli');
|
|
22
|
-
const targetCorePath = path.join(projectModules, '@sapdon/core');
|
|
23
|
-
const targetCliPath = path.join(projectModules, '@sapdon/cli');
|
|
24
|
-
fs.cpSync(corePath, targetCorePath, { recursive: true, force: true });
|
|
25
|
-
fs.cpSync(cliPath, targetCliPath, { recursive: true, force: true });
|
|
26
|
-
fs.writeFileSync(path.join(targetCorePath, 'package.json'), JSON.stringify({
|
|
27
|
-
name: '@sapdon/core',
|
|
28
|
-
main: 'index.js',
|
|
29
|
-
version: '1.0.0',
|
|
30
|
-
}));
|
|
31
|
-
fs.writeFileSync(path.join(targetCliPath, 'package.json'), JSON.stringify({
|
|
32
|
-
name: '@sapdon/cli',
|
|
33
|
-
main: 'index.js',
|
|
34
|
-
version: '1.0.0',
|
|
35
|
-
}));
|
|
36
|
-
}
|
package/dist/cli/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { server as devServer, startDevServer } from "./dev-server/index.js";
|
package/dist/cli/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { server as devServer, startDevServer, } from './dev-server/index.js';
|
package/dist/cli/init.d.ts
DELETED
|
@@ -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
|
-
};
|
package/dist/cli/init.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
import { pathNotExist, copyFolder, saveFile } from './utils.js';
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import cp from "child_process";
|
|
6
|
-
import os from "os";
|
|
7
|
-
// 获取当前文件的路径
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
// 获取当前文件的目录
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
const templateMapping = {
|
|
12
|
-
js: 'test_sapdon',
|
|
13
|
-
ts: 'ts_sapdon'
|
|
14
|
-
};
|
|
15
|
-
export function initMojangPath(projectPath) {
|
|
16
|
-
const mojangPath = path.join(os.homedir(), "AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/");
|
|
17
|
-
const betaPath = path.join(os.homedir(), "AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/");
|
|
18
|
-
const buildConfigPath = path.join(projectPath, './build.config');
|
|
19
|
-
const buildConfig = JSON.parse(fs.readFileSync(buildConfigPath));
|
|
20
|
-
buildConfig.mojangPath = mojangPath;
|
|
21
|
-
buildConfig.betaPath = betaPath;
|
|
22
|
-
saveFile(buildConfigPath, JSON.stringify(buildConfig, null, 2));
|
|
23
|
-
}
|
|
24
|
-
export const initProject = (projectPath, data) => {
|
|
25
|
-
console.log(1, data);
|
|
26
|
-
//检查项目目录是否存在
|
|
27
|
-
//如果不存在则创建项目目录
|
|
28
|
-
//从模板下载项目文件
|
|
29
|
-
//根据用户输入的项目信息生成项目配置文件
|
|
30
|
-
//根据用户选择是否生成脚本文件,生成脚本文件
|
|
31
|
-
if (!pathNotExist(projectPath)) {
|
|
32
|
-
console.log("项目名称已存在,创建项目目录失败");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
//模版目录
|
|
36
|
-
const templateDir = path.join(__dirname, `../../src/templates/${templateMapping[data.language || 'js']}`);
|
|
37
|
-
copyFolder(templateDir, projectPath);
|
|
38
|
-
//生成模组介绍文件
|
|
39
|
-
saveFile(path.join(projectPath, "mod.info"), JSON.stringify(data, null, 2));
|
|
40
|
-
//执行npm i
|
|
41
|
-
cp.execSync('npm i', { cwd: projectPath, stdio: 'inherit' });
|
|
42
|
-
};
|
|
43
|
-
export const initNPMProject = (projectPath, data) => {
|
|
44
|
-
//检查项目文件是否存在
|
|
45
|
-
//如果不存在则创建项目
|
|
46
|
-
//从模板下载项目文件
|
|
47
|
-
//根据用户输入的项目信息生成项目配置文件
|
|
48
|
-
//根据用户选择是否生成脚本文件,生成脚本文件
|
|
49
|
-
if (!pathNotExist(path.join(projectPath, "mod.info")) || !pathNotExist(path.join(projectPath, "main.mjs")) || !pathNotExist(path.join(projectPath, "scripts")) || !pathNotExist(path.join(projectPath, "build.config"))) {
|
|
50
|
-
console.log("项目已存在...");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
//模版目录
|
|
54
|
-
const templateDir = path.join(__dirname, "../templates/test_sapdon");
|
|
55
|
-
copyFolder(templateDir, projectPath);
|
|
56
|
-
//生成模组介绍文件
|
|
57
|
-
saveFile(path.join(projectPath, "mod.info"), JSON.stringify(data, null, 2));
|
|
58
|
-
};
|
|
59
|
-
// 读取package.json文件并提取信息
|
|
60
|
-
export const readPackageJson = (dir) => {
|
|
61
|
-
const packageJsonPath = path.join(dir, 'package.json');
|
|
62
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
63
|
-
try {
|
|
64
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
65
|
-
return {
|
|
66
|
-
name: path.basename(dir),
|
|
67
|
-
description: packageJson.description || "A new sapdon project",
|
|
68
|
-
author: packageJson.author || "Sapdon",
|
|
69
|
-
version: packageJson.version || "1.0.0"
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.error("读取package.json文件时出错:", error);
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
};
|
package/dist/cli/load.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export function processBlocksData(data: any): any;
|
|
2
|
-
export function generateAddonClient(modPath: any, buildPath: any, projectName: any): Promise<void>;
|
|
3
|
-
export function generateAddon(GRegistry: any, UISystemRegistry: any): (modPath: any, buildPath: any, projectName: any) => Promise<void>;
|