From c38518c0358c6a522f0d4880212b65963e2d6574 Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 12 Jan 2022 04:22:09 +0000 Subject: [PATCH] =?UTF-8?q?Deploy=20Production=20Code=20for=20Commit=20b91?= =?UTF-8?q?d0cc12a13c3bb514407e45bfae1e670a6d4c6=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants.d.ts | 6 ++++++ lib/constants.js | 1 + lib/fetch.d.ts | 2 +- lib/fetch.js | 21 +++++++++++++-------- lib/lib.js | 1 + 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/constants.d.ts b/lib/constants.d.ts index cea73f5c8..4c4724753 100644 --- a/lib/constants.d.ts +++ b/lib/constants.d.ts @@ -1,6 +1,9 @@ +/// export interface ActionInterface { /** Allows you to log the retrieved data to the terminal. */ debug?: boolean; + /** The encoding of the data to be finally stored */ + encoding?: BufferEncoding; /** The primary endpoint to fetch data from. */ endpoint: string; /** The configuration for the primary endpoint. Must be a stringified JSON object. */ @@ -35,6 +38,8 @@ export interface DataInterface { export interface ExportInterface { /** The data to save. */ data: string; + /** The encoding of the data to be finally stored */ + encoding?: BufferEncoding; /** The save location. */ saveLocation?: string; /** The name of the file to save. */ @@ -44,6 +49,7 @@ export interface ExportInterface { } export declare const action: { debug: boolean; + encoding: BufferEncoding; endpoint: string; configuration: string; tokenEndpoint: string; diff --git a/lib/constants.js b/lib/constants.js index d9a534002..de2b61850 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -8,6 +8,7 @@ exports.action = { debug: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('debug')) ? (0, core_1.getInput)('debug').toLowerCase() === 'true' : false, + encoding: (0, core_1.getInput)('encoding'), endpoint: (0, core_1.getInput)('endpoint'), configuration: (0, core_1.getInput)('configuration'), tokenEndpoint: (0, core_1.getInput)('token-endpoint'), diff --git a/lib/fetch.d.ts b/lib/fetch.d.ts index 601f794b8..2ee70bc8e 100644 --- a/lib/fetch.d.ts +++ b/lib/fetch.d.ts @@ -1,4 +1,4 @@ import 'cross-fetch/polyfill'; import { DataInterface, ExportInterface, Status } from './constants'; export declare function retrieveData({ debug: requestDebug, endpoint, configuration, auth, isTokenRequest, retry }: DataInterface): Promise; -export declare function generateExport({ data, format, saveLocation, saveName }: ExportInterface): Promise; +export declare function generateExport({ data, encoding, format, saveLocation, saveName }: ExportInterface): Promise; diff --git a/lib/fetch.js b/lib/fetch.js index 7d42a2805..f7056c6ed 100644 --- a/lib/fetch.js +++ b/lib/fetch.js @@ -56,22 +56,27 @@ function retrieveData({ debug: requestDebug, endpoint, configuration, auth, isTo }); } catch (error) { - throw new Error(`There was an error fetching from the API: ${error}`); + throw new Error(`There was an error fetching from the API: ${error} ❌`); } }); } exports.retrieveData = retrieveData; /* Saves the data to the local file system and exports an environment variable containing the retrieved data. */ -function generateExport({ data, format, saveLocation, saveName }) { +function generateExport({ data, encoding, format, saveLocation, saveName }) { return __awaiter(this, void 0, void 0, function* () { (0, core_1.info)('Saving the data... 📁'); const file = `${saveLocation ? saveLocation : 'fetch-api-data-action'}/${saveName ? saveName : 'data'}.${format ? format : 'json'}`; - yield (0, io_1.mkdirP)(`${saveLocation ? saveLocation : 'fetch-api-data-action'}`); - yield fs_1.promises.writeFile(file, data, 'utf8'); - (0, core_1.info)(`Saved ${file} 💾`); - yield fs_1.promises.writeFile(`${saveLocation ? saveLocation : 'fetch-api-data-action'}/${saveName ? saveName : 'data'}.json`, data, 'utf8'); - (0, core_1.exportVariable)('fetch-api-data', data); - return constants_1.Status.SUCCESS; + const dataEncoding = encoding ? encoding : 'utf8'; + try { + yield (0, io_1.mkdirP)(`${saveLocation ? saveLocation : 'fetch-api-data-action'}`); + yield fs_1.promises.writeFile(file, data, dataEncoding); + (0, core_1.info)(`Saved ${file} 💾`); + (0, core_1.exportVariable)('fetch-api-data', data); + return constants_1.Status.SUCCESS; + } + catch (error) { + throw new Error(`There was an error generating the export file: ${error} ❌`); + } }); } exports.generateExport = generateExport; diff --git a/lib/lib.js b/lib/lib.js index f41937842..727e3a4da 100644 --- a/lib/lib.js +++ b/lib/lib.js @@ -55,6 +55,7 @@ function run(configuration) { }); status = yield (0, fetch_1.generateExport)({ data, + encoding: settings.encoding, saveLocation: settings.saveLocation, saveName: settings.saveName, format: settings.format