├── index.html
├── package.json
├── LICENSE.md
├── README.md
└── scat.js
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | scat
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "scat",
3 | "description": "Pipe your javascripts straight into your browser",
4 | "version": "0.0.0",
5 | "main": "index.js",
6 | "dependencies": {
7 | "opener": "^1.3.0",
8 | "bl": "^0.7.0"
9 | },
10 | "bin": {
11 | "scat": "./scat.js"
12 | },
13 | "author": "Hugh Kennedy (http://hughsk.io/)",
14 | "license": "MIT",
15 | "repository": {
16 | "type": "git",
17 | "url": "git://github.com/hughsk/scat"
18 | },
19 | "bugs": {
20 | "url": "https://github.com/hughsk/scat/issues"
21 | },
22 | "homepage": "https://github.com/hughsk/scat",
23 | "keywords": [
24 | "scat",
25 | "bcat",
26 | "browser",
27 | "cat",
28 | "pipe",
29 | "javascript",
30 | "tool",
31 | "quick"
32 | ]
33 | }
34 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | ## The MIT License (MIT) ##
2 |
3 | Copyright (c) 2014 Hugh Kennedy
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # scat [](https://flattr.com/submit/auto?user_id=hughskennedy&url=http://github.com/hughsk/scat&title=scat&description=hughsk/scat%20on%20GitHub&language=en_GB&tags=flattr,github,javascript&category=software)[](http://github.com/hughsk/stability-badges) #
2 |
3 | Pipe your javascripts straight into your browser.
4 |
5 | Inspired by [bcat](https://github.com/kessler/node-bcat), except instead of
6 | piping HTML or text into scat you just pipe JavaScript – which will get wrapped
7 | up with an `index.html` and boot up the page for you.
8 |
9 | ## Usage ##
10 |
11 | [](https://nodei.co/npm/scat)
12 |
13 | Either point scat to a JavaScript file:
14 |
15 | ``` bash
16 | scat bundle.js
17 | ```
18 |
19 | Or pipe your JavaScript into it:
20 |
21 | ``` bash
22 | browserify -d index.js | uglifyjs -cm | scat
23 | ```
24 |
25 | In the interest of keeping things as simple as possible, there's no
26 | command-line flags to use here for now. Enjoy!
27 |
28 | ## License ##
29 |
30 | MIT. See [LICENSE.md](http://github.com/hughsk/scat/blob/master/LICENSE.md) for details.
31 |
--------------------------------------------------------------------------------
/scat.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var open = require('opener')
4 | var http = require('http')
5 | var bl = require('bl')
6 | var fs = require('fs')
7 |
8 | var file = process.argv[2]
9 | if (file) {
10 | boot(fs.readFileSync(file))
11 | } else {
12 | process.stdin.resume()
13 | process.stdin.pipe(bl(function(err, script) {
14 | if (err) throw err
15 | boot(script)
16 | }))
17 | }
18 |
19 | function boot(script) {
20 | var index = fs.readFileSync(__dirname + '/index.html')
21 | var port = process.env.PORT || 6281
22 | var attempts = 100
23 |
24 | var server = http.createServer(function(req, res) {
25 | return req.url === '/bundle.js'
26 | ? sendScript(req, res)
27 | : sendIndex(req, res)
28 | }).once('listening', function() {
29 | open('http://localhost:' + port)
30 | })
31 |
32 | attempt()
33 | function attempt() {
34 | server.listen(port).once('error', function(err) {
35 | if (attempts-- > 0) return attempt(port++)
36 | throw err
37 | })
38 | }
39 |
40 | function sendScript(req, res) {
41 | res.setHeader('content-type', 'text/javascript')
42 | res.once('finish', process.exit)
43 | res.end(script)
44 | }
45 |
46 | function sendIndex(req, res) {
47 | res.setHeader('content-type', 'text/html')
48 | res.end(index)
49 | }
50 | }
51 |
--------------------------------------------------------------------------------