Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved CLI #287

Merged
merged 39 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b031539
chore: add meow, clean up the tact entry point
vitorpy Apr 27, 2024
46bea40
chore: remove tabs from tact script
vitorpy Apr 27, 2024
3c39774
feat: add --func and --check
vitorpy Apr 27, 2024
650d3cb
fix: remove extra packageManager entry from package.json
vitorpy Apr 27, 2024
ce957f6
fix: reintroduce --config and move bin/tact to bin/tact.mjs
vitorpy Apr 28, 2024
ce2a40c
fix: remove extra packageManager entry from package.json and tsconfig…
vitorpy Apr 28, 2024
f13ce1e
fix: rename references to bin/tact in the GitHub workflow
vitorpy Apr 28, 2024
08ba95e
chore: update CHANGELOG.md
vitorpy Apr 28, 2024
94f4dcd
chore: merge upstream/main
vitorpy Apr 28, 2024
5b76f06
Update bin/tact.mjs
vitorpy Apr 28, 2024
df99e2a
Update bin/tact.mjs
vitorpy Apr 28, 2024
b061500
Update bin/tact.mjs
vitorpy Apr 28, 2024
efe0501
Update bin/tact.mjs
vitorpy Apr 28, 2024
cb0455b
Update CHANGELOG.md
vitorpy Apr 28, 2024
d757a47
feat: compile single file
vitorpy Apr 28, 2024
f0ed93a
fix: refactor cli args into the config object
vitorpy Apr 29, 2024
6fe29ea
chore: run prettier
vitorpy Apr 29, 2024
d91ff38
feat: add tests.
vitorpy Apr 29, 2024
3a139b2
chore: run prettier
vitorpy Apr 29, 2024
1531725
fix: bin/tact for Blueprint compatibility
vitorpy Apr 29, 2024
df6813e
fix: handle symlinks in the bin/tact wrapper script
vitorpy Apr 29, 2024
ae2c5f6
fix: handle symlinks in macos, avoid negations on the windows flow
vitorpy Apr 29, 2024
7a02591
fix: rename bin tact.mjs to tact to avoid issues on windows
vitorpy Apr 29, 2024
996b70a
Merge branch 'main' into new-cli
vitorpy Apr 29, 2024
dffe193
fix/feat: debugged and enhanced the CLI
novusnota Apr 30, 2024
8c083cb
fix: debugged issues and simplified configurations
novusnota Apr 30, 2024
2917688
feat: extended JSON Schema for tact.config.json
novusnota Apr 30, 2024
d340daf
fix: moved catching of empty config after `--config` flag onto the bu…
novusnota Apr 30, 2024
4d2ea34
chore: better wording
novusnota Apr 30, 2024
3ccfb6f
chore: updated CHANGELOG
novusnota Apr 30, 2024
81c099e
chore: remove redundant line from CHANGELOG
novusnota May 1, 2024
c38b42c
feat: Introduce an enum for the compilation mode over disjoint boolea…
novusnota May 1, 2024
7dbb345
chore: Visible default values (only as a schema completion hints)
novusnota May 1, 2024
93c7fe0
chore: misc. things
novusnota May 1, 2024
0b18c8c
feat: Enum of strings for compilation `mode` over many disjoint boole…
novusnota May 1, 2024
a0257f8
fix: Bug with single and non-single file usage
novusnota May 1, 2024
b6f9644
chore: Update workflows
novusnota May 1, 2024
dcb8346
Apply suggestions from code review
novusnota May 1, 2024
d21d038
fix: corrected precedence -- local flags override ones in config
novusnota May 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ jobs:
- name: Compare Tact version from CLI flag `--version` against package.json
novusnota marked this conversation as resolved.
Show resolved Hide resolved
if: runner.os != 'Windows'
run: |
if [ "$(./bin/tact --version)" != "$(jq -r '.version' < package.json)" ];
if [ "$(./bin/tact.mjs --version)" != "$(jq -r '.version' < package.json)" ];
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
then false
fi

- name: Tact CLI non-zero exit code
novusnota marked this conversation as resolved.
Show resolved Hide resolved
if: runner.os != 'Windows'
run: |
! ./bin/tact --config test/tact-cli/tact.config.json
! ./bin/tact.mjs --config test/tact-cli/tact.config.json
vitorpy marked this conversation as resolved.
Show resolved Hide resolved

- name: Link Tact compiler
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The `isEmpty` extension function for the `Map` type: PR [#266](https://github.com/tact-lang/tact/pull/266)
- The `pow2` power function with base 2: PR [#267](https://github.com/tact-lang/tact/pull/267)
- The `try` and `try-catch` statements: PR [#212](https://github.com/tact-lang/tact/pull/212)
- The `--func` and `--check` flags: PR [#287](https://github.com/tact-lang/tact/pull/287)
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
- The `del` method for the `Map` type: PR [#95](https://github.com/tact-lang/tact/pull/95)

### Changed
Expand Down
38 changes: 0 additions & 38 deletions bin/tact

This file was deleted.

50 changes: 50 additions & 0 deletions bin/tact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

import * as main from "../dist/node.js";
import meow from "meow";

const cli = meow(
`
Usage
$ tact --config <config_path>

Options
--project <project_name>, -r <project_name>
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
--version Prints the current tact version
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
--func Outputs the intermediate FunC code.
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
--check Performs type checking and stops.
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
--help Displays this text

Examples
$ tact --version
1.2.0
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
`,
{
importMeta: import.meta,
flags: {
config: { shortFlags: "c", type: "string", isRequired: true },
project: { shortFlag: "p", type: "string", isMultiple: true },
version: { shortflag: "v", type: "boolean" },
check: { shortflag: "c", type: "boolean" },
func: { shortFlag: "f", type: "boolean" },
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
},
},
);

if (cli.flags.version) {
cli.showVersion();
}

if (cli.flags.check && cli.flags.func) {
console.log("--func and --check are mutually exclusive");
process.exit(30);
}

const success = await main.run({
configPath: cli.flags.config,
projectNames: cli.flags.project ?? [],
checkOnly: cli.flags.check,
func: cli.flags.func,
});

process.exit(success ? 0 : 30);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
],
"main": "./dist/main.js",
"bin": {
"tact": "./bin/tact"
"tact": "./bin/tact.mjs"
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"@ipld/dag-pb": "2.1.18",
"@tact-lang/opcode": "^0.0.14",
"@ton/core": "0.56.3",
"@ton/crypto": "^3.2.0",
"arg": "^5.0.2",
"blockstore-core": "1.0.5",
"change-case": "^4.1.2",
"ipfs-unixfs-importer": "9.0.10",
"meow": "^13.2.0",
"mkdirp": "^2.1.3",
"multiformats": "^13.1.0",
"ohm-js": "^17.1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { consoleLogger } from "./logger";
export async function run(args: {
configPath: string;
projectNames?: string[];
checkOnly?: boolean;
func?: boolean;
}) {
// Load config
const resolvedPath = path.resolve(args.configPath);
Expand All @@ -28,7 +30,7 @@ export async function run(args: {
// Resolve projects
let projects = config.projects;
if (args.projectNames && args.projectNames.length > 0) {
// Check that all proejct names are valid
// Check that all project names are valid
for (const pp of args.projectNames) {
if (!projects.find((v) => v.name === pp)) {
console.warn("Unable to find project " + pp);
Expand Down Expand Up @@ -58,6 +60,8 @@ export async function run(args: {
project,
stdlib,
logger: consoleLogger,
checkOnly: args.checkOnly,
func: args.func,
});
success = success && built;
}
Expand Down
16 changes: 16 additions & 0 deletions src/pipeline/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export async function build(args: {
project: VirtualFileSystem;
stdlib: string | VirtualFileSystem;
logger?: TactLogger | null | undefined;
checkOnly?: boolean;
func?: boolean;
vitorpy marked this conversation as resolved.
Show resolved Hide resolved
}) {
const { config, project } = args;
const stdlib =
Expand Down Expand Up @@ -68,6 +70,11 @@ export async function build(args: {
return false;
}

if (args.checkOnly) {
logger.log("✔️ Type checking succeeded.");
return true;
}

// Compile contracts
let ok = true;
const built: {
Expand Down Expand Up @@ -127,6 +134,10 @@ export async function build(args: {
continue;
}

if (args.func) {
continue;
}

// Compiling contract to TVM
logger.log(" > " + contract + ": func compiler");
let codeBoc: Buffer;
Expand Down Expand Up @@ -198,6 +209,11 @@ export async function build(args: {
return false;
}

if (args.func) {
logger.log("✔️ FunC code generation succeeded.");
return true;
}

// Package
logger.log(" > Packaging");
const contracts = getContracts(ctx);
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ arg@^4.1.0:
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

arg@^5.0.1, arg@^5.0.2:
arg@^5.0.1:
version "5.0.2"
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.2.tgz#c81433cc427c92c4dcf4865142dbca6f15acd59c"
integrity sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==
Expand Down Expand Up @@ -4105,6 +4105,11 @@ makeerror@1.0.12:
dependencies:
tmpl "1.0.5"

meow@^13.2.0:
version "13.2.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-13.2.0.tgz#6b7d63f913f984063b3cc261b6e8800c4cd3474f"
integrity sha512-pxQJQzB6djGPXh08dacEloMFopsOqGVRKFPYvPOt9XDZ1HasbgDZA74CJGreSU4G3Ak7EFJGoiH2auq+yXISgA==

merge-options@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-3.0.4.tgz#84709c2aa2a4b24c1981f66c179fe5565cc6dbb7"
Expand Down
Loading