From 85b55a9f35c71c32ba0952648f5f9c15f5620983 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 12 Jun 2023 10:36:22 +0200 Subject: [PATCH] move scripts to ws-template --- apps/etherscan/src/app/views/VerifyView.tsx | 16 ++----------- apps/etherscan/webpack.config.js | 8 ++++++- apps/remix-ide/webpack.config.js | 24 +++++++++++++++++++ .../workspace/src/lib/actions/workspace.ts | 11 ++++++--- .../workspace/src/lib/scripts/index.ts | 7 ------ libs/remix-ws-templates/src/index.ts | 3 +++ .../basic-contract-deploy.ts | 0 .../create2-factory-deploy.ts | 0 .../contract-deployer/index.ts | 0 .../src/script-templates}/etherscan/index.ts | 0 .../etherscan/receiptGuidScript.ts | 0 .../etherscan/verifyScript.ts | 0 12 files changed, 44 insertions(+), 25 deletions(-) delete mode 100644 libs/remix-ui/workspace/src/lib/scripts/index.ts rename libs/{remix-ui/workspace/src/lib/scripts => remix-ws-templates/src/script-templates}/contract-deployer/basic-contract-deploy.ts (100%) rename libs/{remix-ui/workspace/src/lib/scripts => remix-ws-templates/src/script-templates}/contract-deployer/create2-factory-deploy.ts (100%) rename libs/{remix-ui/workspace/src/lib/scripts => remix-ws-templates/src/script-templates}/contract-deployer/index.ts (100%) rename libs/{remix-ui/workspace/src/lib/scripts => remix-ws-templates/src/script-templates}/etherscan/index.ts (100%) rename libs/{remix-ui/workspace/src/lib/scripts => remix-ws-templates/src/script-templates}/etherscan/receiptGuidScript.ts (100%) rename libs/{remix-ui/workspace/src/lib/scripts => remix-ws-templates/src/script-templates}/etherscan/verifyScript.ts (100%) diff --git a/apps/etherscan/src/app/views/VerifyView.tsx b/apps/etherscan/src/app/views/VerifyView.tsx index f7d3f9c994..2b8da379c7 100644 --- a/apps/etherscan/src/app/views/VerifyView.tsx +++ b/apps/etherscan/src/app/views/VerifyView.tsx @@ -10,7 +10,7 @@ import { Formik, ErrorMessage, Field } from "formik" import { SubmitButton } from "../components" import { Receipt } from "../types" import { verify } from "../utils/verify" -import { receiptGuidScript, verifyScript } from "../utils/scripts" +import { etherscanScripts } from "@remix-project/remix-ws-templates" interface Props { client: PluginClient @@ -270,19 +270,7 @@ export const VerifyView: React.FC = ({ style={{ padding: "0.25rem 0.4rem", marginRight: "0.5em", marginBottom: "0.5em"}} className="btn btn-secondary btn-block" onClick={async () => { - if (!await client.call('fileManager', 'exists' as any, 'scripts/etherscan/receiptStatus.ts')) { - await client.call('fileManager', 'writeFile', 'scripts/etherscan/receiptStatus.ts', receiptGuidScript) - await client.call('fileManager', 'open', 'scripts/etherscan/receiptStatus.ts') - } else { - client.call('notification' as any, 'toast', 'File receiptStatus.ts already exists') - } - - if (!await client.call('fileManager', 'exists' as any, 'scripts/etherscan/verify.ts')) { - await client.call('fileManager', 'writeFile', 'scripts/etherscan/verify.ts', verifyScript) - await client.call('fileManager', 'open', 'scripts/etherscan/verify.ts') - } else { - client.call('notification' as any, 'toast', 'File verify.ts already exists') - } + etherscanScripts(client) }} > Generate Verification Scripts diff --git a/apps/etherscan/webpack.config.js b/apps/etherscan/webpack.config.js index 9d72c43a6c..e28638e84e 100644 --- a/apps/etherscan/webpack.config.js +++ b/apps/etherscan/webpack.config.js @@ -3,6 +3,10 @@ const webpack = require('webpack') const TerserPlugin = require("terser-webpack-plugin") const CssMinimizerPlugin = require("css-minimizer-webpack-plugin") +const versionData = { + timestamp: Date.now(), + mode: process.env.NODE_ENV === 'production' ? 'production' : 'development' +} // Nx plugins for webpack. module.exports = composePlugins(withNx(), (config) => { // Update the webpack config as needed here. @@ -29,7 +33,6 @@ module.exports = composePlugins(withNx(), (config) => { "buffer": require.resolve("buffer/"), "vm": require.resolve('vm-browserify'), } - // add externals config.externals = { @@ -40,6 +43,9 @@ module.exports = composePlugins(withNx(), (config) => { // add public path config.output.publicPath = '/' + // set filename + config.output.filename = `[name].plugin-etherscan.${versionData.timestamp}.js` + config.output.chunkFilename = `[name].plugin-etherscan.${versionData.timestamp}.js` // add copy & provide plugin diff --git a/apps/remix-ide/webpack.config.js b/apps/remix-ide/webpack.config.js index a6aa923939..ba5258a8f3 100644 --- a/apps/remix-ide/webpack.config.js +++ b/apps/remix-ide/webpack.config.js @@ -83,6 +83,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { config.output.filename = `[name].${versionData.version}.${versionData.timestamp}.js` config.output.chunkFilename = `[name].${versionData.version}.${versionData.timestamp}.js` + // add copy & provide plugin config.plugins.push( new CopyPlugin({ @@ -91,6 +92,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { ...copyPatterns ].filter(Boolean) }), + new CopyFileAfterBuild(), new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'], url: ['url', 'URL'], @@ -131,4 +133,26 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { return config; }); +class CopyFileAfterBuild { + apply(compiler) { + const onEnd = async () => { + try { + console.log('runnning CopyFileAfterBuild') + // This copy the raw-loader files used by the etherscan plugin to the remix-ide root folder. + // This is needed because by default the etherscan resources are served from the /plugins/etherscan/ folder, + // but the raw-loader try to access the resources from the root folder. + const files = fs.readdirSync('./dist/apps/etherscan') + files.forEach(file => { + if (file.startsWith('node_modules_raw-loader_')) { + fs.copyFileSync('./dist/apps/etherscan/' + file, './dist/apps/remix-ide/' + file) + } + }) + } catch (e) { + console.error('running CopyFileAfterBuild failed with error: ' + e.message) + } + } + compiler.hooks.afterEmit.tapPromise('FileManagerPlugin', onEnd); + } +} + diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index b59e756ac0..a994416f3c 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -13,7 +13,7 @@ import { ROOT_PATH, slitherYml, solTestYml, tsSolTestYml } from '../utils/consta import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB' import { getUncommittedFiles } from '../utils/gitStatusFilter' import { AppModal, ModalTypes } from '@remix-ui/app' -import { scripts } from '../scripts' +import { contractDeployerScripts, etherscanScripts } from '@remix-project/remix-ws-templates' declare global { interface Window { remixFileSystemCallback: IndexedDBStorage; } @@ -678,9 +678,14 @@ export const createSlitherGithubAction = async () => { plugin.call('fileManager', 'open', path) } +const scriptsRef = { + 'deployer': contractDeployerScripts, + 'etherscan': etherscanScripts +} export const createHelperScripts = async (script: string) => { - if (!scripts[script]) return - await scripts[script](plugin) + + if (!scriptsRef[script]) return + await scriptsRef[script](plugin) plugin.call('notification', 'toast', 'scripts added in the "scripts" folder') } diff --git a/libs/remix-ui/workspace/src/lib/scripts/index.ts b/libs/remix-ui/workspace/src/lib/scripts/index.ts deleted file mode 100644 index 4f2c005e98..0000000000 --- a/libs/remix-ui/workspace/src/lib/scripts/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { contractDeployerScripts } from '../scripts/contract-deployer' -import { etherscanScripts } from '../scripts/etherscan' - -export const scripts = { - 'etherscan': etherscanScripts, - 'deployer': contractDeployerScripts -} \ No newline at end of file diff --git a/libs/remix-ws-templates/src/index.ts b/libs/remix-ws-templates/src/index.ts index 89d9795dfa..e11a422750 100644 --- a/libs/remix-ws-templates/src/index.ts +++ b/libs/remix-ws-templates/src/index.ts @@ -6,3 +6,6 @@ export { default as ozerc1155 } from './templates/ozerc1155' export { default as zeroxErc20 } from './templates/zeroxErc20' export { default as gnosisSafeMultisig } from './templates/gnosisSafeMultisig' +export { contractDeployerScripts } from './script-templates/contract-deployer' +export { etherscanScripts } from './script-templates/etherscan' + diff --git a/libs/remix-ui/workspace/src/lib/scripts/contract-deployer/basic-contract-deploy.ts b/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts similarity index 100% rename from libs/remix-ui/workspace/src/lib/scripts/contract-deployer/basic-contract-deploy.ts rename to libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts diff --git a/libs/remix-ui/workspace/src/lib/scripts/contract-deployer/create2-factory-deploy.ts b/libs/remix-ws-templates/src/script-templates/contract-deployer/create2-factory-deploy.ts similarity index 100% rename from libs/remix-ui/workspace/src/lib/scripts/contract-deployer/create2-factory-deploy.ts rename to libs/remix-ws-templates/src/script-templates/contract-deployer/create2-factory-deploy.ts diff --git a/libs/remix-ui/workspace/src/lib/scripts/contract-deployer/index.ts b/libs/remix-ws-templates/src/script-templates/contract-deployer/index.ts similarity index 100% rename from libs/remix-ui/workspace/src/lib/scripts/contract-deployer/index.ts rename to libs/remix-ws-templates/src/script-templates/contract-deployer/index.ts diff --git a/libs/remix-ui/workspace/src/lib/scripts/etherscan/index.ts b/libs/remix-ws-templates/src/script-templates/etherscan/index.ts similarity index 100% rename from libs/remix-ui/workspace/src/lib/scripts/etherscan/index.ts rename to libs/remix-ws-templates/src/script-templates/etherscan/index.ts diff --git a/libs/remix-ui/workspace/src/lib/scripts/etherscan/receiptGuidScript.ts b/libs/remix-ws-templates/src/script-templates/etherscan/receiptGuidScript.ts similarity index 100% rename from libs/remix-ui/workspace/src/lib/scripts/etherscan/receiptGuidScript.ts rename to libs/remix-ws-templates/src/script-templates/etherscan/receiptGuidScript.ts diff --git a/libs/remix-ui/workspace/src/lib/scripts/etherscan/verifyScript.ts b/libs/remix-ws-templates/src/script-templates/etherscan/verifyScript.ts similarity index 100% rename from libs/remix-ui/workspace/src/lib/scripts/etherscan/verifyScript.ts rename to libs/remix-ws-templates/src/script-templates/etherscan/verifyScript.ts