|
1 | 1 | const path = require("path");
|
2 |
| -const normalize = require("normalize-path"); |
3 | 2 | const fs = require("fs");
|
4 | 3 |
|
5 | 4 | function TemplatePath() {}
|
@@ -59,7 +58,7 @@ TemplatePath.getLastPathSegment = function (path) {
|
59 | 58 | // Trim a trailing slash if there is one
|
60 | 59 | path = path.replace(/\/$/, "");
|
61 | 60 |
|
62 |
| - return path.substr(path.lastIndexOf("/") + 1); |
| 61 | + return path.slice(path.lastIndexOf("/") + 1); |
63 | 62 | };
|
64 | 63 |
|
65 | 64 | /**
|
@@ -93,22 +92,25 @@ TemplatePath.getAllDirs = function (path) {
|
93 | 92 | * @returns {String} the normalized path.
|
94 | 93 | */
|
95 | 94 | TemplatePath.normalize = function (thePath) {
|
96 |
| - return normalize(path.normalize(thePath)); |
| 95 | + let filePath = path.normalize(thePath); |
| 96 | + if(filePath !== path.sep && filePath.endsWith(path.sep)) { |
| 97 | + return filePath.slice(0, -1 * path.sep.length); |
| 98 | + } |
| 99 | + return filePath; |
97 | 100 | };
|
98 | 101 |
|
99 | 102 | /**
|
100 | 103 | * Joins all given path segments together.
|
101 | 104 | *
|
102 |
| - * It uses Node.js’ [`path.join`][1] method and the [normalize-path][2] package. |
| 105 | + * It uses Node.js’ [`path.join`][1] method. |
103 | 106 | *
|
104 | 107 | * [1]: https://nodejs.org/api/path.html#path_path_join_paths
|
105 |
| - * [2]: https://www.npmjs.com/package/normalize-path |
106 | 108 | *
|
107 | 109 | * @param {String[]} paths An arbitrary amount of path segments.
|
108 | 110 | * @returns {String} the normalized and joined path.
|
109 | 111 | */
|
110 | 112 | TemplatePath.join = function (...paths) {
|
111 |
| - return normalize(path.join(...paths)); |
| 113 | + return TemplatePath.normalize(path.join(...paths)); |
112 | 114 | };
|
113 | 115 |
|
114 | 116 | /**
|
@@ -236,7 +238,7 @@ TemplatePath.stripLeadingSubPath = function (path, subPath) {
|
236 | 238 | subPath = TemplatePath.normalize(subPath);
|
237 | 239 |
|
238 | 240 | if (subPath !== "." && path.startsWith(subPath)) {
|
239 |
| - return path.substr(subPath.length + 1); |
| 241 | + return path.slice(subPath.length + 1); |
240 | 242 | }
|
241 | 243 |
|
242 | 244 | return path;
|
|
0 commit comments