├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── bin ├── cmd.js └── server.js ├── demo └── canvas.js ├── img ├── logo-small.png └── logo-thumb.png ├── index.js ├── lib ├── fix-logs.js ├── hihat.js ├── parse-args.js ├── parse-error.js ├── prelude │ ├── console.js │ ├── node-console.js │ └── node.js ├── watchify-bundler.js └── watchify-server.js ├── package.json ├── spawn.js └── test ├── fixtures ├── browser-field │ ├── browser.js │ ├── index.js │ └── package.json ├── index.html ├── test-browser.js ├── test-electron-builtins.js ├── test-exit.js ├── test-index.js ├── test-node-browser-field.js ├── test-node-no-electron.js └── test-node-with-electron.js ├── run-tests.js └── test-exit.js /.gitignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | node_modules 3 | *.log 4 | .DS_Store 5 | bundle.js 6 | canvas.png -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | node_modules 3 | *.log 4 | .DS_Store 5 | bundle.js 6 | test 7 | test.js 8 | demo/ 9 | .npmignore 10 | LICENSE.md -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2015 Jam3 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 20 | OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hihat 2 | 3 |  4 | 5 | > local Node/Browser development with Chrome DevTools 6 | 7 | Runs a source file in a Chrome DevTools process. Saving the file will reload the tab. 8 | 9 | This is useful for locally unit testing browser code with the full range of Web APIs (WebGL, WebAudio, etc). It provides access to profiling, debugger statements, network requests, and so forth. 10 | 11 | It can also be used to develop typical Node projects, or as a generic [Node REPL](#repl). For example, instead of using [nodemon](https://www.npmjs.com/package/nodemon) during development, you can use `hihat` to make use of a debugger. 12 | 13 | Since it provides Browser and Node APIs, it can also be used for some simple CLI tooling, like [saving a Canvas2D to a PNG file](#save-canvas-2d-to-png-image). 14 | 15 | Under the hood, this uses [electron](https://github.com/atom/electron), [browserify](https://github.com/substack/node-browserify) and [watchify](https://github.com/substack/watchify). 16 | 17 | --- 18 | 19 | #### Update: Jan 2016 20 | 21 | A lot of new efforts are going toward [devtool](https://github.com/Jam3/devtool), a very similar project but without `browserify` and `watchify` under the hood. In many ways it replaces `hihat`, but not all. Both tools will continue to exist, although `devtool` will probably receive more regular enhancements and maintenance. 22 | 23 | ## Install 24 | 25 | [](https://www.npmjs.com/package/hihat) 26 | 27 | This project is currently best suited as a global install. Use `npm` to install it like so: 28 | 29 | ```sh 30 | npm install hihat -g 31 | ``` 32 | 33 | ## Basic Examples 34 | 35 | Simplest case is just to run `hihat` on any source file that can be browserified (Node/CommonJS). 36 | 37 | ```sh 38 | hihat index.js 39 | ``` 40 | 41 | Any options after `--` will be passed to browserify. For example: 42 | 43 | ```sh 44 | # transpile ES6 files 45 | hihat tests/*.js -- --transform babelify 46 | ``` 47 | 48 | You can use `--print` to redirect `console` logging into your terminal: 49 | 50 | ```sh 51 | hihat test.js --print | tap-spec 52 | ``` 53 | 54 | The process will stay open until you call `window.close()` from the client code. Also see the `--quit` and `--timeout` options in [Usage](#usage). 55 | 56 | ## Usage 57 | 58 | Usage: 59 | 60 | ```sh 61 | hihat [entries] [options] -- [browserifyOptions] 62 | ``` 63 | 64 | Options: 65 | 66 | - `--port` (default `9541`) 67 | - the port to host the local server on 68 | - `--host` (default `'localhost'`) 69 | - the host for the local development server 70 | - `--dir` (default `process.cwd()`) 71 | - the root directory to serve static files from 72 | - `--print` 73 | - `console.log` and `console.error` will print to `process.stdout` and `process.stderr` 74 | - `--quit` 75 | - uncaught errors (like syntax) will cause the application to exit (useful for unit testing) 76 | - `--frame` (default `'0,0,0,0'`) 77 | - a comma-separated string for `x,y,width,height` window bounds 78 | - if only two numbers are passed, treated as `width,height` 79 | - if `true` is passed, uses the native default size 80 | - `--no-devtool` 81 | - do not open a DevTools window when running 82 | - `--raw-output` 83 | - do not silence Chromium debug logs on stdout/stderr 84 | - `--node` 85 | - enables Node integration (see [node](#node)) 86 | - `--no-electron-builtins` 87 | - when `--node` is enabled, makes it behave more like Node by ignoring Electron builtins 88 | - `--timeout` (default 0) 89 | - a number, will close the process after this duration. Use 0 for no timeout 90 | - `--exec` 91 | - an alias for `--print`, `--no-devtool` and `--quit` options. Useful for headless executions 92 | - `--index=path/to/index.html` 93 | - optional `index.html` file to override the default (see [HTML index](#html-index)) 94 | - `--serve` 95 | - what to serve your bundle entry point as 96 | - defaults to file name if possible, otherwise 'bundle.js' 97 | - `--browser-field` 98 | - Can specify `true` or `false` to force enable/disable the `"browser"` field resolution, independently of the `--node` option 99 | 100 | By default, browserify will use source maps. You can change this with `--no-debug` as a browserify option: 101 | 102 | ```sh 103 | hihat test.js -- --no-debug 104 | ``` 105 | 106 | ## Node 107 | 108 | > **Note:** Users seeking the Node.js features may be more interested in [devtool](https://github.com/Jam3/devtool) – very similar to `hihat` but better architected to deal with large Node applications. 109 | 110 | hihat can also be used for developing *simple* Node modules. The `--node` flag will disable the `"browser"` field resolution and use actual Node modules for `process`, `Buffer`, `"os"`, etc. It also exposes `require` statement outside of the bundle, so you can use it in the Chrome Console while developing. 111 | 112 | For example, `foobar.js` 113 | 114 | ```js 115 | var fs = require('fs') 116 | 117 | fs.readdir(process.cwd(), function (err, files) { 118 | if (err) throw err 119 | debugger 120 | console.log(files) 121 | }) 122 | ``` 123 | 124 | Now we can run the following on our file: 125 | 126 | ```sh 127 | hihat foobar.js --node 128 | ``` 129 | 130 |  131 | 132 | By default, enabling `--node` will also enable the Electron builtins. You can pass `--no-electron-builtins` to disable Electron modules and make the source behave more like Node. 133 | 134 | #### Limitations 135 | 136 | There are some known limitations with this approach. 137 | 138 | - Modules that use native addons (like [node-canvas](https://github.com/Automattic/node-canvas)) are not supported. 139 | - Unlike a typical Node.js program, you will need to explicitly quit the application with `window.close()` 140 | - Since the source is run through browserify, the initial build time is slow and features like `require.resolve` are not yet supported. [#21](https://github.com/Jam3/hihat/issues/21) 141 | - Some features like `process.stdin` are not possible. [#12](https://github.com/Jam3/hihat/issues/12) 142 | - Since this runs Electron instead of a plain Node.js runtime, it may produce some unusual results 143 | 144 | 145 | ## REPL 146 | 147 | If you specify `hihat` without any entry files, it will not invoke browserify or watchify. For example, you can use this as a generic alternative to the Node REPL, but with better debugging and various Web APIs. 148 | 149 | ```sh 150 | hihat --node 151 | ``` 152 | 153 | Example: 154 | 155 |  156 | 157 | ## HTML index 158 | 159 | By default, hihat will serve a [simple HTML `index.html`](https://www.npmjs.com/package/simple-html-index) file. You can use `--index` for an alternative. The path is relative to your current working directory. 160 | 161 | ```sh 162 | hihat test.js --index=foo.html 163 | ``` 164 | 165 | And the following `foo.html`: 166 | 167 | ```html 168 | 169 |
170 |