Xianny 2d77fce99d
Re-enable all TypeScript Packages on 3.0 (#2181)
* update with WIP artifacts and wrappers

* Update order-utils to get build:contracts working

* get asset-buyer and asset-swapper building with 3.0

* get testnet-faucets building on 3.0

* re-enable build for most packages
2019-09-23 15:52:51 -07:00

57 lines
2.0 KiB
TypeScript

import { deleteNestedProperty, logUtils } from '@0x/utils';
import * as fs from 'fs';
export const REQUIRED_PROPERTIES: string[] = [
'schemaVersion',
'contractName',
'compilerOutput.evm.bytecode.object',
'compilerOutput.evm.deployedBytecode.object',
'compilerOutput.abi',
'compilerOutput.devdoc',
'compiler',
];
export const FORBIDDEN_PROPERTIES: string[] = [
'compilerOutput.evm.bytecode.sourceMap',
'compilerOutput.evm.bytecode.opcodes',
'compilerOutput.evm.bytecode.linkReferences',
'compilerOutput.evm.deployedBytecode.sourceMap',
'compilerOutput.evm.deployedBytecode.opcodes',
'compilerOutput.evm.deployedBytecode.linkReferences',
'compilerOutput.evm.assembly',
'compilerOutput.evm.legacyAssembly',
'compilerOutput.evm.gasEstimates',
'compilerOutput.evm.methodIdentifiers',
'compilerOutput.metadata',
'compilerOutput.userdoc',
'compiler.settings.remappings',
'sourceCodes',
'sources',
'sourceTreeHashHex',
];
function removeForbiddenProperties(inputDir: string, outputDir: string): void {
const filePaths = fs
.readdirSync(inputDir)
.filter(filename => filename.indexOf('.json') !== -1)
.map(filename => `./${inputDir}/${filename}`);
for (const filePath of filePaths) {
const artifact = JSON.parse(fs.readFileSync(filePath).toString()) as { [name: string]: any };
for (const property of FORBIDDEN_PROPERTIES) {
deleteNestedProperty(artifact, property);
}
fs.writeFileSync(filePath.replace(inputDir, outputDir), JSON.stringify(artifact));
}
}
if (require.main === module) {
const inputDir = process.argv[2];
const outputDir = process.argv[3] !== undefined ? process.argv[3] : inputDir;
logUtils.log(`Deleting forbidden properties from artifacts in ${inputDir}. Output to ${outputDir}`);
if (!fs.existsSync(`./${outputDir}`)) {
fs.mkdirSync(`./${outputDir}`);
}
removeForbiddenProperties(inputDir, outputDir);
}