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 7272 "dependencies" : {
7373 "@tencent-sdk/capi" : " ^0.2.17" ,
7474 "@ygkit/request" : " ^0.0.6" ,
75- "klaw-sync" : " ^6.0.0" ,
7675 "moment" : " ^2.25.3" ,
77- "tencent-cloud-sdk" : " ^1.0.2 "
76+ "tencent-cloud-sdk" : " ^1.0.3 "
7877 }
7978}
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ const { cos } = require('tencent-cloud-sdk');
22const util = require ( 'util' ) ;
33const path = require ( 'path' ) ;
44const fs = require ( 'fs' ) ;
5- const klawSync = require ( 'klaw-sync' ) ;
65const exec = util . promisify ( require ( 'child_process' ) . exec ) ;
6+ const { traverseDirSync } = require ( '../../utils' ) ;
77const { TypeError } = require ( '../../utils/error' ) ;
88
99class Cos {
@@ -412,7 +412,7 @@ class Cos {
412412
413413 const items = await new Promise ( ( resolve , reject ) => {
414414 try {
415- resolve ( klawSync ( inputs . dir ) ) ;
415+ resolve ( traverseDirSync ( inputs . dir ) ) ;
416416 } catch ( error ) {
417417 reject ( error ) ;
418418 }
Original file line number Diff line number Diff line change 1+ const path = require ( 'path' ) ;
2+ const fs = require ( 'fs' ) ;
3+
14/**
25 * is array
36 * @param obj object
@@ -120,6 +123,36 @@ function strip(num, precision = 12) {
120123 return + parseFloat ( num . toPrecision ( precision ) ) ;
121124}
122125
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+
123156module . exports = {
124157 isArray,
125158 isObject,
@@ -128,4 +161,5 @@ module.exports = {
128161 uniqueArray,
129162 camelCaseProperty,
130163 strip,
164+ traverseDirSync,
131165} ;
You can’t perform that action at this time.
0 commit comments