Posts

Snowpack - JavaScript Api

Control Over Start

When the Snowpack CLI is not able to provide fine-tune control over start operations, the Snowpack JavaScript Api should be used. Being able to programmatically control Snowpack is made possible when invoked inside other JavaScript files for enabling more configuration options.

Categories: #shell #typescript
Tags: #NodeJs
Testing OpenApi Spec File against Api Server URLs

Verifying Apis

Upon creating a REST API and then documenting with OpenApi, the entire set of routes are defined and described properly when the proper care is taken. To ensure that the server provides an Api that matches up to the OpenApi specification JSON or YAML, testing will be required.

Categories: #api #testing
Nestjs - OpenApi Example

Documenting Apis

Nestjs provides a more opinionated way in expressing structure when developing a backend for your Node.js application, and this prescribed way of doing things coupled with the usage of TypeScript allows for better maintainable code.

As stated in their project README.md:

Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, loosely coupled and easily maintainable applications. The architecture is heavily inspired by Angular.

Categories: #api
reStructuredText - Include External Documents

Inline Variables Within a Paragraph

For general reuse, one can reference another file in reStructuredText using the include directive.

.. main.rst - this document will the insert the external content from the path below

.. include:: the/path/to/my-included-file.rst

This is good when the content which you want to embed directly into your document can stand by itself as a separate paragraph, however, if you wish to embed content inline within an existing paragraph, it would be necessary to place the included content as variables in another document with the following example.

Categories: #markup
Tags: #reStructuredText
Oclif - Delegate / Wrap Existing CLI Commands

CLI Wrap with Spawn and Programmatic Access

Oclif is a Nodejs command line generator tool that grants you the ability to conveniently create a CLI with the following

npx oclif single mycoollistofthings

Supposedly you have your own custom CLI, but you wish to delegate some of these commands to an existing CLI tool. You are then wrapping another CLI command for the intent of adding additional functionality with mycoollistofthings. Here is the new command's mapping behavior of the ls -r command.

npx mycoollistofthings -r
Categories: #shell #typescript
Tags: #NodeJs
Playwright - Cleaner Promise Chains

Fluent API

As with many JavaScript libraries, asynchronous operations are dealt with using promises, and the commonly preferred way of structuring promises flows entails the use of async / await.

From the Playwright documentation

const { webkit } = require('playwright');

(async () => {
  const browser = await webkit.launch();
  const page = await browser.newPage();
  await page.goto('http://whatsmyuseragent.org/');
  await page.screenshot({ path: `example.png` });
  await browser.close();
})();

Every page operation will require the use of an await since each yields a promise. However, this simple example shows the extra effort needed to tame async control flow by having to prepend each operation with an await. This is a bit noisy and detracts from the true intent of the tests steps.

Categories: #testing
Pandoc - LaTeX - Table of Contents

As a LateX document accumulates more content, navigating to a specific piece of information would be cumbersome if there was not an easy way to quickly jump to the area of interest. Providing a table of contents in the beginning of the document will greatly enhance the ability to find relevant data.

Categories: #shell #latex
Tags: #pandoc