Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Iced)Coffeescript, nib, index and backend support #11

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions Readme.md
Expand Up @@ -15,16 +15,20 @@ Usage: serve [options] [dir]

Options:

-v, --version output the version number
-F, --format <fmt> specify the log format string
-p, --port <port> specify the port [3000]
-H, --hidden enable hidden file serving
-S, --no-stylus disable stylus rendering
-J, --no-jade disable jade rendering
-I, --no-icons disable icons
-L, --no-logs disable request logging
-D, --no-dirs disable directory serving
-h, --help output usage information
-v, --version output the version number
-F, --format <fmt> specify the log format string
-i, --index <url> specify the start page
-b, --backend <path> specify a backend script exporting a run(server) function
-p, --port <port> specify the port [3000]
-H, --hidden enable hidden file serving
-S, --no-stylus disable stylus rendering
-N, --no-nib disable nib rendering
-J, --no-jade disable jade rendering
-C, --no-coffee disable (Iced)CoffeeScript rendering
-I, --no-icons disable icons
-L, --no-logs disable request logging
-D, --no-dirs disable directory serving
-h, --help output usage information

```

Expand Down Expand Up @@ -78,4 +82,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 changes: 40 additions & 2 deletions bin/serve
Expand Up @@ -9,7 +9,9 @@ var resolve = require('path').resolve
, program = require('commander')
, connect = require('connect')
, stylus = require('stylus')
, nib = require('nib')
, jade = require('jade')
, iced = require('iced-coffee-script')
, url = require('url')
, fs = require('fs');

Expand All @@ -19,10 +21,14 @@ program
.version('1.1.0')
.usage('[options] [dir]')
.option('-F, --format <fmt>', 'specify the log format string', 'dev')
.option('-i, --index <url>', 'specify the start page')
.option('-b, --backend <path>', 'specify a backend script exporting a run(server) function')
.option('-p, --port <port>', 'specify the port [3000]', Number, 3000)
.option('-H, --hidden', 'enable hidden file serving')
.option('-S, --no-stylus', 'disable stylus rendering')
.option('-N, --no-nib', 'disable nib rendering')
.option('-J, --no-jade', 'disable jade rendering')
.option('-C, --no-coffee', 'disable (Iced)CoffeeScript rendering')
.option('-I, --no-icons', 'disable icons')
.option('-L, --no-logs', 'disable request logging')
.option('-D, --no-dirs', 'disable directory serving')
Expand All @@ -41,6 +47,19 @@ server.use(connect.favicon(program.favicon));
// logger
if (program.logs) server.use(connect.logger(program.format));

if (program.backend) {
require(path + '/' + program.backend).run(server);
}

if (program.index) {
server.use(function(req, res, next){
if (req.url === '/') {
req.url = program.index;
}
return next();
});
}

// convert .styl to .css to trick stylus.middleware
if (program.stylus) {
server.use(function(req, res, next){
Expand All @@ -67,10 +86,29 @@ if (program.jade) {
}
});
});

if (program.nib) {
// stylus nib rendering enabled
function compile(str, path) {
return stylus(str)
.set('filename', path)
.use(nib());
}
server.use(stylus.middleware({ src: path, compile: compile }));
} else {
server.use(stylus.middleware({ src: path }));
}
}

// stylus
server.use(stylus.middleware({ src: path }));
// coffeescript
if (program.coffee) {
server.use(function(req, res, next){
if (!req.url.match(/\.coffee|\.iced$/)) return next();
var file = join(path, url.parse(req.url).pathname);
res.setHeader('Content-Type', 'application/x-javascript');
res.end(iced.compile(fs.readFileSync(file).toString()));
});
}

// static files
server.use(connect.static(path, { hidden: program.hidden }));
Expand Down
4 changes: 3 additions & 1 deletion package.json
@@ -1,13 +1,15 @@
{
"name": "serve"
, "version": "1.1.0"
, "version": "1.1.1"
, "description": "Simple command-line file / directory server built with connect"
, "keywords": ["static", "server", "connect"]
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
, "dependencies": {
"connect": "2.3.x"
, "stylus": "*"
, "nib": "*"
, "jade": "*"
, "iced-coffee-script": "*"
, "commander": "0.6.1"
}
, "bin": { "serve": "./bin/serve" }
Expand Down