Skip to content

Commit

Permalink
Add support for .nojekyll file generation for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Oct 8, 2018
1 parent 0839af0 commit ad66400
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
7 changes: 2 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ gulp.task("test:pre-test", ["build"], preTest());
gulp.task("test", ["test:pre-test"], test({ main: "dist/tests/index.js", coverage: { thresholds: { global: 80 } } }));
gulp.task("watch", watch(["src/**/*"], ["test"]));
gulp.task("default", ["test"]);
gulp.task("docs:no-jekyll", () => {
try { fs.mkdirSync("docs"); } catch (e) {}
try { fs.writeFileSync("docs/.nojekyll", ""); } catch (e) {}
});
gulp.task("docs", ["docs:no-jekyll", "typedoc"], () => gulp.src("src/lib/**/*.ts", { read: false })
gulp.task("docs", ["typedoc"], () => gulp.src("src/lib/**/*.ts", { read: false })
.pipe(typedoc({
tsconfig: "src/lib/tsconfig.typedoc.json",
out: "docs",
Expand All @@ -47,6 +43,7 @@ gulp.task("docs", ["docs:no-jekyll", "typedoc"], () => gulp.src("src/lib/**/*.ts
excludeEmpty: true,
groupCategories: true,
renameModuleToNamespace: true,
noJekyll: true,
categoryOrder: ["Query", "Scalar", "Subquery", "Order", "Join", "Hierarchy", "*", "Other"],
biblio: "./biblio.json",
plugin: [
Expand Down
2 changes: 2 additions & 0 deletions src/typedoc/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { GroupCategoriesPlugin } from "./plugins/groupCategories";
import { MergePlugin } from "./plugins/merge";
import { NamingPlugin } from "./plugins/naming";
import { BiblioPlugin } from "./plugins/biblio";
import { NoJekyllPlugin } from "./plugins/noJekyll";

function load(host: PluginHost) {
const app = host.owner;
Expand All @@ -23,6 +24,7 @@ function load(host: PluginHost) {
app.converter.addComponent("naming", NamingPlugin);
app.converter.addComponent("biblio", BiblioPlugin);
app.converter.addComponent("node:exportDeclaration", ExportDeclarationConverter);
app.renderer.addComponent("no-jekyll", NoJekyllPlugin);
}

export = load;
42 changes: 42 additions & 0 deletions src/typedoc/plugin/plugins/noJekyll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as fs from "fs";
import * as path from "path";
import { RendererComponent, Component } from "typedoc/dist/lib/output/components";
import { Option, writeFile } from "typedoc/dist/lib/utils";
import { ParameterType } from "typedoc/dist/lib/utils/options/declaration";
import { ComponentHost } from "typedoc/dist/lib/utils/component";
import { Renderer } from "typedoc";
import { RendererEvent } from "typedoc/dist/lib/output/events";

@Component({
name: "no-jekyll",
})
export class NoJekyllPlugin extends RendererComponent {
@Option({
name: "noJekyll",
help: "Generates a .nojekyll file as part of the output",
type: ParameterType.Boolean
})
noJekyll!: boolean;

constructor(owner: ComponentHost) {
if (!(owner instanceof Renderer)) throw new TypeError();
super(owner);
}

initialize() {
super.initialize();
this.listenTo(this.owner, RendererEvent.END, this.onEnd);
}

private onEnd(event: RendererEvent) {
if (this.noJekyll) {
const filename = path.resolve(event.outputDirectory, ".nojekyll");
try {
writeFile(filename, "", /*writeByteOrderMark*/ false);
}
catch (e) {
this.application.logger.error("Could not write file %s", filename);
}
}
}
}

0 comments on commit ad66400

Please sign in to comment.