binhend 1.5.6 → 1.5.7

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.5.6",
3
+ "version": "1.5.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -119,6 +119,7 @@ function WebBuilder(binh, Binh) {
119
119
  var content = fs.readFileSync(cssFilePath, { encoding: 'utf8', flag: 'r' });
120
120
  content = UglifyCSS.processString(content);
121
121
  var component = new Function(`return function style() { return ${JSON.stringify(content)}; };`)();
122
+ component.cssFilePath = cssFilePath;
122
123
  binh.component({ module }, null, null, component);
123
124
  binh.final(module);
124
125
  };
@@ -13,6 +13,7 @@ function processEachFile({ source: sourceRootPath, web: outputRootPath, module:
13
13
  console.info('[BINHEND][COMPONENT] to:', outputRootPath);
14
14
 
15
15
  var ref = {};
16
+ externalPath = typeof externalPath === 'string' ? `/${externalPath}/` : null;
16
17
 
17
18
  scanNestedFiles(stageRootPath, (file, done) => {
18
19
  if (done) return callbackDone instanceof Function ? callbackDone({ outputRootPath }) : null;
@@ -37,11 +38,11 @@ function processEachFile({ source: sourceRootPath, web: outputRootPath, module:
37
38
  return cloneFileIfNew(fileSourcePath, fileOutputPath);
38
39
  }
39
40
 
40
- injectComponentURL(component, stageRootPath + path.sep, externalPath ? `/${externalPath}/` : null, ref);
41
+ injectComponentURL(component, stageRootPath + path.sep, externalPath, ref);
41
42
 
42
43
  if (buildCodeMethod === buildLazyCode) collectExternalComponents(component, externalPath);
43
44
 
44
- var code = buildCodeMethod(component, externalPath);
45
+ var code = buildCodeMethod(component);
45
46
  code = Component.minification ? minifyCode(code) : beautifyCode(code);
46
47
 
47
48
  writeToFileIfNew(fileOutputPath, code);
@@ -69,7 +70,8 @@ function lazyload(paths) {
69
70
  }
70
71
 
71
72
  function copyExternalComponentFiles({ outputRootPath }) {
72
- var cache = copyExternalComponentFiles.cache;
73
+ var cache = copyExternalComponentFiles.cache,
74
+ csses = copyExternalComponentFiles.csses;
73
75
 
74
76
  for (var npmPath in cache) {
75
77
  var component = cache[npmPath].component;
@@ -84,17 +86,36 @@ function copyExternalComponentFiles({ outputRootPath }) {
84
86
 
85
87
  writeToFileIfNew(fileOutputPath, code);
86
88
  }
89
+
90
+ for (var cssFileSourcePath in csses) {
91
+ var cssURL = csses[cssFileSourcePath],
92
+ cssFileOutputPath = path.join(outputRootPath, cssURL);
93
+
94
+ makeFullDirPath(cssFileOutputPath);
95
+ cloneFileIfNew(cssFileSourcePath, cssFileOutputPath);
96
+ }
87
97
  }
88
98
 
89
99
  function collectExternalComponents(component, externalPath) {
90
- var cache = copyExternalComponentFiles.cache || (copyExternalComponentFiles.cache = {});
100
+ var cache = copyExternalComponentFiles.cache || (copyExternalComponentFiles.cache = {}),
101
+ csses = copyExternalComponentFiles.csses || (copyExternalComponentFiles.csses = {});
102
+
103
+ component.options.csses.forEach(cssModule => {
104
+ var cssFilePath = cssModule.cssFilePath;
105
+
106
+ if (csses[cssFilePath]) return;
107
+
108
+ if (cssModule.url.startsWith(externalPath)) {
109
+ csses[cssFilePath] = cssModule.url.replace(/.js$/, '');
110
+ }
111
+ });
91
112
 
92
113
  component.eachChild(childComponent => {
93
114
  var url = childComponent.url;
94
115
 
95
116
  if (cache[url]) return;
96
117
 
97
- if (url.startsWith(`/${externalPath}/`)) {
118
+ if (url.startsWith(externalPath)) {
98
119
  cache[url] = {
99
120
  component: childComponent
100
121
  };
package/test.js DELETED
@@ -1,48 +0,0 @@
1
- // const path = require('path');
2
-
3
- // function parseFilePathToVariableName(filePath) {
4
- // return path.parse(filePath).name.replace(/-/g, '').replace(/\W.*/, '');
5
- // // try {
6
- // // }
7
- // // catch (error) {
8
- // // return '';
9
- // // }
10
- // };
11
-
12
- // // console.log(parseFilePathToVariableName(1));
13
- // console.log(parseFilePathToVariableName(''));
14
- // // console.log(parseFilePathToVariableName(null));
15
- // // console.log(parseFilePathToVariableName());
16
- // // console.log(parseFilePathToVariableName('abc.js'));
17
- // // console.log(parseFilePathToVariableName('abc,.js'));
18
- // // console.log(parseFilePathToVariableName('abc.css.js'));
19
- // // console.log(parseFilePathToVariableName('./uhm/abc.css.js'));
20
- // console.log(parseFilePathToVariableName('.css.js'));
21
-
22
- // var abc = function ab() { return 123; };
23
- // var cc = () => {};
24
-
25
- // !function(callback1, callback2) {
26
- // delete callback1.name;
27
- // console.log(callback1.toString());
28
- // console.log(callback2.toString());
29
- // }(abc, cc);
30
-
31
- // console.log(abc.toString());
32
- // console.log(cc.toString());
33
-
34
- const path = require('path');
35
-
36
- // console.log(__dirname);
37
- // console.log(path.join(__dirname, null));
38
-
39
- function abc({ a, b, c }) {
40
- console.log(path.join(__dirname, a));
41
- console.log(path.join(__dirname, b));
42
- console.log(path.join(__dirname, c));
43
- }
44
-
45
- abc({
46
- a: 'a',
47
- b: 'b'
48
- });