Skip to content

Commit

Permalink
Deploy Production Code for Commit b91d0cc 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Jan 12, 2022
1 parent b91d0cc commit c38518c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
6 changes: 6 additions & 0 deletions lib/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// <reference types="node" />
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. */
Expand Down Expand Up @@ -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. */
Expand All @@ -44,6 +49,7 @@ export interface ExportInterface {
}
export declare const action: {
debug: boolean;
encoding: BufferEncoding;
endpoint: string;
configuration: string;
tokenEndpoint: string;
Expand Down
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion lib/fetch.d.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
export declare function generateExport({ data, format, saveLocation, saveName }: ExportInterface): Promise<Status>;
export declare function generateExport({ data, encoding, format, saveLocation, saveName }: ExportInterface): Promise<Status>;
21 changes: 13 additions & 8 deletions lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c38518c

Please sign in to comment.