solidity-docgen
Advanced tools
Comparing version 0.3.14 to 0.4.0-beta.0
#!/usr/bin/env node | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -21,7 +12,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
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); | ||
}); | ||
async run() { | ||
const { flags } = this.parse(Docgen); | ||
await docgen_1.docgen(flags); | ||
} | ||
@@ -28,0 +17,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -25,3 +16,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const semver_1 = __importDefault(require("semver")); | ||
const outputSelection = { | ||
exports.outputSelection = { | ||
'*': { | ||
@@ -33,27 +24,23 @@ '': [ | ||
}; | ||
function compile(filter, 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 filter.glob('*.sol'); | ||
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(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; | ||
}); | ||
async function compile(filter, solcModule = 'solc', solcSettings = { optimizer: { enabled: true, runs: 200 } }) { | ||
const solc = await SolcAdapter.require(solcModule); | ||
const files = await filter.glob('*.sol'); | ||
const sources = lodash_1.fromPairs(await Promise.all(files.map(async (file) => [ | ||
file, | ||
{ content: await fs_extra_1.default.readFile(file, 'utf8') }, | ||
]))); | ||
const solcInput = { | ||
language: "Solidity", | ||
sources: sources, | ||
settings: Object.assign(Object.assign({}, solcSettings), { outputSelection: exports.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; | ||
} | ||
@@ -65,11 +52,11 @@ exports.compile = compile; | ||
} | ||
static require(solcModule) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const solc = yield Promise.resolve().then(() => __importStar(require(solcModule))); | ||
return new SolcAdapter(solc); | ||
}); | ||
static async require(solcModule) { | ||
const solc = await Promise.resolve().then(() => __importStar(require(solcModule))); | ||
return new SolcAdapter(solc); | ||
} | ||
compile(input) { | ||
const inputJSON = JSON.stringify(input); | ||
const solcOutputString = this.solc.compileStandardWrapper(inputJSON, importCallback); | ||
const solcOutputString = semver_1.default.satisfies(this.solc.version(), '^0.6') | ||
? this.solc.compile(inputJSON, { import: importCallback }) | ||
: this.solc.compileStandardWrapper(inputJSON, importCallback); | ||
const solcOutput = JSON.parse(solcOutputString); | ||
@@ -101,2 +88,3 @@ if (semver_1.default.satisfies(this.solc.version(), '^0.4')) { | ||
} | ||
exports.SolcAdapter = SolcAdapter; | ||
function importCallback(path) { | ||
@@ -103,0 +91,0 @@ try { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -29,55 +20,45 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const filter_1 = require("./filter"); | ||
function docgen(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const filter = new filter_1.Filter(options.input, options.exclude); | ||
const solcOutput = yield compile_1.compile(filter, options['solc-module'], options['solc-settings']); | ||
const templates = yield getTemplates(options.templates); | ||
const readmes = yield getReadmes(filter); | ||
const source = new solidity_1.SoliditySource(options.input, solcOutput, templates.contract); | ||
const sitemap = sitemap_1.Sitemap.generate(source, filter, 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)); | ||
} | ||
}); | ||
async function docgen(options) { | ||
const filter = new filter_1.Filter(options.input, options.exclude); | ||
const solcOutput = await compile_1.compile(filter, options['solc-module'], options['solc-settings']); | ||
const templates = await getTemplates(options.templates); | ||
const readmes = await getReadmes(filter); | ||
const source = new solidity_1.SoliditySource(options.input, solcOutput, templates.contract); | ||
const sitemap = sitemap_1.Sitemap.generate(source, filter, readmes, options.extension, options['contract-pages']); | ||
for (const page of sitemap.pages) { | ||
const dest = path_1.default.join(options.output, page.path); | ||
await fs_extra_1.default.outputFile(dest, page.render(templates.prelude)); | ||
} | ||
} | ||
exports.docgen = docgen; | ||
function getReadmes(filter) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const readmes = yield filter.glob('README.*'); | ||
return yield Promise.all(readmes.map((readmePath) => __awaiter(this, void 0, void 0, function* () { | ||
return ({ | ||
path: path_1.default.relative(filter.root, readmePath), | ||
contents: yield fs_extra_1.default.readFile(readmePath, 'utf8'), | ||
}); | ||
}))); | ||
}); | ||
async function getReadmes(filter) { | ||
const readmes = await filter.glob('README.*'); | ||
return await Promise.all(readmes.map(async (readmePath) => ({ | ||
path: path_1.default.relative(filter.root, readmePath), | ||
contents: await fs_extra_1.default.readFile(readmePath, 'utf8'), | ||
}))); | ||
} | ||
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 }; | ||
}); | ||
async function getTemplates(directory) { | ||
if (directory === undefined) { | ||
directory = path_1.default.join(__dirname, '..'); | ||
} | ||
const contract = await readTemplate(path_1.default.join(directory, 'contract.hbs')); | ||
const prelude = await readTemplate(path_1.default.join(directory, 'prelude.hbs'), true); | ||
return { contract, 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); | ||
async function readTemplate(path, allowMissing = false) { | ||
try { | ||
const template = await fs_extra_1.default.readFile(path, 'utf8'); | ||
return handlebars.compile(template); | ||
} | ||
catch (e) { | ||
if (e.code === 'ENOENT' && allowMissing) { | ||
// default to empty template | ||
return () => ''; | ||
} | ||
catch (e) { | ||
if (e.code === 'ENOENT' && allowMissing) { | ||
// default to empty template | ||
return () => ''; | ||
} | ||
else { | ||
throw e; | ||
} | ||
else { | ||
throw e; | ||
} | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=docgen.js.map |
@@ -11,11 +11,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -39,7 +30,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
glob(pattern) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield globby_1.default(path_1.posix.join(this.root, '**', pattern), { | ||
ignore: this.excludePaths.map(e => path_1.posix.join(e, '**/*')), | ||
}); | ||
async glob(pattern) { | ||
return await globby_1.default(path_1.posix.join(this.root, '**', pattern), { | ||
ignore: this.excludePaths.map(e => path_1.posix.join(e, '**/*')), | ||
}); | ||
@@ -46,0 +35,0 @@ } |
{ | ||
"name": "solidity-docgen", | ||
"version": "0.3.14", | ||
"version": "0.4.0-beta.0", | ||
"description": "Solidity API documentation automatic generator.", | ||
@@ -25,3 +25,3 @@ "bin": { | ||
"@oclif/command": "^1.5.19", | ||
"@oclif/config": "^1.13.3", | ||
"@oclif/config": "^1.14.0", | ||
"@oclif/errors": "^1.2.2", | ||
@@ -31,3 +31,3 @@ "@oclif/plugin-help": "^2.2.3", | ||
"globby": "^11.0.0", | ||
"handlebars": "^4.7.2", | ||
"handlebars": "^4.7.3", | ||
"json5": "^2.1.0", | ||
@@ -37,8 +37,8 @@ "lodash": "^4.17.15", | ||
"minimatch": "^3.0.4", | ||
"semver": "^7.1.2", | ||
"solc": "^0.5.14" | ||
"semver": "^7.1.3", | ||
"solc": "^0.6.4" | ||
}, | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@types/fs-extra": "^8.0.0", | ||
"@types/fs-extra": "^8.1.0", | ||
"@types/json5": "0.0.30", | ||
@@ -48,11 +48,13 @@ "@types/lodash": "^4.14.149", | ||
"@types/minimatch": "^3.0.3", | ||
"@types/node": "^10.17.14", | ||
"@types/node": "^10.17.17", | ||
"@types/semver": "^7.1.0", | ||
"ava": "^3.2.0", | ||
"ava": "^3.5.0", | ||
"code-style": "github:OpenZeppelin/code-style", | ||
"codecov": "^3.6.4", | ||
"codecov": "^3.6.5", | ||
"fgbg": "^0.1.4", | ||
"nyc": "^15.0.0", | ||
"openzeppelin-docs-utils": "github:OpenZeppelin/docs-utils", | ||
"typescript": "^3.7.5" | ||
"solc-0-5": "npm:solc@^0.5.14", | ||
"solc-0-4": "npm:solc@^0.4.24", | ||
"typescript": "^3.8.3" | ||
}, | ||
@@ -59,0 +61,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
36
271697
17
1318
+ Addedsolc@0.6.12(transitive)
- Removedsolc@0.5.17(transitive)
Updated@oclif/config@^1.14.0
Updatedhandlebars@^4.7.3
Updatedsemver@^7.1.3
Updatedsolc@^0.6.4