Skip to content

Commit f12959a

Browse files
committed
Continued es lint config
1 parent ac82a14 commit f12959a

File tree

3 files changed

+65
-65
lines changed

3 files changed

+65
-65
lines changed

.eslintrc.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
"sourceType": "module"
1212
},
1313
"rules": {
14-
"no-underscore-dangle": [
15-
"error",
16-
{
17-
"allow": true
18-
}
19-
]
14+
"max-classes-per-file": ["error", 2],
15+
"no-underscore-dangle": ["off"]
2016
}
2117
}

packages/content/lib/content-sources/airtable-source.js

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
*/
44

55
import Airtable from 'airtable';
6-
import ContentSource, { SourceOptions } from './content-source.js';
7-
import ContentResult, { MediaDownload } from './content-result.js';
8-
import Credentials from '../credentials.js';
6+
// eslint-disable-next-line no-unused-vars
97
import { Logger } from '@bluecadet/launchpad-utils';
8+
import { ContentSource, SourceOptions } from './content-source';
9+
import { ContentResult, MediaDownload } from './content-result';
10+
import Credentials from '../credentials';
1011

1112
/**
1213
* Options for AirtableSource
@@ -22,46 +23,47 @@ export class AirtableOptions extends SourceOptions {
2223
...rest
2324
} = {}) {
2425
super(rest);
25-
26+
2627
/**
27-
* Airtable base ID. @see https://help.appsheet.com/en/articles/1785063-using-data-from-airtable#:~:text=To%20obtain%20the%20ID%20of,API%20page%20of%20the%20base.
28+
* Airtable base ID. @see https://help.appsheet.com/en/articles/1785063-using-data-from-airtable#:~:text=To%20obtain%20the%20ID%20of,API%20page%20of%20the%20base.
2829
* @type {string}
2930
*/
3031
this.baseId = baseId;
31-
32+
3233
/**
3334
* @type {string}
3435
* @default 'Grid view'
3536
*/
3637
this.defaultView = defaultView;
37-
38+
3839
/**
3940
* The tables you want to fetch from
4041
* @type {string}
4142
* @default []
4243
*/
4344
this.tables = tables;
44-
45+
4546
/**
46-
* As a convenience feature, you can store tables listed here as key/value pairs. Field names should be `"key"` and `"value"`.
47+
* As a convenience feature, you can store tables listed here as
48+
* key/value pairs. Field names should be `"key"` and `"value"`.
4749
* @type {string}
4850
* @default []
4951
*/
5052
this.keyValueTables = keyValueTables;
51-
53+
5254
/**
5355
* The API endpoint to use for Airtable
5456
* @type {string}
5557
* @default 'https://api.airtable.com'
5658
*/
5759
this.endpointUrl = endpointUrl;
58-
60+
5961
/**
60-
* The table view which to select for syncing by default
62+
* The table view which to select for syncing by default
6163
* @type {string}
62-
*/
64+
*/
6365
this.defaultView = defaultView;
64-
66+
6567
/**
6668
* Appends the local path of attachments to the saved JSON
6769
* @type {boolean}
@@ -73,20 +75,22 @@ export class AirtableOptions extends SourceOptions {
7375

7476
export class AirtableSource extends ContentSource {
7577
/** @type {Airtable.Base} */
76-
_base;
78+
_base = null;
79+
7780
_rawAirtableData = {};
81+
7882
_simplifiedData = {};
7983

8084
/**
81-
*
82-
* @param {*} config
83-
* @param {Logger} logger
85+
*
86+
* @param {*} config
87+
* @param {Logger} logger
8488
*/
8589
constructor(config, logger) {
8690
super(new AirtableOptions(config), logger);
87-
91+
8892
const credentials = Credentials.getCredentials(this.config.id);
89-
93+
9094
if (!credentials.apiKey) {
9195
throw new Error(`No Airtable API Key for '${this.config.id}'`);
9296
}
@@ -97,12 +101,12 @@ export class AirtableSource extends ContentSource {
97101
});
98102

99103
this._base = Airtable.base(this.config.baseId);
100-
this._base.makeRequest
104+
this._base.makeRequest();
101105
}
102-
106+
103107
/**
104-
* @returns {Promise<ContentResult>}
105-
*/
108+
* @returns {Promise<ContentResult>}
109+
*/
106110
async fetchContent() {
107111
const result = new ContentResult();
108112
const tablePromises = [];
@@ -127,19 +131,19 @@ export class AirtableSource extends ContentSource {
127131
}
128132

129133
/**
130-
*
131-
* @param {string} tableId
132-
* @param {boolean} isKeyValueTable
133-
* @param {ContentResult} result
134+
*
135+
* @param {string} tableId
136+
* @param {boolean} isKeyValueTable
137+
* @param {ContentResult} result
134138
* @returns {ContentResult}
135139
*/
136-
async _processTable(tableId, isKeyValueTable = false, result = new ContentResult()) {
140+
async _processTable(tableId, isKeyValueTable = false, result = new ContentResult()) {
137141
// Write raw Data file.
138-
139-
const rawDataPath = tableId + '.raw.json';
142+
143+
const rawDataPath = `${tableId}.raw.json`;
140144
result.addDataFile(rawDataPath, this._rawAirtableData[tableId]);
141-
142-
let simpData = isKeyValueTable ? {} : [];
145+
146+
const simpData = isKeyValueTable ? {} : [];
143147
this._simplifiedData[tableId] = [];
144148

145149
// Process simplified data
@@ -149,7 +153,7 @@ export class AirtableSource extends ContentSource {
149153
if (isKeyValueTable) {
150154
if (Object.keys(row).length < 2) {
151155
this.logger.error(
152-
`Table ${tableId} requires at least 2 columns to map it to a key-value pair.`
156+
`Table ${tableId} requires at least 2 columns to map it to a key-value pair.`,
153157
);
154158
return result;
155159
}
@@ -161,7 +165,7 @@ export class AirtableSource extends ContentSource {
161165
const key = fields[keyField];
162166
const value = fields[valueField];
163167

164-
let matches = key ? [...key.matchAll(regex)] : [];
168+
const matches = key ? [...key.matchAll(regex)] : [];
165169
if (matches.length > 0) {
166170
if (!simpData[matches[0][1]]) {
167171
simpData[matches[0][1]] = [];
@@ -184,19 +188,20 @@ export class AirtableSource extends ContentSource {
184188
// Gather attachments
185189
if (!isKeyValueTable) {
186190
result.addMediaDownloads(
187-
this._getMediaUrls(simpData).map(url => new MediaDownload({url}))
191+
this._getMediaUrls(simpData).map((url) => new MediaDownload({ url })),
188192
);
189193
}
190194

191-
const simpDataPath = tableId + '.json';
195+
const simpDataPath = `${tableId}.json`;
192196
result.addDataFile(simpDataPath, this._simplifiedData[tableId]);
193-
197+
194198
return result;
195199
}
196200

197201
_isBoolStr(str) {
198202
return str === 'true' || str === 'false';
199203
}
204+
200205
_isNumericStr(str) {
201206
return !isNaN(str);
202207
}
@@ -211,28 +216,27 @@ export class AirtableSource extends ContentSource {
211216
if (this._rawAirtableData[table] && this._rawAirtableData[table].length > 0) {
212217
// Return cached data
213218
return Promise.resolve(this._rawAirtableData[table]);
214-
} else {
215-
// Fetch new data
216-
return this._fetchData(table).then((tableData) => {
217-
this._rawAirtableData[table] = tableData;
218-
return this._rawAirtableData[table];
219-
});
220219
}
220+
// Fetch new data
221+
return this._fetchData(table).then((tableData) => {
222+
this._rawAirtableData[table] = tableData;
223+
return this._rawAirtableData[table];
224+
});
221225
}
222226

223227
// Fetch from Airtable.
224228
async _fetchData(table) {
225229
return new Promise((resolve, reject) => {
226-
let rows = [];
230+
const rows = [];
227231

228232
this._base(table)
229233
.select({
230234
view: this.config.defaultView,
231235
})
232236
.eachPage(
233-
function page(records, fetchNextPage) {
237+
(records, fetchNextPage) => {
234238
// This function (`page`) will get called for each page of records.
235-
records.forEach(function (record) {
239+
records.forEach((record) => {
236240
rows.push(record);
237241
});
238242

@@ -241,29 +245,29 @@ export class AirtableSource extends ContentSource {
241245
// If there are no more records, `done` will get called.
242246
fetchNextPage();
243247
},
244-
function done(err) {
248+
(err) => {
245249
if (err) {
246250
reject(err);
247251
} else {
248252
resolve(rows);
249253
}
250-
}
254+
},
251255
);
252256
});
253257
}
254-
258+
255259
/**
256-
*
257-
* @param {*} tableData
260+
*
261+
* @param {*} tableData
258262
* @returns {Array<string>} media urls
259263
*/
260-
_getMediaUrls(tableData) {
264+
_getMediaUrls(tableData) {
261265
const urls = [];
262266
// Loop through all records, for filename fields.
263267
for (const row of tableData) {
264268
for (const colId of Object.keys(row)) {
265269
// We assume it is a file if value is an array and `filename` key exists.
266-
if (Array.isArray(row[colId]) && row[colId][0]['filename']) {
270+
if (Array.isArray(row[colId]) && row[colId][0].filename) {
267271
for (const attachment of row[colId]) {
268272
const url = new URL(attachment.url);
269273
if (this.config.appendLocalAttachmentPaths) {

packages/monitor/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
22

3-
import { LaunchpadMonitor } from './lib/launchpad-monitor.js';
43
import { launchFromCli, onExit } from '@bluecadet/launchpad-utils';
4+
import { LaunchpadMonitor } from './lib/launchpad-monitor';
55

66
// export * from './lib/windows-api.js'; // Includes optional dependencies, so not exported here
7-
export * from './lib/launchpad-monitor.js';
8-
export * from './lib/monitor-options.js';
7+
export * from './lib/launchpad-monitor';
8+
export * from './lib/monitor-options';
99
export default LaunchpadMonitor;
1010

1111
export const launch = async (config) => {
@@ -17,10 +17,10 @@ export const launch = async (config) => {
1717
await monitor.stop();
1818
await monitor.disconnect();
1919
});
20-
}
20+
};
2121

2222
launchFromCli(import.meta, {
23-
relativePaths: ["launchpad-monitor/index.js", ".bin/launchpad-monitor"],
23+
relativePaths: ['launchpad-monitor/index.js', '.bin/launchpad-monitor'],
2424
})
2525
.then(launch)
2626
.catch((err) => {

0 commit comments

Comments
 (0)