Skip to main content
Version: Current

Flow Cadut Generator API Reference

File System

sansExtension(filename)

Arguments

NameTypeDescription
filenamestringfile name with extension

Returns

TypeDescription
stringfilename without extension

Usage


_10
import { sansExtension } from "@onflow/flow-cadut";
_10
_10
const fileName = sansExtension("log-message-and-return.cdc");
_10
console.log({ fileName });

📣 This method is used internally to get value for module name during code generation.

readFile(path)

Reads the contents fo the file as utf8. Syntax sugar for fs.readFileSync(path, "utf8")

Arguments

NameTypeDescription
pathstringpath to the file

Returns

TypeDescription
stringstring representation of file contents

Usage


_10
import { clearPath } from "@onflow/flow-cadut";
_10
_10
const content = readFile("./log.cdc");

writeFile(path, data)

NameTypeDescription
pathstringpath to file, where data should be written
datastringdata to write into file

📣 If path to the file is nested and does not exist, method will create necessary folders to provide place to accommodate your file.

Usage


_10
import { writeFile } from "@onflow/flow-cadut";
_10
_10
const script = `
_10
pub fun main(){
_10
log("Hello, Cadence")
_10
}
_10
`;
_10
_10
writeFile("./cadence/scripts/log.cdc", script);

clearPath(path)

Recursively deletes contents of the provided folder and all it's contents. Syntax sugar for fs.rmdirSync(path, { recursive: true })

Arguments

NameTypeDescription
pathstringpath to folder to process

Usage


_10
import { clearPath } from "@onflow/flow-cadut";
_10
_10
clearPath("./ready-to-go");

getFileList(path)

Recursively looking for files under path and returns list of paths to found items.

NameTypeDescription
pathstringpath to folder to process

Returns

TypeDescription
[string]array of strings, representing paths to files contained within specified folder

Usage


_10
import { getFileList } from "@onflow/flow-cadut";
_10
_10
const list = getFileList("./cadence");

prettify(code, options)

Prettifies code using Prettier and set of options. Default options are:


_10
{
_10
"printWidth": 100,
_10
"endOfLine": "lf",
_10
"trailingComma": "es5",
_10
"tabWidth": 2,
_10
"semi": true,
_10
"useTabs": false,
_10
"singleQuote": false
_10
}

Arguments

NameTypeOptionalDescription
codestringvalid Javascript code
optionsobjectPrettier options. Consult Prettier Options Documentation to learn more.

Returns

TypeDescription
stringprettified version of provided code

Usage


_10
import { prettify } from "@onflow/flow-cadut";
_10
_10
const code = `
_10
const a = "Hello"
_10
const b = "World
_10
console.log(a +b);
_10
`;
_10
_10
const pretty = prettify(code);
_10
console.log(pretty);