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

nirvana-js

v1.2.0

Published

JavaScript file runner built on Electron

Downloads

12

Readme

Nirvana

CircleCI npm version Greenkeeper badge GitHub license

JavaScript runner using Electron. It provides easy DOM manipulation with Node.js scripting :space_invader:.

Getting started

$ npm -g istall electron nirvana-js

Then, write a script:

// your-script.js
console.log(document.querySelector('body').innerHTML);

Finally exec the script with nirvana command :zap:

$ nirvana your-script.js

Install

npm -g install electron nirvana-js

or

yarn global add electron nirvana-js

Usage

nirvana [option] your-javascript.js [script2 script3 ...]

CLI Options

  • c, config : Configuration file path. See Configuration File section at the below.
  • d, debug : Run debug mode. It's equivalent to --watch --show.
  • b, base-path : The root path location to be used to resolve from.
  • w, watch : Watch script files and reload window when they are changed.
  • v, verbose: Display debug logging messages.
  • q, quiet : Suppress logging messages.
  • init : Generate configuration file.
  • show : Whether to desplay browser windows.
  • custom-context-file: HTML context file path.
  • concurrency : How many windows Nirvana launches in parallel. Default 4.
  • noCaptureConsole : Suppress to capture logging message in browser.
  • noTimeout : Suppress closing browser window via timeout.

Configuration File

You can configure nirvana-js using a configuration JavaScript file. Executing nirvana --init the configuration file nirvana.conf.js is created. For example:

'use strict';

module.exports = {
  // scripts: ["a.js", "b.js"],       // Script files to run. Also glob syntax is available e.g. "*.spec.js"
  watch: false,                       // Watch script files and reload window when they are changed.
  concurrency: 4,                     // How many windows Nirvana launches in parallel.
  captureConsole: true,               // Whether to capture logging message in browser.
  // browserNoActivityTimeout: 2000,   // Time period to close window [msec]. If you not want timeout closing, set zero.
  // contextFile: "my-context.html",  // HTML context file.
  
  // Electron BrowserWindow constructor option
  // If you want detail see https://electron.atom.io/docs/api/browser-window/#new-browserwindowoptions.
  windowOption: {
    show: false,
    width: 800,
    height: 600,
    webPreferences: {
      // If you use custom preload script, load 'nirvana-js/preload' in your preload script.
      // preload: 'preload.js'
    },
  },
};

Client Utility Functions

In scripts to run on nirvana-js, some utility functions are available. For example:

const { screenshot } = require('nirvana-js');

function yourFunc() {
  doSomething();
  screenshot('my-capture.png');
}

Interface

export declare function isNirvana(): boolean;
export declare function getCurrentWindow(): Electron.BrowserWindow | undefined;
export declare function exit(code?: number): void;
export declare function screenshot(fname: string): Promise<void>;

export declare function isNirvana(): boolean;

Tell whether the platform is running on nirvana-js.

export declare function getCurrentWindow(): Electron.BrowserWindow | undefined;

Get the current browser window.

return A Electron's BrowserWindow object

export declare function exit(code?: number): void;

Close the current browser process immediately.

param code: Exit code.

export declare function screenshot(fname: string): Promise<void>;

Captures a snapshot of the current window.

param fname: The location of captured PNG file.

Tips

When is browserWindow closed ?

By default, nirvana-js's main process is capturing browser windows' logging events. And if no logging event occurs for a certain period of time(specified browserNoActivityTimeout), the main process closes the browser window. If you want to suppress timeout closing, set --no-timeout CLI option. Or set 0 to browserNoActivityTimeout in nivana.conf.js.

If you want to close browserWindows manually, you should call the exit function included client library.

How to run testing framework ?

It's so easy. See example/jasmine .

Capture CPU profile of Node.js script

Run with --debug and launch Chrome's devtools in the window, you can capture CPU profile or performance timeline of your Node.js script.

License

MIT. See license file under this repository.