Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
More decoupling in CliGenerateFacade
Browse files Browse the repository at this point in the history
  • Loading branch information
jhm-ciberman committed Mar 2, 2018
1 parent 710c953 commit e3428f3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import IDocumentationExtractor from "./src/generator/interfaces/IDocumentationEx
import IJSDocParser from "./src/parser/interfaces/IJSDocParser";
import JSDocParser from "./src/parser/JSDocParser";

import DocumentationGenerator from "./src/generator/DocumentationGenerator";
import IDocumentationGenerator from "./src/generator/interfaces/IDocumentationGenerator";
import ConsoleReporter from "./src/reporter/ConsoleReporter";
import IReporter from "./src/reporter/interfaces/IReporter";
import IRuleValidator from "./src/validation/interfaces/IRuleValidator";
Expand All @@ -31,6 +33,7 @@ container.bind<IRuleValidator>(TYPES.IRuleValidator).to(RuleValidator);

// Generator
container.bind<IDocumentationExtractor>(TYPES.IDocumentationExtractor).to(DocumentationExtractor);
container.bind<IDocumentationGenerator>(TYPES.IDocumentationGenerator).to(DocumentationGenerator);

// Parser
container.bind<IJSDocParser>(TYPES.IJSDocParser).to(JSDocParser);
Expand Down
3 changes: 2 additions & 1 deletion src/cli/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import container from "../../inversify.config";
import { TYPES } from "../../types";

import * as program from "commander";
import { inject } from "inversify";
import { inject, injectable } from "inversify";
import * as os from "os";
import IConfigManager from "../config/interfaces/IConfigManager";
import IReporter from "../reporter/interfaces/IReporter";
Expand All @@ -14,6 +14,7 @@ const packageJSON = require("../package.json");
/**
* This class is responsible for showing the CLI interface. It has a single method parse(argv).
*/
@injectable()
export default class Cli {

/**
Expand Down
32 changes: 23 additions & 9 deletions src/cli/CliGenerateFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import open = require("open");
import * as path from "path";

import { inject, injectable } from "inversify";
import container from "../../inversify.config";
import { TYPES } from "../../types";

import IConfigManager from "../config/interfaces/IConfigManager";
import IProjectConfig from "../config/interfaces/IProjectConfig";
import ProjectConfig from "../config/ProjectConfig";
import DocumentationGenerator from "../generator/DocumentationGenerator";
import ProjectLoader from "../gm_project/ProjectLoader";
import IDocumentationGenerator from "../generator/interfaces/IDocumentationGenerator";
import IGMProjectLoader from "../gm_project/interfaces/IGMProjectLoader";
import IReporter from "../reporter/interfaces/IReporter";
import ICliGenerateFacade from "./interfaces/ICliGenerateFacade.d";

Expand Down Expand Up @@ -50,6 +49,24 @@ export default class CliGenerateFacade implements ICliGenerateFacade {
@inject(TYPES.IReporter)
private _reporter: IReporter;

/**
* The GMProjectLoader
*/
@inject(TYPES.IGMProjectLoader)
private _loader: IGMProjectLoader;

/**
* The config manager
*/
@inject(TYPES.IConfigManager)
private _configManager: IConfigManager;

/**
* The documentation generator
*/
@inject(TYPES.IDocumentationGenerator)
private _documentationGenerator: IDocumentationGenerator;

/**
* Generates the documentation for a given project
* @param projectPath The path to the project
Expand All @@ -59,13 +76,11 @@ export default class CliGenerateFacade implements ICliGenerateFacade {

this._reporter.info("Loading Project...");

const loader = new ProjectLoader();
const project = await loader.load(projectPath);
const project = await this._loader.load(projectPath);

this._reporter.info("Loading project configuration...");

const configManager = container.get<IConfigManager>(TYPES.IConfigManager);
let config = await configManager.loadConfig(projectPath);
let config = await this._configManager.loadConfig(projectPath);

if (!config) {
this._reporter.info("Configuration not found. Using default configuration.");
Expand All @@ -74,8 +89,7 @@ export default class CliGenerateFacade implements ICliGenerateFacade {
config = this._overrideConfig(config);

this._reporter.info("Generating documentation... ");
const docsGenerator = new DocumentationGenerator();
const outFolder = await docsGenerator.generate(project, config);
const outFolder = await this._documentationGenerator.generate(project, config);

this._reporter.info("Ready!");

Expand Down
2 changes: 1 addition & 1 deletion src/config/interfaces/IConfigManager.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IProjectConfig from "./IProjectConfig";

export default class IConfigManager {
export default interface IConfigManager {
exportConfig(outputPath: string): Promise<string>;
loadConfig(jsonOrProjectPath: string): Promise<IProjectConfig | undefined>;
}
3 changes: 2 additions & 1 deletion src/generator/DocumentationGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject } from "inversify";
import { inject, injectable } from "inversify";
import { TYPES } from "../../types";

import * as path from "path";
Expand All @@ -14,6 +14,7 @@ import IDocProjectGenerator from "./interfaces/IDocProjectGenerator";
/**
* Generates the documentation.
*/
@injectable()
export default class DocumentationGenerator {

/**
Expand Down
6 changes: 6 additions & 0 deletions src/generator/interfaces/IDocumentationGenerator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import IProjectConfig from "../../config/interfaces/IProjectConfig";
import IGMProject from "../../gm_project/interfaces/IGMProject";

export default interface IDocumentationGenerator {
generate(project: IGMProject, config?: IProjectConfig): Promise<string>;
}
2 changes: 2 additions & 0 deletions src/gm_project/ProjectLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as globby from "globby";
import * as path from "path";

import { injectable } from "inversify";
import IGMProject from "../gm_project/interfaces/IGMProject";
import GMS1ProjectLoader from "./gms1/GMS1ProjectLoader";
import GMS2ProjectLoader from "./gms2/GMS2ProjectLoader";
Expand All @@ -9,6 +10,7 @@ import IGMProjectLoader from "./interfaces/IGMProjectLoader";
/**
* This Factory class loads a GMS1 or GMS2 project and returns a GMProject object
*/
@injectable()
export default class ProjectLoader implements IGMProjectLoader {

/**
Expand Down
4 changes: 4 additions & 0 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const TYPES = {
// generator
IDocumentationExtractor: Symbol.for("IDocumentationExtractor"),
IDocProjectGenerator: Symbol.for("IDocProjectGenerator"),
IDocumentationGenerator: Symbol.for("IDocumentationGenerator"),

// parser
IJSDocParser: Symbol.for("IJSDocParser"),
Expand All @@ -20,6 +21,9 @@ const TYPES = {
// Validation
IScriptValidator: Symbol.for("IScriptValidator"),
IRuleValidator: Symbol.for("IRuleValidator"),

// Loader
IGMProjectLoader: Symbol.for("IGMProjectLoader"),
};

export {TYPES};

0 comments on commit e3428f3

Please sign in to comment.