-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
7 changed files
with
158 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"supersim": patch | ||
--- | ||
|
||
Initial publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
extends: ['../../.eslintrc.js'], | ||
ignorePatterns: ['.eslintrc.cjs'] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.