Spanish Total.js
English
Documentation For AI agents
Contents

Command line (total5)

The total5 and flow5 programs: a static web server, translations, minifying, bundles, remote editing, a proxy client, tests and running flows.

.md GitHub
On this page

The total5 package installs two programs: total5, a toolbox for the directory you are in, and flow5, which runs FlowStream schemas without an application. Install the package globally to have both on your PATH (see Installation):

npm install -g total5

Each total5 command prints a header with its name, does its work and, for the short tasks, ends with a [Done] line with the time it took:

$ total5 minify /www/app/public/app.js
* Total.js v5: [Minify]
----------------------------------------
Filename  : /www/app/public/app.js
Output    : /www/app/public/app.min.js
----------------------------------------
[Done]: 1.2ms

Command syntax

total5 <command> [arguments]
  • The first word is the command. Two or more dashes in front of it are removed, so total5 --help is the same as total5 help.
  • The words after it are the arguments, in order. Double quotes inside them are removed and spaces at the ends are trimmed.
  • A number as the command (total5 8000) starts the web server on that port.
  • total5 with no command shows the help.
  • A word the program does not know prints only the header and does nothing.

The help

total5 or total5 help lists the commands:

CommandWhat it does
translate <filename>Makes a resource file from the @(...) texts of the current directory
minify <filename>Minifies a .js, .css or .html file
bundle <filename>Packs the current directory into a .bundle file
extract <filename>Unpacks a bundle into the current directory
edit <url>Opens the current directory for remote editing in the Total.js Code Editor
proxy <endpoint> <port>Connects a local port to a remote Total.js proxy server
test [names]Runs the tests of the current directory or of its tests directory
<port>Starts a web server for the current directory

A web server for a directory

A number as the command starts a static web server for the current directory. total5 server [port] does the same, and the port is 8000 when you leave it out.

cd ~/projects/landing
total5 8000
# http://0.0.0.0:8000/
  • Files are served from the current directory. Minification and source maps are off, so you get the files exactly as they are on disk.
  • A URL of a directory shows a listing of its subdirectories and files with their sizes. Click a file (index.html too) to open it.
  • The application folders (controllers/, config, …) are not loaded: it is only a file server.

Stop it with Ctrl+C.

Translations

total5 translate <filename> reads every .js and .html file of the current directory and its subdirectories, finds the texts marked with @(...) and writes them into the resource file you name. Give the full path of the file:

total5 translate "$PWD/resources/default.resource"
T1l964ro     : Hello world
T1j2ql       : Save

Each key is T plus a hash of the text, the same key the view engine uses when it looks up a translation. Copy the file into resources/ under a language name and translate the texts after the colon. See Localization.

Minifying a file

total5 minify <filename> minifies one file and writes the result next to it with .min before the extension. Give the full path of the file:

total5 minify "$PWD/public/js/app.js"     # public/js/app.min.js
total5 minify "$PWD/public/css/site.css"  # public/css/site.min.css
total5 minify "$PWD/views/index.html"     # views/index.min.html

The extension chooses the minifier: JavaScript, CSS or HTML. The HTML minifier removes comments, shortens runs of spaces inside the markup and minifies inline <script> and <style> blocks; it keeps the line breaks and the indentation between tags. A file with another extension is copied without change. These are the same minifiers the framework uses for static files (see Utilities).

Bundles

A bundle is one file that holds a whole application. The framework unpacks the .bundle files of the bundles/ folder when it starts (see Application structure).

total5 bundle <filename> packs the current directory. Give the full path of the bundle and keep it outside the directory you pack:

cd ~/projects/shop
total5 bundle ~/backups/shop     # ~/backups/shop.bundle

.bundle is added to the name when it is missing. The bundle leaves out the files that belong to the machine, not to the application: index.js, debug.js, release.js with their .json and .pid files, bundle.json, package.json, readme.md, license.txt and the folders bundles/, tmp/, .src/ and .git/.

total5 extract <filename> unpacks a bundle into the current directory. Give the full path of the bundle:

mkdir ~/projects/shop-copy && cd ~/projects/shop-copy
total5 extract ~/backups/shop.bundle

Remote editing

total5 edit <url> connects the current directory to the Total.js Code Editor. The editor gives you the URL of the project; the program opens a WebSocket to it (http becomes ws, https becomes wss) and answers the requests of the editor: it lists, reads, saves, creates, renames and removes files, uploads and downloads them, reads log files and runs scripts.

cd ~/projects/shop
total5 edit "https://code.example.com/?id=shop"
# > Total.js Code Editor: Welcome to "Code (1.0)"
# > Project: "shop"

The connection reconnects every 10 seconds when it drops. The program keeps running until you stop it. Without a URL it stops with the error Invalid URL address.

Proxy client

total5 proxy <endpoint> <port> makes a local port reachable through a remote Total.js proxy server, an application that calls PROXYSERVER(). The program connects to the server with a WebSocket and forwards each request it receives to the local port:

total5 8000 &
total5 proxy wss://proxy.example.com/ 8000
total5 proxy wss://proxy.example.com/ 192.168.1.20:8000

The second argument is a port on 127.0.0.1 or an ip:port pair. Each request is printed with its method, the IP address of the visitor and the URL. Without both arguments the program prints how to call it.

Running tests

total5 test runs the test scripts of the tests directory of the current directory, or of the current directory when it has no tests directory. It loads the config file and init.js of that directory first, then the scripts you name, or all .js files when you name none:

cd ~/projects/shop
total5 test
total5 test strings orders

It uses the total5 package installed in the project, also when you run it from a subdirectory. A failed check ends the program with exit code 1, so a CI job fails. See Unit tests.

Running flows with flow5

flow5 loads FlowStream schemas and runs them with a small HTTP server, without an application (see FlowStream):

flow5 "$PWD/flowschema.json"
flow5 "$PWD/flow1.json" "$PWD/flow2.json" 8001
flow5 https://example.com/flowschema.json
  • Every argument that is a number is the port (8000 by default). The other arguments are files, with their full path, or https:// addresses of schemas.
  • A file holds one schema (an object with components and design) or an object of several schemas under their ids.
  • For each flow it prints a link that opens the flow in the Flow editor at flow.totaljs.com, connected to your machine.
  • When you save a flow in the editor, the program writes it back into its file. Give every schema an id, and in a file with several flows use the id as the key.
[Total.js v5 Flow Engine]
|--- http://127.0.0.1:8000
|--- Orders: https://flow.totaljs.com/?socket=http%3A%2F%2F127.0.0.1%3A8000%2Fflowstreams%2Forders%2F

The server has two routes: GET and POST /notify/{id}/ for notifications to the flows, and the WebSocket /flowstreams/{id}/ for the editor. flow5 with no arguments prints its help.

Made in Europe