mbler 0.2.0 → 0.2.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/dist/index.esm.js CHANGED
@@ -1,30 +1,17 @@
1
- import { env, cwd, argv } from 'node:process';
1
+ import { cwd, stdout, argv } from 'node:process';
2
2
  import * as fs$1 from 'node:fs';
3
3
  import fs__default from 'node:fs';
4
4
  import * as path from 'node:path';
5
- import path__default, { isAbsolute } from 'node:path';
5
+ import path__default from 'node:path';
6
6
  import * as fs from 'node:fs/promises';
7
7
  import fs__default$1, { readFile, writeFile, unlink, stat, mkdir, readdir, cp } from 'node:fs/promises';
8
- import os, { tmpdir, homedir } from 'node:os';
8
+ import os, { homedir, tmpdir } from 'node:os';
9
9
  import * as readline from 'readline';
10
10
  import { json } from 'npm-registry-fetch';
11
11
  import { spawn } from 'node:child_process';
12
- import * as mcxDef from '@mbler/mcx-core';
13
- import _chalk from 'chalk';
14
- import jsonPlugin from '@rollup/plugin-json';
15
- import resolvePlugin from '@rollup/plugin-node-resolve';
16
- import minifyPlugin from '@rollup/plugin-terser';
17
- import { watch as watch$1 } from 'chokidar';
18
- import * as rollup from 'rollup';
19
- import crypto from 'node:crypto';
20
- import AdmZip from 'adm-zip';
21
- import commonjs from '@rollup/plugin-commonjs';
22
- import { createMCXLanguagePlugin } from '@mbler/mcx-server';
23
- import typescript from '@rollup/plugin-typescript';
24
- import { runTsc } from '@volar/typescript/lib/quickstart/runTsc';
25
12
 
26
13
  const LanguageNames = ['zh', 'en'];
27
- const cmdList = ['c', 'work', 'help', 'h', 'init', 'version', 'build', 'watch', 'lang', 'set-work-dir'];
14
+ const cmdList = ['c', 'work', 'help', 'h', 'init', 'version', 'build', 'watch', 'lang', 'set-work-dir', 'publish', 'unpublish', 'install', 'uninstall', 'login'];
28
15
  const templateMblerConfig = {
29
16
  name: 'demo',
30
17
  description: 'demo',
@@ -48,12 +35,12 @@ var types = /*#__PURE__*/Object.freeze({
48
35
  templateMblerConfig: templateMblerConfig
49
36
  });
50
37
 
51
- var MBLERVersion = { commit: `commit da7bebe8ce53a502c75fcc7ad53e510fcb233137
38
+ var MBLERVersion = { commit: `commit 81c6f8bb0b33367bd219c7c9168f18ae83e1f2e1
52
39
  Author: Ruanhor <3915264929@qq.com>
53
- Date: Sun Apr 19 12:42:06 2026 +0800
40
+ Date: Sun Apr 19 16:33:01 2026 +0800
54
41
 
55
- feat: use script config when init
56
- `, version: "0.2.0" };
42
+ fix: init and add plan command
43
+ `, version: "0.2.2" };
57
44
 
58
45
  var ZhLang = {
59
46
  description: `MBLER
@@ -78,7 +65,12 @@ git https://github.com/RuanhoR/mbler/`,
78
65
  watch: "mbler watch\n - 启动构建并开启监视模式,文件变化会自动重新构建",
79
66
  lang: 'mbler lang\n- 无参数:显示当前语言\n- 跟 zh 或 en(如 mbler lang en): 设置语言',
80
67
  version: "mbler version - 版本管理命令\n- 无参数:显示当前版本和提交哈希\n- --show=<commit|version>:筛选显示内容\n- <新版本号>:更新package.json和配置文件的版本",
81
- 'set-work-dir': "mbler set-work-dir <on|off>\n - on: 启用工作目录功能\n - off: 禁用工作目录功能,直接使用 process.cwd()"
68
+ 'set-work-dir': "mbler set-work-dir <on|off>\n - on: 启用工作目录功能\n - off: 禁用工作目录功能,直接使用 process.cwd()",
69
+ publish: 'mbler publish\n - 将你的附加包发布到 pmnx\n- 参数:\n- -tag: 版本标签名称',
70
+ uninstall: 'mbler uninstall @<scope>/<name>@version\n从你的游戏中移除一个包',
71
+ install: 'mbler install @<scope>/<name>@version\n将一个包安装到你的游戏中',
72
+ unpublish: 'mbler unpublish @<scope>/<name>@version\n从 pmnx 取消发布一个包',
73
+ login: 'mbler login <?:token>\n使用 token 登录你的 pmnx 账户\n- 如果没有 token,会向你请求'
82
74
  },
83
75
  init: {
84
76
  useUI: '使用UI模块? (y/n): ',
@@ -123,7 +115,12 @@ var enLang = {
123
115
  watch: 'mbler watch\n - run build and enter watch mode; changes will trigger rebuilds',
124
116
  lang: 'mbler lang [?:languare]\n- No args: show current languare\n- languare = "zh” | “en": set languare',
125
117
  version: 'mbler version\n - Version control command\n- No args: Shows version + commit hash\n- --show=<commit|version>: Filters output\n- <new_version>: Updates version in both package.json and config file',
126
- 'set-work-dir': "mbler set-work-dir <on|off>\n - on: Enable work dir feature\n - off: Disable work dir feature, use process.cwd() directly"
118
+ 'set-work-dir': "mbler set-work-dir <on|off>\n - on: Enable work dir feature\n - off: Disable work dir feature, use process.cwd() directly",
119
+ publish: 'mbler publish\n - Publish your package to pmnx\n- Params:\n- -tag: version tag name',
120
+ uninstall: 'mbler uninstall @<scope>/<name>@version\nRemove a package from your game',
121
+ install: 'mbler install @<scope>/<name>@version\nInstall a package to your game',
122
+ unpublish: 'mbler unpublish @<scope>/<name>@version\nUnpublish a package from pmnx',
123
+ login: 'mbler login <?:token>\nUse token login your pmnx account'
127
124
  },
128
125
  init: {
129
126
  useUI: 'Use UI? (y/n): ',
@@ -215,7 +212,7 @@ function Export(lang) {
215
212
  lang.init();
216
213
  Export(lang);
217
214
 
218
- var index$2 = /*#__PURE__*/Object.freeze({
215
+ var index$1 = /*#__PURE__*/Object.freeze({
219
216
  __proto__: null,
220
217
  default: i18n
221
218
  });
@@ -344,7 +341,7 @@ process.stdin.on("keypress", (str, key) => {
344
341
  }, str);
345
342
  });
346
343
 
347
- var index$1 = /*#__PURE__*/Object.freeze({
344
+ var index = /*#__PURE__*/Object.freeze({
348
345
  __proto__: null,
349
346
  Input: Input,
350
347
  click: click,
@@ -352,76 +349,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
352
349
  });
353
350
 
354
351
  const BuildConfig = {
355
- ConfigFile: "mbler.config.js",
356
- salt: {
357
- header: "d61e721d-a2c9-4535-8054-0183bce24767",
358
- sapi: "33e2c698-908f-45ab-8a9f-66018f8486ed",
359
- module: "cbbacfa4-8b1e-4a9c-9cbd-7a0d2e5f0b3c",
360
- },
361
- behavior: "behavior",
362
- resources: "resources",
363
- includes: {
364
- public: {
365
- "pack_icon.png": "file",
366
- "manifest.json": "file",
367
- },
368
- resources: {
369
- "biomes_client.json": "file",
370
- "blocks.json": "file",
371
- "bug_pack_icon.png": "file",
372
- "contents.json": "file",
373
- "loading_messages.json": "file",
374
- "manifest_publish.json": "file",
375
- "signatures.json": "file",
376
- "sounds.json": "file",
377
- "splashes.json": "file",
378
- animation_controllers: "directory",
379
- animations: "directory",
380
- attachables: "directory",
381
- biomes: "directory",
382
- cameras: "directory",
383
- entity: "directory",
384
- fogs: "directory",
385
- font: "directory",
386
- items: "directory",
387
- library: "directory",
388
- materials: "directory",
389
- models: "directory",
390
- particles: "directory",
391
- render_controllers: "directory",
392
- sounds: "directory",
393
- texts: "directory",
394
- textures: "directory",
395
- },
396
- behavior: {
397
- aim_assist: "directory",
398
- animation_controllers: "directory",
399
- animations: "directory",
400
- behavior_trees: "directory",
401
- biomes: "directory",
402
- blocks: "directory",
403
- cameras: "directory",
404
- dimensions: "directory",
405
- entities: "directory",
406
- feature_rules: "directory",
407
- features: "directory",
408
- functions: "directory",
409
- item_catalog: "directory",
410
- items: "directory",
411
- loot_tables: "directory",
412
- recipes: "directory",
413
- scripts: "skip", // special handling
414
- spawn_rules: "directory",
415
- structures: "directory",
416
- texts: "directory",
417
- trading: "directory",
418
- worldgen: "directory",
419
- "contents.json": "file",
420
- "manifest_publish.json": "file",
421
- "signatures.json": "file",
422
- },
423
- },
424
- };
352
+ ConfigFile: "mbler.config.js"};
425
353
 
426
354
  async function FileExsit(file) {
427
355
  try {
@@ -434,19 +362,6 @@ async function FileExsit(file) {
434
362
  }
435
363
  return false;
436
364
  }
437
- function join(baseDir, inputPath) {
438
- return path.isAbsolute(inputPath) ? inputPath : path.join(baseDir, inputPath);
439
- }
440
- async function ReadProjectMblerConfig(project) {
441
- const fileExport = await import(path.join(project, BuildConfig.ConfigFile));
442
- const file = fileExport.default;
443
- for (const key in file) {
444
- if (!(key in templateMblerConfig)) {
445
- throw new Error(`[read config]: read config from '${project}' error: Unexpected '${key}'`);
446
- }
447
- }
448
- return file;
449
- }
450
365
  async function readFileAsJson(filePath) {
451
366
  try {
452
367
  const content = await fs.readFile(filePath, 'utf-8');
@@ -496,12 +411,6 @@ function showText(text, needNextLine = true) {
496
411
  });
497
412
  }
498
413
  }
499
- function stringToNumberArray(str) {
500
- return str
501
- .split('.')
502
- .map((s) => parseInt(s, 10))
503
- .slice(0, 3);
504
- }
505
414
  async function writeJSON(filePath, data) {
506
415
  const content = JSON.stringify(data, null, 2);
507
416
  if (!(await FileExsit(path.dirname(filePath)))) {
@@ -668,28 +577,98 @@ class Logger {
668
577
  }
669
578
  }
670
579
 
671
- // 该模块用于从字符串生成哈希转 uuid
672
- const fromString = (input, salt = '') => {
673
- const combinedInput = salt + input;
674
- const hash = crypto
675
- .createHash('sha256')
676
- .update(combinedInput)
677
- .digest('hex');
678
- const base = hash
679
- .slice(0, 32); // 取前 32 个 hex 字符(16 字节)
680
- const ls = '89ab';
681
- const r = (t) => ls[(combinedInput.length + t + salt.length) % ls.length];
682
- // 构造成标准 UUID v4 格式:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
683
- const uuid = `${base.substring(0, 8)}-${base.substring(8, 12)}-4${base.substring(12, 15)}-8${r(1)}${r(2)}${r(3)}-${base.substring(18, 30)}`;
684
- return uuid;
685
- };
686
- ({
687
- uuid: crypto.randomUUID
688
- });
580
+ async function tryMkdir(point) {
581
+ try {
582
+ await mkdir(point);
583
+ return true;
584
+ }
585
+ catch {
586
+ return false;
587
+ }
588
+ }
589
+ class WorkDirManage {
590
+ cacheDir;
591
+ currentWorkPoint = null;
592
+ enabledPath = path__default.join(homedir(), ".cache/mbler/workdir_enabled.db");
593
+ constructor(cacheDir = path__default.join(homedir(), ".cache/mbler/mp.db")) {
594
+ this.cacheDir = cacheDir;
595
+ }
596
+ async isDisabled() {
597
+ try {
598
+ await readFile(this.enabledPath, "utf-8");
599
+ return false; // 文件存在,表示启用
600
+ }
601
+ catch {
602
+ return true; // 文件不存在,默认禁用
603
+ }
604
+ }
605
+ async setDisabled(disabled) {
606
+ if (!disabled) {
607
+ // 启用:创建文件
608
+ await writeFile(this.enabledPath, "1", { encoding: "utf-8" });
609
+ }
610
+ else {
611
+ try {
612
+ await unlink(this.enabledPath);
613
+ }
614
+ catch {
615
+ // 文件不存在,忽略
616
+ }
617
+ }
618
+ }
619
+ async set(newPointDir) {
620
+ // check
621
+ try {
622
+ const s = await stat(newPointDir);
623
+ if (!s.isDirectory()) {
624
+ throw new Error("Not Dir (0xcvb)");
625
+ }
626
+ }
627
+ catch (err) {
628
+ const code = err.code;
629
+ if (err.message && err.message.includes("0xcvb"))
630
+ return i18n.workdir.nfound;
631
+ if (code == "ENOENT") {
632
+ const res = tryMkdir(newPointDir);
633
+ if (!res) {
634
+ return i18n.workdir.nfound;
635
+ }
636
+ }
637
+ }
638
+ try {
639
+ if (!(await FileExsit(path__default.dirname(this.cacheDir)))) {
640
+ const isC = await tryMkdir(path__default.dirname(this.cacheDir));
641
+ if (!isC)
642
+ return i18n.workdir.nfound;
643
+ }
644
+ await writeFile(this.cacheDir, newPointDir, {
645
+ encoding: "utf-8",
646
+ });
647
+ }
648
+ catch (err) {
649
+ Logger.e("WorkDir", err.stack);
650
+ }
651
+ return i18n.workdir.set + newPointDir;
652
+ }
653
+ async get() {
654
+ if (await this.isDisabled()) {
655
+ return cwd();
656
+ }
657
+ if (this.currentWorkPoint) {
658
+ return this.currentWorkPoint;
659
+ }
660
+ const file = await readFile(this.cacheDir, "utf-8").catch((e) => {
661
+ this.set(cwd());
662
+ return cwd();
663
+ });
664
+ return (this.currentWorkPoint = file);
665
+ }
666
+ }
689
667
 
690
668
  const config = {
691
669
  tmpdir: path.join(tmpdir(), ".mbler"),
692
- mcxVersion: "0.0.2-beta.r7"
670
+ mcxVersion: "0.0.2-beta.r7",
671
+ mcxCoreVersion: "0.0.6"
693
672
  };
694
673
 
695
674
  /**
@@ -818,833 +797,6 @@ const exp = (function () {
818
797
  };
819
798
  })();
820
799
 
821
- async function generateManifest(config, type) {
822
- const manifest = {
823
- format_version: 2,
824
- header: {
825
- name: config.name,
826
- description: config.description,
827
- uuid: fromString(config.name, BuildConfig.salt.header + type),
828
- version: stringToNumberArray(config.version),
829
- min_engine_version: stringToNumberArray(typeof config.mcVersion === "string"
830
- ? config.mcVersion
831
- : (() => {
832
- throw new Error("mcVersion in mblerconfig should be a string");
833
- })()),
834
- },
835
- modules: [
836
- {
837
- type: type,
838
- uuid: fromString(config.name, BuildConfig.salt.module + type),
839
- description: `From Mbler(https://github.com/RuanhoR/mbler). welcome to star and contribute!`,
840
- version: stringToNumberArray(config.version),
841
- },
842
- ],
843
- };
844
- if (type === "data" && config.script) {
845
- manifest.modules.push({
846
- type: "script",
847
- uuid: fromString(config.name, BuildConfig.salt.sapi + type),
848
- description: `sapi generate by mbler, weclome to download and star at https://github.com/RuanhoR/mbler`,
849
- version: stringToNumberArray(config.version),
850
- });
851
- manifest.capabilities = ["script_eval"];
852
- manifest.dependencies = [
853
- {
854
- module_name: "@minecraft/server",
855
- version: (await exp.generateVersion("@minecraft/server", config.mcVersion, config.script?.UseBeta || false)).split("-")[0], // only major.minor.patch, remove -beta or -rc
856
- },
857
- ];
858
- if (config.script.ui) {
859
- manifest.dependencies.push({
860
- module_name: "@minecraft/server-ui",
861
- version: (await exp.generateVersion("@minecraft/server-ui", config.mcVersion, config.script?.UseBeta || false)).split("-")[0], // only major.minor.patch, remove -beta or -rc
862
- });
863
- }
864
- }
865
- return manifest;
866
- }
867
-
868
- function createFullZip(dir) {
869
- const zip = new AdmZip();
870
- zip.addLocalFolder(dir);
871
- return zip;
872
- }
873
- async function createZipWithMoreFolder(dir) {
874
- const zip = new AdmZip();
875
- for (const folder of dir) {
876
- await zip.addLocalFolderPromise(folder[0], {
877
- zipPath: folder[1]
878
- });
879
- }
880
- return zip;
881
- }
882
- async function generateRelease(build) {
883
- if (!build.srcDirs)
884
- throw new Error("invaild Build");
885
- if (env.BUILD_MODULE !== "release")
886
- return;
887
- let zip;
888
- if (build.module == "all") {
889
- zip = await createZipWithMoreFolder([
890
- [build.srcDirs?.behavior, "behavior"],
891
- [build.srcDirs.resources, "resources"]
892
- ]);
893
- }
894
- else if (build.module == "behavior") {
895
- zip = createFullZip(build.srcDirs.behavior);
896
- }
897
- else {
898
- zip = createFullZip(build.srcDirs.resources);
899
- }
900
- await zip.writeZipPromise(build.outdirs?.dist);
901
- }
902
-
903
- // cjs support
904
- const chalk$1 = _chalk instanceof Function ? _chalk : _chalk.default;
905
- class Postgress {
906
- max;
907
- constructor(max) {
908
- this.max = max;
909
- }
910
- update(current) {
911
- const percentage = Math.min(current, this.max) / this.max;
912
- const barWidth = 30;
913
- const filledWidth = Math.round(barWidth * percentage);
914
- const emptyWidth = barWidth - filledWidth;
915
- const filledBar = chalk$1.green('█'.repeat(filledWidth));
916
- const emptyBar = chalk$1.white('█'.repeat(emptyWidth));
917
- const progressBar = `${filledBar}${emptyBar}`;
918
- const percentText = chalk$1.blue(`${Math.round(percentage * 100)}%`);
919
- const progressText = `\n\u001B[1A\r[${progressBar}] ${percentText} (${current}/${this.max})`;
920
- showText(progressText, false);
921
- if (current == this.max) {
922
- showText("", true);
923
- }
924
- }
925
- }
926
-
927
- /**
928
- * 运行 MCX TypeScript 编译器
929
- * 为 .mcx 文件提供 TypeScript 类型检查支持
930
- */
931
- function runTSC(tscpath = require.resolve("typescript/lib/tsc")) {
932
- runTsc(tscpath, {
933
- extraSupportedExtensions: ['.mcx'],
934
- extraExtensionsToRemove: ['.mcx'],
935
- }, (ts) => {
936
- return [createMCXLanguagePlugin(ts)];
937
- });
938
- }
939
-
940
- // cjs support
941
- const chalk = _chalk instanceof Function ? _chalk : _chalk.default;
942
- class Build {
943
- baseBuildDir;
944
- resolve;
945
- isWatch;
946
- currentConfig = null;
947
- srcDirs = null;
948
- outdirs = null;
949
- mcxTs;
950
- mcxLanguagePluginCreator = null;
951
- constructor(opts, baseBuildDir, resolve, isWatch = false) {
952
- this.baseBuildDir = baseBuildDir;
953
- this.resolve = resolve;
954
- this.isWatch = isWatch;
955
- // 初始化 MCX 语言插件创建器,传入 tsHook.ts 使用
956
- try {
957
- const tsModule = require("typescript");
958
- this.mcxLanguagePluginCreator = createMCXLanguagePlugin;
959
- this.mcxTs = tsModule;
960
- Logger.i("Build", "MCX Volar language plugin creator initialized successfully");
961
- }
962
- catch (error) {
963
- this.mcxTs = require("typescript");
964
- Logger.w("Build", `Failed to initialize MCX language plugin: ${error}`);
965
- }
966
- }
967
- /**
968
- * Start the watch mode.
969
- * This will perform an initial build (if not already done) and then
970
- * start filesystem and rollup watchers.
971
- * Returns the watcher handles once they are created so that callers
972
- * (for example tests) can clean them up later.
973
- */
974
- async watch() {
975
- try {
976
- onEnd(() => {
977
- if (this.watchers) {
978
- this.watchers.chokidar.close();
979
- this.watchers.rollup.close();
980
- }
981
- });
982
- await this._watch();
983
- }
984
- catch (e) {
985
- if (e instanceof Error) {
986
- Logger.e('Watcher', e.stack || e.message);
987
- }
988
- else {
989
- Logger.e('Watcher', e + '');
990
- }
991
- showText('MBLER__ERR__WATCHER: ' + e + ' Log at ' + Logger.LogFile);
992
- this.resolve(1);
993
- return null;
994
- }
995
- }
996
- async start() {
997
- try {
998
- return await this.build();
999
- }
1000
- catch (e) {
1001
- if (e instanceof Error) {
1002
- Logger.e('Build', e.stack || e.message);
1003
- }
1004
- else {
1005
- Logger.e('Build', e + '');
1006
- }
1007
- showText('MBLER__ERR__BUILD: ' + e.stack + ' Log at ' + Logger.LogFile);
1008
- this.resolve(1);
1009
- }
1010
- }
1011
- /**
1012
- * Handles returned from the currently-active watchers.
1013
- * Set by {@link createWatcher} and exposed via {@link getWatchers}
1014
- * so that external callers can close them when necessary (e.g. tests).
1015
- */
1016
- watchers = null;
1017
- /**
1018
- * Returns the watcher handles if watch mode has been started.
1019
- * Can be safely called even before `watch()` has been invoked.
1020
- */
1021
- getWatchers() {
1022
- return this.watchers;
1023
- }
1024
- /**
1025
- * Close any active watchers. The build process does not automatically
1026
- * terminate the watchers unless the process exits; tests or CLI wrappers
1027
- * can call this method to clean up resources.
1028
- */
1029
- closeWatchers() {
1030
- if (this.watchers) {
1031
- this.watchers.chokidar.close();
1032
- this.watchers.rollup.close();
1033
- this.watchers = null;
1034
- }
1035
- }
1036
- rollupPlugin = null;
1037
- init = false;
1038
- /**
1039
- * Which modules are present in the current project.
1040
- * - "behavior" when only behavior code exists
1041
- * - "resources" when only resource files exist
1042
- * - "all" when both are present
1043
- * This field is populated during `handlerOtherAddon`.
1044
- */
1045
- module = null;
1046
- /**
1047
- * Determine whether a path refers to a regular file or a directory.
1048
- * Follows symbolic links recursively. Throws if the path exists but
1049
- * is not one of the expected types.
1050
- *
1051
- * @param filePath file system path to inspect
1052
- * @returns "file" or "directory"
1053
- */
1054
- async fileType(filePath) {
1055
- const stat = await fs.lstat(filePath);
1056
- if (stat.isFile()) {
1057
- return 'file';
1058
- }
1059
- if (stat.isDirectory()) {
1060
- return 'directory';
1061
- }
1062
- if (stat.isSymbolicLink()) {
1063
- return await this.fileType(await fs.readlink(filePath));
1064
- }
1065
- throw new Error('[build addon]: invaild file type');
1066
- }
1067
- /**
1068
- * Perform a single build of the project located at {@link baseBuildDir}.
1069
- * The process is roughly:
1070
- * 1. load and validate the configuration file
1071
- * 2. prepare source and output directory information
1072
- * 3. copy addon files (behavior/resources)
1073
- * 4. generate manifest.json files
1074
- * 5. run rollup to bundle any script entry point
1075
- *
1076
- * If anything goes wrong the promise returned by the public wrapper
1077
- * (`build()` function exported at the bottom of this file) will be
1078
- * resolved with a non-zero code and appropriate log entries will be
1079
- * emitted.
1080
- */
1081
- async build() {
1082
- const progress = new Postgress(100);
1083
- this.init = true;
1084
- if (!isAbsolute(this.baseBuildDir)) {
1085
- throw new Error('[init build]: build dir is not absolute path');
1086
- }
1087
- this.currentConfig = await ReadProjectMblerConfig(this.baseBuildDir);
1088
- this.loadData();
1089
- if (!this.isWatch)
1090
- progress.update(10);
1091
- await this.handlerOtherAddon();
1092
- await this.handlerManifest();
1093
- if (!this.isWatch)
1094
- progress.update(30);
1095
- const rBuild = (await this.createRollup());
1096
- if (!this.rollupPlugin || !this.outdirs) {
1097
- throw new Error(`[build addon]: can't resolve rollup instance`);
1098
- }
1099
- if (!this.isWatch)
1100
- progress.update(50);
1101
- // write script
1102
- let output = this.currentConfig.script?.main;
1103
- if (!output)
1104
- output = "index.js";
1105
- if (path__default.extname(output) !== "js")
1106
- output = output.slice(0, output.length - path__default.extname(output).length) + ".js";
1107
- if (this.currentConfig.script)
1108
- await rBuild.write({
1109
- file: join(path__default.join(this.outdirs.behavior, "scripts"), output),
1110
- format: 'esm',
1111
- sourcemap: false,
1112
- });
1113
- if (!this.isWatch)
1114
- progress.update(70);
1115
- await generateRelease(this);
1116
- if (!this.isWatch)
1117
- progress.update(80);
1118
- if (!this.isWatch)
1119
- this.resolve(0);
1120
- if (!this.isWatch)
1121
- progress.update(100);
1122
- }
1123
- /**
1124
- * Create and return a Rollup build instance configured for the
1125
- * project's script. The Rollup configuration mirrors the options
1126
- * used by the CLI when running manual builds.
1127
- *
1128
- * Returns undefined if the project does not define a script section
1129
- * (in which case nothing needs to be bundled).
1130
- */
1131
- async createRollup() {
1132
- if (!this.currentConfig || !this.srcDirs || !this.outdirs)
1133
- throw new Error(`[build addon]: can't first can this method`);
1134
- if (!this.currentConfig.script)
1135
- return;
1136
- const main = path__default.join(this.srcDirs.behavior, 'scripts', this.currentConfig.script.main);
1137
- if (!(await FileExsit(main))) {
1138
- throw new Error(`[build addon]: main script ${main} is not exist: can't resolve entry`);
1139
- }
1140
- const plugin = [
1141
- jsonPlugin(),
1142
- resolvePlugin({
1143
- extensions: ['.ts', '.js', '.json'],
1144
- }),
1145
- commonjs()
1146
- ];
1147
- const moduleDir = path__default.join(this.baseBuildDir, 'node_modules');
1148
- if (!(await FileExsit(moduleDir))) {
1149
- throw new Error(`[build addon]: node_modules is not exist in project root: can't resolve node_modules for rollup: ${moduleDir}`);
1150
- }
1151
- if (this.currentConfig.minify) {
1152
- plugin.push(minifyPlugin({
1153
- format: {
1154
- comments: false,
1155
- },
1156
- compress: {
1157
- unused: true,
1158
- },
1159
- }));
1160
- }
1161
- if (this.currentConfig.script.lang == "ts") {
1162
- const tsconfigPath = path__default.join(this.baseBuildDir, 'tsconfig.json');
1163
- if (!(await FileExsit(tsconfigPath))) {
1164
- throw new Error(`[build addon]: ts-lang: tsconfig.json is not exist in project root: can't resolve tsconfig for rollup: ${tsconfigPath}`);
1165
- }
1166
- plugin.push(typescript({
1167
- sourceMap: false,
1168
- tsconfig: tsconfigPath,
1169
- exclude: [
1170
- this.outdirs.behavior,
1171
- this.outdirs.resources
1172
- ],
1173
- include: [
1174
- this.srcDirs.behavior
1175
- ]
1176
- }));
1177
- }
1178
- if (this.currentConfig.script?.lang == 'mcx') {
1179
- try {
1180
- const tsconfigPath = path__default.join(this.baseBuildDir, 'tsconfig.json');
1181
- if (!(await FileExsit(tsconfigPath))) {
1182
- throw new Error(`[build addon]: ts-lang: tsconfig.json is not exist in project root: can't resolve tsconfig for rollup: ${tsconfigPath}`);
1183
- }
1184
- const pluginConfig = {
1185
- moduleDir: moduleDir,
1186
- tsconfigPath: tsconfigPath,
1187
- sourcemap: false,
1188
- ts: this.mcxTs,
1189
- mcxLanguagePlugin: this.mcxLanguagePluginCreator
1190
- };
1191
- if (this.mcxLanguagePluginCreator) {
1192
- pluginConfig.mcxLanguagePlugin = this.mcxLanguagePluginCreator;
1193
- }
1194
- plugin.push(mcxDef.plugin(pluginConfig, this.outdirs));
1195
- }
1196
- catch (err) {
1197
- throw new Error(`[build addon]: mcx plugin is required but '@mbler/mcx-core' could not be loaded: ${err}`);
1198
- }
1199
- }
1200
- // save plugin array for watcher re-use
1201
- this.rollupPlugin = plugin;
1202
- return await rollup.rollup({
1203
- input: main,
1204
- external: ['@minecraft/server', '@minecraft/server-ui'],
1205
- plugins: plugin,
1206
- });
1207
- }
1208
- /**
1209
- * Internal helper invoked by {@link watch}.
1210
- * Ensures a build has been run before starting the watchers.
1211
- */
1212
- async _watch() {
1213
- // init build
1214
- if (!this.init) {
1215
- await this.build();
1216
- }
1217
- this.createWatcher();
1218
- // watchers field is populated by createWatcher
1219
- }
1220
- isParent(parent, dir) {
1221
- const relative = path__default.relative(parent, dir);
1222
- return (!!relative && !relative.startsWith('..') && !path__default.isAbsolute(relative));
1223
- }
1224
- isChange(oldObj, newObj, checkKeys) {
1225
- for (const key of checkKeys) {
1226
- if (typeof oldObj[key] === 'object' &&
1227
- typeof newObj[key] === 'object' &&
1228
- oldObj[key] !== null &&
1229
- newObj[key] !== null) {
1230
- if (this.isChange(oldObj[key], newObj[key], Object.getOwnPropertyNames(oldObj[key]))) {
1231
- return true;
1232
- }
1233
- }
1234
- else if (oldObj[key] !== newObj[key]) {
1235
- return true;
1236
- }
1237
- }
1238
- return false;
1239
- }
1240
- createRollupWatcher() {
1241
- if (!this.srcDirs ||
1242
- !this.outdirs ||
1243
- !this.currentConfig ||
1244
- !this.rollupPlugin)
1245
- throw new Error(`[build addon]: can't first can this method`);
1246
- let output = this.currentConfig.script?.main;
1247
- if (!output)
1248
- output = "index.js";
1249
- if (path__default.extname(output) !== "js")
1250
- output = output.slice(0, output.length - path__default.extname(output).length) + ".js";
1251
- const rollupWatcher = rollup.watch({
1252
- input: path__default.join(this.srcDirs.behavior, 'scripts', this.currentConfig?.script?.main || ''),
1253
- external: ['@minecraft/server', '@minecraft/server-ui'],
1254
- plugins: this.rollupPlugin,
1255
- output: {
1256
- file: join(path__default.join(this.outdirs.behavior, "scripts"), output),
1257
- format: 'esm',
1258
- sourcemap: false,
1259
- },
1260
- cache: true,
1261
- watch: {
1262
- clearScreen: false,
1263
- include: path__default.join(this.srcDirs.behavior, 'scripts/**/*'),
1264
- exclude: [
1265
- path__default.join(this.baseBuildDir, 'node_modules/**/*'),
1266
- this.outdirs.behavior,
1267
- this.outdirs.resources,
1268
- this.outdirs.dist,
1269
- ],
1270
- },
1271
- });
1272
- rollupWatcher.on('change', async (filePath) => {
1273
- Logger.i('Watcher', `file changed: ${filePath}, start rebuild`);
1274
- });
1275
- rollupWatcher.on('event', async (event) => {
1276
- if (event.code === 'ERROR') {
1277
- Logger.e('Watcher', `rollup error: ${event.error.stack || event.error}`);
1278
- showText('MBLER__ERR__ROLLUP: ' +
1279
- (event.error.stack || event.error) +
1280
- ' Log at ' +
1281
- Logger.LogFile);
1282
- }
1283
- else if (event.code === 'END') {
1284
- Logger.i('Watcher', `rebuild success`);
1285
- }
1286
- });
1287
- return rollupWatcher;
1288
- }
1289
- async onChange(filePath) {
1290
- if (!this.srcDirs ||
1291
- !this.outdirs ||
1292
- !this.currentConfig ||
1293
- !this.rollupPlugin ||
1294
- !this.watchers)
1295
- throw new Error(`[build addon]: can't first can this method`);
1296
- const isConfigChange = path__default.relative(path__default.join(this.baseBuildDir, 'mbler.config.json'), filePath) === '';
1297
- const isBehaviorChange = this.isParent(this.srcDirs.behavior, filePath) && !this.isParent(path__default.join(this.srcDirs.behavior, 'scripts'), filePath);
1298
- const isResourcesChange = this.isParent(this.srcDirs.resources, filePath);
1299
- if (isConfigChange) {
1300
- const oldConfig = this.currentConfig;
1301
- Logger.i('Watcher', 'detected mbler.config.json change, reload config');
1302
- this.currentConfig = await ReadProjectMblerConfig(this.baseBuildDir);
1303
- this.loadData();
1304
- if (this.isChange(oldConfig, this.currentConfig, [
1305
- 'name',
1306
- 'version',
1307
- 'description',
1308
- 'mcVersion',
1309
- ])) {
1310
- await this.handlerManifest();
1311
- }
1312
- if (this.isChange(oldConfig, this.currentConfig, ['script', 'outdir'])) {
1313
- this.watchers.rollup.close();
1314
- await this.createRollup();
1315
- this.watchers.rollup = rollup.watch({
1316
- input: path__default.join(this.srcDirs.behavior, 'scripts', this.currentConfig?.script?.main || ''),
1317
- external: ['@minecraft/server', '@minecraft/server-ui'],
1318
- plugins: this.rollupPlugin,
1319
- output: {
1320
- file: path__default.join(this.outdirs.behavior, 'scripts', this.currentConfig?.script?.main || ''),
1321
- format: 'esm',
1322
- },
1323
- });
1324
- }
1325
- }
1326
- // if behavior or resources change, we can just copy the changed file instead of copy all files again.
1327
- if (isBehaviorChange || isResourcesChange) {
1328
- const handlerBP = async () => {
1329
- if (!this.srcDirs || !this.outdirs)
1330
- throw new Error(`[build addon]: can't first can this method`);
1331
- const relativePath = path__default.relative(this.srcDirs.behavior, filePath);
1332
- await fs.cp(path__default.join(this.srcDirs.behavior, relativePath), path__default.join(this.outdirs.behavior, relativePath), {
1333
- recursive: true,
1334
- force: true,
1335
- });
1336
- };
1337
- const handlerRP = async () => {
1338
- if (!this.srcDirs || !this.outdirs)
1339
- throw new Error(`[build addon]: can't first can this method`);
1340
- const relativePath = path__default.relative(this.srcDirs.resources, filePath);
1341
- await fs.cp(path__default.join(this.srcDirs.resources, relativePath), path__default.join(this.outdirs.resources, relativePath), {
1342
- recursive: true,
1343
- force: true,
1344
- });
1345
- };
1346
- if (isBehaviorChange) {
1347
- await handlerBP();
1348
- }
1349
- if (isResourcesChange) {
1350
- await handlerRP();
1351
- }
1352
- }
1353
- showText(`[${chalk.green('mbler')}] ${chalk.bgYellow(`file changed: ${filePath}`)}`);
1354
- }
1355
- createWatcher() {
1356
- if (!this.srcDirs || !this.outdirs || !this.rollupPlugin)
1357
- throw new Error(`[build addon]: can't first can this method`);
1358
- const chokidar = watch$1(this.baseBuildDir, {
1359
- ignored: [
1360
- this.outdirs.behavior,
1361
- this.outdirs.resources,
1362
- this.outdirs.dist,
1363
- path__default.join(this.baseBuildDir, 'node_modules'),
1364
- ],
1365
- ignoreInitial: true,
1366
- interval: 100,
1367
- });
1368
- const onChange = async (filePath) => {
1369
- await this.onChange(filePath);
1370
- };
1371
- chokidar.on('change', onChange);
1372
- const rollupWatcher = this.createRollupWatcher();
1373
- this.watchers = {
1374
- chokidar,
1375
- rollup: rollupWatcher,
1376
- };
1377
- }
1378
- async handlerManifest() {
1379
- if (!this.currentConfig || !this.outdirs || !this.srcDirs || !this.module)
1380
- throw new Error(`[build addon]: can't first can this method`);
1381
- const otherManifestOption = {
1382
- behavior: {},
1383
- resources: {},
1384
- };
1385
- const handlerBP = async () => {
1386
- if (!this.outdirs || !this.currentConfig)
1387
- throw new Error(`[build addon]: can't first can this method`);
1388
- const manifest = await generateManifest(this.currentConfig, 'data');
1389
- await writeJSON(path__default.join(this.outdirs.behavior, 'manifest.json'), {
1390
- ...manifest,
1391
- ...otherManifestOption.behavior,
1392
- });
1393
- };
1394
- const handlerRP = async () => {
1395
- if (!this.outdirs || !this.currentConfig)
1396
- throw new Error(`[build addon]: can't first can this method`);
1397
- const manifest = await generateManifest(this.currentConfig, 'resources');
1398
- await writeJSON(path__default.join(this.outdirs.resources, 'manifest.json'), {
1399
- ...manifest,
1400
- ...otherManifestOption.resources,
1401
- });
1402
- };
1403
- if (this.module == 'behavior' || this.module == 'all') {
1404
- const filePath = path__default.join(this.srcDirs.behavior, 'manifest.json');
1405
- if (await FileExsit(filePath)) {
1406
- try {
1407
- const content = await fs.readFile(filePath, 'utf-8');
1408
- const json = JSON.parse(content);
1409
- otherManifestOption.behavior = json;
1410
- }
1411
- catch (err) {
1412
- Logger.w('Build', 'invalid manifest.json in behavior');
1413
- }
1414
- }
1415
- await handlerBP();
1416
- }
1417
- if (this.module == 'resources' || this.module == 'all') {
1418
- const filePath = path__default.join(this.srcDirs.resources, 'manifest.json');
1419
- if (await FileExsit(filePath)) {
1420
- try {
1421
- const content = await fs.readFile(filePath, 'utf-8');
1422
- const json = JSON.parse(content);
1423
- otherManifestOption.resources = json;
1424
- }
1425
- catch (err) {
1426
- Logger.w('Build', 'invalid manifest.json in resources');
1427
- }
1428
- }
1429
- await handlerRP();
1430
- }
1431
- }
1432
- loadData() {
1433
- // check run time
1434
- if (!this.currentConfig || !this.baseBuildDir)
1435
- throw new Error("[build data]: can't resolve again");
1436
- // source code dir
1437
- this.srcDirs = {
1438
- behavior: path__default.join(this.baseBuildDir, BuildConfig.behavior),
1439
- resources: path__default.join(this.baseBuildDir, BuildConfig.resources), // res
1440
- };
1441
- // output dir
1442
- this.outdirs = {
1443
- behavior: this.currentConfig.outdir?.behavior
1444
- ? join(this.baseBuildDir, this.currentConfig.outdir.behavior)
1445
- : path__default.join(this.baseBuildDir, 'dist/dep'),
1446
- resources: this.currentConfig.outdir?.resources
1447
- ? join(this.baseBuildDir, this.currentConfig.outdir.resources)
1448
- : path__default.join(this.baseBuildDir, 'dist/res'),
1449
- dist: this.currentConfig.outdir?.dist
1450
- ? join(this.baseBuildDir, this.currentConfig.outdir.dist)
1451
- : path__default.join(this.baseBuildDir, 'dist-pkg'),
1452
- };
1453
- }
1454
- /**
1455
- * Copy the various files (behavior/resources) into the corresponding
1456
- * output directories and determine which modules exist in the project
1457
- * by inspecting the source directories.
1458
- */
1459
- async handlerOtherAddon() {
1460
- if (!this.srcDirs)
1461
- throw new Error("[build addon]: can't first can this method");
1462
- const isHasBp = await FileExsit(this.srcDirs.behavior);
1463
- if (!isHasBp)
1464
- throw new Error("[build addon]: can't resolve behavior");
1465
- // init copy resources
1466
- const handlerBP = async () => {
1467
- if (!this.srcDirs || !this.outdirs)
1468
- throw new Error("[build addon]: can't first can this method");
1469
- for (const f of await fs.readdir(this.srcDirs.behavior)) {
1470
- const fType = await this.fileType(path__default.join(this.srcDirs.behavior, f));
1471
- const includeType = BuildConfig.includes.behavior[f] || BuildConfig.includes.public[f];
1472
- if (includeType == fType) {
1473
- await fs.cp(path__default.join(this.srcDirs.behavior, f), path__default.join(this.outdirs.behavior, f), {
1474
- recursive: true,
1475
- force: true,
1476
- });
1477
- }
1478
- else if (includeType == 'skip') {
1479
- continue;
1480
- }
1481
- else {
1482
- throw new Error(`[build addon]: invaild file: ${path__default.join(this.srcDirs.behavior, f)}: type: ${fType}`);
1483
- }
1484
- }
1485
- };
1486
- const handlerRP = async () => {
1487
- if (!this.srcDirs || !this.outdirs)
1488
- throw new Error("[build addon]: can't first can this method");
1489
- for (const f of await fs.readdir(this.srcDirs.resources)) {
1490
- const fType = await this.fileType(path__default.join(this.srcDirs.resources, f));
1491
- const includeType = BuildConfig.includes.resources[f] || BuildConfig.includes.public[f];
1492
- if (includeType == fType) {
1493
- await fs.cp(path__default.join(this.srcDirs.resources, f), path__default.join(this.outdirs.resources, f), {
1494
- recursive: true,
1495
- force: true,
1496
- });
1497
- }
1498
- else if (includeType == 'skip') {
1499
- continue;
1500
- }
1501
- else {
1502
- throw new Error(`[build addon]: invaild file: ${path__default.join(this.srcDirs.resources, f)}: type: ${fType}`);
1503
- }
1504
- }
1505
- };
1506
- const tasks = [];
1507
- if (await FileExsit(this.srcDirs.behavior)) {
1508
- this.module = 'behavior';
1509
- tasks.push(handlerBP());
1510
- }
1511
- if (await FileExsit(this.srcDirs.resources)) {
1512
- if (this.module == 'behavior') {
1513
- this.module = 'all';
1514
- }
1515
- else {
1516
- this.module = 'resources';
1517
- }
1518
- tasks.push(handlerRP());
1519
- }
1520
- if (!this.module) {
1521
- throw new Error("[build addon]: couldn't resolve source code(your behaivor or reources code is not found)");
1522
- }
1523
- await Promise.all(tasks);
1524
- }
1525
- }
1526
- function build(cliParam, work) {
1527
- return new Promise((resolve) => {
1528
- new Build(cliParam.opts, work, resolve).start();
1529
- });
1530
- }
1531
- function watch(cliParam, work) {
1532
- return new Promise((resolve, reject) => {
1533
- try {
1534
- const build = new Build(cliParam.opts, work, resolve, true);
1535
- build.start().then(() => {
1536
- build.watch();
1537
- showText(`[${chalk.green('mbler')}] ${chalk.bgYellow('watching for file changes...')}`);
1538
- });
1539
- }
1540
- catch (err) {
1541
- if (err instanceof Error) {
1542
- reject(`[watcher]: error ${err.stack || err.message}`);
1543
- }
1544
- else {
1545
- reject(err);
1546
- }
1547
- }
1548
- });
1549
- }
1550
-
1551
- var index = /*#__PURE__*/Object.freeze({
1552
- __proto__: null,
1553
- Build: Build,
1554
- McxTsc: runTSC,
1555
- build: build,
1556
- default: Build,
1557
- watch: watch
1558
- });
1559
-
1560
- async function tryMkdir(point) {
1561
- try {
1562
- await mkdir(point);
1563
- return true;
1564
- }
1565
- catch {
1566
- return false;
1567
- }
1568
- }
1569
- class WorkDirManage {
1570
- cacheDir;
1571
- currentWorkPoint = null;
1572
- enabledPath = path__default.join(homedir(), ".cache/mbler/workdir_enabled.db");
1573
- constructor(cacheDir = path__default.join(homedir(), ".cache/mbler/mp.db")) {
1574
- this.cacheDir = cacheDir;
1575
- }
1576
- async isDisabled() {
1577
- try {
1578
- await readFile(this.enabledPath, "utf-8");
1579
- return false; // 文件存在,表示启用
1580
- }
1581
- catch {
1582
- return true; // 文件不存在,默认禁用
1583
- }
1584
- }
1585
- async setDisabled(disabled) {
1586
- if (!disabled) {
1587
- // 启用:创建文件
1588
- await writeFile(this.enabledPath, "1", { encoding: "utf-8" });
1589
- }
1590
- else {
1591
- try {
1592
- await unlink(this.enabledPath);
1593
- }
1594
- catch {
1595
- // 文件不存在,忽略
1596
- }
1597
- }
1598
- }
1599
- async set(newPointDir) {
1600
- // check
1601
- try {
1602
- const s = await stat(newPointDir);
1603
- if (!s.isDirectory()) {
1604
- throw new Error("Not Dir (0xcvb)");
1605
- }
1606
- }
1607
- catch (err) {
1608
- const code = err.code;
1609
- if (err.message && err.message.includes("0xcvb"))
1610
- return i18n.workdir.nfound;
1611
- if (code == "ENOENT") {
1612
- const res = tryMkdir(newPointDir);
1613
- if (!res) {
1614
- return i18n.workdir.nfound;
1615
- }
1616
- }
1617
- }
1618
- try {
1619
- if (!(await FileExsit(path__default.dirname(this.cacheDir)))) {
1620
- const isC = await tryMkdir(path__default.dirname(this.cacheDir));
1621
- if (!isC)
1622
- return i18n.workdir.nfound;
1623
- }
1624
- await writeFile(this.cacheDir, newPointDir, {
1625
- encoding: "utf-8",
1626
- });
1627
- }
1628
- catch (err) {
1629
- Logger.e("WorkDir", err.stack);
1630
- }
1631
- return i18n.workdir.set + newPointDir;
1632
- }
1633
- async get() {
1634
- if (await this.isDisabled()) {
1635
- return cwd();
1636
- }
1637
- if (this.currentWorkPoint) {
1638
- return this.currentWorkPoint;
1639
- }
1640
- const file = await readFile(this.cacheDir, "utf-8").catch((e) => {
1641
- this.set(cwd());
1642
- return cwd();
1643
- });
1644
- return (this.currentWorkPoint = file);
1645
- }
1646
- }
1647
-
1648
800
  async function isInit(dir) {
1649
801
  return (await Promise.all([BuildConfig.ConfigFile, 'package.json', 'behavior'].map((item) => {
1650
802
  return FileExsit(path__default.join(dir, item));
@@ -1659,12 +811,12 @@ async function findTemplatedir() {
1659
811
  return path__default.join(__dirname, './template');
1660
812
  }
1661
813
  async function initCommand(cliParam, workdir) {
814
+ stdout.write(i18n.init.welcome + "\n");
1662
815
  await exp.refresh();
1663
816
  const cmdParams = cliParam.params.slice(1);
1664
817
  if (await isInit(workdir)) {
1665
818
  return 0;
1666
819
  }
1667
- showText(i18n.init.welcome);
1668
820
  const initOpts = {
1669
821
  name: cmdParams[0] || (await input(i18n.init.name)),
1670
822
  description: cmdParams[1] || (await input(i18n.init.description)),
@@ -1752,12 +904,14 @@ async function initCommand(cliParam, workdir) {
1752
904
  if (initOpts.lang == 'mcx') {
1753
905
  mblerConfig.script.main = 'index.mjs';
1754
906
  packageJSON.devDependencies['@mbler/mcx'] = config.mcxVersion;
907
+ packageJSON.devDependencies['@mbler/mcx-core'] = config.mcxCoreVersion;
1755
908
  }
1756
909
  if (initOpts.lang !== 'js') {
1757
910
  await writeJSON(tsconfigPath, tsconfig);
1758
911
  }
1759
912
  await writeJSON(packageJSONPath, packageJSON);
1760
- await writeJSON(mblerConfigPath, `import { defineConfig } from "mbler";\nexport default ${JSON.stringify(mblerConfig, null, 2)}`);
913
+ const mblerConfigContent = `import { defineConfig } from "mbler";\nexport default ${JSON.stringify(mblerConfig, null, 2)}`;
914
+ await writeFile(mblerConfigPath, mblerConfigContent);
1761
915
  // write template
1762
916
  const templatedir = await findTemplatedir();
1763
917
  if (!templatedir) {
@@ -1841,6 +995,31 @@ function langCommand(cliParam, workdir) {
1841
995
  return 0;
1842
996
  }
1843
997
 
998
+ function unpublishCommand(cliParam, work) {
999
+ showText("unpublish is planing");
1000
+ return 1;
1001
+ }
1002
+
1003
+ function publishCommand(cliParam, work) {
1004
+ showText("publish is planing");
1005
+ return 1;
1006
+ }
1007
+
1008
+ function uninstallCommand(cliParam, work) {
1009
+ showText("uninstall is planing");
1010
+ return 1;
1011
+ }
1012
+
1013
+ function installCommand(cliParam, work) {
1014
+ showText("install is planing");
1015
+ return 1;
1016
+ }
1017
+
1018
+ function loginCommand(cliParam, work) {
1019
+ showText("login is planing");
1020
+ return 1;
1021
+ }
1022
+
1844
1023
  // `showText` moved to `utils` to avoid circular dependency with `build`.
1845
1024
  const main = (function () {
1846
1025
  let currentWDManage;
@@ -1957,9 +1136,11 @@ const main = (function () {
1957
1136
  return async function cli() {
1958
1137
  const cliParam = parseParam();
1959
1138
  const handlerBuild = async (cliParam, workDir) => {
1139
+ const { build } = require("mbler/build");
1960
1140
  return await build(cliParam, workDir);
1961
1141
  };
1962
1142
  const handlerWatch = async (cliParam, workDir) => {
1143
+ const { watch } = require("mbler/build");
1963
1144
  return await watch(cliParam, workDir);
1964
1145
  };
1965
1146
  const cmdMap = {
@@ -1972,7 +1153,12 @@ const main = (function () {
1972
1153
  init: initCommand,
1973
1154
  version: handlerVersion,
1974
1155
  lang: langCommand,
1975
- 'set-work-dir': handlerSetWorkDirCommand
1156
+ 'set-work-dir': handlerSetWorkDirCommand,
1157
+ unpublish: unpublishCommand,
1158
+ publish: publishCommand,
1159
+ uninstall: uninstallCommand,
1160
+ install: installCommand,
1161
+ login: loginCommand
1976
1162
  };
1977
1163
  const cmd = cliParam.params[0];
1978
1164
  if (cliParam.opts.cwp) {
@@ -2012,5 +1198,5 @@ function defineConfig(config) {
2012
1198
  return config;
2013
1199
  }
2014
1200
 
2015
- export { index as Build, types as Types, main as cli, index$1 as commander, defineConfig, index$2 as i18n };
1201
+ export { types as Types, main as cli, index as commander, defineConfig, index$1 as i18n };
2016
1202
  //# sourceMappingURL=index.esm.js.map