Skip to content

Commit

Permalink
Splitting up types into more specific files (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
scalvert authored Apr 16, 2020
1 parent c55cdbd commit 2395367
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 91 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/base-task-result.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TaskMetaData } from './types';
import { TaskMetaData } from './types/tasks';

export default abstract class BaseTaskResult {
meta: TaskMetaData;
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/configuration/checkup-config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as debug from 'debug';
import * as fs from 'fs';
import * as yaml from 'js-yaml';

import { CheckupConfig, CheckupConfigFormat, CheckupConfigLoader, ConfigMapper } from '../types';
import {
CheckupConfig,
CheckupConfigFormat,
CheckupConfigLoader,
ConfigMapper,
} from '../types/configuration';

import { RuntimeCheckupConfig } from '../types/runtime-types';
import { fold } from 'fp-ts/lib/Either';
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/configuration/cosmiconfig-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
import * as path from 'path';
import { CheckupConfigFormat, CosmiconfigServiceResult } from '../types';

import { CheckupConfigFormat, CosmiconfigServiceResult } from '../types/configuration';
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';

type ConfigExtension = '.js' | '.json' | '.yml' | '.yaml';
const EXTENSION_TO_FORMAT: Record<ConfigExtension, CheckupConfigFormat> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CheckupConfigLoader } from '../../types';
import { CheckupConfigLoader } from '../../types/configuration';
import CosmiconfigService from '../cosmiconfig-service';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CheckupConfigFormat, CheckupConfigLoader } from '../../types';
import * as path from 'path';

import { CheckupConfigFormat, CheckupConfigLoader } from '../../types/configuration';

/**
* Get a config loader given a filepath and the config format. This loader should
* be used when initializing a new config (i.e. not loading a config from disk).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CheckupConfigLoader } from '../../types';
import { CheckupConfigLoader } from '../../types/configuration';
import CosmiconfigService from '../cosmiconfig-service';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/file-searcher-task.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BaseTask from './base-task';
import FileSearcher from './searchers/file-searcher';
import { SearchPatterns } from './types';
import { SearchPatterns } from './types/tasks';

/**
* @class FileSearcherTask
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ export { getPackageJson } from './utils/get-package-json';
export { ui } from './utils/ui';
export { toPairs } from './utils/data-transformers';

export * from './types';
export * from './types/parsers';
export * from './types/tasks';
export * from './types/configuration';
export * from './types/ember-template-lint';
2 changes: 1 addition & 1 deletion packages/core/src/parsers/ember-template-lint-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';

import { CreateParser, Parser } from '../types';
import { CreateParser, Parser } from '../types/parsers';
import {
TemplateLintConfig,
TemplateLintMessage,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/parsers/eslint-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateParser, Parser } from '../types';
import { CreateParser, Parser } from '../types/parsers';

import { CLIEngine } from 'eslint';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/parsers/registered-parsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateParser, Parser, ParserName, ParserOptions, ParserReport } from '../types';
import { CreateParser, Parser, ParserName, ParserOptions, ParserReport } from '../types/parsers';

import { createParser as createEmberTemplateLintParser } from './ember-template-lint-parser';
import { createParser as createEslintParser } from './eslint-parser';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/report-components/graded-table-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TaskMetaData, Grade, DependencyResult, ReportComponentType } from '../types';
import { DependencyResult, Grade, ReportComponentType, TaskMetaData } from '../types/tasks';

import { default as TableData } from './table-data';

export default class GradedTableData extends TableData {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/report-components/numerical-card-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TaskMetaData, Grade, ReportComponentType } from '../types';
import { Grade, ReportComponentType, TaskMetaData } from '../types/tasks';

import { ReportComponentData } from './report-component-data';

export default class NumericalCardData extends ReportComponentData {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/report-components/pie-chart-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TaskMetaData, Grade, ReportComponentType } from '../types';
import { Grade, ReportComponentType, TaskMetaData } from '../types/tasks';

import { ReportComponentData } from './report-component-data';

export default class PieChartData extends ReportComponentData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TaskMetaData, ReportComponentType } from '../types';
import { ReportComponentType, TaskMetaData } from '../types/tasks';

export abstract class ReportComponentData {
constructor(public meta: TaskMetaData, public componentType: ReportComponentType) {}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/report-components/table-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TaskMetaData, ReportComponentType, DependencyResult } from '../types';
import { DependencyResult, ReportComponentType, TaskMetaData } from '../types/tasks';

import { ReportComponentData } from './report-component-data';

export default class TableData extends ReportComponentData {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/searchers/file-searcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as globby from 'globby';

import { SearchPatterns, TaskItemData } from '../types';
import { SearchPatterns, TaskItemData } from '../types/tasks';

const IGNORE_PATTERNS: string[] = [
'!**/node_modules/**',
Expand Down
24 changes: 24 additions & 0 deletions packages/core/src/types/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as t from 'io-ts';

import { RuntimeCheckupConfig, RuntimeTaskConfig } from './runtime-types';

import { PromiseValue } from 'type-fest';

export type CheckupConfig = t.TypeOf<typeof RuntimeCheckupConfig>;
export type TaskConfig = t.TypeOf<typeof RuntimeTaskConfig>;

export enum CheckupConfigFormat {
JSON = 'JSON',
YAML = 'YAML',
JavaScript = 'JavaScript',
}

export type CheckupConfigLoader = () => Promise<{
format: CheckupConfigFormat;
filepath: string;
config: CheckupConfig;
}>;

export type ConfigMapper = (config: CheckupConfig) => CheckupConfig;

export type CosmiconfigServiceResult = PromiseValue<ReturnType<CheckupConfigLoader>> | null;
10 changes: 10 additions & 0 deletions packages/core/src/types/parsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type ParserName = string;
export type ParserOptions = Record<string, any>;
export type ParserReport = any;
export interface Parser<ParserReport> {
execute(paths: string[]): Promise<ParserReport>;
}

export interface CreateParser<ParserOptions, TParser = Parser<ParserReport>> {
(config: ParserOptions): TParser;
}
111 changes: 39 additions & 72 deletions packages/core/src/types/index.ts → packages/core/src/types/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import * as t from 'io-ts';

import { JsonObject, PromiseValue } from 'type-fest';
import { RuntimeCheckupConfig, RuntimeTaskConfig } from './runtime-types';

import GradedTableData from '../report-components/graded-table-data';
import { JsonObject } from 'type-fest';
import NumericalCardData from '../report-components/numerical-card-data';
import PieChartData from '../report-components/pie-chart-data';
import TableData from '../report-components/table-data';

export type CheckupConfig = t.TypeOf<typeof RuntimeCheckupConfig>;
export type TaskConfig = t.TypeOf<typeof RuntimeTaskConfig>;
export type ParserName = string;
export type TaskName = string;
export type TaskClassification = {
category: Category;
priority: Priority;
};

export interface Task {
meta: TaskMetaData;

run: () => Promise<TaskResult>;
}

export type ParserOptions = Record<string, any>;
export type ParserReport = any;
export interface Parser<ParserReport> {
execute(paths: string[]): Promise<ParserReport>;
export interface TaskResult {
stdout: () => void;
json: () => JsonMetaTaskResult | JsonTaskResult;
pdf: () => ReportResultData;
}

export interface TaskMetaData {
taskName: TaskName;
friendlyTaskName: TaskName;
taskClassification: TaskClassification;
}

export interface CreateParser<ParserOptions, TParser = Parser<ParserReport>> {
(config: ParserOptions): TParser;
export interface TaskItemData {
type: string;
data: string[];
total: number;
}

export const enum Category {
Expand All @@ -34,16 +46,11 @@ export const enum Priority {
Medium = 'medium',
Low = 'low',
}
export type TaskName = string;
export type TaskClassification = {
category: Category;
priority: Priority;
};

export interface Task {
meta: TaskMetaData;

run: () => Promise<TaskResult>;
export interface DependencyResult {
name: string;
value: string;
grade?: Grade;
}

export type JsonMetaTaskResult = JsonObject;
Expand All @@ -53,6 +60,15 @@ export type JsonTaskResult = {
result: {};
};

export type ReportResultData = NumericalCardData | TableData | GradedTableData | PieChartData;

export const enum ReportComponentType {
NumericalCard = 'numerical-card',
Table = 'table',
GradedTable = 'graded-table',
PieChart = 'pie-chart',
}

export const enum Grade {
A = 'A',
B = 'B',
Expand All @@ -67,53 +83,4 @@ export enum ReporterType {
pdf = 'pdf',
}

export type ReportResultData = NumericalCardData | TableData | GradedTableData | PieChartData;

export const enum ReportComponentType {
NumericalCard = 'numerical-card',
Table = 'table',
GradedTable = 'graded-table',
PieChart = 'pie-chart',
}

export interface TaskResult {
stdout: () => void;
json: () => JsonMetaTaskResult | JsonTaskResult;
pdf: () => ReportResultData;
}

export interface TaskMetaData {
taskName: TaskName;
friendlyTaskName: TaskName;
taskClassification: TaskClassification;
}

export interface TaskItemData {
type: string;
data: string[];
total: number;
}

export interface DependencyResult {
name: string;
value: string;
grade?: Grade;
}

export type SearchPatterns = Record<string, string[]>;

export enum CheckupConfigFormat {
JSON = 'JSON',
YAML = 'YAML',
JavaScript = 'JavaScript',
}

export type CheckupConfigLoader = () => Promise<{
format: CheckupConfigFormat;
filepath: string;
config: CheckupConfig;
}>;

export type ConfigMapper = (config: CheckupConfig) => CheckupConfig;

export type CosmiconfigServiceResult = PromiseValue<ReturnType<CheckupConfigLoader>> | null;
2 changes: 1 addition & 1 deletion packages/core/src/utils/task-result-comparator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Category, Priority, TaskClassification } from '../types';
import { Category, Priority, TaskClassification } from '../types/tasks';

import BaseTaskResult from '../base-task-result';

Expand Down

0 comments on commit 2395367

Please sign in to comment.