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

cockpit-cli

v0.1.2

Published

A CLI to parse data for Cockpit headless CMS

Downloads

2

Readme

Cockpit CLI

A CLI for Cockpit Headless CMS that uses Cockpit SDK

  • Parses data structures from a project outputing meta-data that can be used directly on Cockpit.

  • Gets data from Cockpit collection schemas and components groups to make it easier to manipulate or generate.

Install

cd my-app

npm install cockpit-cli

Usage

cockpit-cli [options]

#For example (--verbose || -v)
cockpit-cli --init, --menu, --components, --help

Configuration

$ cockpit-cli --init

When setting up a project run --init so that the CLI can set up a /cockpit folder with a config.js file to connect the project to cockpit using cockpit-sdk .

module.exports = {
  host: "<HOST>",
  accessToken: "<ACCESS_TOKEN>"
};

To edit the file at ./cockpit/config.js:

  • Go into Cockpit and access a collection edit menu where the tab with the description Other should be selected.

  • Enable the CONTENT PREVIEW option. This is where the host is (or should be).

  • Copy the contents of those fields to the config.js file.

  • The accessToken can be retrieved on Cockpit settings page at API access. Choose between Full access API-key or a Custom key but please bear in mind that a Custom Key permission level can be restricted in comparison to a Full access API-key.
    It's possible to edit the config.js file at anytime but if in doubt about which one to choose, please checkout Cockpit API documentation.

Structure example

└── src
    ├── components
    │       ├── footer
    │       │    └──  definition.js
    │       │    └──  index.js
    |       |
    │       └── heading
    │            └──  definition.js
    │            └──  index.js
    |
    └── layouts
            └── bar
                 └──  definition.js
                 └──  index.js

# Or from the root

├── components
|       └── paragraph
|             └──  definition.js
|             └──  index.js
|
└── layouts
        └── bar
              └──  definition.js
              └──  index.js



folders: ['components', 'layouts', 'materials', 'elements', 'meta', 'pages', 'scripts']

Using components as example

definition.js files should contain the structure for Cockpit components like field names, types and options. Checkout the Cockpit fieldtypes documentation.

A paragraph component could have a definition.js file as described:

module.exports = {
  group: "test",
  fields: [
    {
      name: "color",
      type: "collectionlink",
      options: {
        link: "Colors"
      }
    },
    {
      name: "text",
      type: "textarea",
      default: ""
    },
    {
      name: "container",
      type: "select",
      options: {
        options: ["medium", "small", "spaceless", "left-aligned"]
      },
      default: ""
    },
    {
      name: "lead",
      type: "boolean",
      default: false
    }
  ]
};

The output result from parsing this component with the CLI is this:

 "paragraph": {
    "group": "test",
    "fields": [
      {
        "name": "color",
        "type": "collectionlink",
        "options": {
          "link": "Colors"
        }
      },
      {
        "name": "text",
        "type": "textarea",
        "default": ""
      },
      {
        "name": "container",
        "type": "select",
        "options": {
          "options": [
            "medium",
            "small",
            "spaceless",
            "left-aligned"
          ]
        },
        "default": ""
      },
      {
        "name": "lead",
        "type": "boolean",
        "default": false
      }
    ]
  }

The CLI parses the content of the definition.js file to .json as showed above, and it can separate them in groups by detecting if there is a value assigned to the key group in the component/definition.js file.
If no groups are specified then all groups are selected and this means all the definitions.js files are going to be parsed and it is possible to generate a cockpit/components.json file with all the parsed data or copy that data to the clipboard.

Component groups & Collection schemas

$ cockpit-cli --menu

Launches the CLI menu where it's possible to:

💾 Save schemas :

cli-schemas-menu

  • 💾 All collections creates a folder at /cockpit/schemas that contains data from all the schemas in all the collections in parsed to .json format .

  • 💾 Select a collection creates a folder at /cockpit/schemas that contains data from the schema of the selected collection.

  • The Save option always overwrites previous folders or files created by the CLI.

📄 Get components fields :

cli-fields-menu

  • ✂️ All parses all the definition.js files and copies the parsed result to the clipboard.

  • ✂️ Groups launches a new menu where it is possible to select one of the groups that are defined in the project data structure definition.js and copies the data from the component or components that correspond to the selected group to clipboard.

  • 💾 Save File creates a file at /cockpit/components.json with all the parsed data from all the definition.js files.

  • The Save option always overwrites previous folders or files created by the CLI.

Cockpit has a core components structure, this means that when adding a new component there will always be a group of components already pre-defined to which it is possible to add your own.
The CLI outputs a data structure ready to be added to cockpit components.js file.

Cockpit components.js

  • Go to Cockpit
  • Access finder
  • Select the config folder and inside it the components.js file

The parsed structure by the CLI can be pasted here, for example, adding the data of a specific component group or overwriting the complete file by pasting the data from all component groups. The parsed data should be pasted in components.js as an object:

window.CP_LAYOUT_COMPONENTS = {};

Only the contents of this object should be edited, like this:

window.CP_LAYOUT_COMPONENTS = {
  "paragraph": {
    "group": "test",
    "fields": [
      {
        "name": "color",
        "type": "collectionlink",
        "options": {
          "link": "Colors"
        }
      },
      {
        "name": "text",
        "type": "textarea",
        "default": ""
      },
      {
        "name": "container",
        "type": "select",
        "options": {
          "options": ["medium", "small", "spaceless", "left-aligned"]
        },
        "default": ""
      },
      {
        "name": "lead",
        "type": "boolean",
        "default": false
      }
    ]
  }
}

After the file is saved and when trying to add a new component to a cockpit collection these components that were parsed by the CLI should now appear as an option inside their specified groups.

config/components.js does not exist yet

Do not worry, just creat one:

  • Go to Cockpit
  • Access finder
  • Select this icon create-icon
  • Choose folder and name it config
  • Go inside config folder and click the same icon
  • Choose file and name it components.js
  • Paste this inside the file:
window.CP_LAYOUT_COMPONENTS = {};

$ cockpit-cli --components

This simply acts as a shortcut to create the /cockpit/components.json file and to copy the parsed data to the clipboard.