📢 Announcing NodeCloud 2.0

Feature improvements, Code generation, Automated API Documentation and more!

Rajitha Warusavitarana
Leopards Lab
5 min readNov 20, 2020

--

Our ongoing vision with NodeCloud is to automatically generate the NodeCloud plugins through code generation. With every release, the SCoRe community makes NodeCloud efficient and awesome! We are happy to announce that from now onwards there is no need of writing any JavaScript classes in NodeCloud plugins. Instead, they are automatically generated using the TypeScript compiler API. This automating process is currently working for AWS, Azure and Google Cloud. The API documentation is also auto generated along with the NodeCloud plugins. Furthermore, with NodeCloud 2.0 the project structure has been enhanced with Lerna. Lerna helps to manage all the NodeCloud plugins in a single monorepo.

NodeCloud Code Generator

This is where the new source code is generated by assembling bits and pieces. The aim of this generator is to fill the JavaScript classes in NodeCloud plugins. This process can be mainly divided into three main parts,

  1. Parsing the type definition files of cloud SDKs.
  2. Traversing through the Abstract Syntax Tree of the source code and collecting required data.
  3. Transforming a dummy Abstract Syntax Tree with the collected data to generate a new source code.

The below image visualizes the entire process in a high-level manner.

The execution of the generator starts form the main.ts file. Initially, the basic information regarding the service classes are taken from the node-cloud.yml file. Depending on the cloud provider, the basic information is directed to the respective generator (e.g. - Azure generator). Once a service is added in node-cloud.yml, the plugin can be updated through runing tsc main && node main. You will immediately see the output in generatedClasses directory inside the generator.

Structure of the “node-cloud.yml” file

  • AWS
  • Azure
  • Google Cloud (client based)

projectPath is not an API request. Generator is capable of creating functions which gives relevant objects as well.

  • Google Cloud (class based)

For the class-based SDKs there is a minor change in the node-cloud.yml to record the main class of an SDK. For the above scenario, it’s the DNS class.

Code parsers

Code parsers reads the SDK files from the relevant SDKs as specified in the node-cloud.yml file. Afterwards, it is converted to an Abstract Syntax Tree. Finally, the class declaration Node of that Abstract Syntax Tree will be returned. This returned Node is another Abstract Syntax Tree, since a class declaration itself is type of an Abstract Syntax Tree.

Data extraction functions

Data extraction functions are located in the generator of each cloud provider. Each data extraction function has a unique logic depending on the Abstract Syntax Tree of a SDK class. The goal here is to extract all the data required to generate the new JavaScript class. The data extraction function collects imports, clients, method parameters, types of parameters, method return types and package names. Additionally, class relationships are identified by the Google Cloud data extraction function for the Google Cloud class based transformer.

Transformers

Transformers are the most important component of the code generator tool. Currently, there are four transformers. Two transformers for Google Cloud, and one each for AWS and Azure. All of the transformers runs three main transformations.

  • addFunctions: In this transformation the basic structure of the code is created. Method Nodes are created to the number of functions in the classData object. If there are imports related to the class those statements are also added to the dummy Abstract Syntax Tree.
  • addIdentifiers: In this transformation all the Identifier nodes are updated. After this transformation the code is logically complete. All the necessary code parts are added and finalized such as parameter names, parameter types, client names, class name, package names, SDK function names etc.
  • addComments: This transformation aims to auto-generate the API documentation. All the comments are added to the structure required by JSDoc. The @category is used to categorize the generated classes depending on the cloud provider. This tag is from the better-docs template used with JSDoc.

Google Summer of Code program gave a great opportunity to grow the NodeCloud project. The below articles further explains the changes and decisions taken during the GSoC period. In addition to that, the Hacktoberfest festival helped to improve the project further thanks to the support given by ZenVega(#72) and lumenCodes(#73).

  1. GSoC 2020: Beginning of a New Adventure
  2. GSoC 2020: Getting familiar with the playground
  3. GSoC 2020: One more week left in the community bonding period
  4. GSoC 2020: Coding is Official!
  5. GSoC 2020: Parsing, Transforming and Generating
  6. GSoC 2020: Finally! Automated code generation for Node Cloud Azure plugin
  7. GSoC 2020: Diving into Google Cloud SDKs
  8. GSoC 2020: Easy package management with Lerna
  9. GSoC 2020 : Automated code generation using Google cloud Client based SDKs
  10. GSoC 2020: Completing the Transformers for Google Cloud plugin
  11. GSoC 2020: Tasty Testing with Mocha and Chai ☕️
  12. GSoC 2020: Documentation is equally important as code 📚
  13. GSoC 2020: Working on the Final Touches 🖌️
  14. GSoC 2020: 📢 Ready to hear some awesome news?

Please reach the SCoRe community via the mailing list or the gitter channel for any queries related to the NodeCloud project.

--

--