File tree Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Original file line number Diff line number Diff line change 72
72
"dependencies" : {
73
73
"@tencent-sdk/capi" : " ^0.2.17" ,
74
74
"@ygkit/request" : " ^0.0.6" ,
75
- "klaw-sync" : " ^6.0.0" ,
76
75
"moment" : " ^2.25.3" ,
77
- "tencent-cloud-sdk" : " ^1.0.2 "
76
+ "tencent-cloud-sdk" : " ^1.0.3 "
78
77
}
79
78
}
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ const { cos } = require('tencent-cloud-sdk');
2
2
const util = require ( 'util' ) ;
3
3
const path = require ( 'path' ) ;
4
4
const fs = require ( 'fs' ) ;
5
- const klawSync = require ( 'klaw-sync' ) ;
6
5
const exec = util . promisify ( require ( 'child_process' ) . exec ) ;
6
+ const { traverseDirSync } = require ( '../../utils' ) ;
7
7
const { TypeError } = require ( '../../utils/error' ) ;
8
8
9
9
class Cos {
@@ -412,7 +412,7 @@ class Cos {
412
412
413
413
const items = await new Promise ( ( resolve , reject ) => {
414
414
try {
415
- resolve ( klawSync ( inputs . dir ) ) ;
415
+ resolve ( traverseDirSync ( inputs . dir ) ) ;
416
416
} catch ( error ) {
417
417
reject ( error ) ;
418
418
}
Original file line number Diff line number Diff line change
1
+ const path = require ( 'path' ) ;
2
+ const fs = require ( 'fs' ) ;
3
+
1
4
/**
2
5
* is array
3
6
* @param obj object
@@ -120,6 +123,36 @@ function strip(num, precision = 12) {
120
123
return + parseFloat ( num . toPrecision ( precision ) ) ;
121
124
}
122
125
126
+ function traverseDirSync ( dir , opts , ls ) {
127
+ if ( ! ls ) {
128
+ ls = [ ] ;
129
+ dir = path . resolve ( dir ) ;
130
+ opts = opts || { } ;
131
+ if ( opts . depthLimit > - 1 ) {
132
+ opts . rootDepth = dir . split ( path . sep ) . length + 1 ;
133
+ }
134
+ }
135
+ const paths = fs . readdirSync ( dir ) . map ( ( p ) => dir + path . sep + p ) ;
136
+ for ( let i = 0 ; i < paths . length ; i ++ ) {
137
+ const pi = paths [ i ] ;
138
+ const st = fs . statSync ( pi ) ;
139
+ const item = { path : pi , stats : st } ;
140
+ const isUnderDepthLimit =
141
+ ! opts . rootDepth || pi . split ( path . sep ) . length - opts . rootDepth < opts . depthLimit ;
142
+ const filterResult = opts . filter ? opts . filter ( item ) : true ;
143
+ const isDir = st . isDirectory ( ) ;
144
+ const shouldAdd = filterResult && ( isDir ? ! opts . nodir : ! opts . nofile ) ;
145
+ const shouldTraverse = isDir && isUnderDepthLimit && ( opts . traverseAll || filterResult ) ;
146
+ if ( shouldAdd ) {
147
+ ls . push ( item ) ;
148
+ }
149
+ if ( shouldTraverse ) {
150
+ ls = traverseDirSync ( pi , opts , ls ) ;
151
+ }
152
+ }
153
+ return ls ;
154
+ }
155
+
123
156
module . exports = {
124
157
isArray,
125
158
isObject,
@@ -128,4 +161,5 @@ module.exports = {
128
161
uniqueArray,
129
162
camelCaseProperty,
130
163
strip,
164
+ traverseDirSync,
131
165
} ;
You can’t perform that action at this time.
0 commit comments