diff --git a/apps/remixdocgen/project.json b/apps/remixdocgen/project.json index 7dd6ae0401..b214647ecc 100644 --- a/apps/remixdocgen/project.json +++ b/apps/remixdocgen/project.json @@ -1,5 +1,5 @@ { - "name": "etherscan", + "name": "remixdocgen", "$schema": "../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "apps/remixdocgen/src", "projectType": "application", @@ -18,10 +18,9 @@ "main": "apps/remixdocgen/src/main.tsx", "tsConfig": "apps/remixdocgen/tsconfig.app.json", "assets": [ - "apps/remixdocgen/src/favicon.ico", - "apps/remixdocgen/src/assets" + "apps/remixdocgen/src/favicon.ico" ], - "styles": ["apps/remixdocgen/src/styles.css"], + "styles": [], "scripts": [], "webpackConfig": "apps/remixdocgen/webpack.config.js" }, diff --git a/apps/remixdocgen/src/app/App.tsx b/apps/remixdocgen/src/app/App.tsx index 3bb94bdb99..063fb4e4c3 100644 --- a/apps/remixdocgen/src/app/App.tsx +++ b/apps/remixdocgen/src/app/App.tsx @@ -11,7 +11,7 @@ import { Status } from "@remixproject/plugin-utils"; import { AppContext } from "./AppContext"; import { Routes } from "./routes"; import { useLocalStorage } from "./hooks/useLocalStorage"; -import { createDocumentation } from "../utils/utils"; + import "./App.css"; import { ContractName, Documentation } from "../types"; @@ -59,13 +59,8 @@ const App = () => { console.log("New compilation received"); const existingMap = contractsRef.current; - const newContractsMapWithDocumentation = createDocumentation( - fileName, - data - ); const newMap = new Map([ ...existingMap, - ...newContractsMapWithDocumentation, ]); const status: Status = { @@ -74,7 +69,7 @@ const App = () => { title: "New documentation ready", }; clientInstanceRef.current.emit("statusChanged", status); - setContracts(newMap); + setContracts(new Map()); } ); @@ -93,19 +88,22 @@ const App = () => { }, []); return ( - - - - ); + // + // + // +
+

Testing

+
+ ) }; export default App; diff --git a/apps/remixdocgen/src/app/routes.tsx b/apps/remixdocgen/src/app/routes.tsx index 8fad895972..b16eae3a9e 100644 --- a/apps/remixdocgen/src/app/routes.tsx +++ b/apps/remixdocgen/src/app/routes.tsx @@ -1,12 +1,11 @@ import React from "react"; import { BrowserRouter as Router, - Switch, Route, RouteProps, } from "react-router-dom"; -import { ErrorView, HomeView } from "./views"; + interface Props extends RouteProps { component: any; // TODO: new (props: any) => React.Component @@ -15,17 +14,11 @@ interface Props extends RouteProps { const CustomRoute = ({ component: Component, ...rest }: Props) => { return ( - } /> + <> ); }; export const Routes = () => ( - - - - - - ); diff --git a/apps/remixdocgen/src/app/views/HomeView.tsx b/apps/remixdocgen/src/app/views/HomeView.tsx deleted file mode 100644 index 11feae8bf6..0000000000 --- a/apps/remixdocgen/src/app/views/HomeView.tsx +++ /dev/null @@ -1,203 +0,0 @@ -import React, { useState, useEffect, useRef } from "react"; -import { AppContext } from "../AppContext"; -import { ContractName, Documentation } from "../../types"; -import { publish } from "../../utils"; -import { htmlTemplate } from "../../utils/template"; - -export const HomeView: React.FC = () => { - const [activeItem, setActiveItem] = useState(""); - const [isPublishing, setIsPublishing] = useState(false); - const [htmlDocumentation, setHtmlDocumentation] = useState(""); - const [hasErrorOnPublishing, setHasErrorOnPublishing] = useState(false); - const [publishedURL, setPublishedURL] = useState(""); - const clearMessageFuncRef = useRef(undefined as any); - - useEffect(() => { - const maxNumberOfRetries = 1; - let retries = 0; - - const publishDocumentation = async () => { - try { - if (clearMessageFuncRef.current) { - clearTimeout(clearMessageFuncRef.current); - } - const hash = await publish(htmlDocumentation); - console.log("Hash", hash); - setIsPublishing(false); - - const url = `https://ipfs.io/ipfs/${hash}`; - - window.open(url); - setPublishedURL(url); - } catch (error) { - if (retries < maxNumberOfRetries) { - console.log("Retrying..."); - retries++; - publishDocumentation(); - } else { - setIsPublishing(false); - setHasErrorOnPublishing(true); - - clearMessageFuncRef.current = setTimeout(() => { - setHasErrorOnPublishing(false); - }, 5000); - } - } - }; - - if (isPublishing) { - setHasErrorOnPublishing(false); - publishDocumentation(); - } - }, [isPublishing, htmlDocumentation]); - - const displayDocumentation = ( - client: any, - contractName: ContractName, - documentation: Documentation - ) => { - console.log("Display Documentation", contractName, documentation); - - client.emit("documentation-generated", documentation); - }; - - return ( - - {({ clientInstance, contracts, setContracts, themeType }) => ( -
- {[...contracts.keys()].length === 0 && ( -

Compile a contract with Solidity Compiler

- )} - - {[...contracts.keys()].length > 0 && ( -
-
- {[...contracts.keys()].map((item) => { - const documentation = contracts.get(item) as string; - return ( - - ); - })} -
-
- -
-
- {activeItem !== "" && ( - { - console.log("Is publishing"); - setIsPublishing(true); - }} - /> - )} -
- {!isPublishing && publishedURL !== "" && ( - <> - - - )} - - {hasErrorOnPublishing && ( -
- -
- )} -
- )} -
- )} -
- ); -}; - -interface PublishButtonProps { - isPublishing: boolean; - onClick: any; - item: string; -} - -export const PublishButton: React.FC = ({ - isPublishing, - onClick, - item, -}) => { - return ( - - ); -}; - -// -// -// diff --git a/apps/remixdocgen/src/app/views/index.ts b/apps/remixdocgen/src/app/views/index.ts index 70958d50ae..8b13789179 100644 --- a/apps/remixdocgen/src/app/views/index.ts +++ b/apps/remixdocgen/src/app/views/index.ts @@ -1,2 +1 @@ -export { HomeView } from "./HomeView"; -export { ErrorView } from "./ErrorView"; + diff --git a/apps/remixdocgen/webpack.config.js b/apps/remixdocgen/webpack.config.js index e69de29bb2..45c7c5dd14 100644 --- a/apps/remixdocgen/webpack.config.js +++ b/apps/remixdocgen/webpack.config.js @@ -0,0 +1,82 @@ +const { composePlugins, withNx } = require('@nrwl/webpack') +const webpack = require('webpack') +const TerserPlugin = require("terser-webpack-plugin") +const CssMinimizerPlugin = require("css-minimizer-webpack-plugin") + +// Nx plugins for webpack. +module.exports = composePlugins(withNx(), (config) => { + // Update the webpack config as needed here. + // e.g. `config.plugins.push(new MyPlugin())` + + // add fallback for node modules + config.resolve.fallback = { + ...config.resolve.fallback, + "crypto": require.resolve("crypto-browserify"), + "stream": require.resolve("stream-browserify"), + "path": require.resolve("path-browserify"), + "http": require.resolve("stream-http"), + "https": require.resolve("https-browserify"), + "constants": require.resolve("constants-browserify"), + "os": false, //require.resolve("os-browserify/browser"), + "timers": false, // require.resolve("timers-browserify"), + "zlib": require.resolve("browserify-zlib"), + "fs": false, + "module": false, + "tls": false, + "net": false, + "readline": false, + "child_process": false, + "buffer": require.resolve("buffer/"), + "vm": require.resolve('vm-browserify'), + } + + + // add externals + config.externals = { + ...config.externals, + solc: 'solc', + } + + // add public path + config.output.publicPath = '/' + + + + // add copy & provide plugin + config.plugins.push( + new webpack.ProvidePlugin({ + Buffer: ['buffer', 'Buffer'], + url: ['url', 'URL'], + process: 'process/browser', + }) + ) + + // souce-map loader + config.module.rules.push({ + test: /\.js$/, + use: ["source-map-loader"], + enforce: "pre" + }) + + config.ignoreWarnings = [/Failed to parse source map/] // ignore source-map-loader warnings + + + // set minimizer + config.optimization.minimizer = [ + new TerserPlugin({ + parallel: true, + terserOptions: { + ecma: 2015, + compress: false, + mangle: false, + format: { + comments: false, + }, + }, + extractComments: false, + }), + new CssMinimizerPlugin(), + ]; + + return config; +});