Skip to content

Commit

Permalink
function to upload a file list
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Aug 5, 2023
1 parent bde5506 commit 7989a5e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tasks/aws-s3-builds-page/generateFileList-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const crypto = require('crypto');

const { runTest } = require('./test-utils/runTest');
const { createS3Client } = require('./s3client');
const { generateFileList } = require('./generateFileList');
const assert = require('node:assert');

// This is a test file. It is intended to be run manually with the proper environment variables set
//
// Run it from the project root using "node tasks/aws-s3-builds-page/generateFileList-test.js"

const s3Client = createS3Client();

runTest(async ({ log }) => {
log('Generate file list');
const filename = `test-file-list${crypto.randomUUID()}`;
await generateFileList(filename);

log(`Checking JSON at ${s3Client.fileUrl(`${filename}.json`)}`);
const jsonList = JSON.parse(await s3Client.fetchFile(`${filename}.json`));
assert(jsonList.includes('handlebars-v4.7.7.js'));

log(`Deleting file ${filename}.json`);
await s3Client.deleteFile(`${filename}.json`);
});
13 changes: 13 additions & 0 deletions tasks/aws-s3-builds-page/generateFileList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable no-console */
const { createS3Client } = require('./s3client');

async function generateFileList(nameWithoutExtension) {
const s3Client = createS3Client();
const fileList = await s3Client.listFiles();
const fileListJson = JSON.stringify(fileList, null, 2);
await s3Client.uploadData(fileListJson, nameWithoutExtension + '.json', {
contentType: 'application/json'
});
}

module.exports = { generateFileList };

0 comments on commit 7989a5e

Please sign in to comment.