|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
import React from 'react' |
|
|
|
|
import { Plugin } from '@remixproject/engine' |
|
|
|
|
import { customAction } from '@remixproject/plugin-api' |
|
|
|
|
import { concatSourceFiles, getDependencyGraph } from '@remix-ui/solidity-compiler' |
|
|
|
|
import { concatSourceFiles, getDependencyGraph, normalizeContractPath } from '@remix-ui/solidity-compiler' |
|
|
|
|
|
|
|
|
|
const _paq = window._paq = window._paq || [] |
|
|
|
|
|
|
|
|
@ -9,8 +9,9 @@ const profile = { |
|
|
|
|
name: 'contractflattener', |
|
|
|
|
displayName: 'Contract Flattener', |
|
|
|
|
description: 'Flatten solidity contracts', |
|
|
|
|
methods: ['flattenAContract'], |
|
|
|
|
methods: ['flattenAContract', 'normalizeContractPath'], |
|
|
|
|
events: [], |
|
|
|
|
maintainedBy: 'Remix Team', |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class ContractFlattener extends Plugin { |
|
|
|
@ -29,25 +30,39 @@ export class ContractFlattener extends Plugin { |
|
|
|
|
|
|
|
|
|
async flattenAContract(action: customAction) { |
|
|
|
|
this.fileName = action.path[0] |
|
|
|
|
this.call('manager', 'deactivatePlugin', 'solidityumlgen') |
|
|
|
|
await this.call('solidity', 'compile', this.fileName) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Takes currently compiled contract that has a bunch of imports at the top |
|
|
|
|
* and flattens them ready for UML creation. Takes the flattened result |
|
|
|
|
* and assigns to a local property |
|
|
|
|
* @returns {Promise<void>} |
|
|
|
|
* and flattens them ready, ideally for UML creation or for other purposes. |
|
|
|
|
* Takes the flattened result, writes it to a file and returns the result. |
|
|
|
|
* @returns {Promise<string>} |
|
|
|
|
*/ |
|
|
|
|
async flattenContract (source: any, filePath: string, data: any) { |
|
|
|
|
const filename = filePath.split('/')[1].split('.')[0] |
|
|
|
|
async flattenContract (source: { sources: any, target: string }, |
|
|
|
|
filePath: string, data: { contracts: any, sources: any }): Promise<string> { |
|
|
|
|
const path = normalizeContractPath(filePath) |
|
|
|
|
const ast = data.sources |
|
|
|
|
const dependencyGraph = getDependencyGraph(ast, filePath) |
|
|
|
|
const sorted = dependencyGraph.isEmpty() |
|
|
|
|
? [filePath] |
|
|
|
|
: dependencyGraph.sort().reverse() |
|
|
|
|
const sources = source.sources |
|
|
|
|
const result = concatSourceFiles(sorted, sources) |
|
|
|
|
await this.call('fileManager', 'writeFile', `${filePath.split('/')[0]}/${filename}_flattened.sol`, result) |
|
|
|
|
let dependencyGraph |
|
|
|
|
let sorted |
|
|
|
|
let result |
|
|
|
|
let sources |
|
|
|
|
try{ |
|
|
|
|
dependencyGraph = getDependencyGraph(ast, filePath) |
|
|
|
|
sorted = dependencyGraph.isEmpty() |
|
|
|
|
? [filePath] |
|
|
|
|
: dependencyGraph.sort().reverse() |
|
|
|
|
sources = source.sources |
|
|
|
|
result = concatSourceFiles(sorted, sources) |
|
|
|
|
}catch(err){ |
|
|
|
|
console.warn(err) |
|
|
|
|
} |
|
|
|
|
await this.call('fileManager', 'writeFile', path , result) |
|
|
|
|
_paq.push(['trackEvent', 'plugin', 'contractFlattener', 'flattenAContract']) |
|
|
|
|
sorted = null |
|
|
|
|
sources = null |
|
|
|
|
dependencyGraph = null |
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
|
} |