mm_machine 2.5.8 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/drive.js +11 -0
  2. package/index.js +30 -11
  3. package/package.json +1 -1
package/drive.js CHANGED
@@ -712,6 +712,17 @@ Drive.prototype.offEvent = function (event) {
712
712
  this.getEventer()?.off(event);
713
713
  };
714
714
 
715
+ /**
716
+ * 删除项目
717
+ */
718
+ Drive.prototype.remove = function () {
719
+ let dir = this._getDir();
720
+ if (dir) {
721
+ dir.delDir();
722
+ }
723
+ return dir;
724
+ };
725
+
715
726
  /**
716
727
  * @module 导出Drive类
717
728
  */
package/index.js CHANGED
@@ -920,9 +920,10 @@ Manager.prototype.offEvent = function (event) {
920
920
  /**
921
921
  * 创建模块
922
922
  * @param {object} config 模块配置
923
+ * @param {string} file 模块文件路径
923
924
  * @returns {string} 创建的模块文件路径
924
925
  */
925
- Manager.prototype.createFile = function (config) {
926
+ Manager.prototype.createFile = function (config, file) {
926
927
  if (!config.name) {
927
928
  throw new TypeError('模块名称不能为空');
928
929
  }
@@ -936,24 +937,42 @@ Manager.prototype.createFile = function (config) {
936
937
  throw new Error(`创建失败,原因:模块${config.name}已存在`);
937
938
  }
938
939
  let mod = new this.Drive(config, this);
939
- let file = `${config.name}/${this.config.filename}`;
940
- if (this.config.search_way === 'dir') {
941
- let dir_name = this._getDirName();
942
- file = `${dir_name}/${file}`;
940
+ let f = file;
941
+ if (!f) {
942
+ f = `${config.name}/${this.config.filename}`;
943
+ if (this.config.search_way === 'dir') {
944
+ let dir_name = this._getDirName();
945
+ f = `${dir_name}/${f}`;
946
+ }
943
947
  }
944
- file = file.fullname(this.config.dir);
945
- mod.createConfigFile(file, config);
946
- return file;
948
+ f = f.fullname(this.config.dir);
949
+ mod.createConfigFile(f, config);
950
+ return f;
947
951
  };
948
952
 
949
953
  /**
950
954
  * 创建模块
951
955
  * @param {object} config 模块配置
956
+ * @param {string} file 模块文件路径
952
957
  * @returns {object} 创建的模块实例
953
958
  */
954
- Manager.prototype.create = function (config) {
955
- let file = this.createFile(config);
956
- let mod = this.registerMod(file, config);
959
+ Manager.prototype.create = function (config, file = '') {
960
+ let f = this.createFile(config, file);
961
+ let mod = this.registerMod(f, config);
962
+ return mod;
963
+ };
964
+
965
+ /**
966
+ * 删除模块
967
+ * @param {string} name 模块名称
968
+ * @returns {object} 删除的模块实例
969
+ */
970
+ Manager.prototype.remove = function (name) {
971
+ let mod = this.getMod(name);
972
+ if (mod) {
973
+ mod.remove();
974
+ }
975
+ this.unregisterMod(name);
957
976
  return mod;
958
977
  };
959
978
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.5.8",
3
+ "version": "2.6.0",
4
4
  "description": "A flexible Node.js plugin mechanism system for dynamic loading, management and execution of modules. Supports hot reload, lifecycle management, and modern JavaScript features.",
5
5
  "main": "index.js",
6
6
  "scripts": {