function to upload a file list
This commit is contained in:
@@ -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`);
|
||||
});
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user