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:
npm install jops-corenpx jops-core initCommands
Section titled “Commands”| 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.
Options
Section titled “Options”| 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 |
npx jops-core initinit first asks which template to start from, then detects the project type and writes the files.
Template menu
Section titled “Template menu”| 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).
What init does per project type
Section titled “What init does per project type”The default when no other project type is detected.
- Vendors the library to
lib/jops-core.min.js. - Writes
index.htmlwith the"jops-core"import map and the module script (data-app="./src/App.js"). - Copies the chosen template (
src/, assets). - Adds
.vscode/settings.jsonfor HTML highlighting inlayout`…`templates (see Editor setup). - Adds
"build"and"postinstall": "jops-core update"scripts topackage.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".
Detected from config.xml (Cordova) or capacitor.config.* (Capacitor). Run it from the project root (running it inside the web folder works too).
| Cordova | Capacitor | |
|---|---|---|
index.html, lib/, template |
www/ |
the webDir from capacitor.config.* |
.vscode/ and package.json scripts |
project root | project root |
viewport-fit=cover |
✓ | ✓ |
| Content-Security-Policy | adds 'unsafe-inline' and blob: to script-src |
— |
<script src="cordova.js"> |
✓ | — |
iOS custom scheme in config.xml |
✓ (app://localhost) |
— |
"build" script |
— (use cordova build) |
— (use npx cap sync) |
"postinstall": "jops-core update" |
✓ | ✓ |
With templates 1 or 2, Cordova’s sample www/index.html is renamed to www/index.cordova.html and replaced by a JOPS page. See Mobile.
Detected from electron in package.json.
- Choice 4 writes an Electron Forge project (main process, preload, a JOPS renderer with a sidebar and
<Router jops screens>), merges its dependencies and scripts into an existingpackage.json(existing entries are kept), vendors the library tosrc/lib/and runsnpm install. It refuses to run in a folder that already has an Electron project and changes nothing there. - Choices 1, 2 and 5 in an existing Electron project: the web folder is the folder of the page the main process loads (
src/in Forge’s default template). The library goes to<web folder>/lib/, Forge’s sample page is moved toindex.forge.htmland replaced by a JOPSindex.html(a page you already changed is patched instead), templates are copied with page-relative paths,jops-coremoves todevDependenciesand ajops:updatescript is added. Nobuildorpostinstallscript.
Forge’s vite and webpack templates are not supported. See Electron.
Choice 3 writes a Next.js project into the current folder: a React-only page, a page that renders <JopsApp>, a Route Handler, the JOPS SPA in public/jops-spa/ and the library in public/lib/. It merges dependencies and scripts into an existing package.json (existing entries are kept) and runs npm install.
It refuses to run in a folder that already has a Next.js project (next.config.*, tsconfig.json, src/app) and changes nothing there. To add JOPS to an existing Next.js app, use npx jops-core update and JopsApp (see Next.js).
init –wp
Section titled “init –wp”npx jops-core init --wpnpx jops-core init --wp-root ../wordpressInstalls the JOPS WordPress plugin (the [jops] shortcode and the jops-core library):
wp-envproject (a folder with.wp-env.json): writes the plugin toplugins/jops/and adds"./plugins/jops"to.wp-env.json.npx wp-env startthen installs and activates it.- Otherwise: searches the current folder and the folders above it for WordPress (
wp-load.php+wp-content/, or Bedrock’sweb/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.
update
Section titled “update”npm i jops-core@latestnpx jops-core updateCopies 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 |
npx jops-core buildGenerates 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).
Update check
Section titled “Update check”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.