Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

luvi

Package Overview
Dependencies
Maintainers
0
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

luvi - npm Package Compare versions

Comparing version 5.2.8 to 6.0.0

46

index.js

@@ -6,13 +6,8 @@ #!/usr/bin/env node

const help = require('./lib/help')
const readJSON = require('./lib/read-json')
const clrs = require('./lib/colors')
const pkg = readJSON(__dirname, 'package.json')
const pkg = require('./package.json')
const argv = minimist(process.argv.slice(2))
const l = console.log
const configFile = argv.config || `.${pkg.name}.json`
const config = readJSON(configFile)
const version = `♡ luvi ${pkg.version}`
let servers = Array.isArray(config) ? config : [config]
const nope = () => {

@@ -26,34 +21,11 @@ l(`

const main = () => {
if (argv.v) {
argv.version = argv.v
}
if (argv.h) {
argv.help = argv.h
}
if (argv.r) {
argv.root = argv.r
}
if (argv.p) {
argv.port = argv.p
}
if (argv.n) {
argv.noOpen = argv.n
}
if (argv.m) {
argv.markdown = argv.m
}
if (argv.version) {
return l(clrs.yellow(version))
}
if (argv.help) {
return l(clrs.cyan(help))
}
if (argv.v) { argv.version = argv.v }
if (argv.h) { argv.help = argv.h }
if (argv.r) { argv.root = argv.r }
if (argv.p) { argv.port = argv.p }
if (argv.o) { argv.open = argv.o }
if (argv.version) { return l(clrs.yellow(version)) }
if (argv.help) { return l(clrs.cyan(help)) }
if (argv._.length) {
servers = servers.filter((item) => item && argv._.includes(item.name))
}
servers.forEach((server) => {
luvi(Object.assign({}, server, argv))
})
luvi(argv)
}

@@ -60,0 +32,0 @@

12

lib/help.js

@@ -5,12 +5,10 @@ module.exports = `

usage:
♡ luvi # launch default server
♡ luvi foo bar # start servers 'foo' & 'bar'
♡ luvi # launch server with default config
♡ luvi -p 1337 # listen on specified port
♡ luvi -r /path # serve from specified dir
♡ luvi -n # don't open the browser after start
♡ luvi -m # auto-render markdown files
♡ luvi -o # open the browser after start
♡ luvi -v # luvi version
♡ luvi -h # this help
--------------------
see the readme for config options and api usage
`
--------------------
see the readme for flags and api
`.trim()

@@ -8,3 +8,2 @@ const http = require('http')

const clrs = require('./colors')
const findPort = require('./find-port')
const markdown = require('./markdown')

@@ -16,5 +15,4 @@ const notFound = require('./not-found')

port: 4444,
name: 'luvi',
async onListen (name, port, shouldOpen) {
console.log(clrs.magenta(`♡ ${name} is listening on ${port}`))
async onListen (port, shouldOpen) {
console.log(clrs.magenta(`♡ luvi is listening on ${port}`))
shouldOpen && await open(`http://localhost:${port}`)

@@ -27,3 +25,3 @@ }

const app = connect()
const shouldOpen = !options.noOpen
const shouldOpen = !!config.open

@@ -36,20 +34,12 @@ app.use(

if (config.notFound) {
app.use(notFound(config.notFound))
}
app.use(notFound())
app.use(markdown(config.root))
if (config.markdown) {
app.use(markdown(config.root))
}
findPort(config.port, (err, port) => {
if (err) {
throw err
}
http.createServer(app).listen(port, () => {
config.onListen(config.name, port, shouldOpen)
})
const s = http.createServer(app)
s.listen(config.port, () => {
config.onListen(config.port, shouldOpen)
})
return s
}
module.exports = luvi

@@ -1,11 +0,5 @@

const { createReadStream } = require('fs')
const { resolve } = require('path')
const notFound = (config) => {
const status = 404
const filePath = config
return (req, res) => {
res.writeHead(status, { 'Content-Type': 'text/html' })
createReadStream(resolve(filePath)).pipe(res)
const notFound = () => {
return (_, res) => {
res.writeHead(404, { 'Content-Type': 'text/html' })
res.write('404')
}

@@ -12,0 +6,0 @@ }

{
"name": "luvi",
"description": "Dev server with simple config and API.",
"version": "5.2.8",
"description": "Simple dev server with Markdown support, CLI, and API.",
"version": "6.0.0",
"author": "Zac Anger <zac@zacanger.com> (http://zacanger.com)",

@@ -42,3 +42,3 @@ "license": "MIT",

"devDependencies": {
"sortpack": "2.3.4",
"sortpack": "2.4.0",
"standard": "17.1.0"

@@ -45,0 +45,0 @@ },

# luvi ♡
Dev server with simple config and API.
Simple dev server with Markdown support, CLI, and API.

@@ -12,13 +12,20 @@ [Donate](https://ko-fi.com/zacanger)

$ luvi
luvi listening on 4444
♡ luvi listening on 4444
```
By default, `luvi` acts as a static server, serving the files in `cwd`.
On launch, `luvi` will open a tab in your default browser pointing to your
defined root (you can pass a `-n` flag to disable this).
Originally forked from [freddie](http://npm.im/freddie).
## Changes
* 6.0.0:
* Removed:
* Port finder (undocumented)
* Custom 404 page (has a default)
* Custom onListen
* JSON configs (use the JS API)
* Added:
* Using through the Node API now returns an http.server
* Changed:
* `open` defaults to false
* Markdown support is always on
* 5.2.0: Switch back to MIT license

@@ -43,31 +50,10 @@ * 5.1.0: Add Markdown support

$ npm i -g luvi
$ luvi [server, ...] [options]
$ luvi [options]
```
`luvi` looks inside `cwd` for a `.luvi.json` config file.
If there is no config file, the default static server is launched.
If you'd rather not install globally, you can use `npx`:
`npx luvi [server, ...] [options]`.
`npx luvi [options]`.
#### [server, ...]
```shell
$ luvi foo bar
foo listening on port 4444
bar listening on port 8888
```
List of named servers to launch. Only names matching the ones in config file
will be launched.
### [options]
Command-line arguments take priority over config files and defaults.
In a path with a `.luvi.json` file, running `luvi` will follow the options in
the file, unless any options are passed; if there are multiple servers in the
`.luvi.json` file, every server's options will be overridden. Project root is
`cwd` by default.
```

@@ -77,44 +63,12 @@ ♡ luvi (a server)

usage:
♡ luvi # launch default server
♡ luvi foo bar # start servers 'foo' & 'bar'
♡ luvi # launch server with default config
♡ luvi -p 1337 # listen on specified port
♡ luvi -r /path # serve from specified dir
♡ luvi -n # don't open the browser after start
♡ luvi -m # auto-render markdown files
♡ luvi -o # open the browser after start
♡ luvi -v # luvi version
♡ luvi -h # this help
--------------------
see the readme for config options and api usage
--------------------
see the readme for flags and api
```
### .luvi.json
To configure a single server: `{ "root": "public", "port": 9090 }`.
The object will be passed directly to `luvi`.
For multiple servers, simply use an array of single-server configs.
Use the `name` option to keep track of servers in logs.
```json
[
{
"name": "drafts",
"root": "src",
"port": 1337
},
{
"name": "testing",
"root": "build",
"noOpen": true,
"markdown": true
},
{
"name": "todo",
"root": "doc",
"port": 6565,
"notFound": "/var/www/404.html"
}
]
```
## API

@@ -128,3 +82,3 @@

luvi({
const l = luvi({
name: 'luvi',

@@ -134,2 +88,4 @@ root: process.cwd(),

})
// returns an http.server, so you can call l.close() when you're done with it
```

@@ -153,21 +109,8 @@

* port: `number` (default: `4444`)
* Port on which to listen. If specified port is busy, `luvi` will look for a free port.
* Port on which to listen.
* Example: `port: 3000`
* name: `string` (default: `luvi`)
* Server name. Useful for launching multiple servers, and for keeping track in logs.
* Example: `name: 'foo'`
* markdown: `bool` (default: `false`)
* Auto-render markdown files without extension.
* Example: `markdown: true`
* open: `bool` (default: `false`)
* Open the browser on server start.
* Example: `open: true`
* onListen: `(name: string, port: number): void` (Default: `console.log ; open`)
* Called when `luvi` starts listening.
* Example: `onListen: (name, port) => { console.log(name, 'is listening on', port) }`
* notFound: `string` (default: `undefined`)
* Path to a custom 404 page.
* Example: `notFound: '/path/to/404.html'`
* noOpen: `bool` (default: `undefined`)
* Will not open the browser on server start.
* Example: `noOpen: true`
## Contributing

@@ -174,0 +117,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc