From dbfc4b819a385b97e4f50fdf20f08801589c45b6 Mon Sep 17 00:00:00 2001 From: hdriouach-pcis Date: Fri, 5 Apr 2024 05:58:12 +0200 Subject: [PATCH] Add data:download command to download resources --- README.md | 1 + bin/test-cli.sh | 13 +++++++++++++ cli.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/webdav.js | 3 ++- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f65edf18..a1d7e957 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,7 @@ Use `sfcc-ci --help` or just `sfcc-ci` to get started and see the full list of c client:rotate [options] Rotate credentials of an Oauth client client:delete [options] Delete an Oauth client data:upload [options] Uploads a file onto a Commerce Cloud instance + data:download [options] Downloads a file from a Commerce Cloud instance sandbox:realm:list [options] List realms eligible to manage sandboxes for sandbox:realm:update [options] Update realm settings sandbox:list [options] List all available sandboxes diff --git a/bin/test-cli.sh b/bin/test-cli.sh index 1995eb8c..76d0c97a 100755 --- a/bin/test-cli.sh +++ b/bin/test-cli.sh @@ -1139,6 +1139,19 @@ else exit 1 fi +############################################################################### +###### Testing ´sfcc-ci data:download +############################################################################### + +echo "Testing command ´sfcc-ci data:download´:" +node ./cli.js data:download --instance $ARG_HOST --path impex/src/instance/site_import.zip --target ./test/cli/site_import.zip +if [ $? -eq 0 ]; then + echo -e "\t> OK" +else + echo -e "\t> FAILED" + exit 1 +fi + ############################################################################### ###### Testing ´sfcc-ci instance:export´ ############################################################################### diff --git a/cli.js b/cli.js index d83c827f..9731d948 100755 --- a/cli.js +++ b/cli.js @@ -444,6 +444,50 @@ program console.log(); }); +program + .command('data:download') + .option('-i, --instance ','Instance to download the file from. Can be an ' + + 'instance alias. If not specified the currently configured instance will be used.') + .option('-p, --path ', 'The path of the file (WebDAV) to download') + .option('-t, --target ', 'The local file path where to store the file') + .option('-o, --overrideLocalFile ', 'Override existing local file') + .description('Downloads a file from a Commerce Cloud instance') + .action(function(options) { + var instance = require('./lib/instance').getInstance(options.instance); + var path = ( options.path ? options.path : null ); + if (!path) { + this.missingArgument('path'); + return; + } + var target = ( options.target ? options.target : null ); + if (!target) { + this.missingArgument('target'); + return; + } + require('./lib/webdav').cli.download(instance, '/' + path, require('./lib/auth').getToken(), target, { + overrideLocalFile: options.overrideLocalFile + }); + }).on('--help', function() { + console.log(''); + console.log(' Details:'); + console.log(); + console.log(' Downloads file from an instance WebDAV folder into target local folder.'); + console.log(' Although, there is no defined maximum size for downloaded files. You may want'); + console.log(' to zip or gzip the file you want to download.'); + console.log(); + console.log(' The provided --path is relative to /webdav/Sites/, e.g. "impex/src/myfile.zip".'); + console.log(); + console.log(' Supported top level --path are "impex", "static", "catalogs", "libraries" and "dynamic".'); + console.log(' In order to use "catalogs", "libraries" and "dynamic" you have to set API permissions for'); + console.log(' a specific catalog, library or dynamic folder in WebDAV Client Permissions.'); + console.log(); + console.log(' Examples:'); + console.log(); + console.log(' $ sfcc-ci data:download --instance my-instance.demandware.net ' + + '--path impex/src/instance/myfile.zip --target myfile.zip'); + console.log(); + }); + program .command('sandbox:realm:list') .description('List realms eligible to manage sandboxes for') diff --git a/lib/webdav.js b/lib/webdav.js index 6d9096cc..5f0864c1 100644 --- a/lib/webdav.js +++ b/lib/webdav.js @@ -326,5 +326,6 @@ module.exports.api = { } } module.exports.cli = { - upload : upload + upload : upload, + download : downloadFile }; \ No newline at end of file