solidity-docgen
Advanced tools
Comparing version 0.3.2 to 0.3.3
176
dist/cli.js
#!/usr/bin/env node | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,68 +24,105 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const command_1 = require("@oclif/command"); | ||
const path_1 = __importDefault(require("path")); | ||
const json5_1 = __importDefault(require("json5")); | ||
const docgen_1 = require("./docgen"); | ||
class Docgen extends command_1.Command { | ||
run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { flags } = this.parse(Docgen); | ||
yield docgen_1.docgen(flags); | ||
exports.__esModule = true; | ||
var command_1 = require("@oclif/command"); | ||
var path_1 = require("path"); | ||
var json5_1 = require("json5"); | ||
var docgen_1 = require("./docgen"); | ||
var Docgen = /** @class */ (function (_super) { | ||
__extends(Docgen, _super); | ||
function Docgen() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
Docgen.prototype.run = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var flags; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
flags = this.parse(Docgen).flags; | ||
return [4 /*yield*/, docgen_1.docgen(flags)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
Docgen.flags = { | ||
version: command_1.flags.version(), | ||
help: command_1.flags.help(), | ||
input: command_1.flags.string({ | ||
char: 'i', | ||
default: 'contracts', | ||
description: 'directory where contracts will be taken from', | ||
}), | ||
output: command_1.flags.string({ | ||
char: 'o', | ||
default: 'docs', | ||
description: 'directory where generated docs will be written', | ||
}), | ||
exclude: command_1.flags.build({ | ||
parse: s => s.split(','), | ||
})({ | ||
char: 'e', | ||
description: 'exclude directories that match the pattern (separated by commas)', | ||
}), | ||
templates: command_1.flags.string({ | ||
char: 't', | ||
parse: s => path_1.default.resolve(s), | ||
description: 'directory with template files', | ||
}), | ||
extension: command_1.flags.string({ | ||
char: 'x', | ||
default: 'md', | ||
description: 'file extension for generated pages, not necessary when using READMEs', | ||
}), | ||
'solc-module': command_1.flags.string({ | ||
parse: s => path_1.default.resolve(s), | ||
description: 'path to an alternative solc module', | ||
}), | ||
'solc-settings': command_1.flags.build({ | ||
parse: s => { | ||
const settings = json5_1.default.parse(s); | ||
if (typeof settings !== 'object' || settings === null) { | ||
throw new Error('--solc-settings must be an object'); | ||
}; | ||
Docgen.flags = { | ||
version: command_1.flags.version(), | ||
help: command_1.flags.help(), | ||
input: command_1.flags.string({ | ||
char: 'i', | ||
"default": 'contracts', | ||
description: 'directory where contracts will be taken from' | ||
}), | ||
output: command_1.flags.string({ | ||
char: 'o', | ||
"default": 'docs', | ||
description: 'directory where generated docs will be written' | ||
}), | ||
exclude: command_1.flags.build({ | ||
parse: function (s) { return s.split(','); } | ||
})({ | ||
char: 'e', | ||
description: 'exclude directories that match the pattern (separated by commas)' | ||
}), | ||
templates: command_1.flags.string({ | ||
char: 't', | ||
parse: function (s) { return path_1["default"].resolve(s); }, | ||
description: 'directory with template files' | ||
}), | ||
extension: command_1.flags.string({ | ||
char: 'x', | ||
"default": 'md', | ||
description: 'file extension for generated pages, not necessary when using READMEs' | ||
}), | ||
'solc-module': command_1.flags.string({ | ||
parse: function (s) { return path_1["default"].resolve(s); }, | ||
description: 'path to an alternative solc module' | ||
}), | ||
'solc-settings': command_1.flags.build({ | ||
parse: function (s) { | ||
var settings = json5_1["default"].parse(s); | ||
if (typeof settings !== 'object' || settings === null) { | ||
throw new Error('--solc-settings must be an object'); | ||
} | ||
return settings; | ||
} | ||
return settings; | ||
}, | ||
})({ | ||
description: 'compiler settings for solc module', | ||
}), | ||
'contract-pages': command_1.flags.boolean({ | ||
default: false, | ||
description: 'enable one page per contract', | ||
}), | ||
}; | ||
})({ | ||
description: 'compiler settings for solc module' | ||
}), | ||
'contract-pages': command_1.flags.boolean({ | ||
"default": false, | ||
description: 'enable one page per contract' | ||
}) | ||
}; | ||
return Docgen; | ||
}(command_1.Command)); | ||
Docgen.run().then(undefined, require('@oclif/errors/handle')); | ||
//# sourceMappingURL=cli.js.map |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,73 +21,124 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lodash_1 = require("lodash"); | ||
const path_1 = __importDefault(require("path")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const globby_1 = __importDefault(require("globby")); | ||
const semver_1 = __importDefault(require("semver")); | ||
const outputSelection = { | ||
exports.__esModule = true; | ||
var lodash_1 = require("lodash"); | ||
var path_1 = require("path"); | ||
var fs_extra_1 = require("fs-extra"); | ||
var globby_1 = require("globby"); | ||
var semver_1 = require("semver"); | ||
var outputSelection = { | ||
'*': { | ||
'': [ | ||
'ast', | ||
], | ||
}, | ||
] | ||
} | ||
}; | ||
function compile(directory, ignore = [], solcModule = 'solc', solcSettings = { optimizer: { enabled: true, runs: 200 } }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const solc = yield SolcAdapter.require(solcModule); | ||
const files = yield globby_1.default(path_1.default.join(directory, '**/*.sol'), { | ||
ignore: ignore.map(i => path_1.default.join(i, '**/*')), | ||
function compile(directory, ignore, solcModule, solcSettings) { | ||
if (ignore === void 0) { ignore = []; } | ||
if (solcModule === void 0) { solcModule = 'solc'; } | ||
if (solcSettings === void 0) { solcSettings = { optimizer: { enabled: true, runs: 200 } }; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var solc, files, sources, _a, solcInput, solcOutput, allErrors, errors, firstError, moreErrors; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, SolcAdapter.require(solcModule)]; | ||
case 1: | ||
solc = _b.sent(); | ||
return [4 /*yield*/, globby_1["default"](path_1["default"].join(directory, '**/*.sol'), { | ||
ignore: ignore.map(function (i) { return path_1["default"].join(i, '**/*'); }) | ||
})]; | ||
case 2: | ||
files = _b.sent(); | ||
_a = lodash_1.fromPairs; | ||
return [4 /*yield*/, Promise.all(files.map(function (file) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = [file]; | ||
_b = {}; | ||
return [4 /*yield*/, fs_extra_1["default"].readFile(file, 'utf8')]; | ||
case 1: return [2 /*return*/, _a.concat([ | ||
(_b.content = _c.sent(), _b) | ||
])]; | ||
} | ||
}); | ||
}); }))]; | ||
case 3: | ||
sources = _a.apply(void 0, [_b.sent()]); | ||
solcInput = { | ||
language: "Solidity", | ||
sources: sources, | ||
settings: __assign({}, solcSettings, { outputSelection: outputSelection }) | ||
}; | ||
solcOutput = solc.compile(solcInput); | ||
allErrors = solcOutput.errors; | ||
if (allErrors && allErrors.some(function (e) { return e.severity === 'error'; })) { | ||
errors = allErrors.filter(function (e) { return e.severity === 'error'; }); | ||
firstError = errors[0].formattedMessage; | ||
moreErrors = errors.length === 1 ? '' : " (And " + (errors.length - 1) + " other errors...)"; | ||
throw new Error("Solidity was unable to compile. " + firstError + moreErrors); | ||
} | ||
return [2 /*return*/, solcOutput]; | ||
} | ||
}); | ||
const sources = lodash_1.fromPairs(yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () { | ||
return [ | ||
file, | ||
{ content: yield fs_extra_1.default.readFile(file, 'utf8') }, | ||
]; | ||
})))); | ||
const solcInput = { | ||
language: "Solidity", | ||
sources: sources, | ||
settings: Object.assign({}, solcSettings, { outputSelection }), | ||
}; | ||
const solcOutput = solc.compile(solcInput); | ||
const { errors: allErrors } = solcOutput; | ||
if (allErrors && allErrors.some(e => e.severity === 'error')) { | ||
const errors = allErrors.filter(e => e.severity === 'error'); | ||
const firstError = errors[0].formattedMessage; | ||
const moreErrors = errors.length === 1 ? '' : ` (And ${errors.length - 1} other errors...)`; | ||
throw new Error(`Solidity was unable to compile. ${firstError}${moreErrors}`); | ||
} | ||
return solcOutput; | ||
}); | ||
} | ||
exports.compile = compile; | ||
class SolcAdapter { | ||
constructor(solc) { | ||
var SolcAdapter = /** @class */ (function () { | ||
function SolcAdapter(solc) { | ||
this.solc = solc; | ||
} | ||
static require(solcModule) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const solc = yield Promise.resolve().then(() => __importStar(require(solcModule))); | ||
return new SolcAdapter(solc); | ||
SolcAdapter.require = function (solcModule) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var solc; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return require(solcModule); })]; | ||
case 1: | ||
solc = _a.sent(); | ||
return [2 /*return*/, new SolcAdapter(solc)]; | ||
} | ||
}); | ||
}); | ||
} | ||
compile(input) { | ||
const inputJSON = JSON.stringify(input); | ||
const solcOutputString = this.solc.compileStandardWrapper(inputJSON); | ||
const solcOutput = JSON.parse(solcOutputString); | ||
if (semver_1.default.satisfies(this.solc.version(), '^0.4')) { | ||
for (const source of Object.values(solcOutput.sources)) { | ||
for (const fileNode of source.ast.nodes) { | ||
}; | ||
SolcAdapter.prototype.compile = function (input) { | ||
var inputJSON = JSON.stringify(input); | ||
var solcOutputString = this.solc.compileStandardWrapper(inputJSON); | ||
var solcOutput = JSON.parse(solcOutputString); | ||
if (semver_1["default"].satisfies(this.solc.version(), '^0.4')) { | ||
for (var _i = 0, _a = Object.values(solcOutput.sources); _i < _a.length; _i++) { | ||
var source = _a[_i]; | ||
for (var _b = 0, _c = source.ast.nodes; _b < _c.length; _b++) { | ||
var fileNode = _c[_b]; | ||
if (fileNode.nodeType === 'ContractDefinition') { | ||
for (const contractNode of fileNode.nodes) { | ||
for (var _d = 0, _e = fileNode.nodes; _d < _e.length; _d++) { | ||
var contractNode = _e[_d]; | ||
if (contractNode.nodeType === 'FunctionDefinition') { | ||
@@ -100,4 +162,4 @@ if (contractNode.isConstructor) { | ||
return solcOutput; | ||
} | ||
} | ||
//# sourceMappingURL=compile.js.map | ||
}; | ||
return SolcAdapter; | ||
}()); |
@@ -10,31 +10,69 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const globby_1 = __importDefault(require("globby")); | ||
const handlebars = __importStar(require("./handlebars")); | ||
const compile_1 = require("./compile"); | ||
const solidity_1 = require("./solidity"); | ||
const sitemap_1 = require("./sitemap"); | ||
exports.__esModule = true; | ||
var path_1 = require("path"); | ||
var fs_extra_1 = require("fs-extra"); | ||
var globby_1 = require("globby"); | ||
var handlebars = require("./handlebars"); | ||
var compile_1 = require("./compile"); | ||
var solidity_1 = require("./solidity"); | ||
var sitemap_1 = require("./sitemap"); | ||
function docgen(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const solcOutput = yield compile_1.compile(options.input, options.exclude, options['solc-module'], options['solc-settings']); | ||
const templates = yield getTemplates(options.templates); | ||
const readmes = yield getReadmes(options.input); | ||
const source = new solidity_1.SoliditySource(options.input, solcOutput, templates.contract); | ||
const sitemap = sitemap_1.Sitemap.generate(source, readmes, options.extension, options['contract-pages']); | ||
for (const page of sitemap.pages) { | ||
const dest = path_1.default.join(options.output, page.path); | ||
yield fs_extra_1.default.outputFile(dest, page.render(templates.prelude)); | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
var solcOutput, templates, readmes, source, sitemap, _i, _a, page, dest; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, compile_1.compile(options.input, options.exclude, options['solc-module'], options['solc-settings'])]; | ||
case 1: | ||
solcOutput = _b.sent(); | ||
return [4 /*yield*/, getTemplates(options.templates)]; | ||
case 2: | ||
templates = _b.sent(); | ||
return [4 /*yield*/, getReadmes(options.input)]; | ||
case 3: | ||
readmes = _b.sent(); | ||
source = new solidity_1.SoliditySource(options.input, solcOutput, templates.contract); | ||
sitemap = sitemap_1.Sitemap.generate(source, readmes, options.extension, options['contract-pages']); | ||
_i = 0, _a = sitemap.pages; | ||
_b.label = 4; | ||
case 4: | ||
if (!(_i < _a.length)) return [3 /*break*/, 7]; | ||
page = _a[_i]; | ||
dest = path_1["default"].join(options.output, page.path); | ||
return [4 /*yield*/, fs_extra_1["default"].outputFile(dest, page.render(templates.prelude))]; | ||
case 5: | ||
_b.sent(); | ||
_b.label = 6; | ||
case 6: | ||
_i++; | ||
return [3 /*break*/, 4]; | ||
case 7: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
@@ -44,39 +82,75 @@ } | ||
function getReadmes(inputDir) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const readmes = yield globby_1.default(path_1.default.join(inputDir, '**/README.*')); | ||
return yield Promise.all(readmes.map((readmePath) => __awaiter(this, void 0, void 0, function* () { | ||
return ({ | ||
path: path_1.default.relative(inputDir, readmePath), | ||
contents: yield fs_extra_1.default.readFile(readmePath, 'utf8'), | ||
}); | ||
}))); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var readmes; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, globby_1["default"](path_1["default"].join(inputDir, '**/README.*'))]; | ||
case 1: | ||
readmes = _a.sent(); | ||
return [4 /*yield*/, Promise.all(readmes.map(function (readmePath) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_a = { | ||
path: path_1["default"].relative(inputDir, readmePath) | ||
}; | ||
return [4 /*yield*/, fs_extra_1["default"].readFile(readmePath, 'utf8')]; | ||
case 1: return [2 /*return*/, (_a.contents = _b.sent(), | ||
_a)]; | ||
} | ||
}); | ||
}); }))]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
function getTemplates(directory) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (directory === undefined) { | ||
directory = path_1.default.join(__dirname, '..'); | ||
} | ||
const contract = yield readTemplate(path_1.default.join(directory, 'contract.hbs')); | ||
const prelude = yield readTemplate(path_1.default.join(directory, 'prelude.hbs'), true); | ||
return { contract, prelude }; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var contract, prelude; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (directory === undefined) { | ||
directory = path_1["default"].join(__dirname, '..'); | ||
} | ||
return [4 /*yield*/, readTemplate(path_1["default"].join(directory, 'contract.hbs'))]; | ||
case 1: | ||
contract = _a.sent(); | ||
return [4 /*yield*/, readTemplate(path_1["default"].join(directory, 'prelude.hbs'), true)]; | ||
case 2: | ||
prelude = _a.sent(); | ||
return [2 /*return*/, { contract: contract, prelude: prelude }]; | ||
} | ||
}); | ||
}); | ||
} | ||
function readTemplate(path, allowMissing = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const template = yield fs_extra_1.default.readFile(path, 'utf8'); | ||
return handlebars.compile(template); | ||
} | ||
catch (e) { | ||
if (e.code === 'ENOENT' && allowMissing) { | ||
// default to empty template | ||
return () => ''; | ||
function readTemplate(path, allowMissing) { | ||
if (allowMissing === void 0) { allowMissing = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var template, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, fs_extra_1["default"].readFile(path, 'utf8')]; | ||
case 1: | ||
template = _a.sent(); | ||
return [2 /*return*/, handlebars.compile(template)]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
if (e_1.code === 'ENOENT' && allowMissing) { | ||
// default to empty template | ||
return [2 /*return*/, function () { return ''; }]; | ||
} | ||
else { | ||
throw e_1; | ||
} | ||
return [3 /*break*/, 3]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=docgen.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const handlebars_1 = __importDefault(require("handlebars")); | ||
const H = handlebars_1.default.create(); | ||
exports.__esModule = true; | ||
var handlebars_1 = require("handlebars"); | ||
var H = handlebars_1["default"].create(); | ||
H.registerHelper('slug', slug); | ||
@@ -29,6 +26,6 @@ H.registerHelper({ | ||
and: function () { | ||
return [...arguments].slice(0, -1).every(Boolean); | ||
return arguments.slice().slice(0, -1).every(Boolean); | ||
}, | ||
or: function () { | ||
return [...arguments].slice(0, -1).some(Boolean); | ||
return arguments.slice().slice(0, -1).some(Boolean); | ||
} | ||
@@ -44,2 +41,1 @@ }); | ||
exports.slug = slug; | ||
//# sourceMappingURL=handlebars.js.map |
208
dist/page.js
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const handlebars = __importStar(require("./handlebars")); | ||
const lodash_1 = require("lodash"); | ||
class Page { | ||
constructor(sitemap) { | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
var path_1 = require("path"); | ||
var handlebars = require("./handlebars"); | ||
var lodash_1 = require("lodash"); | ||
var Page = /** @class */ (function () { | ||
function Page(sitemap) { | ||
this.sitemap = sitemap; | ||
} | ||
render(preludeTemplate) { | ||
const links = this.sitemap.links(this); | ||
const prelude = preludeTemplate({ links }); | ||
Page.prototype.render = function (preludeTemplate) { | ||
var links = this.sitemap.links(this); | ||
var prelude = preludeTemplate({ links: links }); | ||
return addPrelude(this.contents, prelude); | ||
} | ||
} | ||
}; | ||
return Page; | ||
}()); | ||
exports.Page = Page; | ||
class DefaultPage extends Page { | ||
constructor(sitemap, ext, contracts) { | ||
super(sitemap); | ||
this.ext = ext; | ||
this.contracts = contracts; | ||
var DefaultPage = /** @class */ (function (_super) { | ||
__extends(DefaultPage, _super); | ||
function DefaultPage(sitemap, ext, contracts) { | ||
var _this = _super.call(this, sitemap) || this; | ||
_this.ext = ext; | ||
_this.contracts = contracts; | ||
return _this; | ||
} | ||
get contents() { | ||
return this.contracts.map(c => c.toString()).join('\n\n'); | ||
} | ||
get path() { | ||
return path_1.default.format({ | ||
name: 'index', | ||
ext: '.' + this.ext, | ||
}); | ||
} | ||
} | ||
Object.defineProperty(DefaultPage.prototype, "contents", { | ||
get: function () { | ||
return this.contracts.map(function (c) { return c.toString(); }).join('\n\n'); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(DefaultPage.prototype, "path", { | ||
get: function () { | ||
return path_1["default"].format({ | ||
name: 'index', | ||
ext: '.' + this.ext | ||
}); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return DefaultPage; | ||
}(Page)); | ||
exports.DefaultPage = DefaultPage; | ||
class ReadmePage extends Page { | ||
constructor(sitemap, readme, contracts) { | ||
super(sitemap); | ||
this.readme = readme; | ||
this.contracts = contracts; | ||
lodash_1.defaults(this, lodash_1.keyBy(this.contracts, c => c.name)); | ||
var ReadmePage = /** @class */ (function (_super) { | ||
__extends(ReadmePage, _super); | ||
function ReadmePage(sitemap, readme, contracts) { | ||
var _this = _super.call(this, sitemap) || this; | ||
_this.readme = readme; | ||
_this.contracts = contracts; | ||
lodash_1.defaults(_this, lodash_1.keyBy(_this.contracts, function (c) { return c.name; })); | ||
return _this; | ||
} | ||
get contents() { | ||
return this.template(this); | ||
} | ||
get template() { | ||
return handlebars.compile(this.readme.contents); | ||
} | ||
get location() { | ||
return path_1.default.dirname(this.readme.path); | ||
} | ||
get path() { | ||
const { dir, ext } = path_1.default.parse(this.readme.path); | ||
return path_1.default.normalize(path_1.default.format({ | ||
dir: path_1.default.dirname(dir), | ||
name: path_1.default.basename(dir) || 'index', | ||
ext, | ||
})); | ||
} | ||
} | ||
Object.defineProperty(ReadmePage.prototype, "contents", { | ||
get: function () { | ||
return this.template(this); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ReadmePage.prototype, "template", { | ||
get: function () { | ||
return handlebars.compile(this.readme.contents); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ReadmePage.prototype, "location", { | ||
get: function () { | ||
return path_1["default"].dirname(this.readme.path); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ReadmePage.prototype, "path", { | ||
get: function () { | ||
var _a = path_1["default"].parse(this.readme.path), dir = _a.dir, ext = _a.ext; | ||
return path_1["default"].normalize(path_1["default"].format({ | ||
dir: path_1["default"].dirname(dir), | ||
name: path_1["default"].basename(dir) || 'index', | ||
ext: ext | ||
})); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ReadmePage; | ||
}(Page)); | ||
exports.ReadmePage = ReadmePage; | ||
class ContractPage extends Page { | ||
constructor(sitemap, contract, ext) { | ||
super(sitemap); | ||
this.contract = contract; | ||
this.ext = ext; | ||
var ContractPage = /** @class */ (function (_super) { | ||
__extends(ContractPage, _super); | ||
function ContractPage(sitemap, contract, ext) { | ||
var _this = _super.call(this, sitemap) || this; | ||
_this.contract = contract; | ||
_this.ext = ext; | ||
return _this; | ||
} | ||
get contents() { | ||
return this.contract.toString(); | ||
} | ||
get contracts() { | ||
return [this.contract]; | ||
} | ||
get path() { | ||
const { dir, name } = path_1.default.parse(this.contract.file.path); | ||
return path_1.default.format({ dir, name, ext: '.' + this.ext }); | ||
} | ||
} | ||
Object.defineProperty(ContractPage.prototype, "contents", { | ||
get: function () { | ||
return this.contract.toString(); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ContractPage.prototype, "contracts", { | ||
get: function () { | ||
return [this.contract]; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ContractPage.prototype, "path", { | ||
get: function () { | ||
var _a = path_1["default"].parse(this.contract.file.path), dir = _a.dir, name = _a.name; | ||
return path_1["default"].format({ dir: dir, name: name, ext: '.' + this.ext }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ContractPage; | ||
}(Page)); | ||
exports.ContractPage = ContractPage; | ||
function addPrelude(contents, prelude) { | ||
const preludeRegex = /^(---\n([^]*?\n)?---\n)?/; | ||
return contents.replace(preludeRegex, (_, frontmatter) => frontmatter ? frontmatter + prelude : prelude); | ||
var preludeRegex = /^(---\n([^]*?\n)?---\n)?/; | ||
return contents.replace(preludeRegex, function (_, frontmatter) { | ||
return frontmatter ? frontmatter + prelude : prelude; | ||
}); | ||
} | ||
//# sourceMappingURL=page.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const minimatch_1 = __importDefault(require("minimatch")); | ||
const lodash_1 = require("lodash"); | ||
const page_1 = require("./page"); | ||
class Sitemap { | ||
static generate(source, readmes, ext, contractPages) { | ||
exports.__esModule = true; | ||
var path_1 = require("path"); | ||
var minimatch_1 = require("minimatch"); | ||
var lodash_1 = require("lodash"); | ||
var page_1 = require("./page"); | ||
var Sitemap = /** @class */ (function () { | ||
function Sitemap() { | ||
} | ||
Sitemap.generate = function (source, readmes, ext, contractPages) { | ||
if (contractPages) { | ||
@@ -21,71 +60,132 @@ return new ContractSitemap(source, ext); | ||
} | ||
} | ||
links(origin) { | ||
function* generate(sitemap) { | ||
for (const { path, contracts } of sitemap.pages) { | ||
const relativePath = relative(origin.path, path); | ||
for (const c of contracts) { | ||
for (const target of c.linkable) { | ||
yield { target, path, relativePath }; | ||
} | ||
}; | ||
Sitemap.prototype.links = function (origin) { | ||
function generate(sitemap) { | ||
var _i, _a, _b, path_2, contracts, relativePath, _c, contracts_1, c, _d, _e, target; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: | ||
_i = 0, _a = sitemap.pages; | ||
_f.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 8]; | ||
_b = _a[_i], path_2 = _b.path, contracts = _b.contracts; | ||
relativePath = relative(origin.path, path_2); | ||
_c = 0, contracts_1 = contracts; | ||
_f.label = 2; | ||
case 2: | ||
if (!(_c < contracts_1.length)) return [3 /*break*/, 7]; | ||
c = contracts_1[_c]; | ||
_d = 0, _e = c.linkable; | ||
_f.label = 3; | ||
case 3: | ||
if (!(_d < _e.length)) return [3 /*break*/, 6]; | ||
target = _e[_d]; | ||
return [4 /*yield*/, { target: target, path: path_2, relativePath: relativePath }]; | ||
case 4: | ||
_f.sent(); | ||
_f.label = 5; | ||
case 5: | ||
_d++; | ||
return [3 /*break*/, 3]; | ||
case 6: | ||
_c++; | ||
return [3 /*break*/, 2]; | ||
case 7: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 8: return [2 /*return*/]; | ||
} | ||
} | ||
}); | ||
} | ||
return Array.from(generate(this)); | ||
} | ||
} | ||
}; | ||
return Sitemap; | ||
}()); | ||
exports.Sitemap = Sitemap; | ||
class DefaultSitemap extends Sitemap { | ||
constructor(source, ext) { | ||
super(); | ||
this.source = source; | ||
this.ext = ext; | ||
var DefaultSitemap = /** @class */ (function (_super) { | ||
__extends(DefaultSitemap, _super); | ||
function DefaultSitemap(source, ext) { | ||
var _this = _super.call(this) || this; | ||
_this.source = source; | ||
_this.ext = ext; | ||
return _this; | ||
} | ||
get pages() { | ||
return [new page_1.DefaultPage(this, this.ext, this.source.contracts)]; | ||
Object.defineProperty(DefaultSitemap.prototype, "pages", { | ||
get: function () { | ||
return [new page_1.DefaultPage(this, this.ext, this.source.contracts)]; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return DefaultSitemap; | ||
}(Sitemap)); | ||
var ReadmeSitemap = /** @class */ (function (_super) { | ||
__extends(ReadmeSitemap, _super); | ||
function ReadmeSitemap(source, readmes) { | ||
var _this = _super.call(this) || this; | ||
_this.source = source; | ||
_this.readmes = readmes; | ||
return _this; | ||
} | ||
} | ||
class ReadmeSitemap extends Sitemap { | ||
constructor(source, readmes) { | ||
super(); | ||
this.source = source; | ||
this.readmes = readmes; | ||
Object.defineProperty(ReadmeSitemap.prototype, "pages", { | ||
get: function () { | ||
var _this = this; | ||
var contracts = groupBy(this.source.contracts, function (c) { return _this.locate(c); }); | ||
return this.readmes.map(function (r) { | ||
return new page_1.ReadmePage(_this, r, contracts[path_1["default"].dirname(r.path)] || []); | ||
}); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ReadmeSitemap.prototype.locate = function (contract) { | ||
var matches = this.locations.filter(function (l) { | ||
return isContainedIn(l, contract.file.path); | ||
}); | ||
return lodash_1.maxBy(matches, function (l) { return l.length; }); | ||
}; | ||
Object.defineProperty(ReadmeSitemap.prototype, "locations", { | ||
get: function () { | ||
return this.readmes.map(function (r) { return path_1["default"].dirname(r.path); }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ReadmeSitemap; | ||
}(Sitemap)); | ||
var ContractSitemap = /** @class */ (function (_super) { | ||
__extends(ContractSitemap, _super); | ||
function ContractSitemap(source, ext) { | ||
var _this = _super.call(this) || this; | ||
_this.source = source; | ||
_this.ext = ext; | ||
return _this; | ||
} | ||
get pages() { | ||
const contracts = groupBy(this.source.contracts, c => this.locate(c)); | ||
return this.readmes.map(r => new page_1.ReadmePage(this, r, contracts[path_1.default.dirname(r.path)] || [])); | ||
} | ||
locate(contract) { | ||
const matches = this.locations.filter(l => isContainedIn(l, contract.file.path)); | ||
return lodash_1.maxBy(matches, l => l.length); | ||
} | ||
get locations() { | ||
return this.readmes.map(r => path_1.default.dirname(r.path)); | ||
} | ||
} | ||
class ContractSitemap extends Sitemap { | ||
constructor(source, ext) { | ||
super(); | ||
this.source = source; | ||
this.ext = ext; | ||
} | ||
get pages() { | ||
return this.source.contracts.map(c => new page_1.ContractPage(this, c, this.ext)); | ||
} | ||
} | ||
Object.defineProperty(ContractSitemap.prototype, "pages", { | ||
get: function () { | ||
var _this = this; | ||
return this.source.contracts.map(function (c) { return new page_1.ContractPage(_this, c, _this.ext); }); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ContractSitemap; | ||
}(Sitemap)); | ||
function isContainedIn(location, file) { | ||
return minimatch_1.default(file, path_1.default.join(location, '**/*')); | ||
return minimatch_1["default"](file, path_1["default"].join(location, '**/*')); | ||
} | ||
function relative(origin, target) { | ||
if (path_1.default.normalize(origin) === path_1.default.normalize(target)) { | ||
if (path_1["default"].normalize(origin) === path_1["default"].normalize(target)) { | ||
return ''; | ||
} | ||
else { | ||
return path_1.default.relative(path_1.default.dirname(origin), target); | ||
return path_1["default"].relative(path_1["default"].dirname(origin), target); | ||
} | ||
} | ||
function groupBy(collection, key) { | ||
const res = {}; | ||
for (const elem of collection) { | ||
const k = key(elem); | ||
var res = {}; | ||
for (var _i = 0, collection_1 = collection; _i < collection_1.length; _i++) { | ||
var elem = collection_1[_i]; | ||
var k = key(elem); | ||
if (k !== undefined) { | ||
@@ -97,2 +197,1 @@ (res[k] || (res[k] = [])).push(elem); | ||
} | ||
//# sourceMappingURL=sitemap.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.__esModule = true; | ||
var ava_1 = require("ava"); | ||
var path_1 = require("path"); | ||
var sitemap_1 = require("./sitemap"); | ||
var solidity_1 = require("./solidity"); | ||
var solc_1 = require("./solc"); | ||
var emptyReadme = function (dir) { | ||
if (dir === void 0) { dir = ''; } | ||
return ({ | ||
path: path_1["default"].join(dir, 'README.md'), | ||
contents: '' | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ava_1 = __importDefault(require("ava")); | ||
const path_1 = __importDefault(require("path")); | ||
const sitemap_1 = require("./sitemap"); | ||
const solidity_1 = require("./solidity"); | ||
const solc_1 = require("./solc"); | ||
const emptyReadme = (dir = '') => ({ | ||
path: path_1.default.join(dir, 'README.md'), | ||
contents: '', | ||
}); | ||
ava_1.default('single readme', t => { | ||
const source = buildSoliditySource(); | ||
const sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme()], 'md', false); | ||
ava_1["default"]('single readme', function (t) { | ||
var source = buildSoliditySource(); | ||
var sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme()], 'md', false); | ||
t.is(sitemap.pages.length, 1); | ||
}); | ||
ava_1.default('single readme no contracts', t => { | ||
const source = buildSoliditySource(b => b | ||
.file('Foo.sol')); | ||
const sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme()], 'md', false); | ||
const { pages: [page] } = sitemap; | ||
ava_1["default"]('single readme no contracts', function (t) { | ||
var source = buildSoliditySource(function (b) { return b | ||
.file('Foo.sol'); }); | ||
var sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme()], 'md', false); | ||
var page = sitemap.pages[0]; | ||
t.is(page.contracts.length, 0); | ||
}); | ||
ava_1.default('single readme multiple contracts', t => { | ||
const source = buildSoliditySource(b => b | ||
ava_1["default"]('single readme multiple contracts', function (t) { | ||
var source = buildSoliditySource(function (b) { return b | ||
.file('Foo.sol') | ||
.contract('Foo') | ||
.contract('Bar')); | ||
const sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme()], 'md', false); | ||
const { pages: [page] } = sitemap; | ||
.contract('Bar'); }); | ||
var sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme()], 'md', false); | ||
var page = sitemap.pages[0]; | ||
t.is(page.contracts.length, 2); | ||
t.assert(page.contracts.some(c => c.name === 'Foo')); | ||
t.assert(page.contracts.some(c => c.name === 'Bar')); | ||
t.assert(page.contracts.some(function (c) { return c.name === 'Foo'; })); | ||
t.assert(page.contracts.some(function (c) { return c.name === 'Bar'; })); | ||
}); | ||
ava_1.default('filter subdirectory', t => { | ||
const source = buildSoliditySource(b => b | ||
ava_1["default"]('filter subdirectory', function (t) { | ||
var source = buildSoliditySource(function (b) { return b | ||
.file('Foo.sol') | ||
.contract('Foo') | ||
.file('sub/Bar.sol') | ||
.contract('Bar')); | ||
const sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme('sub')], 'md', false); | ||
const { pages: [page] } = sitemap; | ||
.contract('Bar'); }); | ||
var sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme('sub')], 'md', false); | ||
var page = sitemap.pages[0]; | ||
t.is(page.contracts.length, 1); | ||
t.is(page.contracts[0].name, 'Bar'); | ||
}); | ||
ava_1.default('filter nested subdirectories', t => { | ||
const source = buildSoliditySource(b => b | ||
ava_1["default"]('filter nested subdirectories', function (t) { | ||
var source = buildSoliditySource(function (b) { return b | ||
.file('sub/Bar.sol') | ||
.contract('Bar') | ||
.file('sub/sub2/Foo.sol') | ||
.contract('Foo')); | ||
const sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme('sub')], 'md', false); | ||
const { pages: [page] } = sitemap; | ||
.contract('Foo'); }); | ||
var sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme('sub')], 'md', false); | ||
var page = sitemap.pages[0]; | ||
t.is(page.contracts.length, 2); | ||
t.assert(page.contracts.some(c => c.name === 'Bar')); | ||
t.assert(page.contracts.some(c => c.name === 'Foo')); | ||
t.assert(page.contracts.some(function (c) { return c.name === 'Bar'; })); | ||
t.assert(page.contracts.some(function (c) { return c.name === 'Foo'; })); | ||
}); | ||
ava_1.default('links', t => { | ||
const source = buildSoliditySource(b => b | ||
ava_1["default"]('links', function (t) { | ||
var source = buildSoliditySource(function (b) { return b | ||
.file('sub1/Bar.sol') | ||
.contract('Bar') | ||
.file('sub2/Foo.sol') | ||
.contract('Foo')); | ||
const sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme('sub1'), emptyReadme('sub2')], 'md', false); | ||
const links = sitemap.links(sitemap.pages[0]); | ||
.contract('Foo'); }); | ||
var sitemap = sitemap_1.Sitemap.generate(source, [emptyReadme('sub1'), emptyReadme('sub2')], 'md', false); | ||
var links = sitemap.links(sitemap.pages[0]); | ||
t.is(links.length, 2); | ||
const bar = links[0]; | ||
var bar = links[0]; | ||
t.is(bar.target.name, 'Bar'); | ||
t.is(bar.path, 'sub1.md'); | ||
t.is(bar.relativePath, ''); | ||
const foo = links[1]; | ||
var foo = links[1]; | ||
t.is(foo.target.name, 'Foo'); | ||
@@ -80,7 +80,6 @@ t.is(foo.path, 'sub2.md'); | ||
function buildSoliditySource(builder) { | ||
const solcOutput = new solc_1.SolcOutputBuilder(); | ||
var solcOutput = new solc_1.SolcOutputBuilder(); | ||
if (builder) | ||
builder(solcOutput); | ||
return new solidity_1.SoliditySource('', solcOutput, c => c.name); | ||
return new solidity_1.SoliditySource('', solcOutput, function (c) { return c.name; }); | ||
} | ||
//# sourceMappingURL=sitemap.test.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.__esModule = true; | ||
// fake solc output builder for tests | ||
class SolcOutputBuilder { | ||
constructor() { | ||
var SolcOutputBuilder = /** @class */ (function () { | ||
function SolcOutputBuilder() { | ||
this.errors = []; | ||
@@ -11,3 +11,3 @@ this.sources = {}; | ||
} | ||
file(fileName) { | ||
SolcOutputBuilder.prototype.file = function (fileName) { | ||
this._currentFile = fileName; | ||
@@ -17,27 +17,32 @@ this.sources[fileName] = { | ||
nodeType: 'SourceUnit', | ||
nodes: [], | ||
}, | ||
nodes: [] | ||
} | ||
}; | ||
return this; | ||
} | ||
contract(contractName, ...baseContracts) { | ||
const fileName = this._currentFile; | ||
}; | ||
SolcOutputBuilder.prototype.contract = function (contractName) { | ||
var _this = this; | ||
var baseContracts = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
baseContracts[_i - 1] = arguments[_i]; | ||
} | ||
var fileName = this._currentFile; | ||
if (fileName === undefined) | ||
throw new Error('No file defined'); | ||
const id = this._getContractId(contractName); | ||
const astNode = { | ||
var id = this._getContractId(contractName); | ||
var astNode = { | ||
nodeType: 'ContractDefinition', | ||
name: contractName, | ||
documentation: null, | ||
id, | ||
id: id, | ||
linearizedBaseContracts: [id].concat( | ||
// this isn't really linearizing, but it'll do | ||
baseContracts.map(name => this._getContractId(name))), | ||
nodes: [], | ||
baseContracts.map(function (name) { return _this._getContractId(name); })), | ||
nodes: [] | ||
}; | ||
this._currentContract = { astNode }; | ||
this._currentContract = { astNode: astNode }; | ||
this.sources[fileName].ast.nodes.push(astNode); | ||
return this; | ||
} | ||
_getContractId(contractName) { | ||
}; | ||
SolcOutputBuilder.prototype._getContractId = function (contractName) { | ||
if (contractName in this._contractIds) { | ||
@@ -47,3 +52,3 @@ return this._contractIds[contractName]; | ||
else { | ||
const id = this._nextId; | ||
var id = this._nextId; | ||
this._nextId += 1; | ||
@@ -53,13 +58,17 @@ this._contractIds[contractName] = id; | ||
} | ||
} | ||
function(functionName, ...argTypes) { | ||
const contract = this._currentContract; | ||
}; | ||
SolcOutputBuilder.prototype["function"] = function (functionName) { | ||
var argTypes = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
argTypes[_i - 1] = arguments[_i]; | ||
} | ||
var contract = this._currentContract; | ||
if (contract === undefined) | ||
throw new Error('No contract defined'); | ||
const kind = functionName === 'fallback' || functionName === 'constructor' | ||
var kind = functionName === 'fallback' || functionName === 'constructor' | ||
? functionName | ||
: 'function'; | ||
const astNode = { | ||
var astNode = { | ||
nodeType: 'FunctionDefinition', | ||
kind, | ||
kind: kind, | ||
visibility: 'public', | ||
@@ -69,3 +78,3 @@ name: functionName, | ||
parameters: { | ||
parameters: argTypes.map(t => ({ | ||
parameters: argTypes.map(function (t) { return ({ | ||
name: '', | ||
@@ -75,16 +84,16 @@ typeName: { | ||
typeDescriptions: { | ||
typeString: t, | ||
}, | ||
}, | ||
})), | ||
typeString: t | ||
} | ||
} | ||
}); }) | ||
}, | ||
returnParameters: { | ||
parameters: [], | ||
}, | ||
parameters: [] | ||
} | ||
}; | ||
contract.astNode.nodes.push(astNode); | ||
return this; | ||
} | ||
} | ||
}; | ||
return SolcOutputBuilder; | ||
}()); | ||
exports.SolcOutputBuilder = SolcOutputBuilder; | ||
//# sourceMappingURL=solc.js.map |
@@ -191,3 +191,3 @@ "use strict"; | ||
get names() { | ||
return this.map(v => v.name); | ||
return this.map(v => (v.name === undefined) ? '_' : v.name); | ||
} | ||
@@ -194,0 +194,0 @@ } |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ava_1 = __importDefault(require("ava")); | ||
const solc_1 = require("./solc"); | ||
const solidity_1 = require("./solidity"); | ||
exports.__esModule = true; | ||
var ava_1 = require("ava"); | ||
var solc_1 = require("./solc"); | ||
var solidity_1 = require("./solidity"); | ||
function buildSource(solcOutput) { | ||
return new solidity_1.SoliditySource('', solcOutput, c => c.name); | ||
return new solidity_1.SoliditySource('', solcOutput, function (c) { return c.name; }); | ||
} | ||
ava_1.default('no files', t => { | ||
const solcOutput = new solc_1.SolcOutputBuilder(); | ||
const source = buildSource(solcOutput); | ||
ava_1["default"]('no files', function (t) { | ||
var solcOutput = new solc_1.SolcOutputBuilder(); | ||
var source = buildSource(solcOutput); | ||
t.is(source.files.length, 0); | ||
t.is(source.contracts.length, 0); | ||
}); | ||
ava_1.default('one empty file', t => { | ||
const solcOutput = new solc_1.SolcOutputBuilder() | ||
ava_1["default"]('one empty file', function (t) { | ||
var solcOutput = new solc_1.SolcOutputBuilder() | ||
.file('Foo.sol'); | ||
const source = buildSource(solcOutput); | ||
var source = buildSource(solcOutput); | ||
t.is(source.files.length, 1); | ||
}); | ||
ava_1.default('one contract', t => { | ||
const solcOutput = new solc_1.SolcOutputBuilder() | ||
ava_1["default"]('one contract', function (t) { | ||
var solcOutput = new solc_1.SolcOutputBuilder() | ||
.file('Foo.sol') | ||
.contract('Foo'); | ||
const source = buildSource(solcOutput); | ||
var source = buildSource(solcOutput); | ||
t.is(source.contracts.length, 1); | ||
}); | ||
ava_1.default('one own function', t => { | ||
const solcOutput = new solc_1.SolcOutputBuilder() | ||
ava_1["default"]('one own function', function (t) { | ||
var solcOutput = new solc_1.SolcOutputBuilder() | ||
.file('Foo.sol') | ||
.contract('Foo') | ||
.function('test'); | ||
const source = buildSource(solcOutput); | ||
const foo = source.contracts[0]; | ||
.contract('Foo')["function"]('test'); | ||
var source = buildSource(solcOutput); | ||
var foo = source.contracts[0]; | ||
t.is(foo.functions.length, 1); | ||
}); | ||
ava_1.default('one inherited function', t => { | ||
const solcOutput = new solc_1.SolcOutputBuilder() | ||
ava_1["default"]('one inherited function', function (t) { | ||
var solcOutput = new solc_1.SolcOutputBuilder() | ||
.file('Foo.sol') | ||
.contract('Foo') | ||
.function('test') | ||
.contract('Foo')["function"]('test') | ||
.contract('Bar', 'Foo'); | ||
const source = buildSource(solcOutput); | ||
const bar = source.contracts[1]; | ||
var source = buildSource(solcOutput); | ||
var bar = source.contracts[1]; | ||
t.is(bar.functions.length, 1); | ||
}); | ||
ava_1.default('one multiply inherited function', t => { | ||
const solcOutput = new solc_1.SolcOutputBuilder() | ||
ava_1["default"]('one multiply inherited function', function (t) { | ||
var solcOutput = new solc_1.SolcOutputBuilder() | ||
.file('Foo.sol') | ||
.contract('Foo') | ||
.function('test') | ||
.contract('FooFlavor') | ||
.function('test') | ||
.contract('Foo')["function"]('test') | ||
.contract('FooFlavor')["function"]('test') | ||
.contract('Bar', 'Foo', 'FooFlavor'); | ||
const source = buildSource(solcOutput); | ||
const bar = source.contracts[2]; | ||
var source = buildSource(solcOutput); | ||
var bar = source.contracts[2]; | ||
t.is(bar.name, 'Bar'); | ||
t.is(bar.functions.length, 1); | ||
}); | ||
ava_1.default('two inherited functions with name overloading', t => { | ||
const solcOutput = new solc_1.SolcOutputBuilder() | ||
ava_1["default"]('two inherited functions with name overloading', function (t) { | ||
var solcOutput = new solc_1.SolcOutputBuilder() | ||
.file('Foo.sol') | ||
.contract('Foo') | ||
.function('test', 'uint256') | ||
.function('test', 'string') | ||
.contract('Foo')["function"]('test', 'uint256')["function"]('test', 'string') | ||
.contract('FooFlavor', 'Foo'); | ||
const source = buildSource(solcOutput); | ||
const foof = source.contracts[1]; | ||
var source = buildSource(solcOutput); | ||
var foof = source.contracts[1]; | ||
t.is(foof.functions.length, 2); | ||
}); | ||
//# sourceMappingURL=solidity.test.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=vfile.js.map | ||
exports.__esModule = true; |
{ | ||
"name": "solidity-docgen", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Solidity API documentation automatic generator.", | ||
@@ -5,0 +5,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
242548
1317
1