binhend 1.2.2 → 1.2.4

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.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
package/src/binh.js CHANGED
@@ -38,6 +38,7 @@ function Binh() {
38
38
  catch (error) {
39
39
  callbackError(error);
40
40
  }
41
+ return this;
41
42
  };
42
43
 
43
44
  function binh(modulePath) {
@@ -1,6 +1,6 @@
1
1
 
2
2
  const { parse } = require('path');
3
- const { scanNestedFiles, cloneFile, writeToFile } = require('./component.file');
3
+ const { scanNestedFiles, cloneFile, writeToFile, makeFullDirPath } = require('./component.file');
4
4
  const CodeFormat = require('./code');
5
5
  const Component = require('./component');
6
6
 
@@ -17,6 +17,8 @@ function generate(sourceRootPath, outputRootPath, stageRootPath) {
17
17
  var fileSourcePath = file.path.replace(stageRootPath, sourceRootPath);
18
18
  var fileOutputPath = file.path.replace(stageRootPath, outputRootPath);
19
19
 
20
+ makeFullDirPath(fileOutputPath);
21
+
20
22
  if (parse(file.name).ext !== '.js') {
21
23
  return cloneFile(fileSourcePath, fileOutputPath);
22
24
  }
@@ -32,7 +34,7 @@ function generate(sourceRootPath, outputRootPath, stageRootPath) {
32
34
  return cloneFile(fileSourcePath, fileOutputPath);
33
35
  }
34
36
 
35
- var code = joinCodes(component, outputRootPath);
37
+ var code = joinCodes(component, stageRootPath);
36
38
 
37
39
  writeToFile(fileOutputPath, code);
38
40
  });
@@ -1,6 +1,6 @@
1
1
 
2
- const { readdir, statSync, copyFile, writeFile } = require('fs');
3
- const { join } = require('path');
2
+ const { readdir, statSync, existsSync, copyFile, writeFile, mkdirSync } = require('fs');
3
+ const { join, dirname } = require('path');
4
4
 
5
5
  // TODO
6
6
  // [-] Enhance code by removing sync logics (except for existsSync, mkdirSync): readdir, readFileSync, (statSync?)
@@ -91,10 +91,17 @@ function cloneFile(filepath, outpath) {
91
91
  });
92
92
  }
93
93
 
94
+ function makeFullDirPath(filePath) {
95
+ var dirPath = dirname(filePath);
96
+ if (existsSync(dirPath)) return true;
97
+ makeFullDirPath(dirPath);
98
+ mkdirSync(dirPath);
99
+ }
100
+
94
101
  function writeToFile(fileOutputPath, content) {
95
102
  writeFile(fileOutputPath, content, { encoding: 'utf8', flag: 'w' }, function(error) {
96
103
  if (error) {
97
- printError('Failed writing file', filepath, error);
104
+ printError('Failed writing file', fileOutputPath, error);
98
105
  }
99
106
  });
100
107
  }
@@ -110,6 +117,7 @@ module.exports = {
110
117
  scanFiles,
111
118
  scanNestedFiles,
112
119
  cloneFile,
120
+ makeFullDirPath,
113
121
  writeToFile,
114
122
  printError
115
123
  };
@@ -1,7 +1,7 @@
1
1
 
2
- const { writeFileSync, existsSync, mkdirSync, readFileSync } = require('fs');
3
- const { dirname, parse } = require('path');
4
- const { scanNestedFiles, cloneFile, printError } = require('./component.file');
2
+ const { writeFileSync, readFileSync } = require('fs');
3
+ const { parse } = require('path');
4
+ const { scanNestedFiles, cloneFile, printError, makeFullDirPath } = require('./component.file');
5
5
 
6
6
  // TODO
7
7
  // [-] Enhance code by removing sync logics (except for existsSync, mkdirSync): readdir, readFileSync, (statSync?)
@@ -22,7 +22,7 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
22
22
  var fileSourcePath = file.path;
23
23
  var fileOutputPath = fileSourcePath.replace(sourceRootPath, outputRootPath);
24
24
 
25
- ensureDirectoryExistence(fileOutputPath);
25
+ makeFullDirPath(fileOutputPath);
26
26
 
27
27
  if (parse(file.name).ext !== '.js') {
28
28
  return cloneFile(fileSourcePath, fileOutputPath);
@@ -39,13 +39,6 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
39
39
  });
40
40
  }
41
41
 
42
- function ensureDirectoryExistence(filePath) {
43
- var dirPath = dirname(filePath);
44
- if (existsSync(dirPath)) return true;
45
- ensureDirectoryExistence(dirPath);
46
- mkdirSync(dirPath);
47
- }
48
-
49
42
  module.exports = {
50
43
  generate
51
44
  };