Skip to content

Commit

Permalink
move scripts to ws-template
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Jun 13, 2023
1 parent 2e3cba8 commit afd8a87
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 25 deletions.
16 changes: 2 additions & 14 deletions apps/etherscan/src/app/views/VerifyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -270,19 +270,7 @@ export const VerifyView: React.FC<Props> = ({
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
Expand Down
8 changes: 7 additions & 1 deletion apps/etherscan/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,7 +33,6 @@ module.exports = composePlugins(withNx(), (config) => {
"buffer": require.resolve("buffer/"),
"vm": require.resolve('vm-browserify'),
}


// add externals
config.externals = {
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions apps/remix-ide/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -91,6 +92,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
...copyPatterns
].filter(Boolean)
}),
new CopyFileAfterBuild(),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
url: ['url', 'URL'],
Expand Down Expand Up @@ -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);
}
}


11 changes: 8 additions & 3 deletions libs/remix-ui/workspace/src/lib/actions/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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')
}

Expand Down
7 changes: 0 additions & 7 deletions libs/remix-ui/workspace/src/lib/scripts/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions libs/remix-ws-templates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit afd8a87

Please sign in to comment.