Skip to content

Commit

Permalink
chore: add meow, clean up the tact entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpy committed Apr 27, 2024
1 parent 8e61206 commit b031539
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
57 changes: 26 additions & 31 deletions bin/tact
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
#!/usr/bin/env node

const main = require("../dist/node");
const arg = require("arg");
const meowModule = import("meow");

// Resolve arguments
const args = arg({
"--config": String,
"--project": String,
"--version": Boolean,
});
meowModule.then((meow) => {
const importMeta = { url: new URL("file://" + __dirname + __filename) };
const cli = meow.default(`
Usage
$ tact <config_path>
if (args["--version"]) {
console.log("1.2.0");
return;
}
Options
--project <project_name>, -r <project_name>
--version Prints the current tact version
--help Displays this text
if (!args["--config"]) {
console.log("USAGE: tact --config <config_path> [--project <project_name]");
return;
}
Examples
$ tact --version
1.2.0
`, { importMeta: importMeta, flags: { project: { shortFlag: "p", type: "string", isMultiple: true }, version: { shortFlag: "v", type: "boolean" }} });

// Perform compilation
(async () => {
try {
const success = await main.run({
configPath: args["--config"],
projectNames: args["--project"] ? args["--project"] : [],
});
// https://nodejs.org/docs/v20.12.1/api/process.html#exit-codes
if (!success) process.exit(30);
} catch (e) {
console.warn(
"Internal compiler error. Please, report it to https://github.com/tact-lang/tact/issues.",
);
console.log(e);
process.exit(30);
if (cli.flags.version) {
cli.showVersion();
return;
}
})();

if (!cli.input.at(0)) {
cli.showHelp();
return;
}

return main.run({ configPath: cli.input.at(0), projectNames: cli.flags.project ?? [] })
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"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
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
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

0 comments on commit b031539

Please sign in to comment.