Skip to content

CLI

The jops-core npm package includes a command line tool for setting up projects, copying the library into them and building for production. Run it with npx in a project where jops-core is installed:

Terminal window
npm install jops-core
npx jops-core init
Command Description
npx jops-core init Asks for a template, vendors the library and configures the project for its type (web, Cordova, Capacitor, Electron), or creates a Next.js or Electron project from a template
npx jops-core init --wp Installs the JOPS WordPress plugin (no template menu)
npx jops-core update Copies jops-core.min.js from node_modules into the project; also refreshes an installed JOPS WordPress plugin
npx jops-core build Generates a production-ready dist/ folder (web projects)

Running npx jops-core without a command prints the usage text.

Option Commands Description
--cordova, --capacitor, --electron, --web init, update Override the detected project type. --web treats the current folder as a plain web app
--wp init Install the JOPS WordPress plugin
--wp-root <path> init, update WordPress folder to use instead of searching for one. Implies --wp. --wp-root=<path> also works
--no-update-check all Skip the check for a newer jops-core version
Terminal window
npx jops-core init

init first asks which template to start from, then detects the project type and writes the files.

Choice Template
1 Empty JOPS project: the basic skeleton of a JOPS app
2 Hello World JOPS project: an example app using every feature
3 Next.js JOPS Embedded SPA: a Next.js project hosting a JOPS SPA
4 Electron JOPS Desktop App: an Electron Forge project whose UI is a JOPS SPA
5 None: only the library, index.html and scripts

Choices 1, 2 and 5 configure the current project for its type. Choices 3 and 4 create a whole project in the current folder (an empty folder or a fresh npm project).

The default when no other project type is detected.

  • Vendors the library to lib/jops-core.min.js.
  • Writes index.html with the "jops-core" import map and the module script (data-app="./src/App.js").
  • Copies the chosen template (src/, assets).
  • Adds .vscode/settings.json for HTML highlighting in layout`…` templates (see Editor setup).
  • Adds "build" and "postinstall": "jops-core update" scripts to package.json.

Every step checks first, so running init again never duplicates anything. When input ends without an answer to the template question (CI, Docker), init uses 5 (None). Projects created before 1.1.8 have "postinstall": "npx jops-core init", which shows the template question on every npm install (since 1.1.8 it uses 5, None, when nobody answers; before, npm install failed in CI). Change it to "postinstall": "jops-core update".

Terminal window
npx jops-core init --wp
npx jops-core init --wp-root ../wordpress

Installs the JOPS WordPress plugin (the [jops] shortcode and the jops-core library):

  • wp-env project (a folder with .wp-env.json): writes the plugin to plugins/jops/ and adds "./plugins/jops" to .wp-env.json. npx wp-env start then installs and activates it.
  • Otherwise: searches the current folder and the folders above it for WordPress (wp-load.php + wp-content/, or Bedrock’s web/wp/ + web/app/) and writes the plugin to its plugins folder. --wp-root <path> points to WordPress directly. Activate the plugin in wp-admin afterwards.

It stops without changes when the plugin is already installed (use update), and warns when package.json sits in the WordPress root, where node_modules/ would be served publicly. See WordPress.

Terminal window
npm i jops-core@latest
npx jops-core update

Copies the installed jops-core.min.js from node_modules into the project:

Project Destination
Web lib/jops-core.min.js
Cordova / Capacitor lib/ in the web folder (www/ or webDir)
Next.js (next.config.*) public/lib/jops-core.min.js
Electron src/lib/jops-core.min.js (the web folder’s lib/)
WordPress plugin installed refreshes the plugin and its library
Terminal window
npx jops-core build

Generates a clean dist/ folder from the project’s web files, ready to serve (see Production). It warns when lib/jops-core.min.js doesn’t match the installed jops-core version.

Skipped in projects that ship their web folder as is: Cordova (use cordova build), Capacitor (use npx cap sync) and Electron (use npm run make).

After each command, the CLI checks npm for a newer jops-core and prints a notice when one is available. The check takes at most 1.5 seconds and is silent when offline. Turn it off with --no-update-check or JOPS_NO_UPDATE_CHECK=1; it is skipped automatically when the CI environment variable is set.