binhend 1.1.5 → 1.1.6

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": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -4,42 +4,42 @@ const path = require('path');
4
4
  const Component = require('./component');
5
5
 
6
6
  function WebBuilder(binh, Binh) {
7
- binh.ui = function(amodule, component, htmltags, links) {
7
+ binh.ui = function(module, component, htmltags, links) {
8
8
  component.htmltags = htmltags;
9
9
  component.links = links;
10
- binh.bundle('ui', amodule, component);
10
+ binh.bundle('ui', module, component);
11
11
  };
12
12
 
13
- binh.service = function(amodule, component, links) {
13
+ binh.service = function(module, component, links) {
14
14
  component.links = links;
15
- binh.bundle('service', amodule, component);
15
+ binh.bundle('service', module, component);
16
16
  };
17
17
 
18
- binh.style = function(amodule, component) {
19
- binh.bundle('style', amodule, component);
18
+ binh.style = function(module, component) {
19
+ binh.bundle('style', module, component);
20
20
  };
21
21
 
22
- binh.css = function(amodule, cssFilename) {
23
- var cssFilePath = cssFilename && path.join(amodule.path, cssFilename) || amodule.filename.replace(/.js$/, '');
22
+ binh.css = function(module, cssFilename) {
23
+ var cssFilePath = cssFilename && path.join(module.path, cssFilename) || module.filename.replace(/.js$/, '');
24
24
  var content = require('fs').readFileSync(cssFilePath, { encoding: 'utf8', flag: 'r' });
25
25
  content = content.replace(/\s+/g, ' ');
26
26
  var component = new Function(`return ${JSON.stringify(content)};`);
27
- binh.bundle('style', amodule, component);
27
+ binh.bundle('style', module, component);
28
28
  };
29
29
 
30
- binh.bundle = function(type, amodule, component) {
30
+ binh.bundle = function(type, module, component) {
31
31
  if (!(component instanceof Function)) return;
32
32
 
33
33
  component.type = type;
34
- component.filename = amodule.filename;
34
+ component.filename = module.filename;
35
35
  component.constructor = Component;
36
- component.module = amodule;
36
+ component.module = module;
37
37
  component.as = alias;
38
38
  component.vars = {};
39
39
 
40
- amodule.exports = component;
40
+ module.exports = component;
41
41
 
42
- amodule.children.forEach(function(child) {
42
+ module.children.forEach(function(child) {
43
43
  child = child.exports;
44
44
  if (child.constructor !== Component) return;
45
45
  if (child.alias) component.vars[child.filename] = child.alias;
package/src/code.js CHANGED
@@ -125,15 +125,29 @@ function IIF(codes) {
125
125
  }
126
126
 
127
127
  function distinctValues(component, key) {
128
- var arrays = [component[key]];
128
+ var arrays = [component[key]], ref = {};
129
+
130
+ ref[component.filename] = true;
129
131
 
130
132
  component.module.children.forEach(function(child) {
133
+ if (ref[child.filename]) return;
134
+ ref[child.filename] = true;
131
135
  arrays.push(child.exports[key]);
136
+ getArraysFromDeeperChildren(ref, arrays, child, key);
132
137
  });
133
138
 
134
139
  return uniquefy(arrays);
135
140
  }
136
141
 
142
+ function getArraysFromDeeperChildren(ref, arrays, module, key) {
143
+ module.children.forEach(function(child) {
144
+ if (ref[child.filename]) return;
145
+ ref[child.filename] = true;
146
+ arrays.push(child.exports[key]);
147
+ getArraysFromDeeperChildren(ref, arrays, child, key);
148
+ });
149
+ }
150
+
137
151
  function uniquefy(arrays) {
138
152
  var map = {};
139
153