UNPKG

ton-assembly

Version:

TON assembler and disassembler

114 lines 4.4 kB
#!/usr/bin/env node "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; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const cac_1 = require("cac"); const fs = __importStar(require("node:fs/promises")); const compile_1 = require("../fift/compile/compile"); const runtime_1 = require("../runtime"); async function getContent(options, file) { if (options.string !== undefined) { return { content: options.string, sourceName: "<string>.fif" }; } if (file === undefined) { throw new Error("Either file or string input is required"); } const content = await fs.readFile(file, "utf8"); return { content, sourceName: file }; } const cli = (0, cac_1.cac)("tfift"); cli.command("[file]", "Compile a Fift assembly file or string to BOC") .option("-o, --output <file>", "Output file path") .option("-f, --format <format>", "Output format (binary|hex|base64)", { default: "binary" }) .option("-s, --string <data>", "Input Fift assembly code as a string instead of file") .option("--verbose", "Verbose output") .action(async (file, options) => { if (!file && options.string === undefined) { console.error("Error: Either input file or string data is required"); process.exit(1); } try { if (options.verbose) { if (options.string === undefined) { console.log(`Reading file: ${file}`); } else { console.log("Reading from string data"); } } const { content, sourceName } = await getContent(options, file); const instructions = (0, compile_1.compile)(sourceName, content); const cell = (0, runtime_1.compileCell)(instructions); const boc = cell.toBoc(); if (options.output) { switch (options.format) { case "binary": await fs.writeFile(options.output, boc); break; case "base64": await fs.writeFile(options.output, boc.toString("base64")); break; default: await fs.writeFile(options.output, boc.toString("hex")); break; } if (options.verbose) { console.log(`Written to: ${options.output}`); } } else { switch (options.format) { case "binary": process.stdout.write(boc); break; case "base64": console.log(boc.toString("base64")); break; default: console.log(boc.toString("hex")); break; } } } catch (error) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions console.error(`Error: ${error instanceof Error ? error.message : error}`); process.exit(1); } }); cli.help(); cli.version("0.0.1"); cli.parse(); //# sourceMappingURL=fift-compiler.js.map