Skip to content

Commit c38518c

Browse files
committed
Deploy Production Code for Commit b91d0cc 🚀
1 parent b91d0cc commit c38518c

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

lib/constants.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
/// <reference types="node" />
12
export interface ActionInterface {
23
/** Allows you to log the retrieved data to the terminal. */
34
debug?: boolean;
5+
/** The encoding of the data to be finally stored */
6+
encoding?: BufferEncoding;
47
/** The primary endpoint to fetch data from. */
58
endpoint: string;
69
/** The configuration for the primary endpoint. Must be a stringified JSON object. */
@@ -35,6 +38,8 @@ export interface DataInterface {
3538
export interface ExportInterface {
3639
/** The data to save. */
3740
data: string;
41+
/** The encoding of the data to be finally stored */
42+
encoding?: BufferEncoding;
3843
/** The save location. */
3944
saveLocation?: string;
4045
/** The name of the file to save. */
@@ -44,6 +49,7 @@ export interface ExportInterface {
4449
}
4550
export declare const action: {
4651
debug: boolean;
52+
encoding: BufferEncoding;
4753
endpoint: string;
4854
configuration: string;
4955
tokenEndpoint: string;

lib/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ exports.action = {
88
debug: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('debug'))
99
? (0, core_1.getInput)('debug').toLowerCase() === 'true'
1010
: false,
11+
encoding: (0, core_1.getInput)('encoding'),
1112
endpoint: (0, core_1.getInput)('endpoint'),
1213
configuration: (0, core_1.getInput)('configuration'),
1314
tokenEndpoint: (0, core_1.getInput)('token-endpoint'),

lib/fetch.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import 'cross-fetch/polyfill';
22
import { DataInterface, ExportInterface, Status } from './constants';
33
export declare function retrieveData({ debug: requestDebug, endpoint, configuration, auth, isTokenRequest, retry }: DataInterface): Promise<string>;
4-
export declare function generateExport({ data, format, saveLocation, saveName }: ExportInterface): Promise<Status>;
4+
export declare function generateExport({ data, encoding, format, saveLocation, saveName }: ExportInterface): Promise<Status>;

lib/fetch.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,27 @@ function retrieveData({ debug: requestDebug, endpoint, configuration, auth, isTo
5656
});
5757
}
5858
catch (error) {
59-
throw new Error(`There was an error fetching from the API: ${error}`);
59+
throw new Error(`There was an error fetching from the API: ${error}`);
6060
}
6161
});
6262
}
6363
exports.retrieveData = retrieveData;
6464
/* Saves the data to the local file system and exports an environment variable containing the retrieved data. */
65-
function generateExport({ data, format, saveLocation, saveName }) {
65+
function generateExport({ data, encoding, format, saveLocation, saveName }) {
6666
return __awaiter(this, void 0, void 0, function* () {
6767
(0, core_1.info)('Saving the data... 📁');
6868
const file = `${saveLocation ? saveLocation : 'fetch-api-data-action'}/${saveName ? saveName : 'data'}.${format ? format : 'json'}`;
69-
yield (0, io_1.mkdirP)(`${saveLocation ? saveLocation : 'fetch-api-data-action'}`);
70-
yield fs_1.promises.writeFile(file, data, 'utf8');
71-
(0, core_1.info)(`Saved ${file} 💾`);
72-
yield fs_1.promises.writeFile(`${saveLocation ? saveLocation : 'fetch-api-data-action'}/${saveName ? saveName : 'data'}.json`, data, 'utf8');
73-
(0, core_1.exportVariable)('fetch-api-data', data);
74-
return constants_1.Status.SUCCESS;
69+
const dataEncoding = encoding ? encoding : 'utf8';
70+
try {
71+
yield (0, io_1.mkdirP)(`${saveLocation ? saveLocation : 'fetch-api-data-action'}`);
72+
yield fs_1.promises.writeFile(file, data, dataEncoding);
73+
(0, core_1.info)(`Saved ${file} 💾`);
74+
(0, core_1.exportVariable)('fetch-api-data', data);
75+
return constants_1.Status.SUCCESS;
76+
}
77+
catch (error) {
78+
throw new Error(`There was an error generating the export file: ${error} ❌`);
79+
}
7580
});
7681
}
7782
exports.generateExport = generateExport;

lib/lib.js

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function run(configuration) {
5555
});
5656
status = yield (0, fetch_1.generateExport)({
5757
data,
58+
encoding: settings.encoding,
5859
saveLocation: settings.saveLocation,
5960
saveName: settings.saveName,
6061
format: settings.format

0 commit comments

Comments
 (0)