binhend 2.1.12 → 2.1.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.12",
3
+ "version": "2.1.14",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
package/src/web/code.js CHANGED
@@ -66,7 +66,7 @@ function getDependencyDelaration(component) {
66
66
  var declarationCode = codes.join(',');
67
67
 
68
68
  codes = [];
69
- codes.push(`var Binh = _Binh;`);
69
+ codes.push(`var Binh = _Binh, require = Binh.r;`);
70
70
 
71
71
  if (declarationCode) {
72
72
  codes.push(`var${declarationCode};`);
@@ -7,7 +7,7 @@ const PREFIX_CODE =
7
7
  `var { context, tag, svg, script, require, css } = binh.context(module, require);
8
8
  var Binh = binh.Binh;
9
9
  binh.component(context, ui, service, style);
10
- var ui = null, service = null, style = null;\r\n\r\n`;
10
+ var ui = ui || null, service = service || null, style = style || null;\r\n\r\n`;
11
11
 
12
12
  function generate(sourceRootPath, outputRootPath, callbackDone) {
13
13
  if (sourceRootPath == undefined || outputRootPath == undefined) return;
@@ -9,7 +9,7 @@ const binh = {};
9
9
 
10
10
  global.binh = binh;
11
11
 
12
- binh.context = function(module, defaultRequire) {
12
+ binh.context = function (module, defaultRequire) {
13
13
  var context = { module, require: defaultRequire };
14
14
 
15
15
  return {
@@ -43,8 +43,10 @@ function script() {
43
43
  }
44
44
 
45
45
  function customRequire(filePath) {
46
- filePath = filePath.endsWith('.css') ? (filePath+'.js') : filePath;
47
- return this.require(filePath);
46
+ filePath = filePath.endsWith('.css') ? (filePath + '.js') : filePath;
47
+ var childComponent = this.require(filePath);
48
+ childComponent.parent = this.component;
49
+ return childComponent;
48
50
  }
49
51
 
50
52
  function applyDefaultFileCSS() {
@@ -53,7 +55,7 @@ function applyDefaultFileCSS() {
53
55
  var cssModule = this.require('./' + cssModuleFile);
54
56
  css.bind(this)(cssModule);
55
57
  }
56
- catch (error) {}
58
+ catch (error) { }
57
59
  }
58
60
 
59
61
  function css() {
@@ -62,7 +64,7 @@ function css() {
62
64
  appliedStyles.push.apply(appliedStyles, csses);
63
65
  }
64
66
 
65
- binh.component = function(context, ui, service, style) {
67
+ binh.component = function (context, ui, service, style) {
66
68
  var component = ui || service || style;
67
69
  var type = ui && 'ui' || service && 'service' || style && 'style';
68
70
 
@@ -72,6 +74,7 @@ binh.component = function(context, ui, service, style) {
72
74
 
73
75
  var module = context.module;
74
76
  module.exports = component;
77
+ module.exportss = component;
75
78
 
76
79
  component.module = module;
77
80
  component.constructor = Component;
@@ -86,17 +89,18 @@ binh.component = function(context, ui, service, style) {
86
89
  component.varname = getVariableName(component.filename);
87
90
  component.as = alias;
88
91
  component.eachChild = loopComponentChildren;
89
-
92
+
90
93
  if (type === 'ui') applyDefaultFileCSS.bind(context)();
91
94
  };
92
95
 
93
- binh.final = function(module) {
94
- var component = module.exports;
96
+ binh.final = function (module) {
97
+ var component = module.exportss || {};
98
+ module.exports = component;
95
99
 
96
100
  component.eachChild && component.eachChild(childComponent => {
97
- if (childComponent.alias) {
98
- component.vars[childComponent.filename] = childComponent.alias;
99
- delete childComponent.alias;
101
+ if (childComponent.alias?.[component.filename]) {
102
+ component.vars[childComponent.filename] = childComponent.alias?.[component.filename];
103
+ delete childComponent.alias?.[component.filename];
100
104
  }
101
105
 
102
106
  if (childComponent.type === 'service') {
@@ -113,7 +117,7 @@ function loopComponentChildren(callback) {
113
117
  });
114
118
  }
115
119
 
116
- binh.css = function(module, cssFilename) {
120
+ binh.css = function (module, cssFilename) {
117
121
  var cssFilePath = cssFilename && path.join(module.path, cssFilename) || module.filename.replace(/.js$/, '');
118
122
  var content = fs.readFileSync(cssFilePath, { encoding: 'utf8', flag: 'r' });
119
123
  content = UglifyCSS.processString(content);
@@ -123,12 +127,18 @@ binh.css = function(module, cssFilename) {
123
127
  binh.final(module);
124
128
  };
125
129
 
126
- binh.Binh = function() {}; // dummy Binh object for binhjs => build web not logging error of undefined
130
+ /** Dummy Binh object for binhjs => build web not logging error of undefined */
131
+ binh.Binh = function () { };
132
+ binh.Binh.Util = { require: function () {} };
127
133
 
128
134
  function alias(name) {
129
135
  if (!isString(name)) return this;
130
136
  name = name.trim();
131
- this.alias = name;
137
+
138
+ var alias = this.alias || (this.alias = {});
139
+ if (this.parent) alias[this.parent.filename] = name;
140
+ delete this.parent;
141
+
132
142
  return this;
133
143
  }
134
144