Shellviz Javascript Package
Installation
npm install shellviz
Usage
import { log } from 'shellviz';
log('hello world')
You can also import other visualizations, and you can choose to import using CommonJS or EJS
const { json, table } = require('shellviz')
json({ test: 'data', timestamp: new Date().toISOString() });
table([
['Name', 'Value'],
['Test', 123],
['Another', 'value']
]);
The package can be importer on both the Node.JS and browser-facing/client side, however due to limitations on the browser-side it can only send data to an existing Shellviz server that has been initialized by the Node.JS or Python library
Basic Client-Side Usage:
<script src="https://unpkg.com/shellviz"></script>
<script>
const { log } = shellviz;
log('hello from the browser');
</script>
Or via Module:
<script type="module">
import Shellviz from 'https://unpkg.com/shellviz/dist/browser.mjs';
const s = new Shellviz()
s.log('hello world')
import { log, json } from 'https://unpkg.com/shellviz/dist/browser.mjs'
log('hello world')
</script>
Building
To build the package locally:
cd client
npm install
npm run build
- Then build the Node.js package:
cd libraries/js
npm install
npm run build
- To create a local package for testing:
npm run pack
- To test locally, you can create a test directory and install the package:
mkdir test
cd test
npm init -y
npm install ../../build/shellviz-x.x.x.tgz
- Create a test file (e.g.,
test.js or test.mjs) and run it:
node test.js
node test.mjs
- To test in the client side, create a simple React app and import the client
npx create-react-app test-web
cd test-web
npm install ../../build/shellviz-x.x.x.tgz
Alternatively, to test during development you can do the following:
<script src="http://localhost:4005/build/browser_client.umd.js"></script>```
and compile and serve the client & js library:
```bash
npm run build
python -m http.server 4005```
This isn't the optimal way of developing, as you will need to re-build on each change. We should have a better solution in place soon
The package supports both CommonJS and ES Modules, so you can use either `require()` or `import` syntax in your code.
## Deploying
To deploy the package to npm:
### 🔐 1. Authenticate with npm
Make sure you have an npm account and are logged in:
```bash
npm login
🔁 2. Bump the version
✅ For a stable release:
Use one of the following depending on the type of change:
npm version patch
npm version minor
npm version major
🧪 For a beta/alpha/pre-release version:
Use the --preid flag to specify the pre-release tag:
Start from a stable version:
npm version prerelease --preid=beta
Or from an existing beta:
npm version prerelease --preid=beta
You can also combine with minor or major if needed:
npm version minor --preid=beta
npm version major --preid=beta
🧱 3. Build the package
Build and verify your output:
npm run build
npm pack
🚀 4. Publish to npm
For stable releases:
npm publish
For beta/pre-release versions:
Publish under a separate tag to avoid affecting the latest version:
npm publish --tag beta
This allows users to explicitly opt-in:
npm install shellviz@beta
You can also use other tags like alpha, next, or experimental.
You can promote a tested beta to latest later using:
npm dist-tag add shellviz@1.1.0-beta.3 latest
ShellViz JavaScript libraries support configuration through environment variables (Node.js) and window objects (browser) with a clear fallback hierarchy.
1. **Constructor parameters** (highest priority)
2. **Environment Variables** (`process.env` in Node.js)
3. **Window Variables** (`window.SHELLVIZ_*` in browser)
4. **Default Values** (visible in function declarations)
All environment variables are prefixed with `SHELLVIZ_`:
- `SHELLVIZ_PORT` - Port number for the server (default: 5544)
- `SHELLVIZ_SHOW_URL` - Whether to show URL on startup (default: true)
- `SHELLVIZ_URL` - Custom base URL for the server (default: None, constructs from port)
For browser environments, you can set global variables:
```javascript
// Set these before importing ShellViz
window.SHELLVIZ_PORT = 8080;
window.SHELLVIZ_SHOW_URL = false;
window.SHELLVIZ_URL = "https://my-custom-domain.com";
Environment Variable Examples (Node.js)
export SHELLVIZ_PORT=8080
export SHELLVIZ_SHOW_URL=false
export SHELLVIZ_URL="https://my-remote-shellviz.com"
node my_script.js
Usage Examples
JavaScript Client
import { ShellvizClient } from 'shellviz';
const sv = new ShellvizClient();
const sv = new ShellvizClient({ port: 9000, url: "https://my-server.com" });
JavaScript Server
import ShellvizServer from 'shellviz/server';
const server = new ShellvizServer();
const server = new ShellvizServer({ port: 9000, showUrl: false });
Cross-Platform Support
The configuration system works seamlessly across different environments:
Node.js Environment
- Checks
process.env.SHELLVIZ_* variables
- Full server and client functionality available
Browser Environment
- Checks
window.SHELLVIZ_* variables
- Client functionality available (no local server)
- Safe fallbacks prevent crashes
Webpack/Bundler Environment
- Uses compile-time environment variables if available
- Falls back to window variables or defaults
Configuration Implementation
The configuration values are computed once when the module is imported:
import { SHELLVIZ_PORT, SHELLVIZ_SHOW_URL, SHELLVIZ_URL } from 'shellviz/config';
console.log(SHELLVIZ_PORT);
console.log(SHELLVIZ_SHOW_URL);
console.log(SHELLVIZ_URL);
Boolean Values
For boolean configuration values, the following are considered true:
true (boolean)
"true" (string)
"1" (string)
"yes" (string)
All other values are considered false.
Default Values
Default values are clearly visible in the constructor declarations:
constructor(opts = {})
constructor({ port = 5544, showUrl = true } = {})
Environment variables and window variables automatically override these defaults when present.
Browser Integration Example
<!DOCTYPE html>
<html>
<head>
<script>
window.SHELLVIZ_PORT = 8080;
window.SHELLVIZ_URL = "https://my-shellviz-server.com";
</script>
</head>
<body>
<script type="module">
import { ShellvizClient } from './path/to/shellviz/client.js';
const sv = new ShellvizClient();
sv.log("Hello from browser!");
</script>
</body>
</html>