本文整理匯總了TypeScript中solc.compile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript compile函數的具體用法?TypeScript compile怎麽用?TypeScript compile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了compile函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: compileAndHighlightErrors
export function compileAndHighlightErrors(contracts: any, diagnosticCollection: vscode.DiagnosticCollection) {
let output = solc.compile({ sources: contracts }, 1);
diagnosticCollection.clear();
if (output.errors) {
outputErrorsToDiagnostics(diagnosticCollection, output.errors);
}
}
示例2: compile
export function compile(contracts: any,
diagnosticCollection: vscode.DiagnosticCollection,
buildDir: string, sourceDir: string, excludePath?: string, singleContractFilePath?: string) {
// Did we find any sol files after all?
if (Object.keys(contracts).length === 0) {
vscode.window.showWarningMessage('No solidity files (*.sol) found');
return;
}
let outputChannel = vscode.window.createOutputChannel('solidity compilation');
outputChannel.clear();
let output = solc.compile({ sources: contracts }, 1);
if (Object.keys(output).length === 0) {
vscode.window.showWarningMessage('No output by the compiler');
return;
}
diagnosticCollection.clear();
if (output.errors) {
const errorWarningCounts = outputErrorsToDiagnostics(diagnosticCollection, output.errors);
outputErrorsToChannel(outputChannel, output.errors);
if (errorWarningCounts.errors > 0) {
vscode.window.showErrorMessage(`Compilation failed with ${errorWarningCounts.errors} errors`);
}
else if (errorWarningCounts.warnings > 0) {
vscode.window.showWarningMessage(`Compilation had ${errorWarningCounts.warnings} warnings`);
}
} else {
let binPath = path.join(vscode.workspace.rootPath, buildDir);
if (!fs.existsSync(binPath)) {
fs.mkdirSync(binPath);
}
// iterate through all the sources, find contracts and output them into the same folder structure to avoid collisions, named as the contract
for (let source in output.sources) {
// TODO: ALL this validation to a method
// Output only single contract compilation or all
if (!singleContractFilePath || source === singleContractFilePath) {
if (!excludePath || !source.startsWith(excludePath)) {
// Output only source directory compilation or all (this will exclude external references)
if (!sourceDir || source.startsWith(sourceDir)) {
output.sources[source].AST.children.forEach(child => {
if (child.name === 'Contract') {
let contractName = child.attributes.name;
let relativePath = path.relative(vscode.workspace.rootPath, source);
let dirName = path.dirname(path.join(binPath, relativePath));
if (!fs.existsSync(dirName)) {
fsex.mkdirsSync(dirName);
}
let contractAbiPath = path.join(dirName, contractName + '.abi');
let contractBinPath = path.join(dirName, contractName + '.bin');
if (fs.existsSync(contractAbiPath)) {
fs.unlinkSync(contractAbiPath);
}
if (fs.existsSync(contractBinPath)) {
fs.unlinkSync(contractBinPath);
}
fs.writeFileSync(contractBinPath, output.contracts[contractName].bytecode);
fs.writeFileSync(contractAbiPath, output.contracts[contractName].interface);
}
});
}
}
}
}
outputChannel.hide();
vscode.window.showInformationMessage('Compilation completed succesfully!');
}
}