Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optional template argument #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/args.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export declare const options: import("yargs").Argv<{
compiler: string;
} & {
format: "markdown";
} & {
template: string;
}>;
export declare const printCliArguments: (x: unknown) => void;
6 changes: 6 additions & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ exports.options = yargs_1.option("input", {
type: "string",
description: "ddocs format",
"default": types_1.cliArgumentsDefault.format
})
.option("template", {
alias: "t",
type: "string",
description: "template to use",
"default": types_1.cliArgumentsDefault.template
})
.help()
.alias("help", "h");
Expand Down
2 changes: 1 addition & 1 deletion lib/bin/vydoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var vyperFileExtentions = ["vy"];
switch (_a.label) {
case 0: return [4 /*yield*/, compile_1.compileContracts(argv.input, filePaths, argv.compiler)
.then(ramda_1.tap(function () { return console.log(chalk_1.blue("\nGenerate docs...")); }))
.then(function (contracts) { return generate_1.generateDocs(argv.format, argv.output, contracts); })];
.then(function (contracts) { return generate_1.generateDocs(argv.format, argv.output, contracts, argv.template); })];
case 1: return [2 /*return*/, _a.sent()];
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/generate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { Contract, Format } from "./types";
export declare const generateDocs: (format: Format, output: string, contracts: {
fileName: string;
data: Contract;
}[]) => Promise<any>;
}[], templatePath: string) => Promise<any>;
8 changes: 4 additions & 4 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ var fs_1 = require("fs");
var path_1 = require("path");
var ramda_1 = require("ramda");
var progress_1 = require("./progress");
var generateDocs = function (format, output, contracts) { return __awaiter(void 0, void 0, void 0, function () {
var generateDocs = function (format, output, contracts, templatePath) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, ramda_1.cond([
[ramda_1.equals("markdown"), function () { return generateMarkDown(contracts, output); }],
[ramda_1.equals("markdown"), function () { return generateMarkDown(contracts, output, templatePath); }],
[
ramda_1.T,
function () {
Expand All @@ -59,7 +59,7 @@ var generateDocs = function (format, output, contracts) { return __awaiter(void
});
}); };
exports.generateDocs = generateDocs;
var generateMarkDown = function (contracts, output) { return __awaiter(void 0, void 0, void 0, function () {
var generateMarkDown = function (contracts, output, templatePath) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, ramda_1.pipe(fs_1.readFileSync, function (buffer) { return buffer.toString(); }, ejs_1["default"].compile, function (template) {
return ramda_1.pipe(function (handler) {
Expand All @@ -77,6 +77,6 @@ var generateMarkDown = function (contracts, output) { return __awaiter(void 0, v
}))
.map(ramda_1.tap(handler));
})(progress_1.makeProgressBar(contracts.length));
})(path_1.join(__dirname, "../src/templates/markdown.ejs"))];
})(templatePath)];
});
}); };
3 changes: 1 addition & 2 deletions lib/table.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface TableOptions {
export interface TableOptions {
chars: Partial<Record<"top" | "top-mid" | "top-left" | "top-right" | "bottom" | "bottom-mid" | "bottom-left" | "bottom-right" | "left" | "left-mid" | "mid" | "mid-mid" | "right" | "right-mid" | "middle", string>>;
truncate: string;
colors: boolean;
Expand All @@ -14,4 +14,3 @@ interface TableOptions {
head: string[];
}
export declare const makeTable: (options?: Partial<TableOptions> | undefined) => (values: any[]) => string;
export {};
1 change: 1 addition & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export declare type CliArguments = {
output: string;
compiler: string;
format: Format;
template: string;
};
export declare type Format = "markdown";
export declare const cliArgumentsDefault: CliArguments;
Expand Down
3 changes: 2 additions & 1 deletion lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ exports.cliArgumentsDefault = {
input: "./contracts",
output: "./docs",
compiler: "vyper",
format: "markdown"
format: "markdown",
template: "../src/templates/markdown.ejs"
};
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/ejs": "^3.0.6",
"@types/node": "^14.14.35",
"@types/ramda": "^0.27.39",
"@types/yargs": "^16.0.0"
"@types/yargs": "^16.0.0",
"typescript": "^4.2.4"
}
}
}
6 changes: 6 additions & 0 deletions src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export const options = option("input", {
description: "ddocs format",
default: cliArgumentsDefault.format,
})
.option("template", {
alias: "t",
type: "string",
description: "template to use",
default: cliArgumentsDefault.template,
})
.help()
.alias("help", "h");

Expand Down
2 changes: 1 addition & 1 deletion src/bin/vydoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const vyperFileExtentions = ["vy"];
async (filePaths) =>
await compileContracts(argv.input, filePaths, argv.compiler)
.then(tap(() => console.log(blue("\nGenerate docs..."))))
.then((contracts) => generateDocs(argv.format, argv.output, contracts))
.then((contracts) => generateDocs(argv.format, argv.output, contracts, argv.template))
)(argv))(options.argv);
11 changes: 7 additions & 4 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { join } from "path";
import { cond, equals, pipe, T, tap } from "ramda";
import { makeProgressBar } from "./progress";
import { Contract, Format } from "./types";
import path from 'path';

export const generateDocs = async (
format: Format,
output: string,
contracts: { fileName: string; data: Contract }[]
contracts: { fileName: string; data: Contract }[],
templatePath: string
) =>
cond<Format, any>([
[equals("markdown"), () => generateMarkDown(contracts, output)],
[equals("markdown"), () => generateMarkDown(contracts, output, templatePath)],
[
T,
() => {
Expand All @@ -22,7 +24,8 @@ export const generateDocs = async (

const generateMarkDown = async (
contracts: { fileName: string; data: Contract }[],
output: string
output: string,
templatePath: string
) =>
pipe(
readFileSync,
Expand Down Expand Up @@ -51,4 +54,4 @@ const generateMarkDown = async (
)
.map(tap(handler))
)(makeProgressBar(contracts.length))
)(join(__dirname, "../src/templates/markdown.ejs"));
)(templatePath);
2 changes: 1 addition & 1 deletion src/table.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from "cli-table";

interface TableOptions {
export interface TableOptions {
chars: Partial<
Record<
| "top"
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type CliArguments = {
output: string;
compiler: string;
format: Format;
template: string
};

export type Format = "markdown";
Expand All @@ -12,6 +13,7 @@ export const cliArgumentsDefault = {
output: "./docs",
compiler: "vyper",
format: "markdown",
template: "../src/templates/markdown.ejs"
} as CliArguments;

export type Contract = {
Expand Down