Skip to content

Commit

Permalink
feat: use ts paths
Browse files Browse the repository at this point in the history
  • Loading branch information
timoheddes committed Nov 27, 2023
1 parent 5930b44 commit f9e222c
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 25 deletions.
15 changes: 13 additions & 2 deletions __tests__/report.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Constants } from '../src/constants';
import type { ReportRecord } from '../src/types';
import { parseData, readFile, saveReport, validateRecords } from '../src/utils';
import {
parseData,
readFile,
saveReport,
stripRecords,
validateRecords,
} from '../src/utils/';

describe('report', () => {
let report: string;
Expand All @@ -9,7 +15,12 @@ describe('report', () => {
const records = await readFile('./__tests__/data/records.csv');
const parsedRecords = await parseData([records], 'csv');
const validatedRecords = validateRecords(parsedRecords);
report = saveReport(validatedRecords, 'test-report', './reports');

report = saveReport(
stripRecords(validatedRecords),
'test-report',
'./reports',
);

expect(report).toEqual(
JSON.stringify([
Expand Down
8 changes: 7 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// eslint-disable-next-line no-undef
/* eslint-disable */
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig.json');
module.exports = {
coverageDirectory: '__tests__/coverage',
preset: 'ts-jest',
testEnvironment: 'node',
coverageReporters: ['lcov', 'text', 'html'],
collectCoverageFrom: [
'src/*.{ts,tsx}',
Expand All @@ -9,6 +13,8 @@ module.exports = {
'!src/cli/*',
'!src/index.ts',
],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
modulePaths: ['<rootDir>'],
transform: {
'^.+\\.ts?$': 'ts-jest',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theddes/rabobank-assignment",
"version": "0.0.6",
"version": "0.0.7",
"description": "Rabobank Customer Statement Processor",
"main": "dist/index.js",
"bin": {
Expand Down
3 changes: 1 addition & 2 deletions src/cli/createReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import chalk from 'chalk';
import figlet from 'figlet';

import { saveReport, stripRecords, validateRecords } from '../utils';
import { count } from './count';
import { scanFolder } from './scanFolder';
import { count, scanFolder } from './';

/**
* Creates a report from the records in a JSON file.
Expand Down
2 changes: 1 addition & 1 deletion src/cli/scanFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import { Constants } from '../constants';
import type { DataFormat, RecordStructure } from '../types';
import { getFolderPath, parseData, readFolder } from '../utils';
import { count } from './count';
import { count } from './';

/**
* Scans a directory for CSV and XML files and reports the number of files and records found.
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#! /usr/bin/env node

import { createReport, scanFolder } from '@cli';
import { generateTimestamp } from '@utils';
import { Command } from 'commander';
import { createReport } from './cli/createReport';
import { scanFolder } from './cli/scanFolder';
import { generateTimestamp } from './utils';

const program = new Command();
program
Expand Down
4 changes: 2 additions & 2 deletions src/utils/file/read.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Constants } from '@constants';
import type { DataFormat } from '@types';
import * as fs from 'fs';
import * as path from 'path';
import { Constants } from '../../constants';
import type { DataFormat } from '../../types';

/**
* Reads the content of a file.
Expand Down
6 changes: 3 additions & 3 deletions src/utils/parser/csv.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Constants } from '@constants';
import type { RecordStructure } from '@types';
import csv from 'csv-parser';
import { Readable } from 'stream';
import { Constants } from '../../constants';
import type { RecordStructure } from '../../types';
import { isValidRecordStructure } from './validity';
import { isValidRecordStructure } from './';

const CSVHeaders = {
reference: 'Reference',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/parser/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DataFormat, RecordStructure } from '../../types';
import type { DataFormat, RecordStructure } from '@types';
import { parseCSV } from './csv';
import { parseXML } from './xml';

Expand Down
4 changes: 2 additions & 2 deletions src/utils/parser/validity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Constants } from '../../constants';
import { Constants } from '@constants';
import type {
RecordStructure,
ValidatedRecord,
ValidationProperties,
} from '../../types';
} from '@types';

/**
* Checks if the structure of a record is valid.
Expand Down
6 changes: 3 additions & 3 deletions src/utils/parser/xml.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Constants } from '@constants';
import type { RecordStructure } from '@types';
import { isValidRecordStructure } from '@utils';
import * as xml2js from 'xml2js';
import { Constants } from '../../constants';
import type { RecordStructure } from '../../types';
import { isValidRecordStructure } from './validity';

/**
* Parses XML data into an array of records.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/report/save.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RecordStructure, ValidatedRecord } from '@types';
import * as fs from 'fs';
import * as path from 'path';
import type { RecordStructure, ValidatedRecord } from '../../types';

/**
* Generates a timestamp with colons and periods replaced by hyphens.
Expand Down
12 changes: 9 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"allowJs": false,
"baseUrl": ".",
"baseUrl": "./",
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand All @@ -17,8 +17,14 @@
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"types": ["node", "jest"]
"types": ["node", "jest"],
"paths": {
"@utils": ["src/utils"],
"@types": ["src/types"],
"@constants": ["src/constants"],
"@cli": ["src/cli"]
}
},
"include": ["./src/**/*.ts"],
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}

0 comments on commit f9e222c

Please sign in to comment.