Skip to content

Commit a4b1680

Browse files
committed
fix: stop trying to assign an array to process.exitCode
1 parent 9001b61 commit a4b1680

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

scripts/tx-push-help.mjs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,27 @@ const txPushResource = async (name, articles, type) => {
7272
};
7373

7474
/**
75-
* get a flattened list of folders
76-
* @param {category} categories array of categories the folders belong to
77-
* @return {Promise} flattened list of folders
75+
* get a flattened list of folders associated with the specified categories
76+
* @param {object[]} categories array of categories the folders belong to
77+
* @return {Promise<object[]>} flattened list of folders from all requested categories
7878
*/
7979
const getFolders = async (categories) => {
80-
let categoryFolders = await Promise.all( // eslint-disable-line no-undef
80+
const categoryFolders = await Promise.all(
8181
categories.map(category => FD.listFolders(category))
8282
);
8383
return [].concat(...categoryFolders);
8484
};
8585

8686
const PUBLISHED = 2; // in Freshdesk, draft status = 1, and published = 2
87-
const saveArticles = (folder) => {
88-
FD.listArticles(folder)
87+
88+
/**
89+
* Save articles in a particular folder
90+
* @param {object} folder The folder object
91+
*/
92+
const saveArticles = async folder => {
93+
await FD.listArticles(folder)
8994
.then(json => {
90-
let txArticles = json.reduce((strings, current) => {
95+
const txArticles = json.reduce((strings, current) => {
9196
if (current.status === PUBLISHED) {
9297
strings[`${current.id}`] = {
9398
title: {
@@ -107,13 +112,16 @@ const saveArticles = (folder) => {
107112
txPushResource(`${makeTxId(folder)}_json`, txArticles, 'STRUCTURED_JSON');
108113
});
109114
};
110-
const getArticles = async (folders) => {
111-
return Promise.all(folders.map(folder => saveArticles(folder))); // eslint-disable-line no-undef
115+
116+
/**
117+
* @param {object[]} folders Array of folders containing articles to be saved
118+
*/
119+
const saveArticleFolders = async (folders) => {
120+
await Promise.all(folders.map(folder => saveArticles(folder)));
112121
};
113122

114123
const syncSources = async () => {
115-
let status = 0;
116-
status = await FD.listCategories()
124+
await FD.listCategories()
117125
.then(json => {
118126
// save category names for translation
119127
for (let cat of json.values()) {
@@ -131,12 +139,7 @@ const syncSources = async () => {
131139
txPushResource('folderNames_json', folderNames, 'KEYVALUEJSON');
132140
return data;
133141
})
134-
.then(getArticles)
135-
.catch((e) => {
136-
process.stdout.write(`Error:${e.message}\n`);
137-
return 1;
138-
});
139-
process.exitCode = status;
142+
.then(saveArticleFolders);
140143
};
141144

142145
syncSources();

0 commit comments

Comments
 (0)