diff --git a/src/commands/aws/s3/test_station_print/test_station_print.ts b/src/commands/aws/s3/test_station_print/test_station_print.ts new file mode 100644 index 0000000..eed225d --- /dev/null +++ b/src/commands/aws/s3/test_station_print/test_station_print.ts @@ -0,0 +1,71 @@ +import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'; +import chalk = require('chalk'); +import { defaultMenuSettings } from '../../../../globals'; +const { AutoComplete, Confirm } = require('enquirer'); + +module.exports = { + name: 'test-station-print', + alias: ['tsp'], + description: 'Test a station print', + hidden: false, + run: async (toolbox: GluegunMenuToolbox) => { + const { system } = toolbox; + + // List all the folders on root level in bucket photowall-prints-dev + const allFiles = await system.run( + `aws s3api list-objects-v2 --bucket photowall-prints-dev --output json` + ); + + const allFilesArray = JSON.parse(allFiles); + + // Organize all the files in different folder if the folder name starts with station + const stations = []; + for (const file of allFilesArray.Contents) { + if (file.Key.startsWith('station')) { + // Get the station name + const stationName = file.Key.split('/')[0]; + if (!stations[stationName]) { + stations[stationName] = []; + } + // Then push the file into the station + stations[stationName].push(file); + } + } + + // Take all the station and create another list with the station and the number of files + const stationList = []; + for (const station in stations) { + if (station !== 'station100') { + stationList.push(`${station} (${stations[station].length} files)`); + } + } + + // Now show these in a enquiere prompt where the user can search and choose a folder + const prompt = new AutoComplete({ + message: 'Choose a dev folder to copy from', + choices: stationList, + }); + const folder = await prompt.run(); + const stationName = folder.split(' ')[0]; + console.log(`stationName`, stationName); + + // Ask the user if he wants to delete all the files in that station + const confirm = new Confirm({ + message: `Are u sure you want to copy files from ${chalk.yellow( + stationName + )} to ${chalk.blue( + 'station100' + )} printing them on station 6 in production?`, + }); + const copyFiles = await confirm.run(); + + if (copyFiles) { + const cmd = `aws s3 sync s3://photowall-prints-dev/${stationName} s3://photowall-prints-dev/station100/`; + await system.run(cmd); + } + + if (toolbox.fromMenu()) { + await toolbox.menu.showMenu('aws s3', defaultMenuSettings); + } + }, +};