Skip to main content

Command Line Tool

Prerequisites

  • Node.js 20 or newer (verify with node -v)
  • npm (ships with Node) — ensure it’s on your $PATH
  • Network reachability to your component registry (VPN/proxy if corporate)

If these are satisfied you can install the CLI as shown below.

Install the cli

To install cli, you should type:

$ npm install oc -g

Configure autocomplete

Autocomplete is supported for Mac and Linux.

To enable it in zsh, you should type:

echo '. <(oc completion)' >> .zshrc

To enable it in bash, you should type:

oc completion >> ~/.bashrc

or

oc completion >> ~/.bash_profile

After enabling autocomplete you should reload the shell.

Commands

Basic usage:

$ oc <command> [options]

Hint: Run -h with any command to show the help

For a list of all the available commands, type oc in your terminal

$ oc

Common Workflows

Here are the most frequently used command sequences for typical OpenComponents workflows:

Creating and Testing a New Component

# Create component
oc init my-component

# Navigate to component
cd my-component

# Start development server
oc dev . 3030

# Preview component (in another terminal)
oc preview http://localhost:3030/my-component

Publishing Workflow

# Add registry (one-time setup)
oc registry add https://my-registry.com

# Package and publish
oc publish my-component --username=myuser --password=mypass

# Or test before publishing
oc publish my-component --dryRun

Development and Debugging

# Start dev server with verbose output
oc dev . 3030 --verbose

# Clean node_modules from all components
oc clean . --yes

# Mock plugins for local development
oc mock plugin hash "test-value"

Most Frequently Used Commands

Essential Commands (Daily Use)

  • oc init <name> - Create new component
  • oc dev . <port> - Start development server
  • oc preview <url> - Preview component
  • oc publish <path> - Publish component

Setup Commands (One-time)

  • oc registry add <url> - Add registry
  • oc registry ls - List registries

Maintenance Commands (Occasional)

  • oc clean <path> - Clean dependencies
  • oc package <path> - Package component
  • oc mock plugin <name> <value> - Mock plugins

Quick Reference

CommandPurposeExample
initCreate componentoc init header
devStart dev serveroc dev . 3030
previewTest componentoc preview http://localhost:3030/header
publishDeploy componentoc publish header/
registry addAdd registryoc registry add https://my-registry.com
cleanRemove node_modulesoc clean . --yes

Installation Troubleshooting

SymptomFix
EACCES permission errors on macOS/LinuxRe-run with sudo npm install -g oc or configure a user-level npm prefix
oc: command not foundEnsure npm global bin folder is in $PATH (npm config get prefix → add prefix/bin)
Port already in use when running oc devChoose another port: oc dev . 3031
Component stuck on "Loading…"Check browser console, verify registry URL, review template syntax

For additional issues search the GitHub discussions or open a new ticket.

clean

Remove the node_modules directory from each component's subfolder

Usage:

$ oc clean <dirPath> [options]

Parameters:

NameDescriptionDefault
dirPathThe name of the directory where the components are stored

Options:

NameDescription
--yesSkip all confirmation prompts

Example:

$ oc clean ../all-components --yes

dev

Runs a local oc test registry to develop and test components

Usage:

$ oc dev <dirPath> [port] [baseUrl] [options]

Parameters:

NameDescriptionDefault
dirPathThe name of the directory to watch, where the components are stored
portThe port where to start a local oc instance.3000
baseUrlThe base url the component is hosted from.http://localhost:port/

Options:

NameDescriptionDefault
--fallbackRegistryUrlUrlUrl to another registry which will be used by dev registry when component cannot be found in local registryempty
--hotReloadingEnables hot reloading. Note: when hot reloading is set to true, each request to the component will make the registry to create a new instance for the javascript closures to be loaded, while when false the instance will be recycled between components executionstrue
--verboseVerbosityfalse
--watchenable the watchertrue
--productionforce packaging for productionfalse

Example:

$ oc dev ../all-components 3001 127.0.0.1:3001 --fallbackRegistryUrl=http://anotherhost:anotherport/

init

Creates a new empty component in the current folder

Usage:

$ oc init <componentPath> [templateType]

Parameters:

NameDescriptionDefault
componentPathThe relative path with a name of the component to create
templateTypeThe name of the published template module on npmoc-template-es6

Example:

$ oc init test-component oc-template-es6

or with using relative path:

$ oc init components/test-component oc-template-es6

which will create test-component in components directory.


mock

Allows mocking configuration to simplify local development

Usage

$ oc mock <targetType> <targetName> <targetValue>

Parameters:

NameDescriptionDefault
targetTypeThe type of item to mock
targetNameThe item to mock
targetValueThe mocked value (static plugin) or the file to read (dynamic plugin)

Example:

$ oc mock plugin hash "always-returned-value"

Creates static mock for a "hash" plugin which always returns "always-returned-value" value

To run a dynamic plugin, you can run a plugin locally. This could be the same one running in your registry, or a mock js that behaves differently locally.

$ oc mock plugin <targetName> <path to mock .js>

package

Creates the packaged component ready to be published

Usage:

$ oc package <componentPath> [options]

Parameters:

NameDescriptionDefault
componentPathThe path of the component to package

Options:

NameDescriptionDefault
--compressCreate zipped filefalse
--useComponentDependenciesReuse already installed dependencies to save packaging time and network bandwidthfalse

Example:

$ oc publish my-new-component/

preview

Runs a test page consuming a component

Usage:

$ oc preview <componentHref>

Parameters:

NameDescriptionDefault
componentHrefThe name of the component to preview

Examples:

$ oc preview "http://localhost:3000/my-new-component/1.0.0/?param1=hello&name=Arthur"

publish

Publish a component

Usage:

$ oc publish <componentPath> [options]

Parameters:

NameDescriptionDefault
componentPathThe path of the component to publish

Options:

NameDescriptionDefault
--passwordpassword used to authenticate when publishing to registry
--usernameusername used to authenticate when publishing to registry
--skipPackageto skip packaging step (useful if you publish at a different stage than packaging)false
--registriesalternative to pass a list of registries directly on the command instead of a json
--dryRunIndicates that you don't want to publish the OC and only report if it's ready tofalse

Examples:

$ oc publish my-new-component/

registry

Shows, adds, removes oc registries to the current project

Usage:

$ oc registry <command>

Parameters:

NameDescriptionDefault
registryUrlurl of registry

Commands:

NameDescriptionDefault
add <registryUrl>Adds oc registries to the current project
lsShows oc registries added to the current project
remove <registryUrl>Removes oc registries from the current project

Examples:

$ oc registry add http://my-registry.in.my.domain/
$ oc registry ls
$ oc registry remove http://my-registry.in.my.domain/