added prints bucket commands
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import chalk = require('chalk');
|
||||
import { confirmMessage, defaultMenuSettings } from '../../../../globals';
|
||||
import { defaultMenuSettings } from '../../../../globals';
|
||||
import { createPrintBucketStationList } from '../../../../services/aws_s3';
|
||||
const { AutoComplete, Confirm } = require('enquirer');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
module.exports = {
|
||||
name: 'clear-prints',
|
||||
@@ -10,43 +10,20 @@ module.exports = {
|
||||
description: 'Clear prints-dev bucket on S3 (a s3 cp)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { print, system, strings } = toolbox;
|
||||
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 stationListDev = await createPrintBucketStationList(
|
||||
toolbox,
|
||||
'photowall-prints-dev'
|
||||
);
|
||||
|
||||
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) {
|
||||
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 folder',
|
||||
choices: stationList,
|
||||
choices: stationListDev.stationNames,
|
||||
});
|
||||
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({
|
||||
@@ -58,7 +35,7 @@ module.exports = {
|
||||
|
||||
if (deleteAll) {
|
||||
// Delete all the files in that station
|
||||
for (const file of stations[stationName]) {
|
||||
for (const file of stationListDev.stationFiles[stationName]) {
|
||||
await system.run(`aws s3 rm s3://photowall-prints-dev/${file.Key}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import chalk = require('chalk');
|
||||
import { defaultMenuSettings } from '../../../../globals';
|
||||
import { createPrintBucketStationList } from '../../../../services/aws_s3';
|
||||
const { AutoComplete, Confirm } = require('enquirer');
|
||||
|
||||
module.exports = {
|
||||
name: 'print-on-station',
|
||||
alias: ['pos'],
|
||||
description: 'Print on a real station (a s3 pos)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { system } = toolbox;
|
||||
|
||||
const stationListDev = await createPrintBucketStationList(
|
||||
toolbox,
|
||||
'photowall-prints-dev'
|
||||
);
|
||||
|
||||
// Now show these in a enquiere prompt where the user can search and choose a folder
|
||||
const promptDev = new AutoComplete({
|
||||
message: 'Choose a dev folder to copy from',
|
||||
choices: stationListDev.stationNames,
|
||||
});
|
||||
const folderDev = await promptDev.run();
|
||||
const stationNameDev = folderDev.split(' ')[0];
|
||||
|
||||
const promptProd = new AutoComplete({
|
||||
message: 'Choose a live folder to copy to',
|
||||
choices: [
|
||||
'station1',
|
||||
'station3',
|
||||
'station5',
|
||||
'station6 (Amanda)',
|
||||
'station80 (Samples 1)',
|
||||
'station81 (Samples 2)',
|
||||
'station90 (Paint 1)',
|
||||
'station91 (Paint 2)',
|
||||
],
|
||||
});
|
||||
const folderProd = await promptProd.run();
|
||||
const stationNameProd = folderProd.split(' ')[0];
|
||||
|
||||
// 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 s3://photowall-prints-dev/${chalk.yellow(
|
||||
stationNameDev
|
||||
)} to s3://photowall-prints/${chalk.blue(
|
||||
stationNameProd
|
||||
)} printing them in production?`,
|
||||
});
|
||||
const confirmResult1 = await confirm.run();
|
||||
|
||||
const confirmAgain = new Confirm({
|
||||
message: `${chalk.black.bgYellow.bold(
|
||||
'Doing this will disrupt the packing process and cause confusion. Are you physically present at the target station?'
|
||||
)}\n\n${chalk.bold('Files to be copied:')}\n${stationListDev.stationFiles[
|
||||
stationNameDev
|
||||
].map((file) => chalk.yellow(file.Key) + '\n')}\n\n${chalk.yellow.bold(
|
||||
'Are you really sure?'
|
||||
)}`,
|
||||
});
|
||||
const confirmResult2 = await confirmAgain.run();
|
||||
|
||||
if (confirmResult1 && confirmResult2) {
|
||||
const cmd = `aws s3 sync s3://photowall-prints-dev/${stationNameDev} s3://photowall-prints/${stationNameProd}/`;
|
||||
await system.run(cmd);
|
||||
}
|
||||
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('aws s3', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1,71 +0,0 @@
|
||||
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);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
export const createPrintBucketStationList = async (toolbox, bucket) => {
|
||||
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 ${bucket} --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) {
|
||||
stationList.push(`${station} (${stations[station].length} files)`);
|
||||
}
|
||||
|
||||
return { stationNames: stationList, stationFiles: stations };
|
||||
};
|
||||
Reference in New Issue
Block a user