UNPKG

locklift

Version:

Node JS framework for working with Ever contracts. Inspired by Truffle and Hardhat. Helps you to build, test, run and maintain your smart contracts.

161 lines (160 loc) 7.5 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSupportedVersions = exports.executableFileName = exports.fileNames = exports.downloadLinks = exports.replaceDots = exports.getGzFileName = exports.platformToSoldTychoPlatform = void 0; const constants_1 = require("./constants"); const httpService_1 = require("../httpService"); const preload_1 = __importDefault(require("semver/preload")); const process = __importStar(require("process")); const platforms = { isWin32: process.platform === "win32", isLinux: process.platform === "linux", isDarwin: process.platform === "darwin", }; exports.platformToSoldTychoPlatform = { win32: "Windows", linux: "Linux", darwin: "macOS", }; const getGzFileName = (fileName) => `${fileName}.gz`; exports.getGzFileName = getGzFileName; const getLinkerUrl = ({ version }) => `https://binaries.tonlabs.io/${(0, exports.getGzFileName)(getLinkerFileName({ version }))}`; const getCompilerUrl = ({ version }) => `https://binaries.tonlabs.io/${(0, exports.getGzFileName)(getCompilerFileName({ version }))}`; const getSoldUrl = ({ version }) => `https://github.com/everx-labs/TVM-Solidity-Compiler/releases/download/${version}/sold_${(0, exports.replaceDots)(version)}_${process.platform}.gz`; const getTychoSoldUrl = ({ version }) => { return `https://github.com/broxus/TVM-Solidity-Compiler/releases/download/v${version}/sold-v${version}-${exports.platformToSoldTychoPlatform[process.platform]}.gz`; }; const getLibUrl = ({ version }) => `http://sdkbinaries.tonlabs.io/${(0, exports.getGzFileName)(getLibFileName({ version }))}`; const replaceDots = (arg) => arg.replace(/\./g, "_"); exports.replaceDots = replaceDots; const getLinkerFileName = ({ version }) => `tvm_linker_${(0, exports.replaceDots)(version)}_${process.platform}`; const getCompilerFileName = ({ version }) => `solc_${(0, exports.replaceDots)(version)}_${process.platform}`; const getLibFileName = ({ version }) => `stdlib_sol_${(0, exports.replaceDots)(version)}.tvm`; const getSoldFileName = ({ version }) => { return `sold_${(0, exports.replaceDots)(version)}_${process.platform}`; }; const getTychoSoldFileName = ({ version }) => { return `sold-v${version}-${exports.platformToSoldTychoPlatform[process.platform]}`; }; exports.downloadLinks = { [constants_1.ComponentType.COMPILER]: getCompilerUrl, [constants_1.ComponentType.LINKER]: getLinkerUrl, [constants_1.ComponentType.LIB]: getLibUrl, [constants_1.ComponentType.SOLD_COMPILER]: getSoldUrl, [constants_1.ComponentType.SOLD_COMPILER_TYCHO]: getTychoSoldUrl, }; exports.fileNames = { [constants_1.ComponentType.COMPILER]: getCompilerFileName, [constants_1.ComponentType.LINKER]: getLinkerFileName, [constants_1.ComponentType.LIB]: getLibFileName, [constants_1.ComponentType.SOLD_COMPILER]: getSoldFileName, [constants_1.ComponentType.SOLD_COMPILER_TYCHO]: getTychoSoldFileName, }; const getExecutableCompilerName = ({ version }) => { const fileName = exports.fileNames[constants_1.ComponentType.COMPILER]({ version }); if (platforms.isWin32) { return fileName + ".exe"; } return fileName; }; const getExecutableLinkerName = ({ version }) => { const fileName = exports.fileNames[constants_1.ComponentType.LINKER]({ version }); if (platforms.isWin32) { return fileName + ".exe"; } return fileName; }; const getExecutableLibName = ({ version }) => { return exports.fileNames[constants_1.ComponentType.LIB]({ version }); }; const getExecutableSoldName = ({ version }) => { const fileName = exports.fileNames[constants_1.ComponentType.SOLD_COMPILER]({ version }); if (platforms.isWin32) { return fileName + ".exe"; } return fileName; }; const getExecutableTychoSoldName = ({ version }) => { const fileName = exports.fileNames[constants_1.ComponentType.SOLD_COMPILER_TYCHO]({ version }); if (platforms.isWin32) { return fileName + ".exe"; } return fileName; }; exports.executableFileName = { [constants_1.ComponentType.COMPILER]: getExecutableCompilerName, [constants_1.ComponentType.LINKER]: getExecutableLinkerName, [constants_1.ComponentType.LIB]: getExecutableLibName, [constants_1.ComponentType.SOLD_COMPILER]: getExecutableSoldName, [constants_1.ComponentType.SOLD_COMPILER_TYCHO]: getExecutableTychoSoldName, }; const getSupportedVersions = ({ component }) => { switch (component) { case constants_1.ComponentType.COMPILER: return httpService_1.httpService .get("https://binaries.tonlabs.io/solc.json") .then(res => res.data.solc); case constants_1.ComponentType.LINKER: return httpService_1.httpService .get("https://binaries.tonlabs.io/tvm_linker.json") .then(res => res.data.tvm_linker); case constants_1.ComponentType.LIB: return httpService_1.httpService .get("https://binaries.tonlabs.io/solc.json") .then(res => res.data.solc); case constants_1.ComponentType.SOLD_COMPILER: return httpService_1.httpService .get("https://api.github.com/repos/tonlabs/TVM-Solidity-Compiler/releases") .then(res => res.data .filter(el => { try { return preload_1.default.gte(el.tag_name, "0.72.0"); // eslint-disable-next-line @typescript-eslint/no-unused-vars } catch (e) { return false; } }) .map(el => el.tag_name)); case constants_1.ComponentType.SOLD_COMPILER_TYCHO: return httpService_1.httpService .get("https://api.github.com/repos/broxus/TVM-Solidity-Compiler/releases") .then(res => res.data.map(el => el.tag_name)); } }; exports.getSupportedVersions = getSupportedVersions;