Skip to content

Commit

Permalink
Implement script to flatten contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Stefanski committed Jan 3, 2018
1 parent 1094c44 commit 5c3aec4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docker/docker-compose.yml
@@ -0,0 +1,8 @@
version: '2'
services:
flatten:
build:
context: .
dockerfile: solidity-flattener/Dockerfile
volumes:
- ../:/project
6 changes: 6 additions & 0 deletions docker/solidity-flattener/Dockerfile
@@ -0,0 +1,6 @@
FROM ethereum/solc:0.4.18 AS solc

FROM python:3.6.4
COPY --from=solc /usr/bin/solc /usr/bin/solc
RUN pip3 install solidity-flattener
ENTRYPOINT ["solidity_flattener"]
8 changes: 7 additions & 1 deletion package.json
Expand Up @@ -25,7 +25,13 @@
"lint:tslint": "tslint --project .",
"lint:tslint:fix": "tslint --fix --project .",
"lint:solhint": "solhint contracts/**/*.sol test/**/*.sol",
"format": "prettier --write *.ts **/*.ts"
"format": "prettier --write *.ts **/*.ts",
"flatten:migrations": "run-s compile:ts flatten:migrations:js",
"flatten:migrations:js": "node scripts/flatten.js -c Migrations",
"flatten:token": "run-s compile:ts flatten:token:js",
"flatten:token:js": "node scripts/flatten.js -c OnLiveToken",
"flatten:externalcrowdsale": "run-s compile:ts flatten:externalcrowdsale:js",
"flatten:externalcrowdsale:js": "node scripts/flatten.js -c ExternalCrowdsale"
},
"repository": {
"type": "git",
Expand Down
49 changes: 49 additions & 0 deletions scripts/flatten.ts
@@ -0,0 +1,49 @@
// tslint:disable:no-console

import * as commander from 'commander';

import { spawn } from 'child_process';
import { createWriteStream } from 'fs';
import { join } from 'path';

interface Options {
contract: string;
}

const argv = (commander
.option('-c, --contract <contract', 'contract name')
.parse(process.argv)
.opts() as any) as Options;

if (!argv.contract) {
throw new Error('Missing contract name [-c, --contract]');
}

const args = [
'run',
'--rm',
'flatten',
'--solc-paths',
'zeppelin-solidity/=/project/node_modules/zeppelin-solidity/',
`/project/contracts/${argv.contract}.sol`
];

const outPath = join(__dirname, '..', 'build', 'flat', `${argv.contract}.sol`);
const outStream = createWriteStream(outPath);

const child = spawn('docker-compose', args, {
cwd: join(__dirname, '..', 'docker')
});

child.stdout.pipe(outStream);
child.stderr.on('data', chunk => {
console.error(chunk.toString());
});

child.on('close', code => {
if (code !== 0) {
console.error(`Failed to flatten ${argv.contract} contract`);
} else {
console.log(`Saved flattened ${argv.contract} contract to ${outPath}`);
}
});

0 comments on commit 5c3aec4

Please sign in to comment.