npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vrtx

v0.6.0

Published

Vertex (vrtx) ====

Downloads

4

Readme

Vertex (vrtx)

oclif Version Downloads/week License

Vertex is a superset of the Apex language that compiles to Apex code. Vertex enhances the quality of life when writing Apex by adding modern language constructs, but still supporting all Apex features.

Installing

For the latest stable version:

npm install -g vrtx

Getting Started

To set up your project to be able to compile Vertex code, you first need to place a vrtxconfig.json file at the root of your project. This configuration file contains information the compiler will use to translate Vertex files into Apex files. Here is an example:

{
  "compilerOptions": {
    "targetApiVersion": 48.0,
    "rootDir": "src",
    "targetDir": "lib"
  }
}
  • The targetApiVersion defines which API Version the cls-meta.xml will be used for the generated Apex files
  • The rootDir defines the directory for the source of the .vrtx files
  • The targetDir defines the directory in which the Apex files will be placed

Building your first Vertex file

To demonstrate some of the capabilities of Vertex lets walk through an example and introduce some of the features.

First, in your root directory, create a Greeter.vrtx file that looks as follows:

Remember to keep your root directory out of a place where it will be pushed to the org OR add it to the .forceignore file as we can't push Vertex files to the Salesforce org

public class Greeter {
  public Greeter(String person) {
    System.debug('Hello ' + person + '!');
  }
}

Compiling your code

You will notice that the source code looks exactly like Apex, since Vertex is a superset of Apex, all Apex code is automatically supported.

To translate your Vertex code to Apex at your command line run:

vrtx build

After running the build command a new Greeter.cls and a Greeter.cls-meta.xml are generated inside of the target directory specified in the configuration file.

The compiler also makes sure that the generated code is formatted appropriately, by running Prettier on the source code.

Optional Parameters

Now lets take advantage of the things that Vertex offers. Let's start by modifying the Greeter.vrtx to use optional parameters:

public class Greeter {
    public Greeter(String person, [String greeting]) {
        if (greeting == null) {
            greeting = 'Hello';
        }
        System.debug(greeting + ' ' + person + '!');
    }
}

Notice the parameter between the [ ], this syntax represents optional parameters, so you can choose to either pass in or ignore:

Greeter myGreeter = new Greeter('World!');
// OR
Greeter myGreeter = new Greeter('World!', 'Hello');

You can combine formal (non-optional) parameters and optional parameters, and you can have as many formal and optional parameters as you want.

Null Coalesce

Notice the null check we need to do in order to make sure that our string is correctly formed. Luckily Vertex vastly simplifies null checks by providing the null coalesce operator ??. This operator returns the left-most non-null value.

public class Greeter {
    public Greeter(String person, [String greeting]) {
        greeting = greeting ?? 'Hello';
        System.debug(greeting + ' ' + person + '!');
    }
}

Default parameter values

Even with the null coalesce our code is still doing a null check, which we can simplify even further. Vertex removes the need for that check by allowing you to set default parameter values with your optional parameters:

public class Greeter {
    public Greeter(String person, [String greeting = 'Hello']) {
        System.debug(greeting + ' ' + person + '!');
    }
}

String templates

Another improvement we can make to our code is to how we are building the message within the System.debug call. Vertex allows you to use string templates to help you out when building complex strings:

public class Greeter {
    public Greeter(String person, [String greeting = 'Hello']) {
        System.debug(`${greeting} ${person}!`);
    }
}

Example Code

The example code is fully available here.

Usage

$ npm install -g vrtx
$ vrtx COMMAND
running command...
$ vrtx (-v|--version|version)
vrtx/0.6.0 win32-x64 node-v12.17.0
$ vrtx --help [COMMAND]
USAGE
  $ vrtx COMMAND
...

Commands

vrtx build

Transcompiles Vertex code into Apex.

USAGE
  $ vrtx build

OPTIONS
  -h, --help  show CLI help

EXAMPLE
  $ vrtx build

See code: src\commands\build.ts

vrtx help [COMMAND]

display help for vrtx

USAGE
  $ vrtx help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help