This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4eb9a6e
commit 17d945a
Showing
27 changed files
with
450 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getInstalledPath } from "get-installed-path"; | ||
|
||
|
||
/* | ||
This file contains all the external (mockable) npm modules types | ||
*/ | ||
|
||
export type IGetInstalledPath = typeof getInstalledPath; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { inject, injectable } from "inversify"; | ||
import { TYPES } from "../../types"; | ||
|
||
import * as fse from "fs-extra"; | ||
import * as globby from "globby"; | ||
import * as nunjucks from "nunjucks"; | ||
import * as path from "path"; | ||
|
||
import DocProject from "../doc_models/DocProject"; | ||
import Design from "./entities/Design"; | ||
import IDesignRenderer from "./interfaces/IDesignRenderer"; | ||
import IRenderablePageGenerator from "./interfaces/IRenderablePageGenerator"; | ||
|
||
/** | ||
* This class renders a given design and writes the files to an output folder. | ||
* It also copy the other files needed by the Design | ||
*/ | ||
@injectable() | ||
export default class DesignRenderer implements IDesignRenderer { | ||
|
||
/** | ||
* The renderable page generator | ||
*/ | ||
@inject(TYPES.IRenderablePageGenerator) | ||
private _renderablePageGenerator: IRenderablePageGenerator; | ||
|
||
/** | ||
* Renders the documentation HTML files for the specified docProject. | ||
* @param outputFolder The output folder | ||
* @param docProject The docProject to generate the documentation for | ||
*/ | ||
public async render(design: Design, docProject: DocProject, outputFolder: string): Promise<void> { | ||
const env = nunjucks.configure(design.template.folder, { autoescape: false }); | ||
for (const page of design.pages) { | ||
const nunjucksTemplate = env.getTemplate(page.in, true); | ||
for (const rp of this._renderablePageGenerator.getPages(page, docProject)) { | ||
const content = nunjucksTemplate.render(rp.encodedData); | ||
const filename = path.resolve(outputFolder, rp.outputFile); | ||
await fse.outputFile(filename, content); | ||
} | ||
} | ||
await this._copyFiles(outputFolder, design); | ||
} | ||
|
||
/** | ||
* Copy the Design files inside the outputFolder. By default, it will copy | ||
* all files except the package.json, template.json and *.njk files. | ||
* @param outputFolder The output folder | ||
*/ | ||
private async _copyFiles(outputFolder: string, design: Design) { | ||
const files = await globby(design.copy, { cwd: design.template.folder }); | ||
for (const file of files) { | ||
const outputFile = path.resolve(outputFolder, file); | ||
const inputFile = path.resolve(design.template.folder, file); | ||
await fse.copy(inputFile, outputFile); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
import { inject, injectable } from "inversify"; | ||
import pkgDir = require("pkg-dir"); | ||
import { TYPES } from "../../types"; | ||
import { IGetInstalledPath } from "../npmmodules"; | ||
import IModuleFinder from "./interfaces/IModuleFinder"; | ||
|
||
/** | ||
* Finds a module installed locally or globally and returns his path | ||
*/ | ||
@injectable() | ||
export default class ModuleFinder implements IModuleFinder { | ||
|
||
/** | ||
* The "getInstalledPath" npm module | ||
*/ | ||
@inject(TYPES.IGetInstalledPath) | ||
private _getInstalledPath: IGetInstalledPath; | ||
|
||
/** | ||
* Gets the path of a template npm module from a global installation or local installation. | ||
* @param templateName The name of the template to find | ||
*/ | ||
public async find(moduleName: string): Promise<string> { | ||
try { | ||
return await this._getInstalledPath(moduleName); | ||
} catch (e) { | ||
try { | ||
const cwd = await pkgDir() as string; | ||
return await this._getInstalledPath(moduleName, { local: true, cwd }); | ||
} catch (e) { | ||
throw new Error(`Cannot find the module ${moduleName}`); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.