@@ -2544,9 +2544,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
2544
2544
exports . HashDiff = exports . fileHash = void 0 ;
2545
2545
const fs_1 = __importDefault ( __nccwpck_require__ ( 5747 ) ) ;
2546
2546
const crypto_1 = __importDefault ( __nccwpck_require__ ( 6417 ) ) ;
2547
- function formatNumber ( number ) {
2548
- return number . toLocaleString ( ) ;
2549
- }
2550
2547
function fileHash ( filename , algorithm ) {
2551
2548
return __awaiter ( this , void 0 , void 0 , function * ( ) {
2552
2549
return new Promise ( ( resolve , reject ) => {
@@ -2575,23 +2572,18 @@ function fileHash(filename, algorithm) {
2575
2572
}
2576
2573
exports . fileHash = fileHash ;
2577
2574
class HashDiff {
2578
- getDiffs ( localFiles , serverFiles , logger ) {
2575
+ getDiffs ( localFiles , serverFiles ) {
2579
2576
var _a , _b , _c ;
2580
2577
const uploadList = [ ] ;
2581
2578
const deleteList = [ ] ;
2582
2579
const replaceList = [ ] ;
2580
+ const sameList = [ ] ;
2583
2581
let sizeUpload = 0 ;
2584
2582
let sizeDelete = 0 ;
2585
2583
let sizeReplace = 0 ;
2586
2584
// alphabetize each list based off path
2587
2585
const localFilesSorted = localFiles . data . sort ( ( first , second ) => first . name . localeCompare ( second . name ) ) ;
2588
2586
const serverFilesSorted = serverFiles . data . sort ( ( first , second ) => first . name . localeCompare ( second . name ) ) ;
2589
- logger . standard ( `----------------------------------------------------------------` ) ;
2590
- logger . standard ( `Local Files:\t${ formatNumber ( localFilesSorted . length ) } ` ) ;
2591
- logger . standard ( `Server Files:\t${ formatNumber ( localFilesSorted . length ) } ` ) ;
2592
- logger . standard ( `----------------------------------------------------------------` ) ;
2593
- logger . standard ( `Calculating differences between client & server` ) ;
2594
- logger . standard ( `----------------------------------------------------------------` ) ;
2595
2587
let localPosition = 0 ;
2596
2588
let serverPosition = 0 ;
2597
2589
while ( localPosition + serverPosition < localFilesSorted . length + serverFilesSorted . length ) {
@@ -2608,15 +2600,11 @@ class HashDiff {
2608
2600
fileNameCompare = localFile . name . localeCompare ( serverFile . name ) ;
2609
2601
}
2610
2602
if ( fileNameCompare < 0 ) {
2611
- let icon = localFile . type === "folder" ? `📁 Create` : `➕ Upload` ;
2612
- logger . standard ( `${ icon } : ${ localFile . name } ` ) ;
2613
2603
uploadList . push ( localFile ) ;
2614
2604
sizeUpload += ( _a = localFile . size ) !== null && _a !== void 0 ? _a : 0 ;
2615
2605
localPosition += 1 ;
2616
2606
}
2617
2607
else if ( fileNameCompare > 0 ) {
2618
- let icon = serverFile . type === "folder" ? `📁` : `🗑️` ;
2619
- logger . standard ( `${ icon } Delete: ${ serverFile . name } ` ) ;
2620
2608
deleteList . push ( serverFile ) ;
2621
2609
sizeDelete += ( _b = serverFile . size ) !== null && _b !== void 0 ? _b : 0 ;
2622
2610
serverPosition += 1 ;
@@ -2625,10 +2613,9 @@ class HashDiff {
2625
2613
// paths are a match
2626
2614
if ( localFile . type === "file" && serverFile . type === "file" ) {
2627
2615
if ( localFile . hash === serverFile . hash ) {
2628
- logger . standard ( `⚖️ File content is the same, doing nothing: ${ localFile . name } ` ) ;
2616
+ sameList . push ( localFile ) ;
2629
2617
}
2630
2618
else {
2631
- logger . standard ( `🔁 File replace: ${ localFile . name } ` ) ;
2632
2619
sizeReplace += ( _c = localFile . size ) !== null && _c !== void 0 ? _c : 0 ;
2633
2620
replaceList . push ( localFile ) ;
2634
2621
}
@@ -2637,10 +2624,26 @@ class HashDiff {
2637
2624
serverPosition += 1 ;
2638
2625
}
2639
2626
}
2627
+ // optimize modifications
2628
+ let foldersToDelete = deleteList . filter ( ( item ) => item . type === "folder" ) ;
2629
+ // remove files/folders that have a nested parent folder we plan on deleting
2630
+ const optimizedDeleteList = deleteList . filter ( ( itemToDelete ) => {
2631
+ const parentFolderIsBeingDeleted = foldersToDelete . find ( ( folder ) => {
2632
+ const isSameFile = itemToDelete . name === folder . name ;
2633
+ const parentFolderExists = itemToDelete . name . startsWith ( folder . name ) ;
2634
+ return parentFolderExists && ! isSameFile ;
2635
+ } ) !== undefined ;
2636
+ if ( parentFolderIsBeingDeleted ) {
2637
+ // a parent folder is being deleted, no need to delete this one
2638
+ return false ;
2639
+ }
2640
+ return true ;
2641
+ } ) ;
2640
2642
return {
2641
2643
upload : uploadList ,
2642
- delete : deleteList ,
2644
+ delete : optimizedDeleteList ,
2643
2645
replace : replaceList ,
2646
+ same : sameList ,
2644
2647
sizeDelete,
2645
2648
sizeReplace,
2646
2649
sizeUpload
@@ -2764,6 +2767,11 @@ function getServerFiles(client, logger, timings, args) {
2764
2767
const serverFiles = yield downloadFileList ( client , logger , args [ "state-name" ] ) ;
2765
2768
logger . all ( `----------------------------------------------------------------` ) ;
2766
2769
logger . all ( `Last published on 📅 ${ new Date ( serverFiles . generatedTime ) . toLocaleDateString ( undefined , { weekday : "long" , year : "numeric" , month : "long" , day : "numeric" , hour : "numeric" , minute : "numeric" } ) } ` ) ;
2770
+ // apply exclude options to server
2771
+ if ( args . exclude . length > 0 ) {
2772
+ const filteredData = serverFiles . data . filter ( ( item ) => utilities_1 . applyExcludeFilter ( { path : item . name , isDirectory : ( ) => item . type === "folder" } , args . exclude ) ) ;
2773
+ serverFiles . data = filteredData ;
2774
+ }
2767
2775
return serverFiles ;
2768
2776
}
2769
2777
catch ( error ) {
@@ -2810,7 +2818,33 @@ function deploy(args, logger, timings) {
2810
2818
const serverFiles = yield getServerFiles ( client , logger , timings , args ) ;
2811
2819
timings . start ( "logging" ) ;
2812
2820
const diffTool = new HashDiff_1 . HashDiff ( ) ;
2813
- const diffs = diffTool . getDiffs ( localFiles , serverFiles , logger ) ;
2821
+ logger . standard ( `----------------------------------------------------------------` ) ;
2822
+ logger . standard ( `Local Files:\t${ utilities_1 . formatNumber ( localFiles . data . length ) } ` ) ;
2823
+ logger . standard ( `Server Files:\t${ utilities_1 . formatNumber ( serverFiles . data . length ) } ` ) ;
2824
+ logger . standard ( `----------------------------------------------------------------` ) ;
2825
+ logger . standard ( `Calculating differences between client & server` ) ;
2826
+ logger . standard ( `----------------------------------------------------------------` ) ;
2827
+ const diffs = diffTool . getDiffs ( localFiles , serverFiles ) ;
2828
+ diffs . upload . filter ( ( itemUpload ) => itemUpload . type === "folder" ) . map ( ( itemUpload ) => {
2829
+ logger . standard ( `📁 Create: ${ itemUpload . name } ` ) ;
2830
+ } ) ;
2831
+ diffs . upload . filter ( ( itemUpload ) => itemUpload . type === "file" ) . map ( ( itemUpload ) => {
2832
+ logger . standard ( `📄 Upload: ${ itemUpload . name } ` ) ;
2833
+ } ) ;
2834
+ diffs . replace . map ( ( itemReplace ) => {
2835
+ logger . standard ( `🔁 File replace: ${ itemReplace . name } ` ) ;
2836
+ } ) ;
2837
+ diffs . delete . filter ( ( itemUpload ) => itemUpload . type === "file" ) . map ( ( itemDelete ) => {
2838
+ logger . standard ( `📄 Delete: ${ itemDelete . name } ` ) ;
2839
+ } ) ;
2840
+ diffs . delete . filter ( ( itemUpload ) => itemUpload . type === "folder" ) . map ( ( itemDelete ) => {
2841
+ logger . standard ( `📁 Delete: ${ itemDelete . name } ` ) ;
2842
+ } ) ;
2843
+ diffs . same . map ( ( itemSame ) => {
2844
+ if ( itemSame . type === "file" ) {
2845
+ logger . standard ( `⚖️ File content is the same, doing nothing: ${ itemSame . name } ` ) ;
2846
+ }
2847
+ } ) ;
2814
2848
timings . stop ( "logging" ) ;
2815
2849
totalBytesUploaded = diffs . sizeUpload + diffs . sizeReplace ;
2816
2850
timings . start ( "upload" ) ;
@@ -2835,7 +2869,7 @@ function deploy(args, logger, timings) {
2835
2869
logger . all ( `----------------------------------------------------------------` ) ;
2836
2870
logger . all ( `Time spent hashing: ${ timings . getTimeFormatted ( "hash" ) } ` ) ;
2837
2871
logger . all ( `Time spent connecting to server: ${ timings . getTimeFormatted ( "connecting" ) } ` ) ;
2838
- logger . all ( `Time spent deploying: ${ timings . getTimeFormatted ( "upload" ) } (${ uploadSpeed } / second)` ) ;
2872
+ logger . all ( `Time spent deploying: ${ timings . getTimeFormatted ( "upload" ) } (${ uploadSpeed } / second)` ) ;
2839
2873
logger . all ( ` - changing dirs: ${ timings . getTimeFormatted ( "changingDir" ) } ` ) ;
2840
2874
logger . all ( ` - logging: ${ timings . getTimeFormatted ( "logging" ) } ` ) ;
2841
2875
logger . all ( `----------------------------------------------------------------` ) ;
@@ -2927,26 +2961,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
2927
2961
return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
2928
2962
} ;
2929
2963
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
2930
- exports . getLocalFiles = exports . applyExcludeFilter = void 0 ;
2964
+ exports . getLocalFiles = void 0 ;
2931
2965
const readdir_enhanced_1 = __importDefault ( __nccwpck_require__ ( 8811 ) ) ;
2932
2966
const types_1 = __nccwpck_require__ ( 6703 ) ;
2933
2967
const HashDiff_1 = __nccwpck_require__ ( 9946 ) ;
2934
- const multimatch_1 = __importDefault ( __nccwpck_require__ ( 8222 ) ) ;
2935
- function applyExcludeFilter ( stat , excludeFilter ) {
2936
- // match exclude, return immediatley
2937
- if ( excludeFilter . length > 0 ) {
2938
- const pathWithFolderSlash = stat . path + ( stat . isDirectory ( ) ? "/" : "" ) ;
2939
- const excludeMatch = multimatch_1 . default ( pathWithFolderSlash , excludeFilter , { matchBase : true , dot : true } ) ;
2940
- if ( excludeMatch . length > 0 ) {
2941
- return false ;
2942
- }
2943
- }
2944
- return true ;
2945
- }
2946
- exports . applyExcludeFilter = applyExcludeFilter ;
2968
+ const utilities_1 = __nccwpck_require__ ( 4389 ) ;
2947
2969
function getLocalFiles ( args ) {
2948
2970
return __awaiter ( this , void 0 , void 0 , function * ( ) {
2949
- const files = yield readdir_enhanced_1 . default . async ( args [ "local-dir" ] , { deep : true , stats : true , sep : "/" , filter : ( stat ) => applyExcludeFilter ( stat , args . exclude ) } ) ;
2971
+ const files = yield readdir_enhanced_1 . default . async ( args [ "local-dir" ] , { deep : true , stats : true , sep : "/" , filter : ( stat ) => utilities_1 . applyExcludeFilter ( stat , args . exclude ) } ) ;
2950
2972
const records = [ ] ;
2951
2973
for ( let stat of files ) {
2952
2974
if ( stat . isDirectory ( ) ) {
@@ -3138,22 +3160,12 @@ class FTPSyncProvider {
3138
3160
} ) ;
3139
3161
}
3140
3162
removeFolder ( folderPath ) {
3141
- var _a , _b ;
3142
3163
return __awaiter ( this , void 0 , void 0 , function * ( ) {
3143
- this . logger . all ( `removing folder "${ folderPath + "/" } "` ) ;
3144
- const path = this . getFileBreadcrumbs ( folderPath + "/" ) ;
3145
- if ( path . folders === null ) {
3146
- this . logger . verbose ( ` no need to change dir` ) ;
3147
- }
3148
- else {
3149
- const relativeFolderPath = path . folders [ ( ( _a = path . folders ) === null || _a === void 0 ? void 0 : _a . length ) - 1 ] + "/" ;
3150
- this . logger . verbose ( ` removing folder "${ relativeFolderPath } "` ) ;
3151
- if ( this . dryRun === false ) {
3152
- yield utilities_1 . retryRequest ( this . logger , ( ) => __awaiter ( this , void 0 , void 0 , function * ( ) { return yield this . client . removeDir ( relativeFolderPath ) ; } ) ) ;
3153
- }
3164
+ const absoluteFolderPath = "/" + ( this . serverPath . startsWith ( "./" ) ? this . serverPath . replace ( "./" , "" ) : this . serverPath ) + folderPath ;
3165
+ this . logger . all ( `removing folder "${ absoluteFolderPath } "` ) ;
3166
+ if ( this . dryRun === false ) {
3167
+ yield utilities_1 . retryRequest ( this . logger , ( ) => __awaiter ( this , void 0 , void 0 , function * ( ) { return yield this . client . removeDir ( absoluteFolderPath ) ; } ) ) ;
3154
3168
}
3155
- // navigate back to the root folder
3156
- yield this . upDir ( ( _b = path . folders ) === null || _b === void 0 ? void 0 : _b . length ) ;
3157
3169
this . logger . verbose ( ` completed` ) ;
3158
3170
} ) ;
3159
3171
}
@@ -3304,10 +3316,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3304
3316
return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
3305
3317
} ;
3306
3318
Object . defineProperty ( exports , "__esModule" , ( { value : true } ) ) ;
3307
- exports . getDefaultSettings = exports . Timer = exports . Timings = exports . retryRequest = exports . pluralize = exports . Logger = void 0 ;
3319
+ exports . applyExcludeFilter = exports . getDefaultSettings = exports . Timer = exports . Timings = exports . retryRequest = exports . formatNumber = exports . pluralize = exports . Logger = void 0 ;
3308
3320
const pretty_ms_1 = __importDefault ( __nccwpck_require__ ( 1127 ) ) ;
3309
3321
const module_1 = __nccwpck_require__ ( 8347 ) ;
3310
3322
const types_1 = __nccwpck_require__ ( 6703 ) ;
3323
+ const multimatch_1 = __importDefault ( __nccwpck_require__ ( 8222 ) ) ;
3311
3324
class Logger {
3312
3325
constructor ( level ) {
3313
3326
this . level = level ;
@@ -3336,6 +3349,10 @@ function pluralize(count, singular, plural) {
3336
3349
return plural ;
3337
3350
}
3338
3351
exports . pluralize = pluralize ;
3352
+ function formatNumber ( number ) {
3353
+ return number . toLocaleString ( ) ;
3354
+ }
3355
+ exports . formatNumber = formatNumber ;
3339
3356
/**
3340
3357
* retry a request
3341
3358
*
@@ -3452,6 +3469,19 @@ function getDefaultSettings(withoutDefaults) {
3452
3469
} ;
3453
3470
}
3454
3471
exports . getDefaultSettings = getDefaultSettings ;
3472
+ function applyExcludeFilter ( stat , excludeFilters ) {
3473
+ // match exclude, return immediatley
3474
+ if ( excludeFilters . length > 0 ) {
3475
+ // todo this could be a performance problem...
3476
+ const pathWithFolderSlash = stat . path + ( stat . isDirectory ( ) ? "/" : "" ) ;
3477
+ const excludeMatch = multimatch_1 . default ( pathWithFolderSlash , excludeFilters , { matchBase : true , dot : true } ) ;
3478
+ if ( excludeMatch . length > 0 ) {
3479
+ return false ;
3480
+ }
3481
+ }
3482
+ return true ;
3483
+ }
3484
+ exports . applyExcludeFilter = applyExcludeFilter ;
3455
3485
3456
3486
3457
3487
/***/ } ) ,
@@ -7954,12 +7984,12 @@ function optionalInt(argumentName, rawValue) {
7954
7984
}
7955
7985
exports . optionalInt = optionalInt ;
7956
7986
function optionalStringArray ( argumentName , rawValue ) {
7957
- if ( typeof rawValue === "string" ) {
7958
- throw new Error ( `${ argumentName } : invalid parameter - you provided "${ rawValue } ". This option expects an list in the EXACT format described in the readme` ) ;
7959
- }
7960
7987
if ( rawValue . length === 0 ) {
7961
7988
return undefined ;
7962
7989
}
7990
+ if ( typeof rawValue === "string" ) {
7991
+ throw new Error ( `${ argumentName } : invalid parameter - you provided "${ rawValue } ". This option expects an list in the EXACT format described in the readme` ) ;
7992
+ }
7963
7993
return rawValue ;
7964
7994
}
7965
7995
exports . optionalStringArray = optionalStringArray ;
0 commit comments