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

apprun-site

v1.3.35

Published

AppRun Site is a framework for building AppRun applications.

Downloads

461

Readme

AppRun Site

AppRun-Site is a server with command-line tool for building modern web applications with AppRun. It has following features:

Quick Start

To create a new AppRun Site, run npx apprun-site init.

The init command provides a few more project templates to choose from:

An AppRun-Site project has the following structure:

/pages              <- pages of the website
  /index.html       <- index file
  /index.tsx        <- home page
  /main.tsx         <- start up code (registers web component and renders the layout)
  /about
    /index.tsx      <- about page
  /contact
    /index.tsx      <- contact page

The pages are tsx/jsx files (AppRun components).

// pages/[page]/index.tsx -- functional component
import app from 'apprun';
export default () => <>
  <p>This is a functional Component</p>
</>;

Or

// pages/[page]/index.tsx -- class component
import { app, Component } from 'apprun';
export default class extends Component {
  view = () => <>
    <p>This is a class Component</p>
  </>;
}

Or markdown files:

# Hello World
This is a markdown file

How does it work?

Build

The npx apprun-site build command compiles your code to the public folder. It generates the following files:

/pages              <- pages of the website
/public             <- static files (genegretd by the build command)
  /index.html       <- index page
  /main.js          <- start up code
  /about
    /index.js       <- about page
  /contact
    /index.js       <- contact page
/server.js          <- server code (genegretd for SPA and SSR)

Static Website

The npx apprun-site build --render command renders your pages to create a static website in the public folder.

/public
  /_.html           <- /defualt page for SPA
  /index.html       <- rendered home page
  /main.js
  /index.js
  /about
    /index.html     <- rendered about page
    /index.js
  /contact
    /index.html     <- rendered contact page
    /index.js
/server.js          <- server code (genegretd for SPA and SSR)

You can deploy the public folder to any static file server.

Serve

You can run the generated server.js file to serve the pages.

node server.js

Modify the server.js file to fit your needs. The compiler will not overwrite the server.js file if it already exists.

File-based Routing

When you run node serve.js, it starts a server that supports your code run as Single Page Applications (SPA) and supports Server-Side Rendering (SSR).

On both the client side and the server side, it loads the pages on demand as dynamic modules using thw following steps:

  • load the index.html
  • load the main.js (for the dynamic layout and the start up code)
  • load the modules by path to render the pages:
/public
  /                 <- /index.js
  /about            <- /about/index.js
  /contact          <- /contact/index.js

Note:

  • The main.js should create a layout and a div with the id main-app to render the pages.
  • The page modules should create a div with the id [page]-app for sub pages. E.g., /docs/index.js should create a div with the id docs-app for its sub pages if any.

Server App

If you add server backend code, you can add an app folder with the following structure:

/app                <- app folder (backend code)
  /_                <- action folder
  /api              <- api folder
/pages              <- pages of the website

The build command will compile the server code to allow the API endpoints and server-side functions.

If you only want to build the server code, you can use the --server-only option:

npx apprun-site build --server-only

API Endpoints

The build command generated server.js can serve API endpoints. You can add your API endpoints in the api folder.

The API endpoints are served at the path /api/[endpoint]. For example, the api/hello.js file will be served at /api/hello.

// api/hello.js
export default (req, res) => {
  res.json({ hello: 'world' });
};

Server-side functions

You can add server-side functions in the _ folder. The server-side functions are served at the path /_/[action]. For example, the _/comic.js file will be served at /_/comic.

Use the //#if server, //#else, and //#endif comments to separate the server-side code from the client-side code. The compiler will strip out the server-side code from the client-side code and vice versa.

// _/comic.js
import action from 'apprun-site/action.js';
export default async (data) => {
  //#if server
  const num = data?.num || Math.floor(Math.random() * 2990) + 1;
  const response = await fetch(`https://xkcd.com/${num}/info.0.json`);
  return response.json();
  //#else
  return action('comic', data);
  //#endif
}

The action function will POST to the comic action on the client side.

You can refer to the server-side action in the client-side code:

// components/comic.tsx
import { app, Component } from 'apprun';
import comic from '../../app/_/comic';
export default class Comic extends Component {
  state = comic();
  view = ({ img, alt }) => img ? <img src={img} alt={alt} /> : `Loading...`;
}

The benefit of referring to the server-side code is that you can get type checking, code completion and goto-definition in your IDE.

Command Line

You can add a few npm scripts to your package.json file:

{
  "scripts": {
    "start": "node server.js",
    "dev": "apprun-site dev",
    "build": "apprun-site build --clean",
    "render": "apprun-site build --render",
    "build:server": "apprun-site build --server-only",
    "build:client": "apprun-site build --client-only"
  }
}

Then you can run the following commands:

  • npm start to start the server
  • npm run dev to start the development
  • npm run build to build for production
  • npm run render to build a static website

Documentation

Please visit https://apprun.js.org/docs/apprun-site

Have fun coding!