Skip to content

Commit e3fada2

Browse files
committed
Harvest seemingly works now, need to update readme and somehow test harvest, add eslint and stuff
1 parent 51974ff commit e3fada2

File tree

6 files changed

+2065
-50
lines changed

6 files changed

+2065
-50
lines changed

.eslintrc.cjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
env: {
3+
es2021: true,
4+
node: true,
5+
},
6+
extends: 'eslint:recommended',
7+
overrides: [
8+
{
9+
env: {
10+
node: true,
11+
},
12+
files: ['.eslintrc.{js,cjs}'],
13+
parserOptions: {
14+
sourceType: 'script',
15+
},
16+
},
17+
{
18+
files: ['**/*.test.js'],
19+
env: {
20+
jest: true,
21+
},
22+
},
23+
],
24+
parserOptions: {
25+
ecmaVersion: 'latest',
26+
sourceType: 'module',
27+
},
28+
rules: {},
29+
plugins: ['jest'],
30+
};

cli/configure.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ const configSchema = yup.object().shape({
8484
* @param {RawBountyConfig} config
8585
* @returns {BountyConfig}
8686
*/
87-
function validateAndProcessBountyConfig(config) {
87+
export function validateAndProcessBountyConfig(config) {
8888
try {
89-
const validatedConfig = configSchema.validateSync(config);
89+
const validatedConfig = { ...configSchema.validateSync(config) };
9090
validatedConfig.referenceDate = ISODateToDate(config.referenceDate);
9191
return validatedConfig;
9292
} catch (error) {
@@ -130,7 +130,7 @@ function validateNumber(input) {
130130
*/
131131
export async function initalizeBountyConfig() {
132132
let config = getConfig();
133-
let isOldHarvestConfig = config != null && !Boolean(config.integration);
133+
let isOldHarvestConfig = config != null && !config.integration;
134134

135135
/** @type {OldHarvestConfig | null} */
136136
let oldHarvestConfig = null;
@@ -247,18 +247,18 @@ export async function initalizeBountyConfig() {
247247
validate: validateNumber,
248248
});
249249

250-
const defualtHoursOnChristmasEve = 3.75;
250+
const defaultHoursOnChristmasEve = 3.75;
251251
const { hoursOnChristmasEve } = await inquirer.prompt({
252252
type: 'input',
253253
name: 'hoursOnChristmasEve',
254-
message: `Enter expected registered hours on Christmas Eve (Julaften, 24. December) (float, default ${defualtHoursOnChristmasEve}):`,
255-
default: defualtHoursOnChristmasEve,
254+
message: `Enter expected registered hours on Christmas Eve (Julaften, 24. December) (float, default ${defaultHoursOnChristmasEve}):`,
255+
default: defaultHoursOnChristmasEve,
256256
validate: validateNumber,
257257
});
258258

259259
config.hoursOnSpecificHolidays = {
260-
[NorwegianHoliday.HOLY_WEDNESDAY]: hoursOnHolyWednesday,
261-
[NorwegianHoliday.CHRISTMAS_EVE]: hoursOnChristmasEve,
260+
[NorwegianHoliday.HOLY_WEDNESDAY]: parseFloat(hoursOnHolyWednesday),
261+
[NorwegianHoliday.CHRISTMAS_EVE]: parseFloat(hoursOnChristmasEve),
262262
};
263263

264264
const validatedconfig = validateAndProcessBountyConfig(config);

integrations/harvest/configuration.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function setupFilesInHomeAndPromptForInfo() {
3434

3535
setConfig(currConfig);
3636
console.log();
37-
console.log(`Config \x1b[32msuccessfully\x1b[m updated at \x1b[33m${CONFIG_FILE}\x1b[m`);
37+
console.log(`Harvest config \x1b[32msuccessfully\x1b[m updated at \x1b[33m${CONFIG_FILE}\x1b[m`);
3838
console.log();
3939
console.log(`If something crashes, make sure that the config values makes sense:`);
4040
console.log(currConfig);
@@ -43,11 +43,18 @@ export async function setupFilesInHomeAndPromptForInfo() {
4343
return currConfig;
4444
}
4545

46+
/** @type {ClockifyConfig | null} */
47+
let config = null;
48+
4649
/**
4750
* @returns {HarvestConfig}
4851
*/
4952
export function getConfig() {
50-
return JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
53+
if (config != null) {
54+
return config;
55+
}
56+
config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
57+
return config;
5158
}
5259

5360
export function setConfig(config) {

integrations/harvest/index.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import * as dates from '../../core/dates.js';
22
import { setupFilesInHomeAndPromptForInfo } from './configuration.js';
3+
import { CONFIG_FILE } from './constants.js';
4+
import axios from 'axios';
5+
import { getConfig as getCoreConfig, validateAndProcessBountyConfig } from '../../cli/configure.js';
36

47
/**
58
* @param {object} headers headers to send to harvest
@@ -52,19 +55,10 @@ export async function getWorkHours(from, to) {
5255
* @param {{to: Date, from: Date , balance: number}} obj
5356
* */
5457
export async function afterRun({ balance }) {
55-
console.log('referenceDate :>> ', getReferenceDate().toLocaleDateString('no-NB'));
56-
console.log('referenceBalance :>> ', getReferenceBalance());
58+
const coreConfig = validateAndProcessBountyConfig(getCoreConfig());
59+
60+
console.log('referenceDate :>> ', coreConfig.toLocaleDateString('no-NB'));
61+
console.log('referenceBalance :>> ', coreConfig.referenceBalance);
5762
console.log('currDate :>> ', new Date().toLocaleDateString('no-NB'));
5863
console.log('currBalance :>> ', balance);
5964
}
60-
61-
import { fileURLToPath } from 'url';
62-
if (process.argv[1] === fileURLToPath(import.meta.url)) {
63-
async function main() {
64-
await beforeRun();
65-
const workedHours = await getWorkHours();
66-
console.log('workedHours :>> ', workedHours);
67-
}
68-
69-
main();
70-
}

0 commit comments

Comments
 (0)