Skip to main content
Version: Next

Flow Cadut Generator API Reference

File System

sansExtension(filename)

Arguments

NameTypeDescription
filenamestringfile name with extension

Returns

TypeDescription
stringfilename without extension

Usage

import { sansExtension } from "@onflow/flow-cadut";

const fileName = sansExtension("log-message-and-return.cdc");
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

import { clearPath } from "@onflow/flow-cadut";

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

import { writeFile } from "@onflow/flow-cadut";

const script = `
pub fun main(){
log("Hello, Cadence")
}
`;

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

import { clearPath } from "@onflow/flow-cadut";

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

import { getFileList } from "@onflow/flow-cadut";

const list = getFileList("./cadence");

prettify(code, options)

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

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

Arguments

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

Returns

TypeDescription
stringprettified version of provided code

Usage

import { prettify } from "@onflow/flow-cadut";

const code = `
const a = "Hello"
const b = "World
console.log(a +b);
`;

const pretty = prettify(code);
console.log(pretty);