1.0.9 • Published 8 months ago

@nodescript/module-generator v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Module Generator

Status: experimental

Sources of API specifications:

How to

Squad ADA docs

TLDR

  1. Generate specs from openapi:
npm run generate:openapi -- --in=openapi/<api-name>.json --out=specs/<api-name>.yaml
  1. Generate libraries
npm run generate:library -- --in=specs/<api-name>.yaml
  1. Publish libraries (See Nodescript publishing for more info.)
NODE_ENV=<env> FORCE_PUBLISH=true npm run publish:library -- --in=specs/<api-name>.yaml

Nodescript publishing

Both in production and development, you will need to set up a service account in NodeScript in the workspace created for the published modules:

  1. In Nodescript, navigate to the desired workspace, then Settings > service accounts and create a service account with WORKSPACE_MODULES_PUBLISH and WORKSPACE_MODULES_VIEW scopes.
  2. On the new service account, generate a key, ensure you copy the key as you'll need it shortly.

Local dev:

  1. Create/update a file in ./secrets/development/ directory named config.json, then inside create/update the object following this format:
{
    "<module title>": {
        "workspaceId": "<workspaceId>"
        "key": "<key>"
    }
}

Add your module title as per the spec filename from ./specs, omitting the file extension, and set the value to your generated key from NodeScript as well as the target workspace ID. Save the file.

  1. Run the publish command outlined in How to, setting the NODE_ENV to development.

Production:

  1. Ensure you have sops installed (See Sops for more info.)
  2. There should already be a file in ./secrets/production named config.json, which is encrypted. Edit the file using Sops. While editing you should see file contents in this format:
{
    "google-docs": {
        "workspaceId": "<workspaceId>"
        "key": "<key>"
    },
    "bigquery": {
        "workspaceId": "<workspaceId>"
        "key": "<key>"
    },
    "youtube": {
        "workspaceId": "<workspaceId>"
        "key": "<key>"
    },
    // ...etc
}

Add your module title as per the spec filename from ./specs, omitting the file extension, and set the value to your generated key from NodeScript. Save/Write and exit the editor.

  1. Run the publish command outlined in How to, setting the NODE_ENV to production.

  2. Commit your changes.

SOPS

Secrets are managed using SOPS. Installing SOPS is required to edit the secrets locally.

  1. Install SOPS:

    brew install sops
  2. Log into GCloud:

    gcloud auth login
    gcloud auth application-default login
  3. Edit the secrets file with sops:

    sops ./secrets/production/config.json