Skip to content

Commit

Permalink
Resolves #4 - Auto generation of output folder path
Browse files Browse the repository at this point in the history
  • Loading branch information
mgriff committed Aug 10, 2023
1 parent 28f7559 commit 155921e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/input/parse-cmdline-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const yargs = require('yargs/yargs');
const {hideBin} = require('yargs/helpers');
const {terminalWidth} = require('yargs');

const cloudinary = require('cloudinary').v2;

const toolDescriptionAndUsage = `
Migrates remote assets from a CSV file to Cloudinary via Cloudinary Upload API.
Expand Down Expand Up @@ -41,10 +43,16 @@ const cmdline_args = yargs(hideBin(process.argv))
})
.option('output-folder', {
alias: 'o',
description: 'Folder name for the migration log and report files',
description: 'Folder name for the migration log and report files, use "auto" to automatically generate the path in the format /logs/<cloud_name>/<data>/<time>/',
type: 'string',
demandOption: true, // Required argument
coerce: folder => {

if(folder === 'auto') {
const partsForDateSpecificFolders = new Date().toISOString().split('T');
folder = `./logs/${cloudinary.config().cloud_name}/${partsForDateSpecificFolders[0]}/${partsForDateSpecificFolders[1]}`
}

const logFilePath = getLogFilePath(folder);
const logFileExists = fs.existsSync(logFilePath);

Expand All @@ -59,9 +67,9 @@ const cmdline_args = yargs(hideBin(process.argv))
throw new Error(message);
}

// Creating output folder if it does not exist yet
//Creating output folder if it does not exist yet
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
fs.mkdirSync(folder, { recursive: true });
}

return folder;
Expand Down
2 changes: 2 additions & 0 deletions migrate-remote-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const migrationLog = log.migration;
const migrationOptions = {
dest_cloud : cloudinary.config().cloud_name,
from_csv_file : args.fromCsvFile,
log_location : args.logFile,
max_concurrent_uploads : args.maxConcurrentUploads
}

Expand Down Expand Up @@ -132,6 +133,7 @@ async function confirmMigrationOptionsOrExit_Async(migrationOptions) {
`❗️WARNING: This script will perform asset migration with the following parameters:
- source file : '${migrationOptions.from_csv_file}'
- destination cloud : '${migrationOptions.dest_cloud}'
- logging to : '${migrationOptions.log_location}'
- max concurrent uploads: ${migrationOptions.max_concurrent_uploads}
Are you sure you want to proceed?`;
const promptConfirmed = await confirm_Async(migrationPrompt);
Expand Down

0 comments on commit 155921e

Please sign in to comment.