Skip to content

Commit

Permalink
Adds supersim pkg (#488)
Browse files Browse the repository at this point in the history
* Adds supersim pkg

* Add README

* add node engine

* Add changeset for supersim

* Adds follow-redirects

This is for the case when github returns a 302 and we need to follow the value
provided in the location header to download the archive
  • Loading branch information
nitaliano authored Oct 1, 2024
1 parent 45d5438 commit 6a08235
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-monkeys-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"supersim": patch
---

Initial publish
5 changes: 5 additions & 0 deletions packages/supersim/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: ['../../.eslintrc.js'],
ignorePatterns: ['.eslintrc.cjs']
}

1 change: 1 addition & 0 deletions packages/supersim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
22 changes: 22 additions & 0 deletions packages/supersim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Supersim

Supersim is a lightweight tool to simulate the Superchain locally (with a single L1 and multiple OP-Stack L2s).

For more detailed documentation please refer to the [supersim repo](https://github.com/ethereum-optimism/supersim)

# Installation

**npm**
```
npx supersim
```

**pnpm**
```
pnpm dlx supersim
```

**yarn**
```
yarn dlx supersim
```
80 changes: 80 additions & 0 deletions packages/supersim/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const fs = require('fs')
const { https } = require('follow-redirects')
const path = require('path')
const os = require('os')
const { exec } = require('child_process')

const PLATFORM = os.platform()
const ARCH = os.arch()
const BIN_PATH = path.join(__dirname, 'bin')
const SUPERSIM_VERSION = '0.1.0-alpha.13'

const archiveFilename = {
darwin: {
arm64: 'supersim_Darwin_arm64.tar.gz',
x64: 'supersim_Darwin_x86_64.tar.gz',
},
linux: {
arm64: 'supersim_Linux_arm64.tar.gz',
x64: 'supersim_Linux_x86_64.tar.gz',
},
win32: {
arm64: 'supersim_Windows_arm64.zip',
x64: 'supersim_Windows_x86_64.zip',
},
}

function extractRelease(filename, outputPath) {
const cmd = filename.endsWith('.tar.gz')
? `tar -xzf ${outputPath} -C ${BIN_PATH}`
: `unzip ${outputPath} -d ${BIN_PATH}`

exec(cmd, (err) => {
if (err) {
console.error('Error extracting', err)
} else {
console.log('Successfully extracted release')
}
})
}

async function main() {
const filename = archiveFilename[PLATFORM][ARCH]
if (!filename) {
console.error('Unsupported platform/architecture')
process.exit(1)
}

const downloadUrl = `https://github.com/ethereum-optimism/supersim/releases/download/${SUPERSIM_VERSION}/${filename}`
const outputPath = path.join(BIN_PATH, filename)

if (!fs.existsSync(BIN_PATH)) {
fs.mkdirSync(BIN_PATH)
}

console.log(`Attempting to fetch ${filename}`)

https
.get(downloadUrl, (res) => {
const fileStream = fs.createWriteStream(outputPath)
res.pipe(fileStream)

fileStream.on('finish', () => {
console.log(`Downloaded ${filename}`)
fileStream.on('close', () => extractRelease(filename, outputPath))
})
})
.on('error', (err) => {
console.error('Error downloading supersim', err)
process.exit(1)
})
}

;(async () => {
try {
await main()
} catch (err) {
console.error('Error setting up supersim', err)
process.exit(1)
}
})()
27 changes: 27 additions & 0 deletions packages/supersim/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "supersim",
"version": "0.0.1",
"description": "Supersim is a lightweight tool to simulate the Superchain locally",
"license": "MIT",
"author": "Optimism PBC",
"keywords": [
"optimism",
"ethereum",
"supersim",
"superchain"
],
"engines": {
"node": ">=18.0.0"
},
"bin": {
"supersim": "./bin/supersim"
},
"scripts": {
"lint": "eslint install.js && pnpm prettier --check install.js",
"lint:fix": "eslint install.js --fix --quiet && pnpm prettier install.js --write --loglevel=warn",
"postinstall": "node install.js"
},
"dependencies": {
"follow-redirects": "^1.15.9"
}
}
26 changes: 18 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a08235

Please sign in to comment.