@hyperionbt/helios-cli
Advanced tools
Comparing version 0.1.0 to 0.1.1
87
index.js
@@ -6,7 +6,10 @@ #!/usr/bin/env node | ||
import { | ||
Address, | ||
deserializeUplc, | ||
Program, | ||
UserError as HeliosError | ||
UserError as HeliosError, | ||
VERSION as HELIOS_VERSION | ||
} from 'helios'; | ||
const VERSION = "0.1.0"; | ||
const VERSION = "0.1.1"; | ||
@@ -17,2 +20,5 @@ const USAGE = `Usage: | ||
Commands: | ||
address <json-file> | ||
-m, --mainnet | ||
compile <input-file> | ||
@@ -62,3 +68,3 @@ -I, --include <include-module-dir> | ||
const option = args.splice(i, 2).shift(); | ||
const option = args.splice(i, 2).slice(1).shift(); | ||
@@ -131,2 +137,47 @@ if (option === undefined) { | ||
function assertEmpty(args) { | ||
if (args.length > 0) { | ||
throw new UsageError(`unused arg '${args[0]}'`); | ||
} | ||
} | ||
function readFile(path) { | ||
if (!fs.existsSync(path)) { | ||
throw new CliError(`"${path}" not found`, 2); | ||
} else if (!fs.lstatSync(path).isFile()) { | ||
throw new CliError(`"${path}" isn't a file`, 2); | ||
} else { | ||
return fs.readFileSync(path, 'utf8'); | ||
} | ||
} | ||
function parseCalcScriptAddressOptions(args) { | ||
const options = { | ||
isMainnet: parseFlag(args, "-m", "--mainnet") | ||
}; | ||
assertNoMoreOptions(args); | ||
return options; | ||
} | ||
async function calcScriptAddress(args) { | ||
const options = parseCalcScriptAddressOptions(args); | ||
const inputFile = args.shift(); | ||
if (inputFile === undefined) { | ||
throw new UsageError("no script file specified") | ||
} | ||
assertEmpty(args); | ||
const uplcProgram = deserializeUplc(readFile(inputFile)); | ||
const address = new Address([options.isMainnet ? 0x71 : 0x70].concat(uplcProgram.hash().slice())); | ||
console.log(address.toBech32()); | ||
} | ||
function parseCompileOptions(args) { | ||
@@ -144,12 +195,2 @@ const options = { | ||
function readFile(path) { | ||
if (!fs.existsSync(path)) { | ||
throw new CliError(`"${path}" not found`, 2); | ||
} else if (!fs.lstatSync(path).isFile()) { | ||
throw new CliError(`"${path}" isn't a file`, 2); | ||
} else { | ||
return fs.readFileSync(path, 'utf8'); | ||
} | ||
} | ||
function listIncludes(inputFile, dirs) { | ||
@@ -186,2 +227,4 @@ const paths = [absPath(inputFile)]; | ||
assertEmpty(args); | ||
const includeDirs = options.includeDirs.slice(); | ||
@@ -198,5 +241,14 @@ includeDirs.unshift("."); | ||
console.log(uplc); | ||
if (options.output !== undefined) { | ||
fs.writeFileSync(options.output, uplc); | ||
} else { | ||
console.log(uplc); | ||
} | ||
} | ||
function printVersion() { | ||
console.log(`Helios-CLI version: ${VERSION}`); | ||
console.log(`Helios lib version: ${HELIOS_VERSION}`); | ||
} | ||
async function mainInternal(args) { | ||
@@ -209,3 +261,3 @@ if (args.some(a => a === "-h" || a === "--help")) { | ||
if (args.length === 0) { | ||
throw new UsageError("expected 1 or more args, got 0"); | ||
throw new UsageError("expected 1 or more args"); | ||
} | ||
@@ -220,2 +272,5 @@ | ||
switch (command) { | ||
case "address": | ||
await calcScriptAddress(args); | ||
break; | ||
case "compile": | ||
@@ -225,3 +280,3 @@ await compile(args); | ||
case "version": | ||
console.log(VERSION); | ||
printVersion(); | ||
break; | ||
@@ -228,0 +283,0 @@ default: |
{ | ||
"name": "@hyperionbt/helios-cli", | ||
"type": "module", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "CLI tool for compiling Cardano smart contracts written in Helios, and building Cardano transactions.", | ||
@@ -11,4 +11,4 @@ "main": "./index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hyperion-bt/helios.git" | ||
"type": "git", | ||
"url": "git+https://github.com/hyperion-bt/helios.git" | ||
}, | ||
@@ -15,0 +15,0 @@ "author": "Daniel Onyesoh", |
# Helios-CLI | ||
A CLI tool for compiled [Helios](https://github.com/Hyperion-BT/Helios) smart contracts. | ||
A CLI tool for compiling [Helios](https://github.com/Hyperion-BT/Helios) smart contracts. | ||
@@ -5,0 +5,0 @@ ## Installation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7228
235