UNPKG

simple-autoreload-server

Version:

Simple Web Server with live/autoreload features without browser extensions.

277 lines (275 loc) 12.2 kB
/* * simple-autoreload-server v0.2.15 - 2021-05-22 * <https://github.com/cytb/simple-autoreload-server> * * Copyright (c) 2021 cytb * * Licensed under the MIT License. */ (function(){ var out$ = typeof exports != 'undefined' && exports || this; out$.options = [ { "label": "path", "short": "d", "type": "string", "def": ".", "help": "set directory to publish.", "desc": "specifies root directory to publish." }, { "label": "watch", "short": "w", "type": "pattern", "def": "**/**", "help": "pattern for file to watch.", "desc": "pattern for file to watch.\nif true, it matches any files, and matches nothing on false." }, { "label": "reload", "short": "r", "type": "pattern", "def": false, "help": "pattern for file to reload the whole page.", "desc": "pattern for file to reload the whole page.\nwhether or not to reload actually depends on behavior of client script.\nif true, it matches any files, and matches nothing on false." }, { "label": "mount.path", "short": "m", "type": "string", "def": ".", "help": "set additional directory to publish.", "desc": "specifies additional directory to publish.\n\nprogram can accept multiple times in commandline.\nother 'mount.*' options are attached to corresponding path by order in commandline.", "examples": { "command": "autoreload-server -H localhost -p 8080 -m ./html -m ./node_modules --mount.path ./build", "result": "the server publishes content of './html', './node_modules' and './build' at 'https://localhost:8080/'.\nif all of those directories contain 'index.html' and client requests 'https://localhost:8080/index.html',\nthe first one will be sent ('./html/index.html' in this case)." } }, { "label": "mount.target", "short": "t", "type": "string", "def": "/", "help": "server side path of mounted direcory", "desc": "server side path of mounted direcory.", "examples": { "command": "autoreload-server . 8080 -m ./www/js -t /components", "result": "the server publishes content of './' to server-root(http://localhost:8080/),\n\"./www/js\" to \"/components\" (http://localhost:8080/components/)." } }, { "label": "mount.watch", "short": "W", "type": "pattern", "def": "**/**", "help": "pattern of file to watch.", "desc": "pattern of file to watch." }, { "label": "host", "short": "H", "type": "string", "def": "0.0.0.0", "help": "set host address to publish.", "desc": "specifies server address to listen.\n'0.0.0.0' means listening all of the (ipv4) interfaces on computer." }, { "label": "port", "short": "p", "type": "number", "def": "8080", "help": "set port to listen (http).", "desc": "specifies server http(s) port to listen." }, { "label": "config", "short": "c", "type": "string", "def": ".autoreload.json", "help": "load options from json.", "desc": "load json as config before starting server.\nthe config overwritten by command-line options and function arguments.\nall of specified pathes regarded as relative path from config location.\n(function arguments, and command-line parameters as well.)\n\nthe server logs nothing when the default config does not exist." }, { "label": "search-config", "short": null, "type": "boolean", "def": true, "help": "search for config json in parent directories.", "desc": "search for config file in parent directories.\nit is no harm when specified absolute path." }, { "label": "list-directory", "short": "l", "type": "boolean", "def": true, "help": "enable directory listing.", "desc": "enable directory listing.\nit should be disabled if you want to invoke default request handler." }, { "label": "browse", "short": "b", "type": "string", "def": false, "help": "open server url by platform default program.", "desc": "invokes platform default program with argumemts after launched. \n\nif provided true via function argument \nor '--browse' option followed by nothing via command-line, \nthe program invokes the default with the server url.\n\nif the 'String' value was specified, it will be passed instead of the server url.\nthe server does nothing if specified Boolean of 'false' or 'null'.", "examples": [ { "command": "autoreload-server -d . -p 8088 -H 192.168.1.15 -b", "result": "opens https://192.168.1.15:8088/" }, { "command": 'autoreload-server -d . -p 8088 -b "http://server1.localdomain:80/"', "result": 'opens "http://server1.localdomain:80/"' } ] }, { "label": "execute", "short": "e", "type": "string", "def": "", "help": "execute command when the server has prepared.", "desc": "executes command when the server has been prepared.\nthe command is passed to shell.\nin other words it has not been invoked directly.\n\nyou can pass Array of above values or many times on command-line,\nand then the server invokes with each values.\n", "examples": { "command": 'autoreload-server -e "firefox"', "result": "opens firefox via shell" } }, { "label": "stop-on-exit", "short": "k", "type": "boolean", "def": false, "help": "exit when invoked process specified by \"execute\" died.", "desc": "the server will stop when invoked process specified by 'execute' option died.\nif there are multiple processes invoked by 'execute' option,\nthe server keep running until all of that has been killed." }, { "label": "ignore-case", "short": "i", "type": "boolean", "def": true, "help": "ignore case of glob patterns.", "desc": "ignoring case of glob-string of patterns.\n\nthis option is no harm to regex pattern of 'pattern' type.\nall of the glob patterns that were passed as 'String' type\nvia function arguments or command-line option will be affected." }, { "label": "include-hidden", "short": "n", "type": "boolean", "def": false, "help": "glob includes hidden files.", "desc": "make globs to include hidden (dot) files.\nthis option is no harm except for glob string patterns." }, { "label": "default-pages", "short": null, "type": "pattern", "def": "index.{htm,html}", "help": "default page file pattern for directory request.", "desc": "default page file pattern for directory request." }, { "label": "encoding", "short": null, "type": "string", "def": "utf-8", "help": "encoding for reading texts and inject target files", "desc": "encoding for reading texts and inject target files" }, { "label": "watch-delay", "short": null, "type": "number", "def": 20, "help": "delay time to supress duplicate watch event (ms).", "desc": "delay time to supress duplicate watch event (in milil-seconds).\nthe watch event is often fired multiple times in short duration." }, { "label": "log", "short": "v", "type": "string", "def": "normal", "help": "set log-level", "desc": "set log mode. choose from followings.\n'silent' -> 'minimum' -> 'normal' -> 'verbose' -> 'noisy'\n(number also acceptable: silent is 0, minimum is 1, ..., and noisy is 4)" }, { "label": "builtin-script", "short": null, "type": "boolean", "def": true, "help": "enable default built-in script injection.", "desc": "enable injection of default built-in script.\n\nif you want to replace for built-in script by another script,\nspecify this option to false or with negative prefix ('no-') without equal,\nand use 'inject' option." }, { "label": "client-module", "short": null, "type": "string", "def": true, "help": "expose client module to 'window' object.", "desc": "expose client side built-in module to 'window' object.\nif you want to use client module in built-in script, set true or String value.\n\nIf true, module will be exposed to 'window.AutoreloadClient'.\nIf String, module will be exposed in window with specified name.\n\nThis option does nothing when 'builtin-script' is false.\nwhen the module is initialized, it emits the 'AutoreloadClient.*' events on 'window'.\nsee 'examples'." }, { "label": "client-log", "short": null, "type": "boolean", "def": false, "help": "inform client to log.", "desc": "inform client to log.\nthe server only send a option to client on connect by this option.\nwhether or not to logs actually depends on behavior of client script." }, { "label": "recursive", "short": "R", "type": "boolean", "def": true, "help": "watch sub-directories recursively.", "desc": "watch sub-directories recursively. this may take a while at startup.\nthe server does not detect cyclic structure and it may cause infinit loop.\nunset follow-symlinks option if need." }, { "label": "follow-symlinks", "short": "L", "type": "boolean", "def": false, "help": "follow symbolic-links. (requires 'recursive' option)", "desc": "lookup files in symbolic-links target when watch directory. \nthis option affects only when the resursive option is enabled." }, { "label": "inject.content", "short": "I", "type": "string", "def": "", "help": "injects specified content.", "desc": "injects specified content. see also: 'inject.type'.\nif no inject.content options are provided,\nand the file '.autoreload.html' exists in current directory\n(or config json directory), server try to inject as a builtin-script." }, { "label": "inject.type", "short": "T", "type": "string", "def": "file", "help": 'type of "inject.content".', "desc": "specifies type of 'inject.content' option.\n'file': treat 'inject.content' as file path.\n'raw': 'inject.content' will be injected directly." }, { "label": "inject.which", "short": "F", "type": "pattern", "def": "**/**.{htm,html}", "help": "specify pattern for injection target.", "desc": "specify pattern for injection target." }, { "label": "inject.where", "short": "P", "type": "string", "def": "</(body|head|html)>", "help": "specify regex string where to inject.", "desc": "this is not a 'pattern' type.\nspecify regex string where to inject.\ncontent will be injected before matched string." }, { "label": "inject.prepend", "short": "E", "type": "boolean", "def": false, "help": "insert content before matched.", "desc": "change injection method to 'prepend'.\nif true, content will be injected 'before' matched string." }, { "label": "help", "short": "h", "type": "boolean", "def": false, "help": "show help", "desc": "show help and exit.\nignored if it was appeared on json or function arguments." }, { "label": "version", "short": "V", "type": "boolean", "def": false, "help": "show version", "desc": "shows version.\nignored if it was appeared on json or function arguments." }, { "label": "onmessage", "short": null, "type": "function", "def": null, "help": "onmessage event handler.", "desc": "specifies server onmessage handler.\nserver calls this function on broadcast the message.", "nocli": true }, { "label": "connect-app", "short": null, "type": "object", "def": null, "help": "specify 'connect' app object as server base.", "desc": "specifies 'connect' app object as server base.\nserver middleware layers willbe stacked to this object.", "nocli": true } ]; }).call(this);