Initialize Functions

Set up Function Type

If you choose to initialize the Functions directory for your project, Catalyst will initiate its setup process.

  1. Select the type of function you would like to develop. Make your selection and press Enter .
    Initialize functions- Setup function type

    The six types of functions that you can develop in Catalyst are: Basic I/O, Advanced I/O, Event, Cron, Browser Logic, Integration, and Browser Logic functions. To learn more about the function types and their purposes, refer to the Functions help page.


    Integration Functions:

    The CLI initialization process is the same for all the other function types, except the Integration functions. If you select Integration from the list, you have to perform these two extra steps before moving on to the next step:

    i. Select the service that you want to integrate with. You can currently only select Cliq integration.Initialize functions- Integration Functions

    ii. Select the handlers that you require. You can learn more about this from the Integration Functions help page .
    Initialize functions- Integration Functions The rest of the setup process is the same for all function types. The process only varies with the function stack.

    Note: Integration Functions is currently not available to Catalyst users accessing from the EU, AU, IN, or CA data centers.

  1. Select a stack to develop the server side functions in and press Enter . The list displays all supported runtimes. You can select the latest supported version of Java, Node.js, or Python from the list.
Note: You can create multiple Java, Node.js or Python functions within a single function directory using the catalyst functions:add command.

Initialize a Java Function of Any Type

  1. If you initialize a Java function, select the required runtime from the supported runtimes: Java 8, Java 11, Java 17.


Note: Before choosing your version of Java function stack, ensure you have the relevant JDK installed in your system. You can also install the relevant JDKs from the following links:
  1. Enter the reference name of the Java function when prompted and press Enter . This will also be the name of the function’s folder.
    Initialize functions- Java Functions

  2. Provide the main class name of the Java function and press Enter . The CLI will then download the Java SDK package and complete the function setup process.

    Initialize functions- Java Functions


  1. If it is your first time initializing Java 11 or Java 17 function, you will need to additionally set the path information of the JDKs installed in your system. You can set this information in a specific configuration file that is present in your local system as a hidden file. The path of the installed JDKs will need to be set using the config:set <key=value> CLI command. You can find out more about this command from this help document.

Set the path information in the configuration file as shown in the example below:

Java 11:

copy
$
catalyst config:set java11.bin=/Library/Java/JavaVirtualMachines/jdk-11.0.17.jdk/Contents/Home/bin

Java 17:

copy
$
catalyst config:set java17.bin=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin

Note:
  • Replace the path listed in the above commands with your JDK path.
  • If your local system is running on Windows OS, kindly enclose the path in double-quotes. For example, you will set the Java 11 path in the following manner:
    
copy
catalyst config:set java11.bin="/Library/Java/JavaVirtualMachines/jdk-11.0.17.jdk/Contents/Home/bin"

catalyst_cli_functions_java_jdk_setup

The Java function’s folder will be created with the main .java class file, the library JAR files, catalyst-config.json , and other configuration files. These values will be updated in the catalyst.json configuration file.
Initialize functions- Java Function Directory

You can learn about the Java function directory structure in detail from the Project Directory Structure help page.


Initialize a Node JS Function of Any Type

  1. If you initialize a Node.js function, select the required runtime from the supported runtimes: Node 18, Node 16, Node 14, Node 12.

Initialize functions- Node.js Functions


  1. Provide a package name for your Node function when prompted and press Enter .
    Initialize functions- Node.js Functions

  2. Provide the name of the entry point file and press Enter .

  3. Provide a name for the function author and press Enter .

  4. The CLI will then prompt you to allow installation of node dependencies. Press Y to confirm the installation, and press Enter to confirm your choice. If you don’t install all the required dependencies, it could cause errors during the function’s execution.
    Initialize functions- Node.js Functions

    The CLI will then download the Node.js SDK package and complete the function setup process.

Note: Catalyst enables you to create an Advanced I/O function in the Express template, which installs the Express.js modules. However, you will not be able to create the Express template from the CLI. But you can install Express on your system independently by executing npm install express –save from a particular function's directory to use the Express modules in it. You can learn more the Express template from the Advanced I/O Function help page .

The Node function’s directory is now set up with the .js main function file, catalyst-config.json , and the necessary node modules and configuration files if you installed the dependencies. These values will be updated in the catalyst.json configuration file.

Initialize functions- Node.js Function Directory

You can learn about the Node.js function directory structure in detail from the Project Directory Structure help page .

Note:
  • You can add any number of sub-folders and files in a Java or a Node.js function’s directory. Besides the main function file, a function’s folder can contain other sub-functions. However, the configuration files and dependencies need to be in the function directory’s root.

  • You can create sub-functions through the Catalyst console , or using external editors. You can also pull an existing function directory from the console to your local system using the catalyst pull command.

  • If you need to initialize more than one function, you can do so by using the catalyst functions:add command.


Initialize a Python Function of Any Type

  1. If you initialize a Python function, select the required runtime from the supported runtime: Python 3.9.

Initialize functions- Python Functions

  1. Provide a package name for your Python function when prompted and press Enter .

  2. Provide the name of the entry point file and press Enter.

Initialize functions- Python Functions

Upon successful initialization of the Python function, the Catalyst Python SDK package will be automatically installed for your project and an entry will be made in the requirements.txt file.

Note: If it is your first time initializing a Python function, you will need to additionally set the path information of Python installed in your system. You can set this information in a specific configuration file that is present in your local system as a hidden file. The path will need to be set using the config:set <key=value> CLI command. You can find out more about this command from this help document.

The Python function’s directory is now set up with the .py main function file, catalyst-config.json and the requirements.txt configuration file. These values will be updated in the catalyst.json configuration file.

Initialize functions- Python Functions

You can learn about the Python function directory structure in detail from the Project Directory Structure help page .

Note:
  • You can add any number of sub-folders and files in a Java, Node.js or Python function’s directory. Besides the main function file, a function’s folder can contain other sub-functions. However, the configuration files and dependencies need to be in the function directory’s root.

  • You can create sub-functions for Node.js functions through the Catalyst console. However, Java and Python functions can only be created and updated from the CLI and using external editors.

  • You can pull an existing function directory from the console to your local system using the catalyst pull command.

  • If you need to initialize more than one function, you can do so by using the catalyst functions:add command.

  • If you are a Visual Studio Code IDE user, you can install the Catalyst Tools extension, and perform CLI operations using your IDE in place of the CLI. Steps to initalize your Catalyst functions using Visual Studio Code IDE can be found here

Last Updated 2024-06-18 12:08:24 +0530 +0530