├── .gitattributes ├── .gitignore ├── .npmignore ├── .npmrc ├── .solhint.json ├── .travis.yml ├── LICENSE ├── README.md ├── dist ├── src │ ├── caching.js │ ├── caching.js.map │ ├── cli.js │ ├── cli.js.map │ ├── compile.js │ ├── compile.js.map │ ├── compile.node.js │ ├── compile.node.js.map │ ├── index.js │ ├── index.js.map │ ├── options.js │ ├── options.js.map │ ├── output-files │ │ ├── index.js │ │ └── index.js.map │ ├── paths.js │ ├── paths.js.map │ ├── read-code.js │ ├── read-code.js.map │ ├── solc-install.js │ ├── solc-install.js.map │ ├── version.js │ └── version.js.map └── test │ ├── index.test.js │ ├── index.test.js.map │ ├── integration.test.js │ ├── integration.test.js.map │ └── unit │ ├── cache.js │ ├── cache.js.map │ ├── caching.test.js │ ├── caching.test.js.map │ ├── compile.test.js │ ├── compile.test.js.map │ ├── issues.test.js │ ├── issues.test.js.map │ ├── output-files.test.js │ ├── output-files.test.js.map │ ├── paths.test.js │ ├── paths.test.js.map │ ├── read-code.test.js │ ├── read-code.test.js.map │ ├── solc-install.test.js │ └── solc-install.test.js.map ├── docs └── solidity.svg ├── package.json ├── src ├── caching.ts ├── cli.ts ├── compile.node.ts ├── compile.ts ├── compiled.d.ts ├── index.ts ├── options.ts ├── output-files │ ├── index.ts │ └── javascript.template.js ├── paths.ts ├── read-code.ts ├── solc-install.ts ├── typings.d.ts └── version.ts ├── test-cli.bash ├── test ├── contracts │ ├── .gitignore │ ├── Basic.sol │ ├── Broken.sol │ ├── DonationBag.sol │ ├── Import.sol │ ├── OlderVersion.sol │ ├── VersionRange.sol │ └── subdir │ │ ├── Basic.sol │ │ └── Import.sol ├── index.test.ts ├── integration.test.ts └── unit │ ├── cache.ts │ ├── caching.test.ts │ ├── compile.test.ts │ ├── issues.test.ts │ ├── output-files.test.ts │ ├── paths.test.ts │ ├── read-code.test.ts │ └── solc-install.test.ts ├── tsconfig.json └── tslint.json /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test_tmp/ 3 | package-lock.json 4 | .idea/ 5 | .transpile_state.json 6 | .com.google.* 7 | shelljs_* 8 | 9 | tmp/ 10 | .tmp/ 11 | solc-installs/ 12 | compile-cache/ 13 | compile-tmp/ 14 | solidity-cli 15 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | solc-installs/ 2 | compile-cache/ 3 | compile-tmp/ 4 | node_modules/ 5 | log.txt 6 | test/ 7 | dist/test/ 8 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | unsafe-perm = true 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "default", 3 | "rules": { 4 | "func-order": false, 5 | "not-rely-on-time": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | os: 3 | - linux 4 | node_js: 5 | - "10.1.0" 6 | script: 7 | - npm install --depth 0 --silent 8 | - npm run lint 9 | - npm run test 10 | - npm run test:cli 11 | - npm run test:cli # must run twice to ensure everything works 12 | - npm run build 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 | 5 |

6 | 7 |

Solidity-Cli

8 |

9 | Compile solidity-code faster, easier and more reliable 10 |

11 | 12 |

13 | 14 | 15 | 16 | follow on Twitter 18 |

19 | 20 |
21 | 22 | * * * 23 | 24 | ## Features 25 | 26 | - **Caching** 27 | 28 | When you run the compilation as one step of your build-process, it could waste you much time always compiling the same contracts again and again. Solidity-Cli caches the compilation output and only recompiles when the code of your contract actually has changed. 29 | 30 | - **Multi-Threading** 31 | 32 | Compiling multiple contracts can take very long when done on a single process in series. Solidity-Cli compiles multiple contracts with a dedicated process per contract. 33 | 34 | - **Version-Discovery** 35 | 36 | Often you have different contracts with different solidity-versions. It is a struggle to install multiple compiler-versions in the same project. Solidity-Cli detects the version by the contracts code `pragma solidity 0.X.X;` and automatically installs it if needed. 37 | 38 | - **Imports** 39 | 40 | Solidity-Cli automatically manages the import-statements of your code. `import "./OtherContract.sol";` just works. 41 | 42 | - **Typescript-Support** 43 | 44 | When you use typescript, you no longer have to manually add typings to the compilation output. Solidity-Cli generates a javascript and a typescript-file which only has to be imported. 45 | 46 | ## Usage 47 | 48 | ### CLI 49 | 50 | `npm install -g solidity-cli` 51 | 52 | Compile all `*.sol` files from one folder into the destination. 53 | 54 | `solidity -i './test/contracts/*.sol' -o ./test/compiled/` 55 | 56 | It's recommended to use solidity-cli inside of a script in your `package.json` 57 | 58 | `npm install solidity-cli --save-dev` 59 | 60 | ```json 61 | { 62 | "scripts": { 63 | "pretest": "solidity-cli -i './contracts/*.sol' -o ./compiled" 64 | }, 65 | "dependencies": { 66 | "solidity-cli": "X.X.X" 67 | } 68 | } 69 | ``` 70 | 71 | ### Programmatically 72 | 73 | Compile the given solidity-code. 74 | 75 | ```js 76 | import * as SolidityCli from 'solidity-cli'; 77 | const compiled = await SolidityCli.compileCode(myCode); 78 | ``` 79 | 80 | Compile the the given solidity-file. 81 | 82 | ```js 83 | import * as SolidityCli from 'solidity-cli'; 84 | const compiled = await SolidityCli.compileFile('/home/foobar/myProject/contracts/Basic.sol'); 85 | ``` 86 | 87 | Compile all files from one folder and write the output to another. 88 | 89 | ```js 90 | import * as SolidityCli from 'solidity-cli'; 91 | await SolidityCli.runCli({ 92 | sourceFolder: '/home/foobar/myProject/contracts/*.sol', 93 | destinationFolder: '/home/foobar/myProject/compiled/*.sol' 94 | }); 95 | ``` 96 | -------------------------------------------------------------------------------- /dist/src/caching.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [op[0] & 2, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | Object.defineProperty(exports, "__esModule", { value: true }); 38 | /** 39 | * saves output to the cache 40 | * and retrieves it again, 41 | * so equal code does not have to be compiled multiple times 42 | */ 43 | var util = require("util"); 44 | var fs = require("fs"); 45 | var path = require("path"); 46 | var directoryExists = require('directory-exists'); 47 | var paths_1 = require("./paths"); 48 | var fileExists = util.promisify(fs.stat); 49 | var writeFile = util.promisify(fs.writeFile); 50 | var readFile = util.promisify(fs.readFile); 51 | function ensureDirectoryExists() { 52 | return __awaiter(this, void 0, void 0, function () { 53 | var exists; 54 | return __generator(this, function (_a) { 55 | switch (_a.label) { 56 | case 0: return [4 /*yield*/, directoryExists(paths_1.default.compileCache + '/')]; 57 | case 1: 58 | exists = _a.sent(); 59 | if (!exists) { 60 | fs.mkdirSync(path.join(paths_1.default.compileCache, '../')); 61 | fs.mkdirSync(paths_1.default.compileCache + '/'); 62 | } 63 | return [2 /*return*/]; 64 | } 65 | }); 66 | }); 67 | } 68 | function fileBySource(hash) { 69 | return path.join(paths_1.default.compileCache, hash + '.json'); 70 | } 71 | function has(hash) { 72 | return __awaiter(this, void 0, void 0, function () { 73 | var err_1; 74 | return __generator(this, function (_a) { 75 | switch (_a.label) { 76 | case 0: 77 | _a.trys.push([0, 2, , 3]); 78 | return [4 /*yield*/, fileExists(fileBySource(hash))]; 79 | case 1: 80 | _a.sent(); 81 | return [2 /*return*/, true]; 82 | case 2: 83 | err_1 = _a.sent(); 84 | return [2 /*return*/, false]; 85 | case 3: return [2 /*return*/]; 86 | } 87 | }); 88 | }); 89 | } 90 | exports.has = has; 91 | function get(hash) { 92 | return __awaiter(this, void 0, void 0, function () { 93 | var content, artifact; 94 | return __generator(this, function (_a) { 95 | switch (_a.label) { 96 | case 0: return [4 /*yield*/, readFile(fileBySource(hash), 'utf-8')]; 97 | case 1: 98 | content = _a.sent(); 99 | artifact = JSON.parse(content); 100 | return [2 /*return*/, artifact]; 101 | } 102 | }); 103 | }); 104 | } 105 | exports.get = get; 106 | function set(hash, artifact) { 107 | return __awaiter(this, void 0, void 0, function () { 108 | var fileContent, filePath; 109 | return __generator(this, function (_a) { 110 | switch (_a.label) { 111 | case 0: return [4 /*yield*/, ensureDirectoryExists()]; 112 | case 1: 113 | _a.sent(); 114 | fileContent = JSON.stringify(artifact); 115 | filePath = fileBySource(hash); 116 | return [4 /*yield*/, writeFile(filePath, fileContent)]; 117 | case 2: 118 | _a.sent(); 119 | return [2 /*return*/]; 120 | } 121 | }); 122 | }); 123 | } 124 | exports.set = set; 125 | //# sourceMappingURL=caching.js.map -------------------------------------------------------------------------------- /dist/src/caching.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"caching.js","sourceRoot":"","sources":["../../src/caching.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,2BAA6B;AAC7B,uBAAyB;AACzB,2BAA6B;AAC7B,IAAM,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEpD,iCAA4B;AAE5B,IAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAC3C,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AAC/C,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAM7C,SAAe,qBAAqB;;;;;wBACjB,qBAAM,eAAe,CAAC,eAAK,CAAC,YAAY,GAAG,GAAG,CAAC,EAAA;;oBAAxD,MAAM,GAAG,SAA+C;oBAC9D,IAAI,CAAC,MAAM,EAAE;wBACT,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,eAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;wBACnD,EAAE,CAAC,SAAS,CAAC,eAAK,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC;qBAC1C;;;;;CACJ;AAED,SAAS,YAAY,CAAC,IAAY;IAC9B,OAAO,IAAI,CAAC,IAAI,CACZ,eAAK,CAAC,YAAY,EAClB,IAAI,GAAG,OAAO,CACjB,CAAC;AACN,CAAC;AAED,SAAsB,GAAG,CAAC,IAAY;;;;;;;oBAE9B,qBAAM,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAA;;oBAApC,SAAoC,CAAC;oBACrC,sBAAO,IAAI,EAAC;;;oBAEZ,sBAAO,KAAK,EAAC;;;;;CAEpB;AAPD,kBAOC;AAED,SAAsB,GAAG,CAAC,IAAY;;;;;wBAClB,qBAAM,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,EAAA;;oBAArD,OAAO,GAAG,SAA2C;oBACrD,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;oBACrC,sBAAO,QAAQ,EAAC;;;;CACnB;AAJD,kBAIC;AAED,SAAsB,GAAG,CACrB,IAAY,EACZ,QAAkB;;;;;wBAElB,qBAAM,qBAAqB,EAAE,EAAA;;oBAA7B,SAA6B,CAAC;oBACxB,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;oBACvC,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;oBACpC,qBAAM,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,EAAA;;oBAAtC,SAAsC,CAAC;;;;;CAC1C;AARD,kBAQC"} -------------------------------------------------------------------------------- /dist/src/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | var yargs = require("yargs"); 5 | var path = require("path"); 6 | var version_1 = require("./version"); 7 | var index_1 = require("./index"); 8 | yargs 9 | .usage('Usage: solidity [options] [input_file...]') 10 | .option('version', { 11 | describe: 'Show version and exit.', 12 | type: 'boolean' 13 | }) 14 | .option('input-dir', { 15 | alias: 'i', 16 | describe: 'Input directory for the solidity-files.', 17 | type: 'string' 18 | }) 19 | .option('output-dir', { 20 | alias: 'o', 21 | describe: 'Output directory for compiled contracts.', 22 | type: 'string' 23 | }) 24 | .global(['version']) 25 | .showHelpOnFail(false, 'Specify --help for available options') 26 | .help(); 27 | var argv = yargs.argv; 28 | if (argv.version) { 29 | console.log(version_1.default); 30 | process.exit(); 31 | } 32 | if (argv.help) { 33 | process.exit(); 34 | } 35 | // default -> compile file 36 | var options = { 37 | sourceFolder: path.join(process.cwd(), argv.inputDir), 38 | destinationFolder: argv.outputDir 39 | }; 40 | if (options.destinationFolder) { 41 | options.destinationFolder = path.join(process.cwd(), options.destinationFolder); 42 | } 43 | // console.log('bbbb'); 44 | // console.dir(yargs.argv); 45 | // console.dir(options); 46 | // console.log(process.cwd()); 47 | index_1.runCli(options); 48 | //# sourceMappingURL=cli.js.map -------------------------------------------------------------------------------- /dist/src/cli.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;AAEA,6BAA+B;AAC/B,2BAA6B;AAE7B,qCAAgC;AAMhC,iCAEiB;AAEjB,KAAK;KACA,KAAK,CAAC,2CAA2C,CAAC;KAClD,MAAM,CAAC,SAAS,EAAE;IACf,QAAQ,EAAE,wBAAwB;IAClC,IAAI,EAAE,SAAS;CAClB,CAAC;KACD,MAAM,CAAC,WAAW,EAAE;IACjB,KAAK,EAAE,GAAG;IACV,QAAQ,EAAE,yCAAyC;IACnD,IAAI,EAAE,QAAQ;CACjB,CAAC;KACD,MAAM,CAAC,YAAY,EAAE;IAClB,KAAK,EAAE,GAAG;IACV,QAAQ,EAAE,0CAA0C;IACpD,IAAI,EAAE,QAAQ;CACjB,CAAC;KACD,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;KACnB,cAAc,CAAC,KAAK,EAAE,sCAAsC,CAAC;KAC7D,IAAI,EAAE,CAAC;AAEZ,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;AAExB,IAAI,IAAI,CAAC,OAAO,EAAE;IACd,OAAO,CAAC,GAAG,CAAC,iBAAO,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,EAAE,CAAC;CAClB;AAED,IAAI,IAAI,CAAC,IAAI,EAAE;IACX,OAAO,CAAC,IAAI,EAAE,CAAC;CAClB;AAED,0BAA0B;AAC1B,IAAM,OAAO,GAAY;IACrB,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC;IACrD,iBAAiB,EAAE,IAAI,CAAC,SAAS;CACpC,CAAC;AACF,IAAI,OAAO,CAAC,iBAAiB,EAAE;IAC3B,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACnF;AAED,uBAAuB;AACvB,2BAA2B;AAC3B,wBAAwB;AACxB,8BAA8B;AAE9B,cAAM,CAAC,OAAO,CAAC,CAAC"} -------------------------------------------------------------------------------- /dist/src/compile.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /** 3 | * compiles the source-code in an own thread 4 | */ 5 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 6 | return new (P || (P = Promise))(function (resolve, reject) { 7 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 8 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 9 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 10 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 11 | }); 12 | }; 13 | var __generator = (this && this.__generator) || function (thisArg, body) { 14 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 15 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 16 | function verb(n) { return function (v) { return step([n, v]); }; } 17 | function step(op) { 18 | if (f) throw new TypeError("Generator is already executing."); 19 | while (_) try { 20 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 21 | if (y = 0, t) op = [op[0] & 2, t.value]; 22 | switch (op[0]) { 23 | case 0: case 1: t = op; break; 24 | case 4: _.label++; return { value: op[1], done: false }; 25 | case 5: _.label++; y = op[1]; op = [0]; continue; 26 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 27 | default: 28 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 29 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 30 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 31 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 32 | if (t[2]) _.ops.pop(); 33 | _.trys.pop(); continue; 34 | } 35 | op = body.call(thisArg, _); 36 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 37 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 38 | } 39 | }; 40 | Object.defineProperty(exports, "__esModule", { value: true }); 41 | var path = require("path"); 42 | var fs = require("fs"); 43 | var util = require("util"); 44 | var readFile = util.promisify(fs.readFile); 45 | var unlink = util.promisify(fs.unlink); 46 | var async_test_util_1 = require("async-test-util"); 47 | var spawn = require('child-process-promise').spawn; 48 | var paths_1 = require("./paths"); 49 | var WARNING_REGEX = /^\:[0-9]*:[0-9]*\: Warning:/; 50 | function compile(source) { 51 | return __awaiter(this, void 0, void 0, function () { 52 | var base64Code, nodeScriptLocation, stdout, stderr, rand, promise, childProcess, err_1, resultLocation, resultString, resultJson, errors; 53 | return __generator(this, function (_a) { 54 | switch (_a.label) { 55 | case 0: 56 | base64Code = Buffer.from(source.code).toString('base64'); 57 | nodeScriptLocation = path.join(__dirname, 'compile.node.js'); 58 | stdout = []; 59 | stderr = []; 60 | rand = async_test_util_1.default.randomString(10); 61 | promise = spawn('node', [ 62 | nodeScriptLocation, 63 | base64Code, 64 | rand 65 | ]); 66 | childProcess = promise.childProcess; 67 | childProcess.stdout.on('data', function (data) { return stdout.push(data.toString()); }); 68 | childProcess.stderr.on('data', function (data) { return stderr.push(data.toString()); }); 69 | _a.label = 1; 70 | case 1: 71 | _a.trys.push([1, 3, , 4]); 72 | return [4 /*yield*/, promise]; 73 | case 2: 74 | _a.sent(); 75 | return [3 /*break*/, 4]; 76 | case 3: 77 | err_1 = _a.sent(); 78 | throw new Error("could not compile\n # Error: " + err_1 + "\n # Output: " + stdout + "\n # ErrOut: " + stderr + "\n "); 79 | case 4: 80 | resultLocation = path.join(paths_1.default.compileTmpFolder, rand + '.json'); 81 | return [4 /*yield*/, readFile(resultLocation, 'utf-8')]; 82 | case 5: 83 | resultString = _a.sent(); 84 | return [4 /*yield*/, unlink(resultLocation)]; 85 | case 6: 86 | _a.sent(); 87 | resultJson = JSON.parse(resultString); 88 | if (resultJson.version !== source.solcVersion) { 89 | throw new Error('solidity-cli: version not equal, this should never happen'); 90 | } 91 | if (resultJson.compiled.errors) { 92 | errors = resultJson.compiled.errors.filter(function (err) { return !WARNING_REGEX.test(err); }); 93 | // const warnings = resultJson.compiled.errors.filter(err => WARNING_REGEX.test(err)); 94 | if (errors.length > 0) { 95 | throw new Error('# could not compile contract ' + source.filename + '\n' + 96 | '# errors: \n' + 97 | '#' + resultJson.compiled.errors.join('\n#')); 98 | } 99 | } 100 | return [2 /*return*/, resultJson.compiled.contracts]; 101 | } 102 | }); 103 | }); 104 | } 105 | exports.default = compile; 106 | //# sourceMappingURL=compile.js.map -------------------------------------------------------------------------------- /dist/src/compile.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2BAA6B;AAC7B,uBAAyB;AACzB,2BAA6B;AAE7B,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC7C,IAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAEzC,mDAA4C;AAEpC,IAAA,8CAAK,CAAsC;AAKnD,iCAA4B;AAK5B,IAAM,aAAa,GAAG,6BAA6B,CAAC;AAEpD,SAA8B,OAAO,CAAC,MAAkB;;;;;;oBAE9C,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBACzD,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;oBAE7D,MAAM,GAAa,EAAE,CAAC;oBACtB,MAAM,GAAa,EAAE,CAAC;oBAEtB,IAAI,GAAG,yBAAa,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;oBACtC,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE;wBAC1B,kBAAkB;wBAClB,UAAU;wBACV,IAAI;qBACP,CAAC,CAAC;oBACG,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;oBAE1C,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,IAAS,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAA5B,CAA4B,CAAC,CAAC;oBAC5E,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,IAAS,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAA5B,CAA4B,CAAC,CAAC;;;;oBAGxE,qBAAM,OAAO,EAAA;;oBAAb,SAAa,CAAC;;;;oBAEd,MAAM,IAAI,KAAK,CAAC,oDACM,KAAG,uCACF,MAAM,uCACN,MAAM,0BACjB,CAAC,CAAC;;oBAGZ,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,eAAK,CAAC,gBAAgB,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC;oBACpD,qBAAM,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,EAAA;;oBAAtD,YAAY,GAAG,SAAuC;oBAC5D,qBAAM,MAAM,CAAC,cAAc,CAAC,EAAA;;oBAA5B,SAA4B,CAAC;oBACvB,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;oBAE5C,IAAI,UAAU,CAAC,OAAO,KAAK,MAAM,CAAC,WAAW,EAAE;wBAC3C,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;qBAChF;oBAED,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE;wBACtB,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,UAAC,GAAW,IAAK,OAAA,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,EAAxB,CAAwB,CAAC,CAAC;wBAC5F,sFAAsF;wBAEtF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;4BACnB,MAAM,IAAI,KAAK,CACX,+BAA+B,GAAG,MAAM,CAAC,QAAQ,GAAG,IAAI;gCACxD,cAAc;gCACd,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAC/C,CAAC;yBACL;qBACJ;oBAED,sBAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,EAAC;;;;CACxC;AApDD,0BAoDC"} -------------------------------------------------------------------------------- /dist/src/compile.node.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /** 3 | * node-script that takes solidity-code as base64 and outputs a json with the compile-output 4 | * we use this to make multi-threading easiser 5 | */ 6 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 7 | return new (P || (P = Promise))(function (resolve, reject) { 8 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 9 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 10 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 11 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 12 | }); 13 | }; 14 | var __generator = (this && this.__generator) || function (thisArg, body) { 15 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 16 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 17 | function verb(n) { return function (v) { return step([n, v]); }; } 18 | function step(op) { 19 | if (f) throw new TypeError("Generator is already executing."); 20 | while (_) try { 21 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 22 | if (y = 0, t) op = [op[0] & 2, t.value]; 23 | switch (op[0]) { 24 | case 0: case 1: t = op; break; 25 | case 4: _.label++; return { value: op[1], done: false }; 26 | case 5: _.label++; y = op[1]; op = [0]; continue; 27 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 28 | default: 29 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 30 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 31 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 32 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 33 | if (t[2]) _.ops.pop(); 34 | _.trys.pop(); continue; 35 | } 36 | op = body.call(thisArg, _); 37 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 38 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 39 | } 40 | }; 41 | Object.defineProperty(exports, "__esModule", { value: true }); 42 | var util = require("util"); 43 | var fs = require("fs"); 44 | var shelljs = require("shelljs"); 45 | var path = require("path"); 46 | var writeFile = util.promisify(fs.writeFile); 47 | var read_code_1 = require("./read-code"); 48 | var paths_1 = require("./paths"); 49 | // const codeBase64 = 'cHJhZ21hIHNvbGlkaXR5IDAuNC4yNDsNCg0KDQpjb250cmFjdCBCYXNpYyB7DQogICAgYWRkcmVzcyBwdWJsaWMgb3duZXI7DQp9DQo='; 50 | // const codeBase64 = 'cHJhZ21hIHNvbGlkaXR5IDAuNC4yNDsNCg0KDQpjb250cmFjdCBCYXNpYyB7DQogICAgYWRkcmVzczEgcHVibGljIG93bmVyOw0KfQ0K'; // broken 51 | var codeBase64 = process.argv[2]; 52 | var location = process.argv[3] + '.json'; 53 | var code = Buffer.from(codeBase64, 'base64').toString(); 54 | var run = function (code) { 55 | return __awaiter(this, void 0, void 0, function () { 56 | var solcVersion, solc, compiled, out; 57 | return __generator(this, function (_a) { 58 | switch (_a.label) { 59 | case 0: 60 | solcVersion = read_code_1.getSolcVersion(code); 61 | solc = require(paths_1.default.solidityInstalls + '/' + solcVersion + '/node_modules/solc'); 62 | compiled = solc.compile(code, 1); 63 | out = { 64 | version: solcVersion, 65 | compiled: compiled 66 | }; 67 | // create destination if not exists 68 | shelljs.mkdir('-p', paths_1.default.compileTmpFolder); 69 | return [4 /*yield*/, writeFile(path.join(paths_1.default.compileTmpFolder, location), JSON.stringify(out, null, 2))]; 70 | case 1: 71 | _a.sent(); 72 | return [2 /*return*/]; 73 | } 74 | }); 75 | }); 76 | }; 77 | run(code); 78 | //# sourceMappingURL=compile.node.js.map -------------------------------------------------------------------------------- /dist/src/compile.node.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"compile.node.js","sourceRoot":"","sources":["../../src/compile.node.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2BAA6B;AAC7B,uBAAyB;AACzB,iCAAmC;AACnC,2BAA6B;AAE7B,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AAE/C,yCAEqB;AACrB,iCAA4B;AAE5B,iIAAiI;AACjI,2IAA2I;AAC3I,IAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACnC,IAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAC3C,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;AAE1D,IAAM,GAAG,GAAG,UAAe,IAAY;;;;;;oBAC7B,WAAW,GAAG,0BAAc,CAAC,IAAI,CAAC,CAAC;oBAEnC,IAAI,GAAG,OAAO,CAAC,eAAK,CAAC,gBAAgB,GAAG,GAAG,GAAG,WAAW,GAAG,oBAAoB,CAAC,CAAC;oBAClF,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;oBAEjC,GAAG,GAAG;wBACR,OAAO,EAAE,WAAW;wBACpB,QAAQ,UAAA;qBACX,CAAC;oBAEF,mCAAmC;oBACnC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,eAAK,CAAC,gBAAgB,CAAC,CAAC;oBAE5C,qBAAM,SAAS,CACX,IAAI,CAAC,IAAI,CAAC,eAAK,CAAC,gBAAgB,EAAE,QAAQ,CAAC,EAC3C,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAC/B,EAAA;;oBAHD,SAGC,CAAC;;;;;CACL,CAAC;AAEF,GAAG,CAAC,IAAI,CAAC,CAAC"} -------------------------------------------------------------------------------- /dist/src/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [op[0] & 2, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | Object.defineProperty(exports, "__esModule", { value: true }); 38 | var path = require("path"); 39 | var util = require("util"); 40 | var fs = require("fs"); 41 | var shelljs = require("shelljs"); 42 | var writeFile = util.promisify(fs.writeFile); 43 | var read_code_1 = require("./read-code"); 44 | var read_code_2 = require("./read-code"); 45 | var read_code_3 = require("./read-code"); 46 | var caching = require("./caching"); 47 | var compile_1 = require("./compile"); 48 | var output_files_1 = require("./output-files"); 49 | var solc_install_1 = require("./solc-install"); 50 | /** 51 | * generates the output 52 | * or retrieves it from cache 53 | */ 54 | function generateOutput(source) { 55 | return __awaiter(this, void 0, void 0, function () { 56 | var isCached, artifact, compiled, artifact, _a; 57 | return __generator(this, function (_b) { 58 | switch (_b.label) { 59 | case 0: return [4 /*yield*/, caching.has(source.codeHash)]; 60 | case 1: 61 | isCached = _b.sent(); 62 | if (!isCached) return [3 /*break*/, 3]; 63 | return [4 /*yield*/, caching.get(source.codeHash)]; 64 | case 2: 65 | artifact = _b.sent(); 66 | return [2 /*return*/, artifact]; 67 | case 3: return [4 /*yield*/, solc_install_1.installVersion(source.solcVersion)]; 68 | case 4: 69 | _b.sent(); 70 | return [4 /*yield*/, compile_1.default(source)]; 71 | case 5: 72 | compiled = _b.sent(); 73 | _a = { 74 | compiled: compiled 75 | }; 76 | return [4 /*yield*/, output_files_1.createJavascriptFile(source, compiled)]; 77 | case 6: 78 | _a.javascript = _b.sent(); 79 | return [4 /*yield*/, output_files_1.createTypescriptFile(source, compiled)]; 80 | case 7: 81 | artifact = (_a.typescript = _b.sent(), 82 | _a); 83 | return [4 /*yield*/, caching.set(source.codeHash, artifact)]; 84 | case 8: 85 | _b.sent(); 86 | return [2 /*return*/, artifact]; 87 | } 88 | }); 89 | }); 90 | } 91 | exports.generateOutput = generateOutput; 92 | /** 93 | * compiles the code 94 | * use this if you dont want to generate files, 95 | * but only get the compiled output 96 | */ 97 | function compileCode(code) { 98 | return __awaiter(this, void 0, void 0, function () { 99 | var pseudoSource, artifact; 100 | return __generator(this, function (_a) { 101 | switch (_a.label) { 102 | case 0: 103 | pseudoSource = { 104 | filename: 'programatically', 105 | code: code, 106 | codeHash: read_code_1.hashCode(code), 107 | solcVersion: read_code_3.getSolcVersion(code) 108 | }; 109 | return [4 /*yield*/, generateOutput(pseudoSource)]; 110 | case 1: 111 | artifact = _a.sent(); 112 | return [2 /*return*/, artifact.compiled]; 113 | } 114 | }); 115 | }); 116 | } 117 | exports.compileCode = compileCode; 118 | function compileFile(fileName) { 119 | return __awaiter(this, void 0, void 0, function () { 120 | var source, artifact; 121 | return __generator(this, function (_a) { 122 | switch (_a.label) { 123 | case 0: return [4 /*yield*/, read_code_1.readCodeFile(fileName)]; 124 | case 1: 125 | source = _a.sent(); 126 | return [4 /*yield*/, generateOutput(source)]; 127 | case 2: 128 | artifact = _a.sent(); 129 | return [2 /*return*/, artifact.compiled]; 130 | } 131 | }); 132 | }); 133 | } 134 | exports.compileFile = compileFile; 135 | function runCli(options) { 136 | return __awaiter(this, void 0, void 0, function () { 137 | var codeFiles, artifacts; 138 | var _this = this; 139 | return __generator(this, function (_a) { 140 | switch (_a.label) { 141 | case 0: return [4 /*yield*/, read_code_2.default(options)]; 142 | case 1: 143 | codeFiles = _a.sent(); 144 | return [4 /*yield*/, Promise.all(codeFiles.map(function (source) { return __awaiter(_this, void 0, void 0, function () { 145 | var artifact, outPath, fileNameFull; 146 | return __generator(this, function (_a) { 147 | switch (_a.label) { 148 | case 0: return [4 /*yield*/, generateOutput(source)]; 149 | case 1: 150 | artifact = _a.sent(); 151 | outPath = output_files_1.outputPath(options, source); 152 | fileNameFull = outPath.split('\/').pop(); 153 | return [2 /*return*/, { 154 | source: source, 155 | artifact: artifact, 156 | destinationFolder: path.join(outPath, '../'), 157 | fileName: fileNameFull.split('.').shift() 158 | }]; 159 | } 160 | }); 161 | }); }))]; 162 | case 2: 163 | artifacts = _a.sent(); 164 | // create destination if not exists 165 | if (options.destinationFolder) { 166 | shelljs.mkdir('-p', options.destinationFolder); 167 | } 168 | // write to files 169 | return [4 /*yield*/, Promise.all(artifacts.map(function (output) { return __awaiter(_this, void 0, void 0, function () { 170 | return __generator(this, function (_a) { 171 | switch (_a.label) { 172 | case 0: return [4 /*yield*/, writeFile(path.join(output.destinationFolder, output.fileName + '.js'), output.artifact.javascript)]; 173 | case 1: 174 | _a.sent(); 175 | return [4 /*yield*/, writeFile(path.join(output.destinationFolder, output.fileName + '.ts'), output.artifact.typescript)]; 176 | case 2: 177 | _a.sent(); 178 | return [2 /*return*/]; 179 | } 180 | }); 181 | }); }))]; 182 | case 3: 183 | // write to files 184 | _a.sent(); 185 | return [2 /*return*/]; 186 | } 187 | }); 188 | }); 189 | } 190 | exports.runCli = runCli; 191 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/src/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/src/options.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=options.js.map -------------------------------------------------------------------------------- /dist/src/options.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/src/output-files/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /** 3 | * generates the output-files from the 4 | * compiled data 5 | */ 6 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 7 | return new (P || (P = Promise))(function (resolve, reject) { 8 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 9 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 10 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 11 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 12 | }); 13 | }; 14 | var __generator = (this && this.__generator) || function (thisArg, body) { 15 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 16 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 17 | function verb(n) { return function (v) { return step([n, v]); }; } 18 | function step(op) { 19 | if (f) throw new TypeError("Generator is already executing."); 20 | while (_) try { 21 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 22 | if (y = 0, t) op = [op[0] & 2, t.value]; 23 | switch (op[0]) { 24 | case 0: case 1: t = op; break; 25 | case 4: _.label++; return { value: op[1], done: false }; 26 | case 5: _.label++; y = op[1]; op = [0]; continue; 27 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 28 | default: 29 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 30 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 31 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 32 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 33 | if (t[2]) _.ops.pop(); 34 | _.trys.pop(); continue; 35 | } 36 | op = body.call(thisArg, _); 37 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 38 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 39 | } 40 | }; 41 | Object.defineProperty(exports, "__esModule", { value: true }); 42 | var fs = require("fs"); 43 | var util = require("util"); 44 | var path = require("path"); 45 | var readFile = util.promisify(fs.readFile); 46 | var paths_1 = require("../paths"); 47 | var javascriptTemplatePromise = null; 48 | function createJavascriptFile(source, compiled) { 49 | return __awaiter(this, void 0, void 0, function () { 50 | var template; 51 | return __generator(this, function (_a) { 52 | switch (_a.label) { 53 | case 0: 54 | if (!javascriptTemplatePromise) { 55 | javascriptTemplatePromise = readFile(path.join(paths_1.default.base, './src/output-files/javascript.template.js'), 'utf-8'); 56 | } 57 | return [4 /*yield*/, javascriptTemplatePromise]; 58 | case 1: 59 | template = _a.sent(); 60 | template = template.replace('', source.codeHash); 61 | template = template.replace('', JSON.stringify(compiled, null, 2)); 62 | return [2 /*return*/, template]; 63 | } 64 | }); 65 | }); 66 | } 67 | exports.createJavascriptFile = createJavascriptFile; 68 | function createTypescriptFile(source, compiled) { 69 | return __awaiter(this, void 0, void 0, function () { 70 | var template; 71 | return __generator(this, function (_a) { 72 | template = "/* tslint:disable */\n/**\n * generated via solidity-cli\n * @link https://www.npmjs.com/package/solidity-cli\n * do not edit this file manually\n * source-code-hash: " + source.codeHash + "\n */\nimport {\n SolcCompiledContract,\n SolcCompiledFile\n} from 'solidity-cli';\n\ndeclare type CompiledType = {\n " + Object.keys(compiled).map(function (k) { return "'" + k + "': SolcCompiledContract;"; }) + "\n};\nconst compiled: CompiledType = " + JSON.stringify(compiled, null, 2) + ";\nexport default compiled;\n"; 73 | return [2 /*return*/, template]; 74 | }); 75 | }); 76 | } 77 | exports.createTypescriptFile = createTypescriptFile; 78 | /** 79 | * determines where the output should be written 80 | */ 81 | function outputPath(options, source) { 82 | var DEBUG = false; 83 | if (DEBUG) 84 | console.log('sourceFolder: ' + options.sourceFolder); 85 | var globBase = options.sourceFolder.replace(/\*.*/, ''); 86 | if (globBase.endsWith('.sol')) // single file 87 | globBase = path.join(globBase, '../'); 88 | if (DEBUG) 89 | console.log('globBase: ' + globBase); 90 | var optDestination = options.destinationFolder ? options.destinationFolder : globBase; 91 | if (DEBUG) 92 | console.log('optDestination: ' + optDestination); 93 | var destinationFolder = path.join(globBase, optDestination); 94 | if (optDestination === globBase) 95 | destinationFolder = globBase; 96 | if (DEBUG) 97 | console.log('destinationFolder: ' + destinationFolder); 98 | // destination-folder is absolut 99 | if (options.destinationFolder && options.destinationFolder.startsWith('/')) 100 | destinationFolder = path.join(options.destinationFolder, './'); 101 | var fileNameRelative = source.filename.replace(globBase, ''); 102 | if (DEBUG) 103 | console.log('fileNameRelative: ' + fileNameRelative); 104 | var goalPath = path.join(destinationFolder, fileNameRelative); 105 | return goalPath; 106 | } 107 | exports.outputPath = outputPath; 108 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/src/output-files/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/output-files/index.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/src/paths.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var path = require("path"); 4 | var version_1 = require("./version"); 5 | var paths = { 6 | base: path.resolve(__dirname, '../../'), 7 | solidityInstalls: path.resolve(__dirname, '../../', 'solc-installs', version_1.default), 8 | compileCache: path.resolve(__dirname, '../../', 'compile-cache', version_1.default), 9 | compileTmpFolder: path.resolve(__dirname, '../../', 'compile-tmp'), 10 | contractsFolder: path.resolve(__dirname, '../../', './test/contracts/'), 11 | }; 12 | exports.default = paths; 13 | //# sourceMappingURL=paths.js.map -------------------------------------------------------------------------------- /dist/src/paths.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/paths.ts"],"names":[],"mappings":";;AAAA,2BAA6B;AAE7B,qCAAgC;AAEhC,IAAM,KAAK,GAAG;IACV,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;IACvC,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,iBAAO,CAAC;IAC7E,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,iBAAO,CAAC;IACzE,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC;IAClE,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,mBAAmB,CAAC;CAC1E,CAAC;AAEF,kBAAe,KAAK,CAAC"} -------------------------------------------------------------------------------- /dist/src/read-code.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /** 3 | * reads all solidity-files defined in the options 4 | */ 5 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 6 | return new (P || (P = Promise))(function (resolve, reject) { 7 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 8 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 9 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 10 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 11 | }); 12 | }; 13 | var __generator = (this && this.__generator) || function (thisArg, body) { 14 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 15 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 16 | function verb(n) { return function (v) { return step([n, v]); }; } 17 | function step(op) { 18 | if (f) throw new TypeError("Generator is already executing."); 19 | while (_) try { 20 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 21 | if (y = 0, t) op = [op[0] & 2, t.value]; 22 | switch (op[0]) { 23 | case 0: case 1: t = op; break; 24 | case 4: _.label++; return { value: op[1], done: false }; 25 | case 5: _.label++; y = op[1]; op = [0]; continue; 26 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 27 | default: 28 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 29 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 30 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 31 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 32 | if (t[2]) _.ops.pop(); 33 | _.trys.pop(); continue; 34 | } 35 | op = body.call(thisArg, _); 36 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 37 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 38 | } 39 | }; 40 | Object.defineProperty(exports, "__esModule", { value: true }); 41 | var util = require("util"); 42 | var fs = require("fs"); 43 | var path = require("path"); 44 | var glob = require("glob"); 45 | var js_sha3_1 = require("js-sha3"); 46 | var globPromise = util.promisify(glob); 47 | var readFile = util.promisify(fs.readFile); 48 | /** 49 | * https://stackoverflow.com/a/432503 50 | */ 51 | function matches(regex, str) { 52 | var ret = []; 53 | var match = regex.exec(str); 54 | while (match !== null) { 55 | ret.push({ 56 | full: match[0], 57 | inner: match[1] 58 | }); 59 | match = regex.exec(str); 60 | } 61 | return ret; 62 | } 63 | /** 64 | * gets the source-code from the file 65 | * and parses all imports 66 | */ 67 | function getSourceCode(fileName) { 68 | return __awaiter(this, void 0, void 0, function () { 69 | var code, codeCommentsRegex, importsRegex, imports; 70 | var _this = this; 71 | return __generator(this, function (_a) { 72 | switch (_a.label) { 73 | case 0: return [4 /*yield*/, readFile(fileName, 'utf-8')]; 74 | case 1: 75 | code = _a.sent(); 76 | codeCommentsRegex = /(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(\/\/.*)/g; 77 | code = code.replace(codeCommentsRegex, ''); 78 | importsRegex = /import "([^"]*)";/g; 79 | imports = matches(importsRegex, code); 80 | return [4 /*yield*/, Promise.all(imports.map(function (match) { return __awaiter(_this, void 0, void 0, function () { 81 | var p, innerCode; 82 | return __generator(this, function (_a) { 83 | switch (_a.label) { 84 | case 0: 85 | p = path.resolve(fileName, '..', match.inner); 86 | return [4 /*yield*/, getSourceCode(p)]; 87 | case 1: 88 | innerCode = _a.sent(); 89 | // remove first line containing version 90 | innerCode = innerCode.replace(/^.*\n/, ''); 91 | code = code.replace(match.full, innerCode); 92 | return [2 /*return*/]; 93 | } 94 | }); 95 | }); }))]; 96 | case 2: 97 | _a.sent(); 98 | return [2 /*return*/, code]; 99 | } 100 | }); 101 | }); 102 | } 103 | exports.getSourceCode = getSourceCode; 104 | function getSolcVersion(code) { 105 | var regex = /^pragma solidity [\^\~]?([0-9\.]*);/g; 106 | var match = regex.exec(code); 107 | if (!match) 108 | throw new Error('no pragma solidity version set'); 109 | return match[1]; 110 | } 111 | exports.getSolcVersion = getSolcVersion; 112 | function hashCode(code) { 113 | return js_sha3_1.sha3_256(code); 114 | } 115 | exports.hashCode = hashCode; 116 | function readCodeFile(fileName) { 117 | return __awaiter(this, void 0, void 0, function () { 118 | var code, ret; 119 | return __generator(this, function (_a) { 120 | switch (_a.label) { 121 | case 0: return [4 /*yield*/, getSourceCode(fileName)]; 122 | case 1: 123 | code = _a.sent(); 124 | ret = { 125 | filename: fileName, 126 | code: code, 127 | codeHash: hashCode(code), 128 | solcVersion: getSolcVersion(code) 129 | }; 130 | return [2 /*return*/, ret]; 131 | } 132 | }); 133 | }); 134 | } 135 | exports.readCodeFile = readCodeFile; 136 | function readCodeFiles(options) { 137 | return __awaiter(this, void 0, void 0, function () { 138 | var filePaths, ret; 139 | return __generator(this, function (_a) { 140 | switch (_a.label) { 141 | case 0: return [4 /*yield*/, globPromise(options.sourceFolder, {})]; 142 | case 1: 143 | filePaths = _a.sent(); 144 | return [4 /*yield*/, Promise.all(filePaths.map(function (file) { return readCodeFile(file); }))]; 145 | case 2: 146 | ret = _a.sent(); 147 | return [2 /*return*/, ret]; 148 | } 149 | }); 150 | }); 151 | } 152 | exports.default = readCodeFiles; 153 | //# sourceMappingURL=read-code.js.map -------------------------------------------------------------------------------- /dist/src/read-code.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"read-code.js","sourceRoot":"","sources":["../../src/read-code.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/src/solc-install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [op[0] & 2, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | Object.defineProperty(exports, "__esModule", { value: true }); 38 | /** 39 | * ensures the required solc-versions are installed 40 | * I tried to use 'npmi' but it always shows output in the console 41 | * So we use a custom shelljs 42 | */ 43 | var util = require("util"); 44 | var directoryExists = require('directory-exists'); 45 | var rimraf = require("rimraf"); 46 | var shelljs_1 = require("shelljs"); 47 | var paths_1 = require("./paths"); 48 | var removeFolder = util.promisify(rimraf); 49 | var INSTALL_VERSIONS_CACHE = {}; 50 | /** 51 | * install the given version into the ./solidity-version - folder 52 | * returns false if already exists 53 | */ 54 | function installVersion(version) { 55 | return __awaiter(this, void 0, void 0, function () { 56 | return __generator(this, function (_a) { 57 | switch (_a.label) { 58 | case 0: 59 | if (!INSTALL_VERSIONS_CACHE[version]) return [3 /*break*/, 2]; 60 | return [4 /*yield*/, INSTALL_VERSIONS_CACHE[version]]; 61 | case 1: 62 | _a.sent(); 63 | return [2 /*return*/, false]; 64 | case 2: 65 | INSTALL_VERSIONS_CACHE[version] = _installVersion(version); 66 | return [4 /*yield*/, INSTALL_VERSIONS_CACHE[version]]; 67 | case 3: 68 | _a.sent(); 69 | return [2 /*return*/, true]; 70 | } 71 | }); 72 | }); 73 | } 74 | exports.installVersion = installVersion; 75 | function _installVersion(version) { 76 | return __awaiter(this, void 0, void 0, function () { 77 | var installPath, exists, err_1; 78 | return __generator(this, function (_a) { 79 | switch (_a.label) { 80 | case 0: 81 | installPath = paths_1.default.solidityInstalls + '/' + version; 82 | return [4 /*yield*/, directoryExists(installPath + '/')]; 83 | case 1: 84 | exists = _a.sent(); 85 | if (exists) 86 | return [2 /*return*/, false]; 87 | _a.label = 2; 88 | case 2: 89 | _a.trys.push([2, 4, , 6]); 90 | // console.log('# installing solc@' + version); 91 | return [4 /*yield*/, new Promise(function (res, rej) { 92 | var shell = 'npm install solc@' + version + ' --prefix ' + installPath + ' --depth 0 --silent --audit false'; 93 | shelljs_1.exec(shell, function (code, stdout, stderr) { 94 | if (code === 0) 95 | res(); 96 | else 97 | rej(new Error(stderr)); 98 | }); 99 | })]; 100 | case 3: 101 | // console.log('# installing solc@' + version); 102 | _a.sent(); 103 | return [3 /*break*/, 6]; 104 | case 4: 105 | err_1 = _a.sent(); 106 | // remove folder 107 | return [4 /*yield*/, removeFolder(installPath)]; 108 | case 5: 109 | // remove folder 110 | _a.sent(); 111 | throw err_1; 112 | case 6: return [2 /*return*/, true]; 113 | } 114 | }); 115 | }); 116 | } 117 | function solcInstall(versions) { 118 | return __awaiter(this, void 0, void 0, function () { 119 | var _this = this; 120 | return __generator(this, function (_a) { 121 | switch (_a.label) { 122 | case 0: return [4 /*yield*/, Promise.all(versions 123 | .filter(function (elem, pos, arr) { return arr.indexOf(elem) === pos; }) // unique 124 | .map(function (version) { return __awaiter(_this, void 0, void 0, function () { 125 | return __generator(this, function (_a) { 126 | switch (_a.label) { 127 | case 0: return [4 /*yield*/, installVersion(version)]; 128 | case 1: 129 | _a.sent(); 130 | return [2 /*return*/]; 131 | } 132 | }); 133 | }); }))]; 134 | case 1: 135 | _a.sent(); 136 | return [2 /*return*/]; 137 | } 138 | }); 139 | }); 140 | } 141 | exports.default = solcInstall; 142 | //# sourceMappingURL=solc-install.js.map -------------------------------------------------------------------------------- /dist/src/solc-install.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"solc-install.js","sourceRoot":"","sources":["../../src/solc-install.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,2BAA6B;AAC7B,IAAM,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEpD,+BAAiC;AACjC,mCAEiB;AAEjB,iCAA4B;AAE5B,IAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAE5C,IAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC;;;GAGG;AACH,SAAsB,cAAc,CAAC,OAAe;;;;;yBAC5C,sBAAsB,CAAC,OAAO,CAAC,EAA/B,wBAA+B;oBAC/B,qBAAM,sBAAsB,CAAC,OAAO,CAAC,EAAA;;oBAArC,SAAqC,CAAC;oBACtC,sBAAO,KAAK,EAAC;;oBAEb,sBAAsB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;oBAC3D,qBAAM,sBAAsB,CAAC,OAAO,CAAC,EAAA;;oBAArC,SAAqC,CAAC;oBACtC,sBAAO,IAAI,EAAC;;;;CAEnB;AATD,wCASC;AAED,SAAe,eAAe,CAAC,OAAe;;;;;;oBACpC,WAAW,GAAG,eAAK,CAAC,gBAAgB,GAAG,GAAG,GAAG,OAAO,CAAC;oBAG5C,qBAAM,eAAe,CAAC,WAAW,GAAG,GAAG,CAAC,EAAA;;oBAAjD,MAAM,GAAG,SAAwC;oBACvD,IAAI,MAAM;wBAAE,sBAAO,KAAK,EAAC;;;;oBAIrB,+CAA+C;oBAC/C,qBAAM,IAAI,OAAO,CAAC,UAAC,GAAG,EAAE,GAAG;4BACvB,IAAM,KAAK,GAAG,mBAAmB,GAAG,OAAO,GAAG,YAAY,GAAG,WAAW,GAAG,mCAAmC,CAAC;4BAC/G,cAAI,CAAC,KAAK,EAAE,UAAS,IAAI,EAAE,MAAc,EAAE,MAAc;gCACrD,IAAI,IAAI,KAAK,CAAC;oCAAE,GAAG,EAAE,CAAC;;oCACjB,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;4BAChC,CAAC,CAAC,CAAC;wBACP,CAAC,CAAC,EAAA;;oBAPF,+CAA+C;oBAC/C,SAME,CAAC;;;;oBAEH,gBAAgB;oBAChB,qBAAM,YAAY,CAAC,WAAW,CAAC,EAAA;;oBAD/B,gBAAgB;oBAChB,SAA+B,CAAC;oBAChC,MAAM,KAAG,CAAC;wBAGd,sBAAO,IAAI,EAAC;;;;CACf;AAED,SAA8B,WAAW,CAAC,QAAkB;;;;;wBACxD,qBAAM,OAAO,CAAC,GAAG,CACb,QAAQ;yBACH,MAAM,CAAC,UAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAK,OAAA,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,EAAzB,CAAyB,CAAC,CAAC,SAAS;yBAC/D,GAAG,CAAC,UAAO,OAAO;;;wCACf,qBAAM,cAAc,CAAC,OAAO,CAAC,EAAA;;oCAA7B,SAA6B,CAAC;;;;yBACjC,CAAC,CACT,EAAA;;oBAND,SAMC,CAAC;;;;;CACL;AARD,8BAQC"} -------------------------------------------------------------------------------- /dist/src/version.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var packageJson = require("../../package.json"); 4 | var version = packageJson['version']; 5 | exports.default = version; 6 | //# sourceMappingURL=version.js.map -------------------------------------------------------------------------------- /dist/src/version.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;AAAA,gDAAkD;AAElD,IAAM,OAAO,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;AACvC,kBAAe,OAAO,CAAC"} -------------------------------------------------------------------------------- /dist/test/index.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("./unit/paths.test"); 4 | require("./unit/read-code.test"); 5 | require("./unit/solc-install.test"); 6 | require("./unit/compile.test"); 7 | require("./unit/output-files.test"); 8 | require("./unit/caching.test"); 9 | require("./unit/issues.test"); 10 | //# sourceMappingURL=index.test.js.map -------------------------------------------------------------------------------- /dist/test/index.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../test/index.test.ts"],"names":[],"mappings":";;AAAA,6BAA2B;AAC3B,iCAA+B;AAC/B,oCAAkC;AAClC,+BAA6B;AAC7B,oCAAkC;AAClC,+BAA6B;AAC7B,8BAA4B"} -------------------------------------------------------------------------------- /dist/test/integration.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var _this = this; 39 | Object.defineProperty(exports, "__esModule", { value: true }); 40 | var assert = require("assert"); 41 | var async_test_util_1 = require("async-test-util"); 42 | var path = require("path"); 43 | var fs = require("fs"); 44 | var paths_1 = require("../src/paths"); 45 | var read_code_1 = require("../src/read-code"); 46 | var SolidityCli = require("../src/index"); 47 | describe('integration.test.js', function () { 48 | it('.generateOutput()', function () { return __awaiter(_this, void 0, void 0, function () { 49 | var source, artifact; 50 | return __generator(this, function (_a) { 51 | switch (_a.label) { 52 | case 0: return [4 /*yield*/, read_code_1.readCodeFile(paths_1.default.contractsFolder + '/Basic.sol')]; 53 | case 1: 54 | source = _a.sent(); 55 | return [4 /*yield*/, SolidityCli.generateOutput(source)]; 56 | case 2: 57 | artifact = _a.sent(); 58 | assert.ok(artifact); 59 | return [2 /*return*/]; 60 | } 61 | }); 62 | }); }); 63 | it('.compileCode()', function () { return __awaiter(_this, void 0, void 0, function () { 64 | var source, compiled; 65 | return __generator(this, function (_a) { 66 | switch (_a.label) { 67 | case 0: return [4 /*yield*/, read_code_1.readCodeFile(paths_1.default.contractsFolder + '/Basic.sol')]; 68 | case 1: 69 | source = _a.sent(); 70 | return [4 /*yield*/, SolidityCli.compileCode(source.code)]; 71 | case 2: 72 | compiled = _a.sent(); 73 | assert.ok(compiled); 74 | return [2 /*return*/]; 75 | } 76 | }); 77 | }); }); 78 | it('.compileFile()', function () { return __awaiter(_this, void 0, void 0, function () { 79 | var compiled; 80 | return __generator(this, function (_a) { 81 | switch (_a.label) { 82 | case 0: return [4 /*yield*/, SolidityCli.compileFile(paths_1.default.contractsFolder + '/Basic.sol')]; 83 | case 1: 84 | compiled = _a.sent(); 85 | assert.ok(compiled); 86 | return [2 /*return*/]; 87 | } 88 | }); 89 | }); }); 90 | it('.runCli()', function () { 91 | return __awaiter(this, void 0, void 0, function () { 92 | var rand, destinationFolder; 93 | return __generator(this, function (_a) { 94 | switch (_a.label) { 95 | case 0: 96 | this.timeout(1000 * 30); 97 | rand = async_test_util_1.default.randomString(10); 98 | destinationFolder = path.join(paths_1.default.base, './tmp', rand); 99 | return [4 /*yield*/, SolidityCli.runCli({ 100 | sourceFolder: paths_1.default.contractsFolder + '/subdir/*.sol', 101 | destinationFolder: destinationFolder 102 | })]; 103 | case 1: 104 | _a.sent(); 105 | assert.ok(fs.existsSync(destinationFolder + '/Basic.js')); 106 | assert.ok(fs.existsSync(destinationFolder + '/Basic.ts')); 107 | assert.ok(fs.existsSync(destinationFolder + '/Import.js')); 108 | assert.ok(fs.existsSync(destinationFolder + '/Import.ts')); 109 | return [2 /*return*/]; 110 | } 111 | }); 112 | }); 113 | }); 114 | }); 115 | //# sourceMappingURL=integration.test.js.map -------------------------------------------------------------------------------- /dist/test/integration.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"integration.test.js","sourceRoot":"","sources":["../../test/integration.test.ts"],"names":[],"mappings":";AAAA,gEAAgE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhE,iBA0CA;;AA1CA,+BAAiC;AACjC,mDAA4C;AAC5C,2BAA6B;AAC7B,uBAAyB;AAEzB,sCAAiC;AACjC,8CAE0B;AAE1B,0CAA4C;AAE5C,QAAQ,CAAC,qBAAqB,EAAE;IAC5B,EAAE,CAAC,mBAAmB,EAAE;;;;wBACL,qBAAM,wBAAY,CAAC,eAAK,CAAC,eAAe,GAAG,YAAY,CAAC,EAAA;;oBAAjE,MAAM,GAAG,SAAwD;oBACtD,qBAAM,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,EAAA;;oBAAnD,QAAQ,GAAG,SAAwC;oBACzD,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;;;;SACvB,CAAC,CAAC;IACH,EAAE,CAAC,gBAAgB,EAAE;;;;wBACF,qBAAM,wBAAY,CAAC,eAAK,CAAC,eAAe,GAAG,YAAY,CAAC,EAAA;;oBAAjE,MAAM,GAAG,SAAwD;oBACtD,qBAAM,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAA;;oBAArD,QAAQ,GAAG,SAA0C;oBAC3D,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;;;;SACvB,CAAC,CAAC;IACH,EAAE,CAAC,gBAAgB,EAAE;;;;wBACA,qBAAM,WAAW,CAAC,WAAW,CAAC,eAAK,CAAC,eAAe,GAAG,YAAY,CAAC,EAAA;;oBAA9E,QAAQ,GAAG,SAAmE;oBACpF,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;;;;SACvB,CAAC,CAAC;IACH,EAAE,CAAC,WAAW,EAAE;;;;;;wBACZ,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;wBAClB,IAAI,GAAG,yBAAa,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;wBACtC,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;wBAC/D,qBAAM,WAAW,CAAC,MAAM,CAAC;gCACrB,YAAY,EAAE,eAAK,CAAC,eAAe,GAAG,eAAe;gCACrD,iBAAiB,mBAAA;6BACpB,CAAC,EAAA;;wBAHF,SAGE,CAAC;wBAEH,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,GAAG,WAAW,CAAC,CAAC,CAAC;wBAC1D,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,GAAG,WAAW,CAAC,CAAC,CAAC;wBAC1D,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,GAAG,YAAY,CAAC,CAAC,CAAC;wBAC3D,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,GAAG,YAAY,CAAC,CAAC,CAAC;;;;;KAC9D,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /dist/test/unit/cache.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [op[0] & 2, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | Object.defineProperty(exports, "__esModule", { value: true }); 38 | /** 39 | * caches some compiled code 40 | * so we do not have to recompile all time in tests 41 | */ 42 | var compile_1 = require("../../src/compile"); 43 | var read_code_1 = require("../../src/read-code"); 44 | var paths_1 = require("../../src/paths"); 45 | var clone = require("clone"); 46 | var basicCompiledPromise = null; 47 | function basicCompiled() { 48 | return __awaiter(this, void 0, void 0, function () { 49 | var value; 50 | var _this = this; 51 | return __generator(this, function (_a) { 52 | switch (_a.label) { 53 | case 0: 54 | if (!basicCompiledPromise) { 55 | basicCompiledPromise = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () { 56 | var files, compiled; 57 | return __generator(this, function (_a) { 58 | switch (_a.label) { 59 | case 0: return [4 /*yield*/, read_code_1.default({ 60 | sourceFolder: paths_1.default.contractsFolder + '/Basic.sol' 61 | })]; 62 | case 1: 63 | files = _a.sent(); 64 | return [4 /*yield*/, compile_1.default(files[0])]; 65 | case 2: 66 | compiled = _a.sent(); 67 | res({ 68 | source: files[0], 69 | compiled: compiled 70 | }); 71 | return [2 /*return*/]; 72 | } 73 | }); 74 | }); }); 75 | } 76 | return [4 /*yield*/, basicCompiledPromise]; 77 | case 1: 78 | value = _a.sent(); 79 | return [2 /*return*/, clone(value)]; 80 | } 81 | }); 82 | }); 83 | } 84 | exports.basicCompiled = basicCompiled; 85 | //# sourceMappingURL=cache.js.map -------------------------------------------------------------------------------- /dist/test/unit/cache.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../test/unit/cache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,6CAAwC;AACxC,iDAAgD;AAChD,yCAAoC;AACpC,6BAA+B;AAS/B,IAAI,oBAAoB,GAAQ,IAAI,CAAC;AACrC,SAAsB,aAAa;;;;;;;oBAI/B,IAAI,CAAC,oBAAoB,EAAE;wBACvB,oBAAoB,GAAG,IAAI,OAAO,CAAC,UAAO,GAAG;;;;4CAC3B,qBAAM,mBAAa,CAAC;4CAC9B,YAAY,EAAE,eAAK,CAAC,eAAe,GAAG,YAAY;yCACrD,CAAC,EAAA;;wCAFI,KAAK,GAAG,SAEZ;wCACe,qBAAM,iBAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAA;;wCAAlC,QAAQ,GAAG,SAAuB;wCACxC,GAAG,CAAC;4CACA,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;4CAChB,QAAQ,UAAA;yCACX,CAAC,CAAC;;;;6BACN,CAAC,CAAC;qBACN;oBAEa,qBAAM,oBAAoB,EAAA;;oBAAlC,KAAK,GAAG,SAA0B;oBACxC,sBAAO,KAAK,CAAC,KAAK,CAAC,EAAC;;;;CACvB;AAnBD,sCAmBC"} -------------------------------------------------------------------------------- /dist/test/unit/caching.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var _this = this; 39 | Object.defineProperty(exports, "__esModule", { value: true }); 40 | var assert = require("assert"); 41 | var cache_1 = require("./cache"); 42 | var output_files_1 = require("../../src/output-files"); 43 | var caching = require("../../src/caching"); 44 | describe('caching.test.js', function () { 45 | describe('.set()', function () { 46 | it('should write to cache', function () { return __awaiter(_this, void 0, void 0, function () { 47 | var _a, source, compiled, javascript, typescript; 48 | return __generator(this, function (_b) { 49 | switch (_b.label) { 50 | case 0: return [4 /*yield*/, cache_1.basicCompiled()]; 51 | case 1: 52 | _a = _b.sent(), source = _a.source, compiled = _a.compiled; 53 | return [4 /*yield*/, output_files_1.createJavascriptFile(source, compiled)]; 54 | case 2: 55 | javascript = _b.sent(); 56 | return [4 /*yield*/, output_files_1.createTypescriptFile(source, compiled)]; 57 | case 3: 58 | typescript = _b.sent(); 59 | return [4 /*yield*/, caching.set(source.codeHash, { 60 | compiled: compiled, 61 | javascript: javascript, 62 | typescript: typescript 63 | })]; 64 | case 4: 65 | _b.sent(); 66 | return [2 /*return*/]; 67 | } 68 | }); 69 | }); }); 70 | }); 71 | describe('.has()', function () { 72 | it('should not have this in cache', function () { return __awaiter(_this, void 0, void 0, function () { 73 | var source, has; 74 | return __generator(this, function (_a) { 75 | switch (_a.label) { 76 | case 0: return [4 /*yield*/, cache_1.basicCompiled()]; 77 | case 1: 78 | source = (_a.sent()).source; 79 | source.codeHash = 'foobar'; 80 | return [4 /*yield*/, caching.has(source.codeHash)]; 81 | case 2: 82 | has = _a.sent(); 83 | assert.equal(has, false); 84 | return [2 /*return*/]; 85 | } 86 | }); 87 | }); }); 88 | it('should have cached the output', function () { return __awaiter(_this, void 0, void 0, function () { 89 | var _a, source, compiled, javascript, typescript, has; 90 | return __generator(this, function (_b) { 91 | switch (_b.label) { 92 | case 0: return [4 /*yield*/, cache_1.basicCompiled()]; 93 | case 1: 94 | _a = _b.sent(), source = _a.source, compiled = _a.compiled; 95 | return [4 /*yield*/, output_files_1.createJavascriptFile(source, compiled)]; 96 | case 2: 97 | javascript = _b.sent(); 98 | return [4 /*yield*/, output_files_1.createTypescriptFile(source, compiled)]; 99 | case 3: 100 | typescript = _b.sent(); 101 | return [4 /*yield*/, caching.set(source.codeHash, { 102 | compiled: compiled, 103 | javascript: javascript, 104 | typescript: typescript 105 | })]; 106 | case 4: 107 | _b.sent(); 108 | return [4 /*yield*/, caching.has(source.codeHash)]; 109 | case 5: 110 | has = _b.sent(); 111 | assert.equal(has, true); 112 | return [2 /*return*/]; 113 | } 114 | }); 115 | }); }); 116 | }); 117 | describe('.get()', function () { 118 | it('should return the cached artifact', function () { return __awaiter(_this, void 0, void 0, function () { 119 | var _a, source, compiled, javascript, typescript, artifact; 120 | return __generator(this, function (_b) { 121 | switch (_b.label) { 122 | case 0: return [4 /*yield*/, cache_1.basicCompiled()]; 123 | case 1: 124 | _a = _b.sent(), source = _a.source, compiled = _a.compiled; 125 | return [4 /*yield*/, output_files_1.createJavascriptFile(source, compiled)]; 126 | case 2: 127 | javascript = _b.sent(); 128 | return [4 /*yield*/, output_files_1.createTypescriptFile(source, compiled)]; 129 | case 3: 130 | typescript = _b.sent(); 131 | return [4 /*yield*/, caching.set(source.codeHash, { 132 | compiled: compiled, 133 | javascript: javascript, 134 | typescript: typescript 135 | })]; 136 | case 4: 137 | _b.sent(); 138 | return [4 /*yield*/, caching.get(source.codeHash)]; 139 | case 5: 140 | artifact = _b.sent(); 141 | assert.deepEqual(artifact, { 142 | compiled: compiled, 143 | javascript: javascript, 144 | typescript: typescript 145 | }); 146 | return [2 /*return*/]; 147 | } 148 | }); 149 | }); }); 150 | }); 151 | }); 152 | //# sourceMappingURL=caching.test.js.map -------------------------------------------------------------------------------- /dist/test/unit/caching.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"caching.test.js","sourceRoot":"","sources":["../../../test/unit/caching.test.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /dist/test/unit/compile.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | Object.defineProperty(exports, "__esModule", { value: true }); 39 | var assert = require("assert"); 40 | var async_test_util_1 = require("async-test-util"); 41 | var paths_1 = require("../../src/paths"); 42 | var compile_1 = require("../../src/compile"); 43 | var read_code_1 = require("../../src/read-code"); 44 | describe('compile.test.js', function () { 45 | it('should compile the code', function () { 46 | return __awaiter(this, void 0, void 0, function () { 47 | var files, compiled; 48 | return __generator(this, function (_a) { 49 | switch (_a.label) { 50 | case 0: 51 | this.timeout(1000 * 50); 52 | return [4 /*yield*/, read_code_1.default({ 53 | sourceFolder: paths_1.default.contractsFolder + '/Basic.sol' 54 | })]; 55 | case 1: 56 | files = _a.sent(); 57 | return [4 /*yield*/, compile_1.default(files[0])]; 58 | case 2: 59 | compiled = _a.sent(); 60 | assert.equal(typeof compiled[':Basic'].interface, 'string'); 61 | return [2 /*return*/]; 62 | } 63 | }); 64 | }); 65 | }); 66 | it('should give a useable error', function () { 67 | return __awaiter(this, void 0, void 0, function () { 68 | var files, error, str; 69 | return __generator(this, function (_a) { 70 | switch (_a.label) { 71 | case 0: 72 | this.timeout(1000 * 50); 73 | return [4 /*yield*/, read_code_1.default({ 74 | sourceFolder: paths_1.default.contractsFolder + '/Broken.sol' 75 | })]; 76 | case 1: 77 | files = _a.sent(); 78 | return [4 /*yield*/, async_test_util_1.default.assertThrows(function () { return compile_1.default(files[0]); })]; 79 | case 2: 80 | error = _a.sent(); 81 | str = error.toString(); 82 | assert.ok(str.includes('Broken')); 83 | assert.ok(str.includes('whoever')); 84 | return [2 /*return*/]; 85 | } 86 | }); 87 | }); 88 | }); 89 | }); 90 | //# sourceMappingURL=compile.test.js.map -------------------------------------------------------------------------------- /dist/test/unit/compile.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"compile.test.js","sourceRoot":"","sources":["../../../test/unit/compile.test.ts"],"names":[],"mappings":";AAAA,mEAAmE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnE,+BAAiC;AACjC,mDAA4C;AAE5C,yCAAoC;AAEpC,6CAAwC;AACxC,iDAAgD;AAEhD,QAAQ,CAAC,iBAAiB,EAAE;IACxB,EAAE,CAAC,yBAAyB,EAAE;;;;;;wBAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;wBACV,qBAAM,mBAAa,CAAC;gCAC9B,YAAY,EAAE,eAAK,CAAC,eAAe,GAAG,YAAY;6BACrD,CAAC,EAAA;;wBAFI,KAAK,GAAG,SAEZ;wBACe,qBAAM,iBAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAA;;wBAAlC,QAAQ,GAAG,SAAuB;wBAExC,MAAM,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;;;;;KAC/D,CAAC,CAAC;IACH,EAAE,CAAC,6BAA6B,EAAE;;;;;;wBAC9B,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;wBACV,qBAAM,mBAAa,CAAC;gCAC9B,YAAY,EAAE,eAAK,CAAC,eAAe,GAAG,aAAa;6BACtD,CAAC,EAAA;;wBAFI,KAAK,GAAG,SAEZ;wBACY,qBAAM,yBAAa,CAAC,YAAY,CAC1C,cAAM,OAAA,iBAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAC1B,EAAA;;wBAFK,KAAK,GAAG,SAEb;wBACK,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;wBAC7B,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;wBAClC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;;;;;KACtC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /dist/test/unit/issues.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | Object.defineProperty(exports, "__esModule", { value: true }); 39 | var assert = require("assert"); 40 | // import AsyncTestUtil from 'async-test-util'; 41 | var paths_1 = require("../../src/paths"); 42 | var compile_1 = require("../../src/compile"); 43 | var read_code_1 = require("../../src/read-code"); 44 | describe('issues.test.js', function () { 45 | it('could not compile complex contract with warnings', function () { 46 | return __awaiter(this, void 0, void 0, function () { 47 | var files, compiled; 48 | return __generator(this, function (_a) { 49 | switch (_a.label) { 50 | case 0: 51 | this.timeout(60 * 1000); 52 | return [4 /*yield*/, read_code_1.default({ 53 | sourceFolder: paths_1.default.contractsFolder + '/DonationBag.sol' 54 | })]; 55 | case 1: 56 | files = _a.sent(); 57 | return [4 /*yield*/, compile_1.default(files[0])]; 58 | case 2: 59 | compiled = _a.sent(); 60 | assert.ok(compiled); 61 | return [2 /*return*/]; 62 | } 63 | }); 64 | }); 65 | }); 66 | }); 67 | //# sourceMappingURL=issues.test.js.map -------------------------------------------------------------------------------- /dist/test/unit/issues.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"issues.test.js","sourceRoot":"","sources":["../../../test/unit/issues.test.ts"],"names":[],"mappings":";AAAA,mEAAmE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnE,+BAAiC;AACjC,+CAA+C;AAE/C,yCAAoC;AAEpC,6CAAwC;AACxC,iDAAgD;AAEhD,QAAQ,CAAC,gBAAgB,EAAE;IACvB,EAAE,CAAC,kDAAkD,EAAE;;;;;;wBACnD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;wBACV,qBAAM,mBAAa,CAAC;gCAC9B,YAAY,EAAE,eAAK,CAAC,eAAe,GAAG,kBAAkB;6BAC3D,CAAC,EAAA;;wBAFI,KAAK,GAAG,SAEZ;wBACe,qBAAM,iBAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAA;;wBAAlC,QAAQ,GAAG,SAAuB;wBACxC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;;;;;KACvB,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /dist/test/unit/output-files.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __generator = (this && this.__generator) || function (thisArg, body) { 12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 14 | function verb(n) { return function (v) { return step([n, v]); }; } 15 | function step(op) { 16 | if (f) throw new TypeError("Generator is already executing."); 17 | while (_) try { 18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 19 | if (y = 0, t) op = [op[0] & 2, t.value]; 20 | switch (op[0]) { 21 | case 0: case 1: t = op; break; 22 | case 4: _.label++; return { value: op[1], done: false }; 23 | case 5: _.label++; y = op[1]; op = [0]; continue; 24 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 25 | default: 26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 30 | if (t[2]) _.ops.pop(); 31 | _.trys.pop(); continue; 32 | } 33 | op = body.call(thisArg, _); 34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 36 | } 37 | }; 38 | var _this = this; 39 | Object.defineProperty(exports, "__esModule", { value: true }); 40 | var assert = require("assert"); 41 | var cache_1 = require("./cache"); 42 | var output_files_1 = require("../../src/output-files"); 43 | describe('output-files.test.js', function () { 44 | describe('.createJavascriptFile()', function () { 45 | it('should fill all placeholders', function () { 46 | return __awaiter(this, void 0, void 0, function () { 47 | var _a, source, compiled, output; 48 | return __generator(this, function (_b) { 49 | switch (_b.label) { 50 | case 0: 51 | this.timeout(1000 * 50); 52 | return [4 /*yield*/, cache_1.basicCompiled()]; 53 | case 1: 54 | _a = _b.sent(), source = _a.source, compiled = _a.compiled; 55 | return [4 /*yield*/, output_files_1.createJavascriptFile(source, compiled)]; 56 | case 2: 57 | output = _b.sent(); 58 | assert.equal(output.includes(' 3 | 4 | 7 | Vector 1 8 | Created with Sketch. 9 | 10 | 11 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solidity-cli", 3 | "version": "1.0.3", 4 | "description": "Comple solidity-code faster, easier and more reliable", 5 | "keywords": [ 6 | "solidity", 7 | "ethereum", 8 | "eth", 9 | "web3", 10 | "dapp", 11 | "blockchain", 12 | "smart-contract", 13 | "solc" 14 | ], 15 | "bin": { 16 | "solidity": "./dist/src/cli.js", 17 | "solidity-cli": "./dist/src/cli.js" 18 | }, 19 | "main": "./dist/src/index.js", 20 | "types": "./src/index.ts", 21 | "scripts": { 22 | "lint": "tslint --project .", 23 | "pretranspile": "rimraf -rf ./dist && mkdir ./dist && rimraf -rf ./solc-installs && rimraf -rf ./compile-cache && rimraf -rf ./tmp", 24 | "transpile": "tsc -p ./ && echo '# transpile sucess!'", 25 | "pretest": "npm run transpile", 26 | "test": "mocha --bail --exit ./dist/test/index.test.js ./dist/test/integration.test.js", 27 | "test:cli": "npm run transpile && bash ./test-cli.bash", 28 | "build": "npm run transpile", 29 | "dev": "watch 'npm run test:node' src/ test/", 30 | "tcompile": "npm run transpile && node ./tmp/src/compile.node.js cHJhZ21hIHNvbGlkaXR5IDAuNC4yNDsNCg0KDQpjb250cmFjdCBCYXNpYyB7DQogICAgYWRkcmVzcyBwdWJsaWMgb3duZXI7DQp9DQo=" 31 | }, 32 | "repository": { 33 | "type": "git", 34 | "url": "git+https://github.com/pubkey/solidity-cli.git" 35 | }, 36 | "author": "pubkey", 37 | "license": "Apache-2.0", 38 | "bugs": { 39 | "url": "https://github.com/pubkey/solidity-cli/issues" 40 | }, 41 | "pre-commit": [ 42 | "lint" 43 | ], 44 | "homepage": "https://github.com/pubkey/solidity-cli#readme", 45 | "dependencies": { 46 | "async-test-util": "1.6.2", 47 | "child-process-promise": "2.2.1", 48 | "directory-exists": "2.0.1", 49 | "glob": "7.1.3", 50 | "js-sha3": "0.8.0", 51 | "shelljs": "0.8.3", 52 | "solc": "0.5.0", 53 | "yargs": "12.0.5" 54 | }, 55 | "devDependencies": { 56 | "@types/clone": "0.1.30", 57 | "@types/glob": "7.1.1", 58 | "@types/mocha": "5.2.5", 59 | "@types/node": "10.12.11", 60 | "@types/rimraf": "2.0.2", 61 | "@types/shelljs": "0.8.0", 62 | "@types/yargs": "12.0.1", 63 | "assert": "1.4.1", 64 | "command-line-args": "5.0.2", 65 | "concurrently": "4.1.0", 66 | "delete": "1.1.0", 67 | "exists-file": "3.0.2", 68 | "mocha": "5.2.0", 69 | "node": "11.2.0", 70 | "pre-commit": "1.2.2", 71 | "rimraf": "2.6.2", 72 | "solhint": "1.4.0", 73 | "tslint": "5.11.0", 74 | "typescript": "3.2.1", 75 | "walk-sync": "0.3.3" 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/caching.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * saves output to the cache 3 | * and retrieves it again, 4 | * so equal code does not have to be compiled multiple times 5 | */ 6 | import * as util from 'util'; 7 | import * as fs from 'fs'; 8 | import * as path from 'path'; 9 | const directoryExists = require('directory-exists'); 10 | 11 | import paths from './paths'; 12 | 13 | const fileExists = util.promisify(fs.stat); 14 | const writeFile = util.promisify(fs.writeFile); 15 | const readFile = util.promisify(fs.readFile); 16 | 17 | import { 18 | Artifact 19 | } from './compiled.d'; 20 | 21 | async function ensureDirectoryExists(): Promise { 22 | const exists = await directoryExists(paths.compileCache + '/'); 23 | if (!exists) { 24 | fs.mkdirSync(path.join(paths.compileCache, '../')); 25 | fs.mkdirSync(paths.compileCache + '/'); 26 | } 27 | } 28 | 29 | function fileBySource(hash: string): string { 30 | return path.join( 31 | paths.compileCache, 32 | hash + '.json' 33 | ); 34 | } 35 | 36 | export async function has(hash: string): Promise { 37 | try { 38 | await fileExists(fileBySource(hash)); 39 | return true; 40 | } catch (err) { 41 | return false; 42 | } 43 | } 44 | 45 | export async function get(hash: string): Promise { 46 | const content = await readFile(fileBySource(hash), 'utf-8'); 47 | const artifact = JSON.parse(content); 48 | return artifact; 49 | } 50 | 51 | export async function set( 52 | hash: string, 53 | artifact: Artifact 54 | ): Promise { 55 | await ensureDirectoryExists(); 56 | const fileContent = JSON.stringify(artifact); 57 | const filePath = fileBySource(hash); 58 | await writeFile(filePath, fileContent); 59 | } 60 | -------------------------------------------------------------------------------- /src/cli.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import * as yargs from 'yargs'; 4 | import * as path from 'path'; 5 | 6 | import version from './version'; 7 | 8 | import { 9 | Options 10 | } from './options'; 11 | 12 | import { 13 | runCli 14 | } from './index'; 15 | 16 | yargs 17 | .usage('Usage: solidity [options] [input_file...]') 18 | .option('version', { 19 | describe: 'Show version and exit.', 20 | type: 'boolean' 21 | }) 22 | .option('input-dir', { 23 | alias: 'i', 24 | describe: 'Input directory for the solidity-files.', 25 | type: 'string' 26 | }) 27 | .option('output-dir', { 28 | alias: 'o', 29 | describe: 'Output directory for compiled contracts.', 30 | type: 'string' 31 | }) 32 | .global(['version']) 33 | .showHelpOnFail(false, 'Specify --help for available options') 34 | .help(); 35 | 36 | const argv = yargs.argv; 37 | 38 | if (argv.version) { 39 | console.log(version); 40 | process.exit(); 41 | } 42 | 43 | if (argv.help) { 44 | process.exit(); 45 | } 46 | 47 | // default -> compile file 48 | const options: Options = { 49 | sourceFolder: path.join(process.cwd(), argv.inputDir), 50 | destinationFolder: argv.outputDir 51 | }; 52 | if (options.destinationFolder) { 53 | options.destinationFolder = path.join(process.cwd(), options.destinationFolder); 54 | } 55 | 56 | // console.log('bbbb'); 57 | // console.dir(yargs.argv); 58 | // console.dir(options); 59 | // console.log(process.cwd()); 60 | 61 | runCli(options); 62 | -------------------------------------------------------------------------------- /src/compile.node.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * node-script that takes solidity-code as base64 and outputs a json with the compile-output 3 | * we use this to make multi-threading easiser 4 | */ 5 | 6 | import * as util from 'util'; 7 | import * as fs from 'fs'; 8 | import * as shelljs from 'shelljs'; 9 | import * as path from 'path'; 10 | 11 | const writeFile = util.promisify(fs.writeFile); 12 | 13 | import { 14 | getSolcVersion 15 | } from './read-code'; 16 | import paths from './paths'; 17 | 18 | // const codeBase64 = 'cHJhZ21hIHNvbGlkaXR5IDAuNC4yNDsNCg0KDQpjb250cmFjdCBCYXNpYyB7DQogICAgYWRkcmVzcyBwdWJsaWMgb3duZXI7DQp9DQo='; 19 | // const codeBase64 = 'cHJhZ21hIHNvbGlkaXR5IDAuNC4yNDsNCg0KDQpjb250cmFjdCBCYXNpYyB7DQogICAgYWRkcmVzczEgcHVibGljIG93bmVyOw0KfQ0K'; // broken 20 | const codeBase64 = process.argv[2]; 21 | const location = process.argv[3] + '.json'; 22 | const code = Buffer.from(codeBase64, 'base64').toString(); 23 | 24 | const run = async function(code: string): Promise { 25 | const solcVersion = getSolcVersion(code); 26 | 27 | const solc = require(paths.solidityInstalls + '/' + solcVersion + '/node_modules/solc'); 28 | const compiled = solc.compile(code, 1); 29 | 30 | const out = { 31 | version: solcVersion, 32 | compiled 33 | }; 34 | 35 | // create destination if not exists 36 | shelljs.mkdir('-p', paths.compileTmpFolder); 37 | 38 | await writeFile( 39 | path.join(paths.compileTmpFolder, location), 40 | JSON.stringify(out, null, 2) 41 | ); 42 | }; 43 | 44 | run(code); 45 | -------------------------------------------------------------------------------- /src/compile.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * compiles the source-code in an own thread 3 | */ 4 | 5 | import * as path from 'path'; 6 | import * as fs from 'fs'; 7 | import * as util from 'util'; 8 | 9 | const readFile = util.promisify(fs.readFile); 10 | const unlink = util.promisify(fs.unlink); 11 | 12 | import AsyncTestUtil from 'async-test-util'; 13 | 14 | const { spawn } = require('child-process-promise'); 15 | 16 | import { 17 | SourceCode 18 | } from './read-code'; 19 | import paths from './paths'; 20 | import { 21 | SolcCompiledFile 22 | } from './compiled.d'; 23 | 24 | const WARNING_REGEX = /^\:[0-9]*:[0-9]*\: Warning:/; 25 | 26 | export default async function compile(source: SourceCode): Promise { 27 | 28 | const base64Code = Buffer.from(source.code).toString('base64'); 29 | const nodeScriptLocation = path.join(__dirname, 'compile.node.js'); 30 | 31 | const stdout: string[] = []; 32 | const stderr: string[] = []; 33 | 34 | const rand = AsyncTestUtil.randomString(10); 35 | const promise = spawn('node', [ 36 | nodeScriptLocation, 37 | base64Code, 38 | rand 39 | ]); 40 | const childProcess = promise.childProcess; 41 | 42 | childProcess.stdout.on('data', (data: any) => stdout.push(data.toString())); 43 | childProcess.stderr.on('data', (data: any) => stderr.push(data.toString())); 44 | 45 | try { 46 | await promise; 47 | } catch (err) { 48 | throw new Error(`could not compile 49 | # Error: ${err} 50 | # Output: ${stdout} 51 | # ErrOut: ${stderr} 52 | `); 53 | } 54 | 55 | const resultLocation = path.join(paths.compileTmpFolder, rand + '.json'); 56 | const resultString = await readFile(resultLocation, 'utf-8'); 57 | await unlink(resultLocation); 58 | const resultJson = JSON.parse(resultString); 59 | 60 | if (resultJson.version !== source.solcVersion) { 61 | throw new Error('solidity-cli: version not equal, this should never happen'); 62 | } 63 | 64 | if (resultJson.compiled.errors) { 65 | const errors = resultJson.compiled.errors.filter((err: string) => !WARNING_REGEX.test(err)); 66 | // const warnings = resultJson.compiled.errors.filter(err => WARNING_REGEX.test(err)); 67 | 68 | if (errors.length > 0) { 69 | throw new Error( 70 | '# could not compile contract ' + source.filename + '\n' + 71 | '# errors: \n' + 72 | '#' + resultJson.compiled.errors.join('\n#') 73 | ); 74 | } 75 | } 76 | 77 | return resultJson.compiled.contracts; 78 | } 79 | -------------------------------------------------------------------------------- /src/compiled.d.ts: -------------------------------------------------------------------------------- 1 | declare type CodeBlock = { 2 | begin: number, 3 | end: number, 4 | name: string, 5 | value?: string 6 | }; 7 | 8 | export type SolcCompiledContract = { 9 | assembly: { 10 | '.code': CodeBlock[], 11 | '.data': { 12 | 0: { 13 | '.auxdata': string, 14 | '.code': CodeBlock[] 15 | } 16 | } 17 | }; 18 | bytecode: string, 19 | functionHashes: { 20 | [k: string]: string; 21 | }; 22 | gasEstimates: { 23 | creation: number[]; 24 | external: { 25 | [k: string]: number; 26 | }; 27 | internal: { 28 | [k: string]: number; 29 | }; 30 | }; 31 | interface: string; 32 | metadata: string; 33 | opcodes: string; 34 | runtimeBytecode: string; 35 | srcmap: string; 36 | srcmapRuntime: string; 37 | }; 38 | 39 | export type SolcCompiledFile = { 40 | [contractName: string]: SolcCompiledContract 41 | }; 42 | 43 | export type Artifact = { 44 | compiled: SolcCompiledFile, 45 | javascript: string, 46 | typescript: string 47 | }; 48 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as util from 'util'; 3 | import * as fs from 'fs'; 4 | import * as shelljs from 'shelljs'; 5 | 6 | const writeFile = util.promisify(fs.writeFile); 7 | 8 | import { 9 | Options 10 | } from './options'; 11 | 12 | import { 13 | SolcCompiledFile, 14 | Artifact 15 | } from './compiled.d'; 16 | 17 | export { 18 | SolcCompiledContract, 19 | SolcCompiledFile 20 | } from './compiled.d'; 21 | 22 | import { 23 | hashCode, 24 | readCodeFile 25 | } from './read-code'; 26 | import readCodeFiles from './read-code'; 27 | import { 28 | SourceCode, 29 | getSolcVersion 30 | } from './read-code'; 31 | 32 | import * as caching from './caching'; 33 | 34 | import compile from './compile'; 35 | 36 | import { 37 | createJavascriptFile, 38 | createTypescriptFile, 39 | outputPath 40 | } from './output-files'; 41 | 42 | import { 43 | installVersion 44 | } from './solc-install'; 45 | 46 | /** 47 | * generates the output 48 | * or retrieves it from cache 49 | */ 50 | export async function generateOutput(source: SourceCode): Promise { 51 | const isCached = await caching.has(source.codeHash); 52 | if (isCached) { 53 | const artifact = await caching.get(source.codeHash); 54 | return artifact; 55 | } else { 56 | await installVersion(source.solcVersion); 57 | const compiled = await compile(source); 58 | const artifact = { 59 | compiled: compiled, 60 | javascript: await createJavascriptFile(source, compiled), 61 | typescript: await createTypescriptFile(source, compiled) 62 | }; 63 | 64 | await caching.set(source.codeHash, artifact); 65 | return artifact; 66 | } 67 | } 68 | 69 | /** 70 | * compiles the code 71 | * use this if you dont want to generate files, 72 | * but only get the compiled output 73 | */ 74 | export async function compileCode(code: string): Promise { 75 | const pseudoSource: SourceCode = { 76 | filename: 'programatically', 77 | code: code, 78 | codeHash: hashCode(code), 79 | solcVersion: getSolcVersion(code) 80 | }; 81 | const artifact = await generateOutput(pseudoSource); 82 | return artifact.compiled; 83 | } 84 | 85 | export async function compileFile(fileName: string): Promise { 86 | const source = await readCodeFile(fileName); 87 | const artifact = await generateOutput(source); 88 | return artifact.compiled; 89 | } 90 | 91 | export async function runCli(options: Options) { 92 | const codeFiles = await readCodeFiles(options); 93 | const artifacts: { 94 | source: SourceCode, 95 | artifact: Artifact, 96 | destinationFolder: string, 97 | fileName: string 98 | }[] = await Promise.all( 99 | codeFiles.map(async (source) => { 100 | const artifact = await generateOutput(source); 101 | const outPath = outputPath(options, source); 102 | const fileNameFull = outPath.split('\/').pop() as string; 103 | return { 104 | source, 105 | artifact, 106 | destinationFolder: path.join(outPath, '../') as string, 107 | fileName: fileNameFull.split('.').shift() as string 108 | }; 109 | }) 110 | ); 111 | 112 | // create destination if not exists 113 | if (options.destinationFolder) { 114 | shelljs.mkdir('-p', options.destinationFolder); 115 | } 116 | 117 | // write to files 118 | await Promise.all( 119 | artifacts.map(async (output) => { 120 | await writeFile( 121 | path.join(output.destinationFolder, output.fileName + '.js'), 122 | output.artifact.javascript 123 | ); 124 | await writeFile( 125 | path.join(output.destinationFolder, output.fileName + '.ts'), 126 | output.artifact.typescript 127 | ); 128 | }) 129 | ); 130 | } 131 | -------------------------------------------------------------------------------- /src/options.ts: -------------------------------------------------------------------------------- 1 | export type Options = { 2 | sourceFolder: string; 3 | /** 4 | * destinationFolder, relative to the sourceFolder 5 | */ 6 | destinationFolder?: string; 7 | }; 8 | -------------------------------------------------------------------------------- /src/output-files/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * generates the output-files from the 3 | * compiled data 4 | */ 5 | 6 | import * as fs from 'fs'; 7 | import * as util from 'util'; 8 | import * as path from 'path'; 9 | 10 | const readFile = util.promisify(fs.readFile); 11 | 12 | import { 13 | SolcCompiledFile 14 | } from '../compiled.d'; 15 | 16 | import { 17 | SourceCode 18 | } from '../read-code'; 19 | import { 20 | Options 21 | } from '../options'; 22 | 23 | import paths from '../paths'; 24 | 25 | let javascriptTemplatePromise: any = null; 26 | export async function createJavascriptFile( 27 | source: SourceCode, 28 | compiled: SolcCompiledFile 29 | ): Promise { 30 | if (!javascriptTemplatePromise) { 31 | javascriptTemplatePromise = readFile( 32 | path.join(paths.base, './src/output-files/javascript.template.js'), 33 | 'utf-8' 34 | ); 35 | } 36 | 37 | let template = await javascriptTemplatePromise; 38 | template = template.replace('', source.codeHash); 39 | template = template.replace('', JSON.stringify(compiled, null, 2)); 40 | 41 | return template; 42 | } 43 | 44 | export async function createTypescriptFile( 45 | source: SourceCode, 46 | compiled: SolcCompiledFile 47 | ): Promise { 48 | const template = 49 | `/* tslint:disable */ 50 | /** 51 | * generated via solidity-cli 52 | * @link https://www.npmjs.com/package/solidity-cli 53 | * do not edit this file manually 54 | * source-code-hash: ${source.codeHash} 55 | */ 56 | import { 57 | SolcCompiledContract, 58 | SolcCompiledFile 59 | } from 'solidity-cli'; 60 | 61 | declare type CompiledType = { 62 | ${Object.keys(compiled).map(k => `'${k}': SolcCompiledContract;`)} 63 | }; 64 | const compiled: CompiledType = ${JSON.stringify(compiled, null, 2)}; 65 | export default compiled; 66 | `; 67 | 68 | return template; 69 | } 70 | 71 | /** 72 | * determines where the output should be written 73 | */ 74 | export function outputPath(options: Options, source: SourceCode): string { 75 | const DEBUG = false; 76 | if (DEBUG) console.log('sourceFolder: ' + options.sourceFolder); 77 | 78 | let globBase = options.sourceFolder.replace(/\*.*/, ''); 79 | if (globBase.endsWith('.sol')) // single file 80 | globBase = path.join(globBase, '../'); 81 | 82 | if (DEBUG) console.log('globBase: ' + globBase); 83 | 84 | const optDestination = options.destinationFolder ? options.destinationFolder : globBase; 85 | if (DEBUG) console.log('optDestination: ' + optDestination); 86 | let destinationFolder = path.join(globBase, optDestination); 87 | if (optDestination === globBase) destinationFolder = globBase; 88 | if (DEBUG) console.log('destinationFolder: ' + destinationFolder); 89 | 90 | // destination-folder is absolut 91 | if (options.destinationFolder && options.destinationFolder.startsWith('/')) 92 | destinationFolder = path.join(options.destinationFolder, './'); 93 | 94 | const fileNameRelative = source.filename.replace(globBase, ''); 95 | if (DEBUG) console.log('fileNameRelative: ' + fileNameRelative); 96 | 97 | const goalPath = path.join( 98 | destinationFolder, 99 | fileNameRelative 100 | ); 101 | 102 | return goalPath; 103 | } 104 | -------------------------------------------------------------------------------- /src/output-files/javascript.template.js: -------------------------------------------------------------------------------- 1 | // eslint-disable 2 | /** 3 | * generated via solidity-cli 4 | * @link https://www.npmjs.com/package/solidity-cli 5 | * do not edit this file manually 6 | * source-code-hash: 7 | */ 8 | module.exports = ; 9 | -------------------------------------------------------------------------------- /src/paths.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import version from './version'; 4 | 5 | const paths = { 6 | base: path.resolve(__dirname, '../../'), 7 | solidityInstalls: path.resolve(__dirname, '../../', 'solc-installs', version), 8 | compileCache: path.resolve(__dirname, '../../', 'compile-cache', version), 9 | compileTmpFolder: path.resolve(__dirname, '../../', 'compile-tmp'), 10 | contractsFolder: path.resolve(__dirname, '../../', './test/contracts/'), 11 | }; 12 | 13 | export default paths; 14 | -------------------------------------------------------------------------------- /src/read-code.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * reads all solidity-files defined in the options 3 | */ 4 | 5 | import * as util from 'util'; 6 | import * as fs from 'fs'; 7 | import * as path from 'path'; 8 | import * as glob from 'glob'; 9 | import { 10 | sha3_256 11 | } from 'js-sha3'; 12 | 13 | const globPromise = util.promisify(glob); 14 | const readFile = util.promisify(fs.readFile); 15 | 16 | import { 17 | Options 18 | } from './options'; 19 | 20 | export type SourceCode = { 21 | filename: string, 22 | code: string, 23 | codeHash: string, 24 | solcVersion: string 25 | }; 26 | 27 | /** 28 | * https://stackoverflow.com/a/432503 29 | */ 30 | function matches(regex: RegExp, str: string): { inner: string, full: string }[] { 31 | const ret: any = []; 32 | let match = regex.exec(str); 33 | while (match !== null) { 34 | ret.push({ 35 | full: match[0], 36 | inner: match[1] 37 | }); 38 | match = regex.exec(str); 39 | } 40 | return ret; 41 | } 42 | 43 | /** 44 | * gets the source-code from the file 45 | * and parses all imports 46 | */ 47 | export async function getSourceCode(fileName: string): Promise { 48 | let code = await readFile(fileName, 'utf-8'); 49 | 50 | const codeCommentsRegex = /(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(\/\/.*)/g; 51 | code = code.replace(codeCommentsRegex, ''); 52 | 53 | const importsRegex = /import "([^"]*)";/g; 54 | const imports = matches(importsRegex, code); 55 | 56 | await Promise.all( 57 | imports.map(async (match) => { 58 | const p = path.resolve(fileName, '..', match.inner); 59 | let innerCode = await getSourceCode(p); 60 | // remove first line containing version 61 | innerCode = innerCode.replace(/^.*\n/, ''); 62 | code = code.replace(match.full, innerCode); 63 | }) 64 | ); 65 | 66 | return code; 67 | } 68 | 69 | export function getSolcVersion(code: string): string { 70 | const regex = /^pragma solidity [\^\~]?([0-9\.]*);/g; 71 | const match = regex.exec(code); 72 | if (!match) throw new Error('no pragma solidity version set'); 73 | return match[1]; 74 | } 75 | 76 | export function hashCode(code: string): string { 77 | return sha3_256(code); 78 | } 79 | 80 | export async function readCodeFile(fileName: string): Promise { 81 | const code = await getSourceCode(fileName); 82 | const ret: SourceCode = { 83 | filename: fileName, 84 | code, 85 | codeHash: hashCode(code), 86 | solcVersion: getSolcVersion(code) 87 | }; 88 | return ret; 89 | } 90 | 91 | export default async function readCodeFiles(options: Options): Promise { 92 | const filePaths: string[] = await globPromise(options.sourceFolder, {}); 93 | const ret: SourceCode[] = await Promise.all( 94 | filePaths.map(file => readCodeFile(file)) 95 | ); 96 | return ret; 97 | } 98 | -------------------------------------------------------------------------------- /src/solc-install.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * ensures the required solc-versions are installed 3 | * I tried to use 'npmi' but it always shows output in the console 4 | * So we use a custom shelljs 5 | */ 6 | import * as util from 'util'; 7 | const directoryExists = require('directory-exists'); 8 | 9 | import * as rimraf from 'rimraf'; 10 | import { 11 | exec 12 | } from 'shelljs'; 13 | 14 | import paths from './paths'; 15 | 16 | const removeFolder = util.promisify(rimraf); 17 | 18 | const INSTALL_VERSIONS_CACHE = {}; 19 | 20 | /** 21 | * install the given version into the ./solidity-version - folder 22 | * returns false if already exists 23 | */ 24 | export async function installVersion(version: string): Promise { 25 | if (INSTALL_VERSIONS_CACHE[version]) { 26 | await INSTALL_VERSIONS_CACHE[version]; 27 | return false; 28 | } else { 29 | INSTALL_VERSIONS_CACHE[version] = _installVersion(version); 30 | await INSTALL_VERSIONS_CACHE[version]; 31 | return true; 32 | } 33 | } 34 | 35 | async function _installVersion(version: string): Promise { 36 | const installPath = paths.solidityInstalls + '/' + version; 37 | 38 | // check if already exists 39 | const exists = await directoryExists(installPath + '/'); 40 | if (exists) return false; 41 | 42 | // not exists -> install it 43 | try { 44 | // console.log('# installing solc@' + version); 45 | await new Promise((res, rej) => { 46 | const shell = 'npm install solc@' + version + ' --prefix ' + installPath + ' --depth 0 --silent --audit false'; 47 | exec(shell, function(code, stdout: string, stderr: string) { 48 | if (code === 0) res(); 49 | else rej(new Error(stderr)); 50 | }); 51 | }); 52 | } catch (err) { 53 | // remove folder 54 | await removeFolder(installPath); 55 | throw err; 56 | } 57 | 58 | return true; 59 | } 60 | 61 | export default async function solcInstall(versions: string[]) { 62 | await Promise.all( 63 | versions 64 | .filter((elem, pos, arr) => arr.indexOf(elem) === pos) // unique 65 | .map(async (version) => { 66 | await installVersion(version); 67 | }) 68 | ); 69 | } 70 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.json' { 2 | const value: any; 3 | export default value; 4 | } 5 | -------------------------------------------------------------------------------- /src/version.ts: -------------------------------------------------------------------------------- 1 | import * as packageJson from '../../package.json'; 2 | 3 | const version = packageJson['version']; 4 | export default version; 5 | -------------------------------------------------------------------------------- /test-cli.bash: -------------------------------------------------------------------------------- 1 | echo "# testing the cli-commands (nothing should crash)"; 2 | 3 | ln -s "${PWD}/" "${PWD}/node_modules/solidity-cli" 4 | 5 | echo "## help" 6 | node ./dist/src/cli.js --help 7 | 8 | echo "## version" 9 | node ./dist/src/cli.js --version 10 | 11 | echo "## compile single file" 12 | rm -rf ./test/contracts/Basic.js 13 | rm -rf ./test/contracts/Basic.ts 14 | node ./dist/src/cli.js -i ./test/contracts/Basic.sol 15 | node ./test/contracts/Basic.js # test if valid 16 | 17 | 18 | rm -rf solidity-cli 19 | -------------------------------------------------------------------------------- /test/contracts/.gitignore: -------------------------------------------------------------------------------- 1 | *.js 2 | *.ts 3 | -------------------------------------------------------------------------------- /test/contracts/Basic.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.24; 2 | 3 | 4 | contract Basic { 5 | address public owner; 6 | 7 | /** 8 | * default function 9 | */ 10 | function() public payable { 11 | // got money 12 | } 13 | 14 | function anyFunction() public pure returns(bytes32) { 15 | return "foobar"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/contracts/Broken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.24; 2 | 3 | 4 | /** 5 | * this contract has broken code 6 | */ 7 | contract Broken { 8 | address public owner; 9 | 10 | function anyFunction( 11 | addressFoobar whoever // broken because unknown type 12 | ) public pure returns(bytes32) { 13 | return "foobar"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/contracts/DonationBag.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.23; 2 | 3 | 4 | contract DonationBag { 5 | 6 | // donation-signatures must be created by the owner 7 | address public owner; 8 | 9 | // each donation contains this amount of wei 10 | uint public amountPerDonation = 1000000000000000000; // one ether 11 | 12 | // one address can recieve only one donation 13 | // the ones already recieved one, are stored here 14 | mapping (address => bool) public alreadyRecieved; 15 | 16 | // constructor 17 | function DonationBag(address _owner) public { 18 | owner = _owner; 19 | } 20 | 21 | /** 22 | * default function 23 | * Whenever ether is send to the contract without 24 | * transaction data, the default function is called. 25 | * If you do not have a default-function and send ether to this contract, 26 | * the transaction will be reverted with 'VM Exception while processing transaction: revert' 27 | */ 28 | function() public payable { 29 | // got money 30 | } 31 | 32 | /** 33 | * to ensure the signatures for this contract cannot be 34 | * replayed somewhere else, we add this prefix to the signed hash 35 | */ 36 | string public signPrefix = "Signed for DonationBag:"; 37 | 38 | /** 39 | * generates a prefixed hash of the address 40 | * We hash the following together: 41 | * - signPrefix 42 | * - address of this contract 43 | * - the recievers-address 44 | */ 45 | function prefixedHash( 46 | address receiver 47 | ) public constant returns(bytes32) { 48 | bytes32 hash = keccak256( 49 | signPrefix, 50 | address(this), 51 | receiver 52 | ); 53 | return hash; 54 | } 55 | 56 | /** 57 | * validates if the signature is valid 58 | * by checking if the correct message was signed 59 | */ 60 | function isSignatureValid( 61 | address receiver, 62 | uint8 v, 63 | bytes32 r, 64 | bytes32 s 65 | ) public constant returns (bool correct) { 66 | bytes32 mustBeSigned = prefixedHash(receiver); 67 | address signer = ecrecover( 68 | mustBeSigned, 69 | v, r, s 70 | ); 71 | 72 | return (signer == owner); 73 | } 74 | 75 | /** 76 | * checks if the signature and message is valid 77 | * if yes we send some wei to the submitter 78 | */ 79 | function recieveDonation( 80 | uint8 v, 81 | bytes32 r, 82 | bytes32 s 83 | ) public { 84 | 85 | // already recieved donation -> revert 86 | if (alreadyRecieved[msg.sender] == true) revert(); 87 | 88 | // signature not valid -> revert 89 | if (isSignatureValid( 90 | msg.sender, 91 | v, r, s 92 | ) == false) { 93 | revert(); 94 | } 95 | 96 | // all valid -> send wei 97 | alreadyRecieved[msg.sender] = true; 98 | msg.sender.transfer(amountPerDonation); 99 | } 100 | 101 | /** 102 | * returns the current contract-balance 103 | */ 104 | function getBalance() public constant returns (uint256 balance) { 105 | return this.balance; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /test/contracts/Import.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.24; 2 | 3 | import "./Basic.sol"; 4 | import "./OlderVersion.sol"; // we do 2 imports to ensure they work 5 | 6 | contract Import { 7 | address public owner; 8 | } 9 | -------------------------------------------------------------------------------- /test/contracts/OlderVersion.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.21; 2 | 3 | 4 | contract OlderVersion { 5 | address public owner; 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/VersionRange.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.21; 2 | 3 | /** 4 | * this contract has a range as version 5 | */ 6 | 7 | contract VersionRange { 8 | address public owner; 9 | } 10 | -------------------------------------------------------------------------------- /test/contracts/subdir/Basic.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.24; 2 | 3 | 4 | contract Basic { 5 | address public owner; 6 | 7 | /** 8 | * default function 9 | */ 10 | function() public payable { 11 | // got money 12 | } 13 | 14 | function anyFunction() public pure returns(bytes32) { 15 | return "foobar"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/contracts/subdir/Import.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.24; 2 | 3 | import "./Basic.sol"; 4 | import "../OlderVersion.sol"; // we do 2 imports to ensure they work 5 | 6 | contract Import { 7 | address public owner; 8 | } 9 | -------------------------------------------------------------------------------- /test/index.test.ts: -------------------------------------------------------------------------------- 1 | import './unit/paths.test'; 2 | import './unit/read-code.test'; 3 | import './unit/solc-install.test'; 4 | import './unit/compile.test'; 5 | import './unit/output-files.test'; 6 | import './unit/caching.test'; 7 | import './unit/issues.test'; 8 | -------------------------------------------------------------------------------- /test/integration.test.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as assert from 'assert'; 4 | import AsyncTestUtil from 'async-test-util'; 5 | import * as path from 'path'; 6 | import * as fs from 'fs'; 7 | 8 | import paths from '../src/paths'; 9 | import { 10 | readCodeFile 11 | } from '../src/read-code'; 12 | 13 | import * as SolidityCli from '../src/index'; 14 | 15 | describe('integration.test.js', () => { 16 | it('.generateOutput()', async () => { 17 | const source = await readCodeFile(paths.contractsFolder + '/Basic.sol'); 18 | const artifact = await SolidityCli.generateOutput(source); 19 | assert.ok(artifact); 20 | }); 21 | it('.compileCode()', async () => { 22 | const source = await readCodeFile(paths.contractsFolder + '/Basic.sol'); 23 | const compiled = await SolidityCli.compileCode(source.code); 24 | assert.ok(compiled); 25 | }); 26 | it('.compileFile()', async () => { 27 | const compiled = await SolidityCli.compileFile(paths.contractsFolder + '/Basic.sol'); 28 | assert.ok(compiled); 29 | }); 30 | it('.runCli()', async function() { 31 | this.timeout(1000 * 30); 32 | const rand = AsyncTestUtil.randomString(10); 33 | const destinationFolder = path.join(paths.base, './tmp', rand); 34 | await SolidityCli.runCli({ 35 | sourceFolder: paths.contractsFolder + '/subdir/*.sol', 36 | destinationFolder 37 | }); 38 | 39 | assert.ok(fs.existsSync(destinationFolder + '/Basic.js')); 40 | assert.ok(fs.existsSync(destinationFolder + '/Basic.ts')); 41 | assert.ok(fs.existsSync(destinationFolder + '/Import.js')); 42 | assert.ok(fs.existsSync(destinationFolder + '/Import.ts')); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /test/unit/cache.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * caches some compiled code 3 | * so we do not have to recompile all time in tests 4 | */ 5 | import compile from '../../src/compile'; 6 | import readCodeFiles from '../../src/read-code'; 7 | import paths from '../../src/paths'; 8 | import * as clone from 'clone'; 9 | 10 | import { 11 | SolcCompiledFile 12 | } from '../../src/compiled.d'; 13 | import { 14 | SourceCode 15 | } from '../../src/read-code'; 16 | 17 | let basicCompiledPromise: any = null; 18 | export async function basicCompiled(): Promise<{ 19 | source: SourceCode, 20 | compiled: SolcCompiledFile 21 | }> { 22 | if (!basicCompiledPromise) { 23 | basicCompiledPromise = new Promise(async (res) => { 24 | const files = await readCodeFiles({ 25 | sourceFolder: paths.contractsFolder + '/Basic.sol' 26 | }); 27 | const compiled = await compile(files[0]); 28 | res({ 29 | source: files[0], 30 | compiled 31 | }); 32 | }); 33 | } 34 | 35 | const value = await basicCompiledPromise; 36 | return clone(value); 37 | } 38 | -------------------------------------------------------------------------------- /test/unit/caching.test.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as assert from 'assert'; 4 | 5 | import { 6 | basicCompiled 7 | } from './cache'; 8 | 9 | import { 10 | createJavascriptFile, 11 | createTypescriptFile 12 | } from '../../src/output-files'; 13 | 14 | import * as caching from '../../src/caching'; 15 | 16 | describe('caching.test.js', () => { 17 | describe('.set()', () => { 18 | it('should write to cache', async () => { 19 | const { source, compiled } = await basicCompiled(); 20 | const javascript = await createJavascriptFile(source, compiled); 21 | const typescript = await createTypescriptFile(source, compiled); 22 | await caching.set( 23 | source.codeHash, { 24 | compiled, 25 | javascript, 26 | typescript 27 | } 28 | ); 29 | }); 30 | }); 31 | describe('.has()', () => { 32 | it('should not have this in cache', async () => { 33 | const { source } = await basicCompiled(); 34 | source.codeHash = 'foobar'; 35 | const has = await caching.has(source.codeHash); 36 | assert.equal(has, false); 37 | }); 38 | it('should have cached the output', async () => { 39 | const { source, compiled } = await basicCompiled(); 40 | const javascript = await createJavascriptFile(source, compiled); 41 | const typescript = await createTypescriptFile(source, compiled); 42 | await caching.set( 43 | source.codeHash, { 44 | compiled, 45 | javascript, 46 | typescript 47 | } 48 | ); 49 | const has = await caching.has(source.codeHash); 50 | assert.equal(has, true); 51 | }); 52 | }); 53 | describe('.get()', () => { 54 | it('should return the cached artifact', async () => { 55 | const { source, compiled } = await basicCompiled(); 56 | const javascript = await createJavascriptFile(source, compiled); 57 | const typescript = await createTypescriptFile(source, compiled); 58 | await caching.set( 59 | source.codeHash, { 60 | compiled, 61 | javascript, 62 | typescript 63 | } 64 | ); 65 | const artifact = await caching.get(source.codeHash); 66 | assert.deepEqual(artifact, { 67 | compiled, 68 | javascript, 69 | typescript 70 | }); 71 | }); 72 | }); 73 | }); 74 | -------------------------------------------------------------------------------- /test/unit/compile.test.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as assert from 'assert'; 4 | import AsyncTestUtil from 'async-test-util'; 5 | 6 | import paths from '../../src/paths'; 7 | 8 | import compile from '../../src/compile'; 9 | import readCodeFiles from '../../src/read-code'; 10 | 11 | describe('compile.test.js', () => { 12 | it('should compile the code', async function() { 13 | this.timeout(1000 * 50); 14 | const files = await readCodeFiles({ 15 | sourceFolder: paths.contractsFolder + '/Basic.sol' 16 | }); 17 | const compiled = await compile(files[0]); 18 | 19 | assert.equal(typeof compiled[':Basic'].interface, 'string'); 20 | }); 21 | it('should give a useable error', async function() { 22 | this.timeout(1000 * 50); 23 | const files = await readCodeFiles({ 24 | sourceFolder: paths.contractsFolder + '/Broken.sol' 25 | }); 26 | const error = await AsyncTestUtil.assertThrows( 27 | () => compile(files[0]) 28 | ); 29 | const str = error.toString(); 30 | assert.ok(str.includes('Broken')); 31 | assert.ok(str.includes('whoever')); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /test/unit/issues.test.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as assert from 'assert'; 4 | // import AsyncTestUtil from 'async-test-util'; 5 | 6 | import paths from '../../src/paths'; 7 | 8 | import compile from '../../src/compile'; 9 | import readCodeFiles from '../../src/read-code'; 10 | 11 | describe('issues.test.js', () => { 12 | it('could not compile complex contract with warnings', async function() { 13 | this.timeout(60 * 1000); 14 | const files = await readCodeFiles({ 15 | sourceFolder: paths.contractsFolder + '/DonationBag.sol' 16 | }); 17 | const compiled = await compile(files[0]); 18 | assert.ok(compiled); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /test/unit/output-files.test.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import * as assert from 'assert'; 4 | 5 | import { 6 | basicCompiled 7 | } from './cache'; 8 | 9 | import { 10 | createJavascriptFile, 11 | createTypescriptFile, 12 | outputPath 13 | } from '../../src/output-files'; 14 | 15 | describe('output-files.test.js', () => { 16 | describe('.createJavascriptFile()', () => { 17 | it('should fill all placeholders', async function() { 18 | this.timeout(1000 * 50); 19 | const { source, compiled } = await basicCompiled(); 20 | const output = await createJavascriptFile(source, compiled); 21 | 22 | assert.equal(output.includes('