7
7
* file that was distributed with this source code.
8
8
*/
9
9
10
+ import { normalize , sep } from 'path'
11
+
10
12
export class Path {
11
13
private static _tempBuild = null
12
14
private static _forceBuild = false
13
- private static _defaultBuild = ' dist'
15
+ private static _defaultBuild = ` ${ sep } dist`
14
16
private static _verifyNodeEnv = true
15
17
16
18
static noBuild ( ) {
17
- this . _tempBuild = '/'
19
+ this . _tempBuild = sep
18
20
19
21
return this
20
22
}
21
23
22
24
static forBuild ( name : string ) {
23
- this . _tempBuild = name
25
+ this . _tempBuild = normalize ( ` ${ sep } ${ name } ` )
24
26
25
27
return this
26
28
}
@@ -38,7 +40,7 @@ export class Path {
38
40
}
39
41
40
42
static changeBuild ( name : string ) {
41
- this . _defaultBuild = name
43
+ this . _defaultBuild = normalize ( ` ${ sep } ${ name } ` )
42
44
43
45
return this
44
46
}
@@ -47,94 +49,95 @@ export class Path {
47
49
let cwdNodePath = process . cwd ( )
48
50
49
51
if ( this . _tempBuild ) {
50
- cwdNodePath += this . adjustSlashes ( this . _tempBuild )
52
+ cwdNodePath += this . _tempBuild
51
53
52
54
this . _tempBuild = null
53
55
54
- return cwdNodePath
56
+ return this . removeSlashFromEnd ( cwdNodePath )
55
57
}
56
58
57
59
if ( this . _forceBuild ) {
58
- cwdNodePath += this . adjustSlashes ( this . _defaultBuild )
60
+ cwdNodePath += this . _defaultBuild
59
61
60
- return cwdNodePath
62
+ return this . removeSlashFromEnd ( cwdNodePath )
61
63
}
62
64
63
65
if (
64
66
! this . _forceBuild &&
65
67
this . _verifyNodeEnv &&
66
68
process . env . NODE_TS === 'false'
67
69
) {
68
- cwdNodePath += this . adjustSlashes ( this . _defaultBuild )
70
+ cwdNodePath += this . _defaultBuild
69
71
70
- return cwdNodePath
72
+ return this . removeSlashFromEnd ( cwdNodePath )
71
73
}
72
74
73
- return this . adjustSlashes ( cwdNodePath )
75
+ return this . removeSlashFromEnd ( cwdNodePath )
74
76
}
75
77
76
- static pwd ( subPath = '/' ) {
77
- return `${ this . nodeCwdPath ( ) } ${ this . adjustSlashes ( subPath ) } `
78
- }
78
+ static pwd ( subPath = sep ) {
79
+ const pwd = normalize ( `${ this . nodeCwdPath ( ) } ${ sep } ${ normalize ( subPath ) } ` )
79
80
80
- static app ( subPath = '/' ) {
81
- return this . pwd ( 'app' + this . adjustSlashes ( subPath ) )
81
+ return this . removeSlashFromEnd ( pwd )
82
82
}
83
83
84
- static logs ( subPath = '/' ) {
85
- return this . storage ( 'logs ' + this . adjustSlashes ( subPath ) )
84
+ static app ( subPath = sep ) {
85
+ return this . pwd ( 'app ' + sep + normalize ( subPath ) )
86
86
}
87
87
88
- static start ( subPath = '/' ) {
89
- return this . pwd ( 'start ' + this . adjustSlashes ( subPath ) )
88
+ static logs ( subPath = sep ) {
89
+ return this . storage ( 'logs ' + sep + normalize ( subPath ) )
90
90
}
91
91
92
- static views ( subPath = '/' ) {
93
- return this . resources ( 'views ' + this . adjustSlashes ( subPath ) )
92
+ static start ( subPath = sep ) {
93
+ return this . pwd ( 'start ' + sep + normalize ( subPath ) )
94
94
}
95
95
96
- static config ( subPath = '/' ) {
97
- return this . pwd ( 'config ' + this . adjustSlashes ( subPath ) )
96
+ static views ( subPath = sep ) {
97
+ return this . resources ( 'views ' + sep + normalize ( subPath ) )
98
98
}
99
99
100
- static tests ( subPath = '/' ) {
101
- return this . pwd ( 'tests ' + this . adjustSlashes ( subPath ) )
100
+ static config ( subPath = sep ) {
101
+ return this . pwd ( 'config ' + sep + normalize ( subPath ) )
102
102
}
103
103
104
- static public ( subPath = '/' ) {
105
- return this . pwd ( 'public ' + this . adjustSlashes ( subPath ) )
104
+ static tests ( subPath = sep ) {
105
+ return this . pwd ( 'tests ' + sep + normalize ( subPath ) )
106
106
}
107
107
108
- static assets ( subPath = '/' ) {
109
- return this . public ( 'assets ' + this . adjustSlashes ( subPath ) )
108
+ static public ( subPath = sep ) {
109
+ return this . pwd ( 'public ' + sep + normalize ( subPath ) )
110
110
}
111
111
112
- static storage ( subPath = '/' ) {
113
- return this . pwd ( 'storage ' + this . adjustSlashes ( subPath ) )
112
+ static assets ( subPath = sep ) {
113
+ return this . public ( 'assets ' + sep + normalize ( subPath ) )
114
114
}
115
115
116
- static database ( subPath = '/' ) {
117
- return this . pwd ( 'database ' + this . adjustSlashes ( subPath ) )
116
+ static storage ( subPath = sep ) {
117
+ return this . pwd ( 'storage ' + sep + normalize ( subPath ) )
118
118
}
119
119
120
- static locales ( subPath = '/' ) {
121
- return this . resources ( 'locales ' + this . adjustSlashes ( subPath ) )
120
+ static database ( subPath = sep ) {
121
+ return this . pwd ( 'database ' + sep + normalize ( subPath ) )
122
122
}
123
123
124
- static resources ( subPath = '/' ) {
125
- return this . pwd ( 'resources ' + this . adjustSlashes ( subPath ) )
124
+ static locales ( subPath = sep ) {
125
+ return this . resources ( 'locales ' + sep + normalize ( subPath ) )
126
126
}
127
127
128
- static providers ( subPath = '/' ) {
129
- return this . pwd ( 'providers ' + this . adjustSlashes ( subPath ) )
128
+ static resources ( subPath = sep ) {
129
+ return this . pwd ( 'resources ' + sep + normalize ( subPath ) )
130
130
}
131
131
132
- private static adjustSlashes ( path : string ) {
133
- let subPathArray = path . split ( '/' )
132
+ static providers ( subPath = sep ) {
133
+ return this . pwd ( 'providers' + sep + normalize ( subPath ) )
134
+ }
134
135
135
- subPathArray = subPathArray . filter ( p => p !== '' )
136
- subPathArray . unshift ( '' )
136
+ private static removeSlashFromEnd ( path : string ) {
137
+ if ( path . endsWith ( sep ) ) {
138
+ return path . slice ( 0 , - 1 )
139
+ }
137
140
138
- return subPathArray . join ( '/' )
141
+ return path
139
142
}
140
143
}
0 commit comments