1
- import fs from 'fs' ;
2
- import Queue from 'queue-fifo' ;
3
- import path from 'path' ;
4
- let q = new Queue ( ) ;
1
+ "use strict" ;
2
+ var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
3
+ return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
4
+ } ;
5
+ Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
6
+ exports . getFilesForUpload = void 0 ;
7
+ var fs_1 = __importDefault ( require ( "fs" ) ) ;
8
+ var queue_fifo_1 = __importDefault ( require ( "queue-fifo" ) ) ;
9
+ var path_1 = __importDefault ( require ( "path" ) ) ;
10
+ var q = new queue_fifo_1 . default ( ) ;
5
11
/**
6
12
* Traverses the disk and builds a list/map of which files to upload and with what relative paths.
7
13
*
@@ -13,42 +19,46 @@ let q = new Queue();
13
19
* @returns an array of objects which carry absolute path on disk
14
20
* and where they would be uploaded in cloud
15
21
*/
16
- export function getFilesForUpload ( scanDirectory , shouldRecurse , baseContainerPath , extensionsToUpload ) {
17
- let filesToUpload = [ ] ;
22
+ function getFilesForUpload ( scanDirectory , shouldRecurse , baseContainerPath , extensionsToUpload ) {
23
+ var filesToUpload = [ ] ;
18
24
q . enqueue ( scanDirectory ) ;
19
- while ( ! q . isEmpty ( ) ) {
20
- const currentDirectoryPath = q . dequeue ( ) ;
25
+ var _loop_1 = function ( ) {
26
+ var currentDirectoryPath = q . dequeue ( ) ;
21
27
console . log ( 'Traversing directory: ' , currentDirectoryPath ) ;
22
- const currentDirectoryContents = fs . readdirSync ( currentDirectoryPath ) ;
23
- const filesInCurrentDirectory = currentDirectoryContents
28
+ var currentDirectoryContents = fs_1 . default . readdirSync ( currentDirectoryPath ) ;
29
+ var filesInCurrentDirectory = currentDirectoryContents
24
30
// filter for files only
25
- . filter ( t => ! fs . lstatSync ( path . join ( currentDirectoryPath , t ) ) . isDirectory ( ) )
31
+ . filter ( function ( t ) { return ! fs_1 . default . lstatSync ( path_1 . default . join ( currentDirectoryPath , t ) ) . isDirectory ( ) ; } )
26
32
// filenames to full path
27
- . map ( t => path . join ( currentDirectoryPath , t ) ) ;
28
- console . log ( ` Files in ${ currentDirectoryPath } ` , filesInCurrentDirectory ) ;
29
- let uploadCandidates = filesInCurrentDirectory
33
+ . map ( function ( t ) { return path_1 . default . join ( currentDirectoryPath , t ) ; } ) ;
34
+ console . log ( " Files in " . concat ( currentDirectoryPath ) , filesInCurrentDirectory ) ;
35
+ var uploadCandidates = filesInCurrentDirectory
30
36
// make sure we only target the specified extensions
31
- . filter ( t => extensionsToUpload . some ( x => t . endsWith ( x ) ) ) ;
32
- console . log ( ` Upload candidates from ${ currentDirectoryPath } ` , uploadCandidates ) ;
33
- filesToUpload . push ( ... uploadCandidates ) ;
37
+ . filter ( function ( t ) { return extensionsToUpload . some ( function ( x ) { return t . endsWith ( x ) ; } ) ; } ) ;
38
+ console . log ( " Upload candidates from " . concat ( currentDirectoryPath ) , uploadCandidates ) ;
39
+ filesToUpload . push . apply ( filesToUpload , uploadCandidates ) ;
34
40
if ( shouldRecurse ) {
35
- let dirsInDir = currentDirectoryContents
36
- . filter ( t => fs . lstatSync ( path . join ( currentDirectoryPath , t ) )
41
+ var dirsInDir = currentDirectoryContents
42
+ . filter ( function ( t ) { return fs_1 . default . lstatSync ( path_1 . default . join ( currentDirectoryPath , t ) )
37
43
// this time, query for directories only
38
- . isDirectory ( ) ) . map ( t => path . join ( currentDirectoryPath , t ) ) ;
44
+ . isDirectory ( ) ; } ) . map ( function ( t ) { return path_1 . default . join ( currentDirectoryPath , t ) ; } ) ;
39
45
if ( dirsInDir && dirsInDir . length ) {
40
46
// enqueue directories, continue traversing
41
- dirsInDir . forEach ( t => q . enqueue ( t ) ) ;
47
+ dirsInDir . forEach ( function ( t ) { return q . enqueue ( t ) ; } ) ;
42
48
}
43
49
}
50
+ } ;
51
+ while ( ! q . isEmpty ( ) ) {
52
+ _loop_1 ( ) ;
44
53
}
45
- let uploadStructure = filesToUpload . map ( t => {
46
- let relativePath = t . replace ( scanDirectory , '' ) ;
54
+ var uploadStructure = filesToUpload . map ( function ( t ) {
55
+ var relativePath = t . replace ( scanDirectory , '' ) ;
47
56
if ( relativePath [ 0 ] === '/' )
48
57
relativePath = relativePath . substring ( 1 ) ;
49
58
if ( baseContainerPath !== undefined )
50
- relativePath = ` ${ baseContainerPath } / ${ relativePath } ` ;
59
+ relativePath = "" . concat ( baseContainerPath , "/" ) . concat ( relativePath ) ;
51
60
return { absoluteDiskPath : t , relativeUploadPath : relativePath } ;
52
61
} ) ;
53
62
return uploadStructure ;
54
63
}
64
+ exports . getFilesForUpload = getFilesForUpload ;
0 commit comments