diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dca0de..d70acf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## [0.22.0] - 2024-07-08 ### Added diff --git a/package.json b/package.json index 493c2a2..74d8b0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ton/blueprint", - "version": "0.21.0", + "version": "0.22.0", "description": "Framework for development of TON smart contracts", "main": "dist/index.js", "bin": "./dist/cli/cli.js", @@ -35,7 +35,7 @@ }, "dependencies": { "@orbs-network/ton-access": "^2.3.3", - "@tact-lang/compiler": "^1.3.0", + "@tact-lang/compiler": "^1.4.0", "@ton-community/func-js": "^0.7.0", "@tonconnect/sdk": "^2.2.0", "arg": "^5.0.2", diff --git a/src/cli/constants.ts b/src/cli/constants.ts index bbfecd0..3128d97 100644 --- a/src/cli/constants.ts +++ b/src/cli/constants.ts @@ -29,7 +29,7 @@ List of available commands: - create - run - build -- custom +- set - help - test - verify @@ -69,9 +69,9 @@ Flags: set: `Usage: blueprint set [value] Available keys: - func - overrides @ton-community/func-js-bin version, effectively setting the func version. The required version may be passed as the value, otherwise available versions will be displayed.`, - test: `Usage: blueprint test + test: `Usage: blueprint test [...args] -Just runs \`npm test\`, which by default runs \`jest\`.`, +Just runs \`npm test [...args]\`, which by default runs \`jest\`.`, verify: `Usage: blueprint verify [contract name] [flags] Builds a contract (similar to build command) and verifies it on https://verifier.ton.org. The contract must be already deployed on the network. If the contract's name is not specified on the command line, it will be asked interactively. diff --git a/src/cli/test.ts b/src/cli/test.ts index ad77d19..9bc54d2 100644 --- a/src/cli/test.ts +++ b/src/cli/test.ts @@ -9,7 +9,7 @@ export const test: Runner = async (args, ui) => { ui.write(helpMessages['test']); return; } - + const testArgs = args._.slice(1); // first argument is `test`, need to get rid of it execSync(`npm test ${testArgs.join(' ')}`, { stdio: 'inherit' }); }; diff --git a/src/utils.ts b/src/utils.ts deleted file mode 100644 index 475a00e..0000000 --- a/src/utils.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { Address, Cell } from '@ton/core'; -import path from 'path'; -import fs from 'fs/promises'; -import { UIProvider } from './ui/UIProvider'; -import { SCRIPTS_DIR, WRAPPERS_DIR } from './paths'; -import { File } from './types/file'; - -export const tonDeepLink = (address: Address, amount: bigint, body?: Cell, stateInit?: Cell) => - `ton://transfer/${address.toString({ - urlSafe: true, - bounceable: true, - })}?amount=${amount.toString()}${body ? '&bin=' + body.toBoc().toString('base64url') : ''}${ - stateInit ? '&init=' + stateInit.toBoc().toString('base64url') : '' - }`; - -export function sleep(ms: number) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); -} - -export function oneOrZeroOf(options: T): keyof T | undefined { - let opt: keyof T | undefined = undefined; - for (const k in options) { - if (options[k]) { - if (opt === undefined) { - opt = k; - } else { - throw new Error(`Please pick only one of the options: ${Object.keys(options).join(', ')}`); - } - } - } - return opt; -} - -const compileEnd = '.compile.ts'; - -export const findCompiles = async (): Promise => - (await fs.readdir(WRAPPERS_DIR)) - .filter((f) => f.endsWith(compileEnd)) - .map((f) => ({ path: path.join(WRAPPERS_DIR, f), name: f.slice(0, f.length - compileEnd.length) })); - -export const findScripts = async (): Promise => { - const dirents = await fs.readdir(SCRIPTS_DIR, { recursive: true, withFileTypes: true }); - const scripts = dirents.filter((dirent) => dirent.isFile() && dirent.name.endsWith('.ts')); - - return scripts - .map((script) => ({ - name: path.join(script.path.slice(SCRIPTS_DIR.length), script.name), - path: path.join(SCRIPTS_DIR, script.path, script.name), - })) - .sort((a, b) => (a.name >= b.name ? 1 : -1)); -}; - -export async function selectOption( - options: { name: string; value: string }[], - opts: { - ui: UIProvider; - msg: string; - hint?: string; - }, -) { - if (opts.hint) { - const found = options.find((o) => o.value === opts.hint); - if (found === undefined) { - throw new Error(`Could not find option '${opts.hint}'`); - } - return found; - } else { - return await opts.ui.choose(opts.msg, options, (o) => o.name); - } -} - -export async function selectFile( - files: File[], - opts: { - ui: UIProvider; - hint?: string; - import?: boolean; - }, -) { - let selected: File; - - if (opts.hint) { - const found = files.find((f) => f.name.toLowerCase() === opts.hint?.toLowerCase()); - if (found === undefined) { - throw new Error(`Could not find file with name '${opts.hint}'`); - } - selected = found; - opts.ui.write(`Using file: ${selected.name}`); - } else { - if (files.length === 1) { - selected = files[0]; - opts.ui.write(`Using file: ${selected.name}`); - } else { - selected = await opts.ui.choose('Choose file to use', files, (f) => f.name); - } - } - - return { - ...selected, - module: opts.import !== false ? await import(selected.path) : undefined, - }; -} - -export function getExplorerLink(address: string, network: string, explorer: string) { - const networkPrefix = network === 'testnet' ? 'testnet.' : ''; - - switch (explorer) { - case 'tonscan': - return `https://${networkPrefix}tonscan.org/address/${address}`; - - case 'tonviewer': - return `https://${networkPrefix}tonviewer.com/${address}`; - - case 'toncx': - return `https://${networkPrefix}ton.cx/address/${address}`; - - case 'dton': - return `https://${networkPrefix}dton.io/a/${address}`; - - default: - return `https://${networkPrefix}tonscan.org/address/${address}`; - } -} diff --git a/src/utils/selection.utils.ts b/src/utils/selection.utils.ts index 4267f65..01a29ae 100644 --- a/src/utils/selection.utils.ts +++ b/src/utils/selection.utils.ts @@ -6,11 +6,11 @@ import { COMPILE_END, getCompilablesDirectory } from '../compile/compile'; import { File } from '../types/file'; export const findCompiles = async (directory?: string): Promise => { - directory ??= await getCompilablesDirectory(); - const files = await fs.readdir(directory); + const dir = directory ?? await getCompilablesDirectory(); + const files = await fs.readdir(dir); const compilables = files.filter((file) => file.endsWith(COMPILE_END)); return compilables.map((file) => ({ - path: path.join(directory, file), + path: path.join(dir, file), name: file.slice(0, file.length - COMPILE_END.length), })); }; @@ -21,8 +21,8 @@ export const findScripts = async (): Promise => { return scripts .map((script) => ({ - name: path.join(script.path.slice(SCRIPTS_DIR.length), script.name), - path: path.join(SCRIPTS_DIR, script.path, script.name), + name: path.join(script.path.slice(SCRIPTS_DIR.length+1), path.parse(script.name).name), + path: path.join(script.path, script.name), })) .sort((a, b) => (a.name >= b.name ? 1 : -1)); }; diff --git a/yarn.lock b/yarn.lock index ad0d962..dae1754 100644 --- a/yarn.lock +++ b/yarn.lock @@ -153,9 +153,9 @@ __metadata: languageName: node linkType: hard -"@tact-lang/compiler@npm:^1.3.0": - version: 1.3.0 - resolution: "@tact-lang/compiler@npm:1.3.0" +"@tact-lang/compiler@npm:^1.4.0": + version: 1.4.0 + resolution: "@tact-lang/compiler@npm:1.4.0" dependencies: "@ipld/dag-pb": 2.1.18 "@tact-lang/opcode": ^0.0.14 @@ -174,7 +174,7 @@ __metadata: zod: ^3.22.4 bin: tact: bin/tact - checksum: d5f1b33750f852835a63f49c41ce96186e8f00b3cc8b13a0070e46441453cca984c67c3431db0d17851c1789ad8830397e4276a6965a0754193843b7e3c4d98e + checksum: 7f01eb44de22b52f884f45f90637660009e1882ab341bde21eaea0ab26273dc4757638a713ed7f363d5097c64fa5a680109cb753abcc17e5a47242fc91d59296 languageName: node linkType: hard @@ -212,7 +212,7 @@ __metadata: resolution: "@ton/blueprint@workspace:." dependencies: "@orbs-network/ton-access": ^2.3.3 - "@tact-lang/compiler": ^1.3.0 + "@tact-lang/compiler": ^1.4.0 "@ton-community/func-js": ^0.7.0 "@ton/core": ^0.56.0 "@ton/crypto": ^3.2.0