binhend 2.1.9 → 2.1.11

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.9",
3
+ "version": "2.1.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
package/src/web/code.js CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  const path = require('path');
3
+ const Component = require('./component');
3
4
 
4
5
  function getCodeOfDependencies(component, metadata) {
5
6
  var global = metadata || {};
@@ -54,7 +55,10 @@ function getDependencyDelaration(component) {
54
55
 
55
56
  for (var filePath in dependencies) {
56
57
  var { name, url, type } = dependencies[filePath];
57
- if (name) {
58
+ if (name && type === 'service') {
59
+ codes.push(` ${name} = this.${type}('${url}')`);
60
+ }
61
+ else if (name) {
58
62
  codes.push(` ${name} = Binh.${type}('${url}')`);
59
63
  }
60
64
  }
@@ -92,20 +96,32 @@ function getMetadataOfDependencies(component) {
92
96
  return component.dependencies;
93
97
  }
94
98
 
95
- function generateOptionCode(component, varname) {
96
- var options = component.options, urls = [];
99
+ function generateOptionCode(component, baseCode) {
100
+ var options = component.options;
101
+
102
+ if (!options) return ''; // TODO remove this line, seem like always have this object 'options'
97
103
 
98
- if (!options) return '';
104
+ var cssUrls = [], serviceUrls = [];
99
105
 
106
+ // CSS
100
107
  component.type === 'ui' && options.csses.forEach(function(cssModule) {
101
- urls.push(JSON.stringify(cssModule.url));
108
+ cssUrls.push(JSON.stringify(cssModule.url));
109
+ });
110
+
111
+ if (cssUrls.length) {
112
+ baseCode += `.style([${cssUrls.join(',')}])`;
113
+ }
114
+
115
+ // Services
116
+ if (Component.isLazy) options.services.forEach(function(serviceModule) {
117
+ serviceUrls.push(serviceModule.url);
102
118
  });
103
119
 
104
- if (urls.length) {
105
- return `${varname}.style([${urls.join(',')}])`;
120
+ if (serviceUrls.length) {
121
+ baseCode += `.service(['${serviceUrls.join("', '")}'])`;
106
122
  }
107
123
 
108
- return '';
124
+ return baseCode;
109
125
  }
110
126
 
111
127
  function getRelativeFilePath(filePath, rootPath) {
@@ -70,6 +70,7 @@ function lazyload(paths) {
70
70
  processEachFile(paths, buildLazyCode, copyExternalComponentFiles);
71
71
  }
72
72
 
73
+ /** case of components or modules are required from node_modules installed by NPM */
73
74
  function copyExternalComponentFiles({ outputRootPath }) {
74
75
  var cache = copyExternalComponentFiles.cache,
75
76
  csses = copyExternalComponentFiles.csses;
@@ -81,7 +81,7 @@ binh.component = function(context, ui, service, style) {
81
81
  component.htmltags = [];
82
82
  component.svgtags = [];
83
83
  component.links = [];
84
- component.options = { csses: [] };
84
+ component.options = { csses: [], services: [] };
85
85
  component.vars = {};
86
86
  component.varname = getVariableName(component.filename);
87
87
  component.as = alias;
@@ -98,6 +98,10 @@ binh.final = function(module) {
98
98
  component.vars[childComponent.filename] = childComponent.alias;
99
99
  delete childComponent.alias;
100
100
  }
101
+
102
+ if (childComponent.type === 'service') {
103
+ component.options.services.push(childComponent);
104
+ }
101
105
  });
102
106
  };
103
107
 
package/src/web/index.js CHANGED
@@ -21,10 +21,12 @@ function WebBuilder(source, { output, external } = {}) {
21
21
  var external = mustString(external) || 'NPM';
22
22
 
23
23
  this.bundle = () => {
24
+ Component.isLazy = false;
24
25
  ComponentFormat.generate(source, module, () => ComponentBuild.bundle({ source, web, module }));
25
26
  };
26
27
 
27
28
  this.lazy = () => {
29
+ Component.isLazy = true;
28
30
  ComponentFormat.generate(source, module, () => ComponentBuild.lazyload({ source, web, module, external }));
29
31
  };
30
32