npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ubc-farm/server

v3.0.0

Published

Server tool and core code for the ubc-farm program suite.

Downloads

16

Readme

ubc-farm

Server tool and core code for the ubc-farm program suite.

The server is a static file server that maps to folders in each page package. Rather than have the server handle templates and data, files are precompiled with other tools in this package.

server

Creates and launches a static web server. Files are loaded from the www folder, along with files from other page packages. The returned promise resolves once the server begins listening on the provided port.

function server(port?: number): Promise<express.Application>

listPagePackages

Obtains a list of ubc-farm page packages, along with their absolute paths in the filesystem. Each package.json must have a "ubc-farm" property to be detected. Additional data can be specified in the "ubc-farm" object, but if unspecified defaults will be used.

  • url: The name of the package, without the @ubc-farm prefix if present.
  • www: The path to the folder containing public files. Defaults to "www".
  • views: The path to the folder containing template files. Defaults to "views".

Paths are relative to the package.json location.

interface PageData {
	name: string
	url: string
	paths: {
		www: string
		views: string
	}
}

function listPagePackages(): Promise<PageData[]>

readData

YAML and JSON data files in the data folder represent information that is provided to the handlebars templates. readData returns all the data in that folder. The keys of the returned object correspond to the filenames of each file in the data folder.

function readData(): Promise<{ [filename: string]: any }>

compileViews

Compiles the view files from the given folder and saves them to the given output folder. Can be set to watch for futher changes. If watch is true, the files in the from folder will be watched and recompiled when changes are made. A FSWatcher object is returned. If a folder starts with an underscore, it is ignored.

function compileViews(options: { from: string, to: string, watch: true }): Promise<fs.FSWatcher>
function compileViews(options: { from: string, to: string }): Promise<void>

compileAll

Runs compileViews in every packages' view folder (including this one). The files can optionally be watched. By default, the view folder is a sibling of the www folder named 'views'. This can be changed by altering the viewFolder option.

type GetViewFolder = (packageName: string) => Promise<string> | string;

function compileAll(options?: { viewFolder?: GetViewFolder, watch: true }): Promise<fs.FSWatcher[]>
function compileAll(options?: { viewFolder?: GetViewFolder }): Promise<void>

Command Line API

npm registers the ubc-farm bin command, which can be called with different mode arguments.

serve

Calls server() with an optional --port (alias -p) argument.

ubc-farm serve --port 8080

list

Calls listAllPackages(). If the --paths flag is used, the paths to each package's static files will also be returned.

ubc-farm list --paths

compile

Calls compileViews() with --from and --to path arguments. The --watch flag can also be used to watch the files for changes instead of closing. All arguments have aliases that correspond to the first letter of their name.

ubc-farm compile -f ./views -t ./www

compile-all

Calls compileAll() with an optional --watch flag (alias -w).

ubc-farm compile-all --watch

help

Shows a help dialog for the ubc-farm command line.

ubc-farm help