@ton-contests/tact-utils
Version:
Tact utilities for TON Contests plaform
67 lines (66 loc) • 2.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.build = build;
const stdlib_js_1 = __importDefault(require("@tact-lang/compiler/dist/stdlib/stdlib.js"));
const fs_js_1 = require("./misc/fs.js");
const compiler_1 = require("@tact-lang/compiler");
const fs_1 = require("fs");
const FileSystem_js_1 = require("./vfs/FileSystem.js");
const precompileWithAst_js_1 = require("./ast/precompileWithAst.js");
const getProjectStructure_js_1 = require("./project/getProjectStructure.js");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
BigInt.prototype.toJSON = function () {
return Number(this);
};
async function build({ root, withAst }) {
const fileSystem = (0, getProjectStructure_js_1.getProjectStructure)(root);
/* Remove previous build */
(0, fs_js_1.rmForceSync)(fileSystem.buildDir);
/* Get Tact build configuration */
const tactConfig = getTactConfig(fileSystem.tactConfig);
const stdlib = (0, compiler_1.createVirtualFileSystem)("@stdlib", stdlib_js_1.default);
const logger = new compiler_1.Logger(compiler_1.LogLevel.NONE);
/* Build projects specified in tact.config.json */
Promise.all(tactConfig.projects.map(async (config) => {
const project = new FileSystem_js_1.FileSystem(fileSystem.rootDir);
try {
/* Get AST and save it into file */
if (withAst) {
const ast = (0, precompileWithAst_js_1.precompileWithAst)({
project,
stdlib,
entrypoint: config.path,
});
(0, fs_js_1.writeToOutput)({
projectRoot: fileSystem.rootDir,
path: "./ast.json",
data: Buffer.from(JSON.stringify(ast), "utf-8"),
});
}
const { ok, error } = await (0, compiler_1.build)({
config,
project,
stdlib,
logger,
});
if (ok) {
console.log("Compiled successfully!");
}
else {
error.map((e) => console.log(e.message));
console.log("Tact compilation failed");
}
}
catch (err) {
console.log(err.message);
console.log("Tact compilation failed");
}
}));
}
function getTactConfig(path) {
const tactConfig = JSON.parse((0, fs_1.readFileSync)(path).toString("utf-8"));
return tactConfig;
}