From 5703f65322e384c4d7f9268afe4cfb46a1b27e27 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 17 Mar 2022 14:33:19 +0530 Subject: [PATCH] intermediate commiy --- .../solidity-compiler/src/app/compiler-api.ts | 34 + apps/solidity-compiler/webpack.config.js | 1 + libs/remix-lib/src/types/ICompilerApi.ts | 1 + .../src/lib/compiler-container.tsx | 31 +- .../src/lib/logic/compileTabLogic.ts | 35 +- .../src/lib/solidity-compiler.tsx | 6 +- .../solidity-compiler/src/lib/types/index.ts | 1 + package-lock.json | 1231 ++++++++++++++++- package.json | 2 + 9 files changed, 1305 insertions(+), 37 deletions(-) diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 64747b3c51..98a5abe00c 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -1,6 +1,11 @@ +import React from 'react'; import { compile, helper } from '@remix-project/remix-solidity' import { CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line import type { ConfigurationSettings } from '@remix-project/remix-lib-ts' +import Schema from "@truffle/contract-schema" +import Config from '@truffle/config' +import { Compile } from "@truffle/compile-solidity" +import { Shims } from "@truffle/compile-common" export const CompilerApiMixin = (Base) => class extends Base { currentFile: string @@ -100,6 +105,35 @@ export const CompilerApiMixin = (Base) => class extends Base { return this.call('hardhat', 'compile', configFile) } + async compileWithTruffle (fileName, CompConfig) { + console.log('fileName-in compileWithTruffle-->', fileName) + console.log('config-in compileWithTruffle-->', CompConfig) + + const sources = { + Example: await this.call('fileManager', 'getFile', fileName) + } + let config = Config.default().with(CompConfig) + console.log('config---->', config) + console.log('sources---->', sources) + // Compile first + const { compilations } = await Compile.sources({ + sources, + options: config + }); + console.log('compilations----->', compilations) + const { contracts } = compilations[0]; + // use forEach + const exampleContract = contracts.find( + contract => contract.contractName === "Owner" + ); + const compiled = Schema.normalize( + Shims.NewToLegacy.forContract(exampleContract) + ); + if(!compiled.updatedAt) compiled.updatedAt = new Date().toISOString() + console.log('compiled----->', compiled) + return "done" + } + logToTerminal (content) { return this.call('terminal', 'log', content) } diff --git a/apps/solidity-compiler/webpack.config.js b/apps/solidity-compiler/webpack.config.js index 02143af15b..201a50c365 100644 --- a/apps/solidity-compiler/webpack.config.js +++ b/apps/solidity-compiler/webpack.config.js @@ -7,6 +7,7 @@ module.exports = config => { ...nxWebpackConfig, node: { fs: 'empty', + path: 'empty', tls: 'empty', readline: 'empty', net: 'empty', diff --git a/libs/remix-lib/src/types/ICompilerApi.ts b/libs/remix-lib/src/types/ICompilerApi.ts index 4c796ee3c1..1c92aa38f0 100644 --- a/libs/remix-lib/src/types/ICompilerApi.ts +++ b/libs/remix-lib/src/types/ICompilerApi.ts @@ -41,6 +41,7 @@ export interface ICompilerApi { logToTerminal: (log: terminalLog) => void compileWithHardhat: (configPath: string) => Promise + compileWithTruffle: (file: string, config: Record) => Promise statusChanged: (data: { key: string, title?: string, type?: string }) => void, emit?: (key: string, ...payload: any) => void } diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index f2efb75360..0d896d3498 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -20,7 +20,7 @@ declare global { const _paq = window._paq = window._paq || [] //eslint-disable-line export const CompilerContainer = (props: CompilerContainerProps) => { - const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject } = props // eslint-disable-line + const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject } = props // eslint-disable-line const [state, setState] = useState({ hideWarnings: false, autoCompile: false, @@ -42,6 +42,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const compileIcon = useRef(null) const promptMessageInput = useRef(null) const [hhCompilation, sethhCompilation] = useState(false) + const [truffleCompilation, setTruffleCompilation] = useState(false) const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState) useEffect(() => { @@ -325,7 +326,10 @@ export const CompilerContainer = (props: CompilerContainerProps) => { if (!isSolFileSelected()) return _setCompilerVersionFromPragma(currentFile) - compileTabLogic.runCompiler(hhCompilation) + let externalCompType + if (hhCompilation) externalCompType = 'hardhat' + else if (truffleCompilation) externalCompType = 'truffle' + compileTabLogic.runCompiler(externalCompType) } const _updateVersionSelector = (version, customUrl = '') => { @@ -500,6 +504,13 @@ export const CompilerContainer = (props: CompilerContainerProps) => { api.setAppParameter('hardhat-compilation', checked) } + const updateTruffleCompilation = (event) => { + const checked = event.target.checked + + setTruffleCompilation(checked) + api.setAppParameter('truffle-compilation', checked) + } + /* The following functions map with the above event handlers. They are an external API for modifying the compiler configuration. @@ -594,6 +605,22 @@ export const CompilerContainer = (props: CompilerContainerProps) => { } + { + isTruffleProject && +
+ + + + + Learn how to use Truffle Compilation + + }> + + + +
+ }