mbler 0.1.1 → 0.1.3-alpha
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/LICENSE +21 -0
- package/README.md +28 -0
- package/lib/build/base.js +297 -1
- package/lib/build/build-g-config.json +11 -11
- package/lib/build/getModule.js +182 -1
- package/lib/build/index.js +370 -1
- package/lib/build/manifest.build.js +103 -1
- package/lib/build/mcVersion.js +86 -1
- package/lib/build/utils.js +6 -1
- package/lib/code-processor/c-handler-export.js +12 -1
- package/lib/code-processor/index.js +141 -1
- package/lib/code-processor/mtreehandler.js +164 -1
- package/lib/commander/index.js +154 -1
- package/lib/data/includes.json +12 -12
- package/lib/git/clone.js +28 -1
- package/lib/git/index.js +12 -1
- package/lib/git/pull.js +100 -1
- package/lib/lang/__translate.js +93 -1
- package/lib/lang/en.js +128 -1
- package/lib/lang/index.js +78 -1
- package/lib/lang/zh.js +146 -1
- package/lib/loger/colors.js +13 -1
- package/lib/loger/index.js +136 -1
- package/lib/mcx/ast/index.js +11 -1
- package/lib/mcx/ast/prop.js +78 -1
- package/lib/mcx/ast/tag.js +246 -1
- package/lib/mcx/compile-component/lib.js +106 -1
- package/lib/mcx/compile-component/types.js +2 -1
- package/lib/mcx/compile-component/utils.js +26 -1
- package/lib/mcx/compile-mcx/_compile.js +1 -1
- package/lib/mcx/compile-mcx/compile.js +34 -1
- package/lib/mcx/compile-mcx/context.js +19 -1
- package/lib/mcx/compile-mcx/index.js +10 -1
- package/lib/mcx/compile-mcx/mcx/index.js +2 -1
- package/lib/mcx/compile-mcx/mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/template/module.js +42 -1
- package/lib/mcx/compile-mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/utils.node.js +207 -1
- package/lib/mcx/index.js +13 -1
- package/lib/mcx/test/index.js +7 -1
- package/lib/mcx/test.js +21 -1
- package/lib/mcx/types.js +2 -1
- package/lib/mcx/utils.js +86 -1
- package/lib/module-handler/index.js +482 -1
- package/lib/modules/create-game/src/Runner/RunnerManager.js +113 -1
- package/lib/modules/create-game/src/Runner/scriptRunner.js +70 -1
- package/lib/modules/create-game/src/config.js +27 -1
- package/lib/modules/create-game/src/constants.js +19 -1
- package/lib/modules/create-game/src/createGameModule.js +24 -1
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +38 -1
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +76 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +90 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +87 -1
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +53 -1
- package/lib/modules/create-game/src/gameComponent/index.js +31 -1
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +40 -1
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +22 -1
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +59 -1
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +69 -1
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +53 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +71 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +20 -1
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +77 -1
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +83 -1
- package/lib/modules/create-game/src/gameContext.js +6 -1
- package/lib/modules/create-game/src/gameEngine.js +139 -1
- package/lib/modules/create-game/src/gameEvent/eventManager.js +108 -1
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +28 -1
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +41 -1
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +77 -1
- package/lib/modules/create-game/src/gameEvent/events/interval.js +51 -1
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +36 -1
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +106 -1
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +105 -1
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +45 -1
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +54 -1
- package/lib/modules/create-game/src/gameEvent/index.js +20 -1
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +101 -1
- package/lib/modules/create-game/src/gameEvent/subscription.js +17 -1
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +102 -1
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +38 -1
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +96 -1
- package/lib/modules/create-game/src/gamePlayer/index.js +25 -1
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +145 -1
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +57 -1
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +229 -1
- package/lib/modules/create-game/src/gameRegion/index.js +43 -1
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +79 -1
- package/lib/modules/create-game/src/gameState/common/autoStop.js +39 -1
- package/lib/modules/create-game/src/gameState/gameState.js +169 -1
- package/lib/modules/create-game/src/gameState/index.js +7 -1
- package/lib/modules/create-game/src/gameState/types.js +35 -1
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +36 -1
- package/lib/modules/create-game/src/main.js +86 -1
- package/lib/modules/create-game/src/system/gameCommand.js +107 -1
- package/lib/modules/create-game/src/system/gameManager.js +124 -1
- package/lib/modules/create-game/src/system/globalPlayerManager.js +119 -1
- package/lib/modules/create-game/src/utils/GameError.js +31 -1
- package/lib/modules/create-game/src/utils/algorithm.js +95 -1
- package/lib/modules/create-game/src/utils/chunk.js +63 -1
- package/lib/modules/create-game/src/utils/deferredObject.js +27 -1
- package/lib/modules/create-game/src/utils/duration.js +25 -1
- package/lib/modules/create-game/src/utils/func.js +20 -1
- package/lib/modules/create-game/src/utils/index.js +52 -1
- package/lib/modules/create-game/src/utils/interfaces.js +2 -1
- package/lib/modules/create-game/src/utils/logger.js +47 -1
- package/lib/modules/create-game/src/utils/random.js +76 -1
- package/lib/modules/create-game/src/utils/vanila-data.js +123 -1
- package/lib/modules/create-game/src/utils/vector.js +96 -1
- package/lib/modules/gameLib/src/config.js +134 -1
- package/lib/modules/gameLib/src/data.js +77 -1
- package/lib/modules/gameLib/src/entity.js +256 -1
- package/lib/modules/gameLib/src/event.js +285 -1
- package/lib/modules/gameLib/src/index.js +20 -1
- package/lib/modules/gameLib/src/loger.js +21 -1
- package/lib/modules/gameLib/src/ui.js +209 -1
- package/lib/modules/gameLib/src/utils.js +122 -1
- package/lib/modules/gutils/src/index.js +22 -1
- package/lib/runTemp/File.js +54 -1
- package/lib/runTemp/index.js +137 -1
- package/lib/runTemp/securityFile.js +93 -1
- package/lib/start/addPack.js +3 -1
- package/lib/start/clean.js +84 -1
- package/lib/start/create.js +146 -1
- package/lib/start/dev.js +99 -1
- package/lib/start/getResConfig.js +3 -1
- package/lib/start/incg.js +3 -1
- package/lib/start/index.js +207 -1
- package/lib/start/init.js +125 -1
- package/lib/start/rechce.js +57 -1
- package/lib/start/unaddPack.js +3 -1
- package/lib/start/unincg.js +67 -1
- package/lib/start/version.js +73 -1
- package/lib/utils/index.js +298 -1
- package/lib/uuid/index.js +27 -1
- package/package.json +1 -1
- package/test/script-mbler/behavior/scripts/index.js +0 -5
|
@@ -1 +1,141 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.default = processor;
|
|
40
|
+
const fs = __importStar(require("fs/promises"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const utils = __importStar(require("../utils/index.js"));
|
|
43
|
+
const c_handler_export_1 = __importDefault(require("./c-handler-export"));
|
|
44
|
+
const terser_1 = require("terser");
|
|
45
|
+
const getModule_js_1 = __importDefault(require("../build/getModule.js"));
|
|
46
|
+
let gamelib_modules;
|
|
47
|
+
let forInscript = false;
|
|
48
|
+
/**
|
|
49
|
+
* 替换模块 import 路径
|
|
50
|
+
*/
|
|
51
|
+
async function replaceModuleImports(code, modules, targetDir, sourceDir) {
|
|
52
|
+
const im = (0, c_handler_export_1.default)(code);
|
|
53
|
+
if (Array.isArray(modules)) {
|
|
54
|
+
const imports = im.get();
|
|
55
|
+
if (imports.length < 1)
|
|
56
|
+
return code;
|
|
57
|
+
for (const item of modules) {
|
|
58
|
+
const moduleDir = await gamelib_modules.getDir(item);
|
|
59
|
+
const main = (await utils.handlerPackage(moduleDir)).main;
|
|
60
|
+
const relPath = path
|
|
61
|
+
.relative(path.dirname(targetDir), path.join(sourceDir, 'node_modules', path.basename(moduleDir), main))
|
|
62
|
+
.split(path.sep).join('/');
|
|
63
|
+
const found = imports.find((imp) => imp.ModuleName === item);
|
|
64
|
+
if (found)
|
|
65
|
+
im.set({
|
|
66
|
+
ModuleName: `./${relPath}`,
|
|
67
|
+
ImportItem: found.ImportItem
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return im.generate();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 处理单个文件
|
|
75
|
+
*/
|
|
76
|
+
async function processFile(filePath, modules, sourceDir, shouldMinify) {
|
|
77
|
+
try {
|
|
78
|
+
const ext = path.extname(filePath).slice(1);
|
|
79
|
+
const code = await fs.readFile(filePath, "utf-8");
|
|
80
|
+
switch (ext) {
|
|
81
|
+
case 'js':
|
|
82
|
+
let replaced = await replaceModuleImports(code, modules, filePath, sourceDir);
|
|
83
|
+
if (shouldMinify === true) {
|
|
84
|
+
const result = await (0, terser_1.minify)(replaced);
|
|
85
|
+
if (result.code)
|
|
86
|
+
replaced = result.code;
|
|
87
|
+
}
|
|
88
|
+
await fs.writeFile(filePath, replaced, 'utf-8');
|
|
89
|
+
break;
|
|
90
|
+
case 'json':
|
|
91
|
+
let re = code;
|
|
92
|
+
if (shouldMinify === true) {
|
|
93
|
+
const json = utils.JSONparse(code);
|
|
94
|
+
re = JSON.stringify(json);
|
|
95
|
+
if (forInscript) {
|
|
96
|
+
await Promise.all([
|
|
97
|
+
fs.writeFile(`${filePath}.js`, `export const data=${re}`),
|
|
98
|
+
fs.rm(filePath, { recursive: true, force: true })
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
case 'map':
|
|
104
|
+
case 'ts':
|
|
105
|
+
await fs.rm(filePath, { recursive: true, force: true });
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.log(filePath, err.message);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 递归遍历并处理文件
|
|
115
|
+
*/
|
|
116
|
+
async function processDir(targetDir, modules, sourceDir, baseDir, shouldMinify) {
|
|
117
|
+
const stat = await fs.stat(targetDir);
|
|
118
|
+
gamelib_modules = await (0, getModule_js_1.default)(baseDir);
|
|
119
|
+
let inScriptTemp = false;
|
|
120
|
+
if (stat.isDirectory()) {
|
|
121
|
+
const files = await fs.readdir(targetDir);
|
|
122
|
+
if (path.basename(targetDir) === "scripts") {
|
|
123
|
+
forInscript = true;
|
|
124
|
+
inScriptTemp = true;
|
|
125
|
+
}
|
|
126
|
+
for (const file of files) {
|
|
127
|
+
await processDir(path.join(targetDir, file), modules, sourceDir, baseDir, shouldMinify);
|
|
128
|
+
}
|
|
129
|
+
if (forInscript && inScriptTemp)
|
|
130
|
+
forInscript = false;
|
|
131
|
+
}
|
|
132
|
+
else if (stat.isFile()) {
|
|
133
|
+
await processFile(targetDir, modules, sourceDir, shouldMinify);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
console.warn(`跳过未知类型:${targetDir}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function processor(targetDir, options) {
|
|
140
|
+
await processDir(targetDir, options.modules || [], options.sourceDir, options.baseDir, options.minify);
|
|
141
|
+
}
|
|
@@ -1 +1,164 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const parser_1 = require("@babel/parser");
|
|
40
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
41
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
42
|
+
const types = __importStar(require("@babel/types"));
|
|
43
|
+
class ImportManager {
|
|
44
|
+
code;
|
|
45
|
+
ast;
|
|
46
|
+
imports;
|
|
47
|
+
constructor(code) {
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.ast = null;
|
|
50
|
+
this.imports = [];
|
|
51
|
+
this._parse();
|
|
52
|
+
}
|
|
53
|
+
_parse() {
|
|
54
|
+
if (!this.code) {
|
|
55
|
+
this.ast = { program: { body: [] } };
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// 解析源码为 AST
|
|
59
|
+
this.ast = (0, parser_1.parse)(this.code, {
|
|
60
|
+
sourceType: 'module'
|
|
61
|
+
});
|
|
62
|
+
this._collectImports();
|
|
63
|
+
}
|
|
64
|
+
_collectImports() {
|
|
65
|
+
this.imports = [];
|
|
66
|
+
(0, traverse_1.default)(this.ast, {
|
|
67
|
+
ImportDeclaration: (path) => {
|
|
68
|
+
const source = path.node.source.value;
|
|
69
|
+
const specifiers = path.node.specifiers.map(specifier => {
|
|
70
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
71
|
+
return specifier.local.name;
|
|
72
|
+
}
|
|
73
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
74
|
+
if (specifier.imported.type == "Identifier")
|
|
75
|
+
return specifier.imported.name;
|
|
76
|
+
return specifier.imported.value;
|
|
77
|
+
}
|
|
78
|
+
else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
79
|
+
return '*' + specifier.local.name; // * as name
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}).filter(name => name !== null);
|
|
83
|
+
this.imports.push({
|
|
84
|
+
moduleName: source,
|
|
85
|
+
importItem: specifiers
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// 检查是否导入了某个包
|
|
91
|
+
has(moduleName) {
|
|
92
|
+
return this.imports
|
|
93
|
+
.some(imp => imp.moduleName === moduleName);
|
|
94
|
+
}
|
|
95
|
+
// 返回所有导入包
|
|
96
|
+
get() {
|
|
97
|
+
return this.imports.map(imp => ({
|
|
98
|
+
ModuleName: imp.moduleName,
|
|
99
|
+
ImportItem: [...imp.importItem]
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
// 设置/修改导入项
|
|
103
|
+
set({ ModuleName, ImportItem }) {
|
|
104
|
+
// 查找是否已有该包,或有相同的包名或导入项
|
|
105
|
+
const exists = this.imports.findIndex(imp => imp.moduleName === ModuleName ||
|
|
106
|
+
imp.importItem.some(item => ImportItem.includes(item)));
|
|
107
|
+
if (exists > -1) {
|
|
108
|
+
// 修改已存在的项
|
|
109
|
+
this.imports[exists] = {
|
|
110
|
+
moduleName: ModuleName,
|
|
111
|
+
importItem: [...ImportItem]
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// 新增
|
|
116
|
+
this.imports.push({
|
|
117
|
+
moduleName: ModuleName,
|
|
118
|
+
importItem: [...ImportItem]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// 同步更新 AST
|
|
122
|
+
this._syncAST();
|
|
123
|
+
}
|
|
124
|
+
// 同步 imports 数据到 AST
|
|
125
|
+
_syncAST() {
|
|
126
|
+
// 先删除所有 import 声明
|
|
127
|
+
(0, traverse_1.default)(this.ast, {
|
|
128
|
+
ImportDeclaration(path) {
|
|
129
|
+
path.remove();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
// 重新插入 import 声明
|
|
133
|
+
this.imports.forEach(imp => {
|
|
134
|
+
const specifiers = [];
|
|
135
|
+
imp.importItem.forEach(name => {
|
|
136
|
+
if (name === '*') {
|
|
137
|
+
// 处理 * as xx 的情况
|
|
138
|
+
const match = name.match(/\*\s+as\s+(\w+)/) || [];
|
|
139
|
+
if (match)
|
|
140
|
+
specifiers.push(types.importNamespaceSpecifier(types.identifier(match[1] || "")));
|
|
141
|
+
}
|
|
142
|
+
else if (name.endsWith('*')) {
|
|
143
|
+
// 默认导入
|
|
144
|
+
specifiers
|
|
145
|
+
.push(types.importDefaultSpecifier(types.identifier(name.replace('*', ''))));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
specifiers
|
|
149
|
+
.push(types.importSpecifier(types.identifier(name), types.identifier(name)));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
// 构造 ImportDeclaration 节点
|
|
153
|
+
const importNode = types.importDeclaration(specifiers, types.stringLiteral(imp.moduleName));
|
|
154
|
+
this.ast.program.body.unshift(importNode);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
// 生成最终代码
|
|
158
|
+
generate() {
|
|
159
|
+
return (0, generator_1.default)(this.ast, {
|
|
160
|
+
compact: false
|
|
161
|
+
}).code;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.default = ImportManager;
|
package/lib/commander/index.js
CHANGED
|
@@ -1 +1,154 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
// input-handler.ts
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.Input = void 0;
|
|
38
|
+
const readline = __importStar(require("readline"));
|
|
39
|
+
// 启用 raw mode 和键盘事件
|
|
40
|
+
process.stdin.setRawMode(true);
|
|
41
|
+
readline.emitKeypressEvents(process.stdin);
|
|
42
|
+
const promises = [];
|
|
43
|
+
const tasks = [];
|
|
44
|
+
process.on('exit', (code) => {
|
|
45
|
+
process.stdout.write('\x1b[?25h');
|
|
46
|
+
});
|
|
47
|
+
click("c", {
|
|
48
|
+
ctrl: true
|
|
49
|
+
}).then(() => process.exit(0));
|
|
50
|
+
/**
|
|
51
|
+
* 监听键盘输入并触发对应的 Promise 或任务
|
|
52
|
+
*/
|
|
53
|
+
function handler(name, { ctrl, alt }, raw) {
|
|
54
|
+
// 查找是否有匹配的 Promise 等待触发
|
|
55
|
+
const find = promises.find((e) => e.name === name && e.ctrl === ctrl && e.alt === alt);
|
|
56
|
+
if (find) {
|
|
57
|
+
find.resolve();
|
|
58
|
+
promises.splice(promises.indexOf(find), 1);
|
|
59
|
+
}
|
|
60
|
+
// 通知所有注册的监听任务
|
|
61
|
+
tasks.forEach((item) => item(name, ctrl, alt, raw));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 模拟等待某个按键被按下,返回一个 Promise
|
|
65
|
+
*/
|
|
66
|
+
function click(name, { ctrl = false, alt = false }) {
|
|
67
|
+
return new Promise((resolve) => {
|
|
68
|
+
promises.push({
|
|
69
|
+
name,
|
|
70
|
+
ctrl: ctrl || false,
|
|
71
|
+
alt: alt || false,
|
|
72
|
+
resolve
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 工具类:提供控制台交互功能,比如高亮菜单渲染、交互式选择等
|
|
78
|
+
*/
|
|
79
|
+
class Input {
|
|
80
|
+
/**
|
|
81
|
+
* 渲染一个字符串数组,高亮当前选中的项
|
|
82
|
+
* @param arr 菜单项数组
|
|
83
|
+
* @param index 当前选中索引
|
|
84
|
+
* @returns 格式化后的字符串
|
|
85
|
+
*/
|
|
86
|
+
static render(arr, index) {
|
|
87
|
+
return arr
|
|
88
|
+
.map((item, pindex) => {
|
|
89
|
+
if (pindex === index)
|
|
90
|
+
return '\x1b[1m\x1b[32m' + item + '\x1b[0m'; // 亮绿,高亮
|
|
91
|
+
return '\x1b[1m\x1b[33m' + item + '\x1b[0m'; // 亮黄
|
|
92
|
+
})
|
|
93
|
+
.join(' ');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 提供一个交互式菜单选择器
|
|
97
|
+
* @param tip 提示文本
|
|
98
|
+
* @param arr 选项数组
|
|
99
|
+
* @returns 用户选中的选项内容(Promise<string>)
|
|
100
|
+
*/
|
|
101
|
+
static select(tip, arr) {
|
|
102
|
+
let index = 0;
|
|
103
|
+
let win = false;
|
|
104
|
+
console.log(`\x1b[2K\x1b[47m\x1b[1m\x1b[30m${tip} (按 b 确认,n 键选择下一个) \x1b[0m\x1b[?25l`);
|
|
105
|
+
console.log(Input.render(arr, index) + '\n\x1b[1A');
|
|
106
|
+
const handlerNext = () => {
|
|
107
|
+
if (win)
|
|
108
|
+
return;
|
|
109
|
+
index++;
|
|
110
|
+
if (index >= arr.length)
|
|
111
|
+
index = 0;
|
|
112
|
+
console.log(`\x1b[1A${Input.render(arr, index)}\n\x1b[1A`);
|
|
113
|
+
click('n', {
|
|
114
|
+
ctrl: false,
|
|
115
|
+
alt: false
|
|
116
|
+
}).then(handlerNext);
|
|
117
|
+
};
|
|
118
|
+
return new Promise((resolve) => {
|
|
119
|
+
// 监听 n 按键来切换选项
|
|
120
|
+
click('n', {
|
|
121
|
+
ctrl: false,
|
|
122
|
+
alt: false
|
|
123
|
+
}).then(handlerNext);
|
|
124
|
+
// 监听 b 按键来确认选择
|
|
125
|
+
click('b', {
|
|
126
|
+
ctrl: false,
|
|
127
|
+
alt: false
|
|
128
|
+
}).then(() => {
|
|
129
|
+
win = true;
|
|
130
|
+
process.stdout.
|
|
131
|
+
write('\x1b[?25h');
|
|
132
|
+
resolve(arr[index]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 注册一个全局任务,每次按键都会被调用
|
|
138
|
+
* @param task 回调函数
|
|
139
|
+
*/
|
|
140
|
+
static use(task) {
|
|
141
|
+
tasks.push(task);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.Input = Input;
|
|
145
|
+
// 监听键盘输入事件
|
|
146
|
+
process.stdin.on('keypress', (str, key) => {
|
|
147
|
+
const rawKeyName = key?.name || '';
|
|
148
|
+
const ctrl = Boolean(key?.ctrl);
|
|
149
|
+
const alt = Boolean(key?.alt);
|
|
150
|
+
handler(rawKeyName, {
|
|
151
|
+
ctrl,
|
|
152
|
+
alt
|
|
153
|
+
}, str);
|
|
154
|
+
});
|
package/lib/data/includes.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
]
|
|
2
|
+
"items",
|
|
3
|
+
"entities",
|
|
4
|
+
"texts",
|
|
5
|
+
"pack_icon.png",
|
|
6
|
+
"recipes",
|
|
7
|
+
"functions",
|
|
8
|
+
"loot_tables",
|
|
9
|
+
"blocks",
|
|
10
|
+
"animation_controllers",
|
|
11
|
+
"spawn_rules",
|
|
12
|
+
"animations"
|
|
13
|
+
]
|
package/lib/git/clone.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = gitClone;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
/**
|
|
6
|
+
* 克隆 Git 仓库
|
|
7
|
+
* @param {string} repoUrl - Git 仓库地址
|
|
8
|
+
* @param {string} targetDir - 本地目标目录(如 './my-project')
|
|
9
|
+
* @returns {Promise<void>}
|
|
10
|
+
*/
|
|
11
|
+
function gitClone(repoUrl, targetDir) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const gitProcess = (0, child_process_1.spawn)('git', ['clone', repoUrl, targetDir], {
|
|
14
|
+
stdio: 'inherit',
|
|
15
|
+
});
|
|
16
|
+
gitProcess.on('close', (code) => {
|
|
17
|
+
if (code === 0) {
|
|
18
|
+
resolve(`Git 克隆成功: ${repoUrl} → ${targetDir}`);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
reject(new Error(` Git 克隆失败,退出码: ${code}`));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
gitProcess.on('error', (err) => {
|
|
25
|
+
reject(new Error(`${err.message}`));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
package/lib/git/index.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const clone_js_1 = __importDefault(require("./clone.js"));
|
|
7
|
+
const pull_js_1 = __importDefault(require("./pull.js"));
|
|
8
|
+
class GitRepo {
|
|
9
|
+
static clone = clone_js_1.default;
|
|
10
|
+
static pull = pull_js_1.default;
|
|
11
|
+
}
|
|
12
|
+
exports.default = GitRepo;
|
package/lib/git/pull.js
CHANGED
|
@@ -1 +1,100 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = gitPull;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const index_js_1 = require("./../utils/index.js");
|
|
9
|
+
const index_js_2 = __importDefault(require("./../lang/index.js"));
|
|
10
|
+
/**
|
|
11
|
+
* 拉取 Git 仓库
|
|
12
|
+
* @param {string} repoDir - 本地 Git 仓库目录(如 './my-project')
|
|
13
|
+
* @returns {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
function gitPull(repoDir) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const gitPullProcess = (0, child_process_1.spawn)('git', ['pull'], {
|
|
18
|
+
cwd: repoDir,
|
|
19
|
+
stdio: 'inherit'
|
|
20
|
+
});
|
|
21
|
+
gitPullProcess.on('close', (code) => {
|
|
22
|
+
if (code === 0) {
|
|
23
|
+
console.log(`Git 拉取成功: ${repoDir}`);
|
|
24
|
+
resolve(true);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// 如果失败,检查是否是 "dubious ownership" 错误
|
|
28
|
+
let errorOutput = '';
|
|
29
|
+
const gitPullProcessWithError = (0, child_process_1.spawn)('git', ['pull'], {
|
|
30
|
+
cwd: repoDir,
|
|
31
|
+
stdio: ['ignore', 'pipe', 'pipe'] // 捕获 stderr
|
|
32
|
+
});
|
|
33
|
+
gitPullProcessWithError.stderr.on('data', (data) => {
|
|
34
|
+
errorOutput += data.toString();
|
|
35
|
+
});
|
|
36
|
+
gitPullProcessWithError.on('close', async (code) => {
|
|
37
|
+
if (code !== 0 && errorOutput.includes('dubious ownership')) {
|
|
38
|
+
const tip = index_js_2.default.noGit;
|
|
39
|
+
const answer = await (0, index_js_1.input)(tip);
|
|
40
|
+
if (answer === '1') {
|
|
41
|
+
// 选项 1:仅当前目录可信
|
|
42
|
+
await runGitConfig(`--global --add safe.directory "${repoDir}"`);
|
|
43
|
+
retryGitPull();
|
|
44
|
+
}
|
|
45
|
+
else if (answer === '2') {
|
|
46
|
+
// 选项 2:全局信任所有目录(不推荐)
|
|
47
|
+
await runGitConfig('--global --replace-all safe.directory "*"');
|
|
48
|
+
retryGitPull();
|
|
49
|
+
}
|
|
50
|
+
else if (answer === '3') {
|
|
51
|
+
reject(new Error('用户取消 Git 拉取'));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
reject(new Error('无效的用户输入'));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// 其他错误(非安全限制)
|
|
59
|
+
reject(new Error(`❌ Git 拉取失败,退出码: ${code}\n错误信息: ${errorOutput}`));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
async function retryGitPull() {
|
|
64
|
+
const retryProcess = (0, child_process_1.spawn)('git', ['pull'], {
|
|
65
|
+
cwd: repoDir,
|
|
66
|
+
stdio: 'inherit'
|
|
67
|
+
});
|
|
68
|
+
retryProcess.on('close', (retryCode) => {
|
|
69
|
+
if (retryCode === 0) {
|
|
70
|
+
resolve(true);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
reject(new Error(`❌ Git 拉取重试失败,退出码: ${retryCode}`));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
retryProcess.on('error', (err) => {
|
|
77
|
+
reject(new Error(`❌ 重试执行错误: ${err.message}`));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function runGitConfig(configArgs) {
|
|
83
|
+
return new Promise((configResolve, configReject) => {
|
|
84
|
+
const configProcess = (0, child_process_1.spawn)('git', ['config', ...configArgs.split(' ')], {
|
|
85
|
+
stdio: 'inherit'
|
|
86
|
+
});
|
|
87
|
+
configProcess.on('close', (code) => {
|
|
88
|
+
if (code === 0) {
|
|
89
|
+
configResolve(true);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.warn(`执行 git config 失败(可能不影响后续操作),退出码: ${code}`);
|
|
93
|
+
configResolve(true); // 即使失败也继续尝试 git pull
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
configProcess.on('error', (err) => {
|
|
97
|
+
configResolve(true); // 即使出错也继续尝试 git pull
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|