Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
refactor(store): allow only one analyzer per styleguide
Browse files Browse the repository at this point in the history
  • Loading branch information
faselbaum committed Mar 9, 2018
1 parent 25b939d commit 90f8a2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as FileUtils from 'fs';
import { TypescriptReactAnalyzer } from './styleguide/typescript-react-analyzer/index';
import { SyntheticAnalyzer } from './styleguide/synthetic-analyzer/index';
import { JsonArray, JsonObject, Persister } from './json';
import * as MobX from 'mobx';
import { IObservableArray } from 'mobx/lib/types/observablearray';
Expand Down Expand Up @@ -366,12 +365,11 @@ export class Store {
this.currentPage = undefined;

const typescriptReactAnalyzer = new TypescriptReactAnalyzer('react');
const syntheticAnalyzer = new SyntheticAnalyzer('synthetic');

const styleguide = new Styleguide(`${styleguidePath}/lib/patterns`, [
typescriptReactAnalyzer,
syntheticAnalyzer
]);
const styleguide = new Styleguide(
`${styleguidePath}/lib/patterns`,
typescriptReactAnalyzer
);

this.styleguide = styleguide;
this.styleguide.load();
Expand Down
29 changes: 23 additions & 6 deletions src/store/styleguide/styleguide.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
import { Folder } from './utils/folder';
import { Pattern } from '../pattern/pattern';
import { StyleguideAnalyzer } from './styleguide-analyzer';
import { SyntheticAnalyzer } from './synthetic-analyzer';

export interface Analyzers {
default?: StyleguideAnalyzer;
synthetic: StyleguideAnalyzer;
[id: string]: StyleguideAnalyzer | undefined;
}

export class Styleguide {
private readonly analyzers: StyleguideAnalyzer[];
private readonly analyzers: Analyzers;
private readonly path: string;
private patterns: Map<string, Pattern> = new Map();
private folders: Folder<Pattern>[] = [];

public constructor(path: string, analyzers?: StyleguideAnalyzer[]) {
this.analyzers = analyzers || [];
public constructor(path: string, analyzer?: StyleguideAnalyzer) {
this.analyzers = {
default: analyzer,
synthetic: new SyntheticAnalyzer('synthetic')
};

this.path = path;
}

public getPath(): string {
return this.path;
}

public getAnalyzers(): ReadonlyArray<StyleguideAnalyzer> {
return this.analyzers;
public getDefaultAnalyzer(): StyleguideAnalyzer | undefined {
return this.analyzers.default;
}

public getPatterns(): ReadonlyMap<string, Pattern> {
Expand All @@ -33,7 +44,13 @@ export class Styleguide {
this.patterns = new Map();
this.folders = [];

this.analyzers.forEach(analyzer => {
Object.keys(this.analyzers).forEach(analyzerId => {
const analyzer = this.analyzers[analyzerId];

if (analyzer === undefined) {
return;
}

const groupedPatterns = analyzer.analyze(this.path);
const patterns = groupedPatterns.flatten();

Expand Down

0 comments on commit 90f8a2c

Please sign in to comment.