Make an app

Every page of these docs is also one file at /llms.txt, to give an AI assistant.

npx tinylib-sdk init my-app
cd my-app
npm install

init makes the folder from a template: journal, an app for one person with a daily reminder, or tictactoe, a game for two in a room, with rules. In a terminal it asks for the template, the app's name, its slug and its description; --template, --name, --slug and --description give them, and without a terminal each takes its default. It writes only into an empty folder or a new one. package.json has tinylib-sdk and two scripts, npm run dev and npm run publish, which run tinylib dev and tinylib publish.

The folder

my-app/
  tinylib.json
  index.html
  app.js
  icon.svg
  rules.js      only for an app with rooms
  package.json
{ "slug": "my-app", "name": "My app", "description": "What it does, in a line.", "icon": "icon.svg" }
<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<main id="app"></main>
<script type="module" src="app.js"></script>
const count = tinylib.data.get('count') ?? 0
document.getElementById('app').textContent = `Hello, ${tinylib.persona.name}. Opened ${count + 1} times.`
tinylib.data.set('count', count + 1)

Tinylib puts its script first in every HTML page of the folder, so tinylib is there from the first line of app.js, with the person's data already loaded. Every file in the folder ships in the publish, at the same path, except dotfiles, node_modules, and the folder's package.json and package-lock.json. The fields of tinylib.json are on its reference page.

Run it

npm run dev

dev serves Tinylib at localhost:4400 with the app in it, and opens the browser. It runs rules.js on your computer, with simulated people to share rooms with. Any change in the folder reloads every page. In a folder without init's package.json, npx tinylib-sdk dev does the same.

Publish

npm run publish

publish builds the folder, checks it against the rooms open on the current publish, and makes it the one everyone gets. The first time, it opens the browser to log this computer in. It prints the app's link, which opens on a phone.

A publish reloads every open page of the app. The first publish claims the slug, first come first served.

Preview

npx tinylib-sdk preview --tester ben@example.com

preview publishes the folder as the app's preview, open only to you and the testers it emails. A preview has its own data and rooms. --end ends it.

Types

/// <reference types="tinylib-sdk" />

With tinylib-sdk installed in the folder, a script that starts with this line has tinylib typed; init's scripts start with it. rules.js imports from tinylib-sdk/rules, which types its kinds. Scripts and rules may be TypeScript: dev and publish strip the types and don't check them. Register types an app's data and the messages each kind of room sends.